From 19f863ec13a07afd65fe0518ad72f7219a4b8d99 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Sat, 2 Mar 2013 00:17:46 +0400 Subject: [PATCH] add possibility to create CUDA powered modules with ocv_define_module macro --- cmake/OpenCVModule.cmake | 29 +++++++++++++++++++++++++---- modules/core/CMakeLists.txt | 19 +++---------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index b6d129a267..e9bd277b85 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -432,11 +432,27 @@ macro(ocv_glob_module_sources) file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h") + file(GLOB_RECURSE lib_device_srcs "src/*.cu") + set(device_objs "") + set(lib_device_hdrs "") + + if (HAVE_CUDA AND lib_device_srcs) + ocv_include_directories(${CUDA_INCLUDE_DIRS}) + file(GLOB_RECURSE lib_device_hdrs "src/cuda/*.hpp") + + ocv_cuda_compile(device_objs ${lib_device_srcs}) + source_group("Src\\Cuda" FILES ${lib_device_srcs} ${lib_device_hdrs}) + if (lib_device_hdrs) + list(REMOVE_ITEM lib_int_hdrs ${lib_device_hdrs}) + endif() + endif() + + ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} + SOURCES ${lib_srcs} ${lib_int_hdrs} ${device_objs} ${lib_device_srcs} ${lib_device_hdrs}) + source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) source_group("Include" FILES ${lib_hdrs}) source_group("Include\\detail" FILES ${lib_hdrs_detail}) - - ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} SOURCES ${lib_srcs} ${lib_int_hdrs}) endmacro() # creates OpenCV module in current folder @@ -446,9 +462,14 @@ endmacro() # ocv_create_module(SKIP_LINK) macro(ocv_create_module) add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES}) + set(cuda_libs "") + + if (HAVE_CUDA) + set(cuda_libs ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) + endif() if(NOT "${ARGN}" STREQUAL "SKIP_LINK") - target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) + target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${cuda_libs} ${ARGN}) endif() add_dependencies(opencv_modules ${the_module}) @@ -530,8 +551,8 @@ endmacro() # ocv_define_module(module_name [INTERNAL] [REQUIRED] [] [OPTIONAL ]) macro(ocv_define_module module_name) ocv_add_module(${module_name} ${ARGN}) - ocv_glob_module_sources() ocv_module_include_directories() + ocv_glob_module_sources() ocv_create_module() ocv_add_precompiled_headers(${the_module}) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 4c5112e3f9..e538d1acae 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -1,27 +1,14 @@ set(the_description "The Core Functionality") ocv_add_module(core ${ZLIB_LIBRARIES}) -ocv_module_include_directories(${ZLIB_INCLUDE_DIR}) +ocv_module_include_directories(${ZLIB_INCLUDE_DIR} "${OpenCV_SOURCE_DIR}/modules/gpu/include") if(HAVE_CUDA) - ocv_source_group("Src\\Cuda" GLOB "src/cuda/*.cu") - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include" ${CUDA_INCLUDE_DIRS}) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) - - file(GLOB lib_cuda "src/cuda/*.cu") - ocv_cuda_compile(cuda_objs ${lib_cuda}) - - set(cuda_link_libs ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) -else() - set(lib_cuda "") - set(cuda_objs "") - set(cuda_link_libs "") endif() -ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs} "${opencv_core_BINARY_DIR}/version_string.inc") - -ocv_create_module(${cuda_link_libs}) +ocv_glob_module_sources(SOURCES "${opencv_core_BINARY_DIR}/version_string.inc") +ocv_create_module() ocv_add_precompiled_headers(${the_module}) ocv_add_accuracy_tests() ocv_add_perf_tests() -