CMakeLists.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. set(the_description "The Core Functionality")
  2. ocv_add_dispatched_file(mathfuncs_core SSE2 AVX AVX2)
  3. ocv_add_dispatched_file(stat SSE4_2 AVX2)
  4. ocv_add_dispatched_file(arithm SSE2 SSE4_1 AVX2 VSX3)
  5. ocv_add_dispatched_file(convert SSE2 AVX2 VSX3)
  6. ocv_add_dispatched_file(convert_scale SSE2 AVX2)
  7. ocv_add_dispatched_file(count_non_zero SSE2 AVX2)
  8. ocv_add_dispatched_file(matmul SSE2 SSE4_1 AVX2 AVX512_SKX)
  9. ocv_add_dispatched_file(mean SSE2 AVX2)
  10. ocv_add_dispatched_file(merge SSE2 AVX2)
  11. ocv_add_dispatched_file(split SSE2 AVX2)
  12. ocv_add_dispatched_file(sum SSE2 AVX2)
  13. # dispatching for accuracy tests
  14. ocv_add_dispatched_file_force_all(test_intrin128 TEST SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX)
  15. ocv_add_dispatched_file_force_all(test_intrin256 TEST AVX2 AVX512_SKX)
  16. ocv_add_dispatched_file_force_all(test_intrin512 TEST AVX512_SKX)
  17. set(PARALLEL_ENABLE_PLUGINS_DEFAULT ON)
  18. if(EMSCRIPTEN OR IOS OR WINRT)
  19. set(PARALLEL_ENABLE_PLUGINS_DEFAULT OFF)
  20. endif()
  21. # parallel backends configuration
  22. set(PARALLEL_ENABLE_PLUGINS "${PARALLEL_ENABLE_PLUGINS_DEFAULT}" CACHE BOOL "Allow building parallel plugin support")
  23. # TODO building plugins with OpenCV is not supported yet
  24. #set(PARALLEL_PLUGIN_LIST "" CACHE STRING "List of parallel backends to be compiled as plugins (tbb, openmp or special value 'all')")
  25. #string(REPLACE "," ";" PARALLEL_PLUGIN_LIST "${PARALLEL_PLUGIN_LIST}") # support comma-separated list (,) too
  26. #string(TOLOWER "${PARALLEL_PLUGIN_LIST}" PARALLEL_PLUGIN_LIST)
  27. ocv_add_module(core
  28. OPTIONAL opencv_cudev
  29. WRAP java objc python js)
  30. set(extra_libs "")
  31. if(WINRT AND WINDOWS_STORE AND CMAKE_SYSTEM_VERSION MATCHES "8.0")
  32. list(APPEND extra_libs ole32.lib)
  33. endif()
  34. if(HAVE_TBB)
  35. list(APPEND extra_libs tbb)
  36. endif()
  37. if(DEFINED WINRT AND NOT DEFINED ENABLE_WINRT_MODE_NATIVE)
  38. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
  39. endif()
  40. if(HAVE_CUDA)
  41. if(NOT HAVE_opencv_cudev)
  42. message(FATAL_ERROR "CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib' repository: https://github.com/opencv/opencv_contrib")
  43. endif()
  44. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wenum-compare -Wunused-function -Wshadow)
  45. endif()
  46. if(CV_TRACE AND HAVE_ITT)
  47. add_definitions(-DOPENCV_WITH_ITT=1)
  48. endif()
  49. file(GLOB lib_cuda_hdrs
  50. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/*.hpp"
  51. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/*.h")
  52. file(GLOB lib_cuda_hdrs_detail
  53. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/detail/*.hpp"
  54. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/cuda/detail/*.h")
  55. file(GLOB_RECURSE module_opencl_hdrs
  56. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/opencl/*")
  57. source_group("Include\\Cuda Headers" FILES ${lib_cuda_hdrs})
  58. source_group("Include\\Cuda Headers\\Detail" FILES ${lib_cuda_hdrs_detail})
  59. file(GLOB_RECURSE core_parallel_hdrs
  60. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/parallel/*.hpp"
  61. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/parallel/*.h")
  62. ocv_source_group("Include" DIRBASE "${CMAKE_CURRENT_LIST_DIR}/include" FILES ${core_parallel_hdrs})
  63. source_group("Src" FILES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc")
  64. ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc"
  65. HEADERS ${core_parallel_hdrs} ${module_opencl_hdrs} ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
  66. ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
  67. if(ANDROID AND HAVE_CPUFEATURES)
  68. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/system.cpp "HAVE_CPUFEATURES=1")
  69. ocv_module_include_directories(${CPUFEATURES_INCLUDE_DIRS})
  70. endif()
  71. if(ITT_INCLUDE_DIRS)
  72. ocv_module_include_directories(${ITT_INCLUDE_DIRS})
  73. endif()
  74. if(HAVE_POSIX_MEMALIGN)
  75. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/alloc.cpp "HAVE_POSIX_MEMALIGN=1")
  76. endif()
  77. if(HAVE_MALLOC_H)
  78. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/alloc.cpp "HAVE_MALLOC_H=1")
  79. endif()
  80. if(HAVE_MEMALIGN)
  81. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/alloc.cpp "HAVE_MEMALIGN=1")
  82. endif()
  83. if(HAVE_WIN32_ALIGNED_MALLOC)
  84. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/alloc.cpp "HAVE_WIN32_ALIGNED_MALLOC=1")
  85. endif()
  86. if(HAVE_VA_INTEL_OLD_HEADER)
  87. ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "HAVE_VA_INTEL_OLD_HEADER")
  88. endif()
  89. if(OPENCV_LIBVA_LINK)
  90. ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "OPENCV_LIBVA_LINK=1")
  91. endif()
  92. option(OPENCV_ENABLE_ALLOCATOR_STATS "Enable Allocator metrics" ON)
  93. if(NOT OPENCV_ENABLE_ALLOCATOR_STATS)
  94. add_definitions(-DOPENCV_DISABLE_ALLOCATOR_STATS=1)
  95. elseif(HAVE_CXX11 OR DEFINED OPENCV_ALLOCATOR_STATS_COUNTER_TYPE)
  96. if(NOT DEFINED OPENCV_ALLOCATOR_STATS_COUNTER_TYPE)
  97. if(HAVE_ATOMIC_LONG_LONG AND OPENCV_ENABLE_ATOMIC_LONG_LONG)
  98. if(MINGW)
  99. # command-line generation issue due to space in value, int/int64_t should be used instead
  100. # https://github.com/opencv/opencv/issues/16990
  101. message(STATUS "Consider adding OPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int/int64_t according to your build configuration")
  102. else()
  103. set(OPENCV_ALLOCATOR_STATS_COUNTER_TYPE "long long")
  104. endif()
  105. else()
  106. set(OPENCV_ALLOCATOR_STATS_COUNTER_TYPE "int")
  107. endif()
  108. endif()
  109. if(DEFINED OPENCV_ALLOCATOR_STATS_COUNTER_TYPE)
  110. message(STATUS "Allocator metrics storage type: '${OPENCV_ALLOCATOR_STATS_COUNTER_TYPE}'")
  111. add_definitions("-DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=${OPENCV_ALLOCATOR_STATS_COUNTER_TYPE}")
  112. endif()
  113. endif()
  114. if(PARALLEL_ENABLE_PLUGINS)
  115. ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/parallel/parallel.cpp "PARALLEL_ENABLE_PLUGINS=1")
  116. if(OPENCV_DEBUG_POSTFIX)
  117. ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/parallel/parallel.cpp" "DEBUG_POSTFIX=${OPENCV_DEBUG_POSTFIX}")
  118. endif()
  119. endif()
  120. ocv_create_module(${extra_libs})
  121. ocv_target_link_libraries(${the_module} PRIVATE
  122. "${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
  123. "${OPENGL_LIBRARIES}"
  124. "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}"
  125. "${ITT_LIBRARIES}"
  126. "${OPENCV_HAL_LINKER_LIBS}"
  127. )
  128. if(OPENCV_CORE_EXCLUDE_C_API)
  129. ocv_target_compile_definitions(${the_module} PRIVATE "OPENCV_EXCLUDE_C_API=1")
  130. endif()
  131. if(OPENCV_DISABLE_THREAD_SUPPORT)
  132. ocv_target_compile_definitions(${the_module} PUBLIC "OPENCV_DISABLE_THREAD_SUPPORT=1")
  133. endif()
  134. if(OPENCV_SEMIHOSTING)
  135. ocv_target_compile_definitions(${the_module} PRIVATE "-DOPENCV_SEMIHOSTING")
  136. endif(OPENCV_SEMIHOSTING)
  137. if(HAVE_HPX)
  138. ocv_target_link_libraries(${the_module} LINK_PRIVATE "${HPX_LIBRARIES}")
  139. endif()
  140. ocv_add_accuracy_tests()
  141. ocv_add_perf_tests()
  142. ocv_install_3rdparty_licenses(SoftFloat "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/SoftFloat/COPYING.txt")
  143. # generate data (samples data) config file
  144. set(OPENCV_DATA_CONFIG_FILE "${CMAKE_BINARY_DIR}/opencv_data_config.hpp")
  145. set(OPENCV_DATA_CONFIG_STR "")
  146. if(CMAKE_INSTALL_PREFIX)
  147. set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
  148. #define OPENCV_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\"
  149. ")
  150. endif()
  151. if(OPENCV_OTHER_INSTALL_PATH)
  152. set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
  153. #define OPENCV_DATA_INSTALL_PATH \"${OPENCV_OTHER_INSTALL_PATH}\"
  154. ")
  155. endif()
  156. set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
  157. #define OPENCV_BUILD_DIR \"${CMAKE_BINARY_DIR}\"
  158. ")
  159. file(RELATIVE_PATH SOURCE_DIR_RELATIVE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
  160. set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
  161. #define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \\
  162. \"${SOURCE_DIR_RELATIVE}/\"
  163. ")
  164. if(WIN32)
  165. file(RELATIVE_PATH INSTALL_DATA_DIR_RELATIVE "${CMAKE_INSTALL_PREFIX}/${OPENCV_BIN_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}")
  166. else()
  167. file(RELATIVE_PATH INSTALL_DATA_DIR_RELATIVE "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}")
  168. endif()
  169. list(APPEND OPENCV_INSTALL_DATA_DIR_RELATIVE "${INSTALL_DATA_DIR_RELATIVE}")
  170. string(REPLACE ";" "\",\\\n \"" OPENCV_INSTALL_DATA_DIR_RELATIVE_STR "\"${OPENCV_INSTALL_DATA_DIR_RELATIVE}\"")
  171. set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
  172. #define OPENCV_INSTALL_DATA_DIR_RELATIVE ${OPENCV_INSTALL_DATA_DIR_RELATIVE_STR}
  173. ")
  174. if(EXISTS "${OPENCV_DATA_CONFIG_FILE}")
  175. file(READ "${OPENCV_DATA_CONFIG_FILE}" __content)
  176. endif()
  177. if(NOT OPENCV_DATA_CONFIG_STR STREQUAL "${__content}")
  178. file(WRITE "${OPENCV_DATA_CONFIG_FILE}" "${OPENCV_DATA_CONFIG_STR}")
  179. endif()