# The verbose template for OpenCV module:
#
# ocv_add_module(modname <dependencies>)
-# ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...)
+# ocv_glob_module_sources(([EXCLUDE_CUDA] <extra sources&headers>)
+# or glob them manually and ocv_set_module_sources(...)
# ocv_module_include_directories(<extra include directories>)
# ocv_create_module()
# <add extra link dependencies, compiler options, etc>
# Usage:
# ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
# Example:
-# ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_gpu)
+# ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_cuda)
macro(ocv_add_module _name)
string(TOLOWER "${_name}" name)
string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
# finds and sets headers and sources for the standard OpenCV module
# Usage:
-# ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>)
+# ocv_glob_module_sources([EXCLUDE_CUDA] <extra sources&headers in the same format as used in ocv_set_module_sources>)
macro(ocv_glob_module_sources)
+ set(_argn ${ARGN})
+ list(FIND _argn "EXCLUDE_CUDA" exclude_cuda)
+ if(NOT exclude_cuda EQUAL -1)
+ list(REMOVE_AT _argn ${exclude_cuda})
+ endif()
+
file(GLOB_RECURSE lib_srcs "src/*.cpp")
file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
- file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
+ file(GLOB lib_hdrs "include/opencv2/*.hpp" "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_srcs_apple "src/*.mm")
if (APPLE)
list(APPEND lib_srcs ${lib_srcs_apple})
endif()
- file(GLOB lib_cuda_srcs "src/cuda/*.cu")
- set(cuda_objs "")
- set(lib_cuda_hdrs "")
- if(HAVE_CUDA)
- ocv_include_directories(${CUDA_INCLUDE_DIRS})
- file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
+ ocv_source_group("Src" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/src" FILES ${lib_srcs} ${lib_int_hdrs})
+ ocv_source_group("Include" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${lib_hdrs} ${lib_hdrs_detail})
- ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs})
- source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs})
- endif()
+ if (exclude_cuda EQUAL -1)
+ file(GLOB lib_cuda_srcs "src/cuda/*.cu")
+ set(cuda_objs "")
+ set(lib_cuda_hdrs "")
+ if(HAVE_CUDA)
+ ocv_include_directories(${CUDA_INCLUDE_DIRS})
+ file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
- source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
+ ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs})
+ source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs})
+ endif()
+ else()
+ set(cuda_objs "")
+ set(lib_cuda_srcs "")
+ set(lib_cuda_hdrs "")
+ endif()
file(GLOB cl_kernels "src/opencl/*.cl")
- if(HAVE_opencv_ocl AND cl_kernels)
+ if(cl_kernels)
ocv_include_directories(${OPENCL_INCLUDE_DIRS})
+ string(REGEX REPLACE "opencv_" "" the_module_barename "${the_module}")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp"
- COMMAND ${CMAKE_COMMAND} -DCL_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/opencl" -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" -P "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake"
+ COMMAND ${CMAKE_COMMAND} -DMODULE_NAME="${the_module_barename}" -DCL_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/opencl" -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" -P "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake"
DEPENDS ${cl_kernels} "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake")
- source_group("OpenCL" FILES ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
+ ocv_source_group("Src\\opencl\\kernels" FILES ${cl_kernels})
+ ocv_source_group("Src\\opencl\\kernels\\autogenerated" FILES "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
list(APPEND lib_srcs ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
endif()
- 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} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs})
+ ocv_set_module_sources(${_argn} HEADERS ${lib_hdrs} ${lib_hdrs_detail}
+ SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs})
endmacro()
# creates OpenCV module in current folder
add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES}
"${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp"
${${the_module}_pch})
+ if(NOT the_module STREQUAL opencv_ts)
+ set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL)
+ endif()
if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS})
target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS})
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
+ if (HAVE_CUDA)
+ target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
+ endif()
endif()
add_dependencies(opencv_modules ${the_module})
if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
- if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$")
+ if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
endif()
endforeach()
# short command for adding simple OpenCV module
# see ocv_add_module for argument details
# Usage:
-# ocv_define_module(module_name [INTERNAL] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
+# ocv_define_module(module_name [INTERNAL] [EXCLUDE_CUDA] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
macro(ocv_define_module module_name)
- ocv_add_module(${module_name} ${ARGN})
+ set(_argn ${ARGN})
+ set(exclude_cuda "")
+ foreach(arg ${_argn})
+ if("${arg}" STREQUAL "EXCLUDE_CUDA")
+ set(exclude_cuda "${arg}")
+ list(REMOVE_ITEM _argn ${arg})
+ endif()
+ endforeach()
+
+ ocv_add_module(${module_name} ${_argn})
ocv_module_include_directories()
- ocv_glob_module_sources()
+ ocv_glob_module_sources(${exclude_cuda})
ocv_create_module()
ocv_add_precompiled_headers(${the_module})
ocv_module_include_directories(${perf_deps} "${perf_path}")
if(NOT OPENCV_PERF_${the_module}_SOURCES)
- file(GLOB perf_srcs "${perf_path}/*.cpp")
- file(GLOB perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h")
- source_group("Src" FILES ${perf_srcs})
- source_group("Include" FILES ${perf_hdrs})
+ file(GLOB_RECURSE perf_srcs "${perf_path}/*.cpp")
+ file(GLOB_RECURSE perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h")
+ ocv_source_group("Src" DIRBASE "${perf_path}" FILES ${perf_srcs})
+ ocv_source_group("Include" DIRBASE "${perf_path}" FILES ${perf_hdrs})
set(OPENCV_PERF_${the_module}_SOURCES ${perf_srcs} ${perf_hdrs})
endif()
ocv_module_include_directories(${test_deps} "${test_path}")
if(NOT OPENCV_TEST_${the_module}_SOURCES)
- file(GLOB test_srcs "${test_path}/*.cpp")
- file(GLOB test_hdrs "${test_path}/*.hpp" "${test_path}/*.h")
- source_group("Src" FILES ${test_srcs})
- source_group("Include" FILES ${test_hdrs})
+ file(GLOB_RECURSE test_srcs "${test_path}/*.cpp")
+ file(GLOB_RECURSE test_hdrs "${test_path}/*.hpp" "${test_path}/*.h")
+ ocv_source_group("Src" DIRBASE "${test_path}" FILES ${test_srcs})
+ ocv_source_group("Include" DIRBASE "${test_path}" FILES ${test_hdrs})
set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs})
endif()