opencv/modules/gpu/CMakeLists.txt

150 lines
5.1 KiB
CMake
Raw Normal View History

2010-08-11 23:52:55 +08:00
set(name "gpu")
2010-07-19 17:31:12 +08:00
set(DEPS "opencv_core")
2010-08-11 23:52:55 +08:00
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} opencv_gpu)
2010-07-15 21:36:00 +08:00
set(the_target "opencv_${name}")
2010-07-15 21:36:00 +08:00
project(${the_target})
2010-07-15 21:36:00 +08:00
add_definitions(-DCVAPI_EXPORTS)
2010-07-15 21:36:00 +08:00
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
2010-07-19 17:31:12 +08:00
"${CMAKE_CURRENT_SOURCE_DIR}/src/cuda"
2010-07-15 21:36:00 +08:00
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_BINARY_DIR}")
2010-07-15 21:36:00 +08:00
foreach(d ${DEPS})
2010-08-11 23:52:55 +08:00
if(${d} MATCHES "opencv_")
2010-07-15 21:36:00 +08:00
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
2010-08-11 23:52:55 +08:00
include_directories("${d_dir}/include")
endif()
2010-08-11 23:52:55 +08:00
endforeach()
2010-07-15 21:36:00 +08:00
file(GLOB lib_srcs "src/*.cpp")
file(GLOB lib_int_hdrs "src/*.h*")
2010-07-26 16:13:23 +08:00
file(GLOB lib_cuda "src/cuda/*.cu*")
2010-08-11 23:52:55 +08:00
file(GLOB lib_cuda_hdrs "src/cuda/*.h*")
source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs})
2010-07-20 01:35:39 +08:00
source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs})
2010-08-11 23:52:55 +08:00
file(GLOB lib_hdrs "include/opencv2/${name}/*.h*")
2010-07-15 21:36:00 +08:00
source_group("Include" FILES ${lib_hdrs})
2010-07-15 21:36:00 +08:00
if (HAVE_CUDA)
include_directories(${CUDA_INCLUDE_DIRS})
link_directories(${CUDA_LIBRARIES})
2010-08-11 23:52:55 +08:00
2010-08-12 18:59:51 +08:00
set(CUDA_COMPUTE_CAPABILITIES " 1.0 1.1 1.2 1.3 2.0 " CACHE STRING "Add or remove compute capability")
set(CUDA_NVCC_FLAGS_ARCH ${CUDA_COMPUTE_CAPABILITIES})
2010-08-11 23:52:55 +08:00
set(CUDA_NVCC_FLAGS_NUM "")
while(NOT ${CUDA_NVCC_FLAGS_ARCH} STREQUAL "")
string(REGEX MATCH "[0-9]+.[0-9]+" RESULT_NUM ${CUDA_NVCC_FLAGS_ARCH})
string(REGEX MATCHALL "[0-9]" RESULT_STR ${RESULT_NUM})
string(REGEX REPLACE ";" "\ " RESULT ${RESULT_STR})
list(APPEND CUDA_NVCC_FLAGS_NUM ${RESULT})
string(REGEX REPLACE "${RESULT_NUM}" "\ " CUDA_NVCC_FLAGS_ARCH_STR ${CUDA_NVCC_FLAGS_ARCH})
string(STRIP ${CUDA_NVCC_FLAGS_ARCH_STR} CUDA_NVCC_FLAGS_ARCH)
endwhile()
set (loop_var "")
foreach( loop_var IN LISTS CUDA_NVCC_FLAGS_NUM)
2010-08-12 15:57:53 +08:00
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_${loop_var},code=sm_${loop_var})
2010-08-11 23:52:55 +08:00
endforeach()
message(STATUS " CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS} ")
2010-07-15 21:36:00 +08:00
if (UNIX OR APPLE)
2010-07-20 01:35:39 +08:00
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-fPIC;")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-fPIC")
2010-08-11 23:52:55 +08:00
endif()
2010-07-20 01:35:39 +08:00
#set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep")
#set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;")
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
2010-08-11 23:52:55 +08:00
2010-07-20 01:35:39 +08:00
if(MSVC)
#string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
#string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
2010-08-11 23:52:55 +08:00
#string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408")
2010-07-20 19:46:04 +08:00
string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
2010-08-11 23:52:55 +08:00
string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
2010-07-20 01:35:39 +08:00
endif()
2010-08-11 23:52:55 +08:00
2010-07-15 21:36:00 +08:00
CUDA_COMPILE(cuda_objs ${lib_cuda})
#CUDA_BUILD_CLEAN_TARGET()
endif()
2010-08-11 23:52:55 +08:00
2010-07-15 21:36:00 +08:00
add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${lib_cuda} ${lib_cuda_hdrs} ${cuda_objs})
2010-07-20 01:35:39 +08:00
2010-07-15 21:36:00 +08:00
if(PCHSupport_FOUND)
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
if(${CMAKE_GENERATOR} MATCHES "Visual*")
set(${the_target}_pch "src/precomp.cpp")
2010-08-11 23:52:55 +08:00
endif()
2010-07-15 21:36:00 +08:00
add_native_precompiled_header(${the_target} ${pch_header})
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
add_precompiled_header(${the_target} ${pch_header})
endif()
endif()
# For dynamic link numbering convenions
set_target_properties(${the_target} PROPERTIES
VERSION ${OPENCV_VERSION}
SOVERSION ${OPENCV_SOVERSION}
2010-08-11 23:52:55 +08:00
OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}"
2010-07-15 21:36:00 +08:00
)
# Additional target properties
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
2010-08-11 23:52:55 +08:00
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
2010-07-15 21:36:00 +08:00
)
# Add the required libraries for linking:
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} ${CUDA_LIBRARIES})
if(MSVC)
if(CMAKE_CROSSCOMPILING)
set_target_properties(${the_target} PROPERTIES
2010-07-15 21:36:00 +08:00
LINK_FLAGS "/NODEFAULTLIB:secchk"
)
endif()
2010-07-15 21:36:00 +08:00
set_target_properties(${the_target} PROPERTIES
LINK_FLAGS "/NODEFAULTLIB:libc"
)
endif()
2010-07-15 21:36:00 +08:00
# Dependencies of this target:
add_dependencies(${the_target} ${DEPS})
2010-07-15 21:36:00 +08:00
install(TARGETS ${the_target}
RUNTIME DESTINATION bin COMPONENT main
LIBRARY DESTINATION lib COMPONENT main
ARCHIVE DESTINATION lib COMPONENT main)
2010-07-15 21:36:00 +08:00
install(FILES ${lib_hdrs}
DESTINATION include/opencv2/${name}
COMPONENT main)