NiceModules.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. # clean flags for modules enabled on previous cmake run
  2. # this is necessary to correctly handle modules removal
  3. foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
  4. if(HAVE_${mod})
  5. unset(HAVE_${mod} CACHE)
  6. endif()
  7. unset(OPENCV_MODULE_${mod}_REQ_DEPS CACHE)
  8. unset(OPENCV_MODULE_${mod}_OPT_DEPS CACHE)
  9. endforeach()
  10. # clean modules info which needs to be recalculated
  11. set(OPENCV_MODULES_PUBLIC "" CACHE INTERNAL "List of OpenCV modules marked for export")
  12. set(OPENCV_MODULES_BUILD "" CACHE INTERNAL "List of OpenCV modules included into the build")
  13. set(OPENCV_MODULES_DISABLED_USER "" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
  14. set(OPENCV_MODULES_DISABLED_AUTO "" CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
  15. set(OPENCV_MODULES_DISABLED_FORCE "" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
  16. # get a list of all sub directories in curdir
  17. MACRO(SUBDIRLIST result curdir)
  18. FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
  19. SET(dirlist "")
  20. FOREACH(child ${children})
  21. IF(IS_DIRECTORY ${curdir}/${child})
  22. SET(dirlist ${dirlist} ${child})
  23. ENDIF()
  24. ENDFOREACH()
  25. SET(${result} ${dirlist})
  26. ENDMACRO()
  27. # collect modules from specified directories
  28. # NB: must be called only once!
  29. macro(ocv_glob_modules modulepath)
  30. if(DEFINED OPENCV_INITIAL_PASS)
  31. message(FATAL_ERROR "OpenCV has already loaded its modules. Calling ocv_glob_modules second time is not allowed.")
  32. endif()
  33. set(__directories_observed "")
  34. #nice-----
  35. #get_filename_component(currDirName ${CMAKE_CURRENT_SOURCE_DIR} NAME )
  36. #get_filename_component(currDirName ${modulepath} NAME )
  37. #set(the_module "${the_module}_${currDirName}")
  38. #message(STATUS "currDirName=${currDirName}")
  39. #------
  40. # collect modules
  41. set(OPENCV_INITIAL_PASS ON)
  42. foreach(__path ${modulepath} ) #${ARGN})
  43. ocv_get_real_path(__path "${__path}")
  44. list(FIND __directories_observed "${__path}" __pathIdx)
  45. if(__pathIdx GREATER -1)
  46. message(FATAL_ERROR "The directory ${__path} is observed for OpenCV modules second time.")
  47. endif()
  48. list(APPEND __directories_observed "${__path}")
  49. file(GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*")
  50. if(__ocvmodules)
  51. list(SORT __ocvmodules)
  52. foreach(mod ${__ocvmodules})
  53. ocv_get_real_path(__modpath "${__path}/${mod}")
  54. if(EXISTS "${__modpath}/CMakeLists.txt")
  55. #message(STATUS "${__modpath} adding subdir")
  56. list(FIND __directories_observed "${__modpath}" __pathIdx)
  57. if(__pathIdx GREATER -1)
  58. message(FATAL_ERROR "The module from ${__modpath} is already loaded.")
  59. endif()
  60. list(APPEND __directories_observed "${__modpath}")
  61. if(OCV_MODULE_RELOCATE_ON_INITIAL_PASS)
  62. #file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
  63. file(COPY "${__modpath}/CMakeLists.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
  64. add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
  65. if("${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
  66. set(OPENCV_MODULE_opencv_${mod}_LOCATION "${__modpath}" CACHE PATH "" FORCE)
  67. endif()
  68. else()
  69. #org: add_subdirectory("${__modpath}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
  70. add_subdirectory("${__modpath}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}")
  71. endif()
  72. endif()
  73. endforeach()
  74. endif()
  75. endforeach()
  76. ocv_clear_vars(__ocvmodules __directories_observed __path __modpath __pathIdx)
  77. # resolve dependencies
  78. # __ocv_flatten_module_dependencies()
  79. # create modules
  80. set(OPENCV_INITIAL_PASS OFF PARENT_SCOPE)
  81. set(OPENCV_INITIAL_PASS OFF)
  82. foreach(m ${OPENCV_MODULES_BUILD})
  83. message(STATUS "${OPENCV_MODULES_BUILD}")
  84. if(m MATCHES "^opencv_")
  85. string(REGEX REPLACE "^opencv_" "" __shortname "${m}")
  86. add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${__shortname}")
  87. endif()
  88. endforeach()
  89. unset(__shortname)
  90. endmacro()
  91. # adds dependencies to OpenCV module
  92. # Usage:
  93. # add_dependencies(opencv_<name> [REQUIRED] [<list of dependencies>] [OPTIONAL <list of modules>])
  94. # Notes:
  95. # * <list of dependencies> - can include full names of modules or full pathes to shared/static libraries or cmake targets
  96. macro(ocv_add_dependencies full_modname)
  97. #we don't clean the dependencies here to allow this macro several times for every module
  98. foreach(d "REQUIRED" ${ARGN})
  99. if(d STREQUAL "REQUIRED")
  100. set(__depsvar OPENCV_MODULE_${full_modname}_REQ_DEPS)
  101. elseif(d STREQUAL "OPTIONAL")
  102. set(__depsvar OPENCV_MODULE_${full_modname}_OPT_DEPS)
  103. else()
  104. list(APPEND ${__depsvar} "${d}")
  105. endif()
  106. endforeach()
  107. unset(__depsvar)
  108. ocv_list_unique(OPENCV_MODULE_${full_modname}_REQ_DEPS)
  109. ocv_list_unique(OPENCV_MODULE_${full_modname}_OPT_DEPS)
  110. message(STATUS "OPENCV_MODULE_${full_modname}_REQ_DEPS: ${OPENCV_MODULE_${full_modname}_REQ_DEPS}")
  111. message(STATUS "OPENCV_MODULE_${full_modname}_OPT_DEPS: ${OPENCV_MODULE_${full_modname}_OPT_DEPS}")
  112. set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS} CACHE INTERNAL "Required dependencies of ${full_modname} module")
  113. set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS} CACHE INTERNAL "Optional dependencies of ${full_modname} module")
  114. endmacro()
  115. # declare new OpenCV module in current folder
  116. # Usage:
  117. # ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
  118. # Example:
  119. # ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_gpu)
  120. macro(ocv_add_module _name)
  121. #string(TOLOWER "${_name}" name)
  122. #string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
  123. #set(the_module opencv_${name})
  124. #-----
  125. get_filename_component(currDirName ${CMAKE_CURRENT_SOURCE_DIR} NAME )
  126. set(the_module "${the_module}_${currDirName}")
  127. #----
  128. # the first pass - collect modules info, the second pass - create targets
  129. if(OPENCV_INITIAL_PASS)
  130. #guard agains redefinition
  131. if(";${OPENCV_MODULES_BUILD};${OPENCV_MODULES_DISABLED_USER};" MATCHES ";${the_module};")
  132. message(FATAL_ERROR "Redefinition of the ${the_module} module.
  133. at: ${CMAKE_CURRENT_SOURCE_DIR}
  134. previously defined at: ${OPENCV_MODULE_${the_module}_LOCATION}
  135. ")
  136. endif()
  137. if(NOT DEFINED the_description)
  138. set(the_description "The ${name} OpenCV module")
  139. endif()
  140. if(NOT DEFINED BUILD_${the_module}_INIT)
  141. set(BUILD_${the_module}_INIT ON)
  142. endif()
  143. # create option to enable/disable this module
  144. # option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${BUILD_${the_module}_INIT})
  145. # remember the module details
  146. set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module")
  147. set(OPENCV_MODULE_${the_module}_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources")
  148. # parse list of dependencies
  149. if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
  150. set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The cathegory of the module")
  151. set(__ocv_argn__ ${ARGN})
  152. list(REMOVE_AT __ocv_argn__ 0)
  153. ocv_add_dependencies(${the_module} ${__ocv_argn__})
  154. unset(__ocv_argn__)
  155. else()
  156. set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The cathegory of the module")
  157. ocv_add_dependencies(${the_module} ${ARGN})
  158. if(BUILD_${the_module})
  159. set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
  160. endif()
  161. endif()
  162. # add self to the world dependencies
  163. if(NOT DEFINED OPENCV_MODULE_IS_PART_OF_WORLD AND NOT OPENCV_MODULE_${the_module}_CLASS STREQUAL "BINDINGS" OR OPENCV_MODULE_IS_PART_OF_WORLD)
  164. ocv_add_dependencies(opencv_world OPTIONAL ${the_module})
  165. endif()
  166. if(BUILD_${the_module})
  167. set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build")
  168. else()
  169. set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
  170. endif()
  171. # TODO: add submodules if any
  172. # stop processing of current file
  173. # return()
  174. else(OPENCV_INITIAL_PASS)
  175. if(NOT BUILD_${the_module})
  176. return() # extra protection from redefinition
  177. endif()
  178. project(${the_module})
  179. endif(OPENCV_INITIAL_PASS)
  180. endmacro()
  181. # setup include paths for the list of passed modules
  182. macro(ocv_include_modules)
  183. foreach(d ${ARGN})
  184. if(d MATCHES "^opencv_" AND HAVE_${d})
  185. # message(STATUS "${OPENCV_MODULE_${d}_LOCATION}")
  186. if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
  187. ocv_include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
  188. endif()
  189. elseif(EXISTS "${d}")
  190. ocv_include_directories("${d}")
  191. endif()
  192. endforeach()
  193. endmacro()
  194. # setup include path for OpenCV headers for specified module
  195. # ocv_module_include_directories(<extra include directories/extra include modules>)
  196. macro(ocv_module_include_directories)
  197. # ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include"
  198. # "${OPENCV_MODULE_${the_module}_LOCATION}/src"
  199. # "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
  200. # )
  201. ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/"
  202. "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
  203. )
  204. ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN})
  205. endmacro()
  206. # sets header and source files for the current module
  207. # NB: all files specified as headers will be installed
  208. # Usage:
  209. # ocv_set_module_sources([HEADERS] <list of files> [SOURCES] <list of files>)
  210. macro(ocv_set_module_sources)
  211. #opencv: set(OPENCV_MODULE_${the_module}_HEADERS "" )
  212. #opencv: set(OPENCV_MODULE_${the_module}_SOURCES "" )
  213. set(OPENCV_MODULE_${the_module}_HEADERS "" PARENT_SCOPE)
  214. set(OPENCV_MODULE_${the_module}_SOURCES "" PARENT_SCOPE)
  215. foreach(f "HEADERS" ${ARGN})
  216. if(f STREQUAL "HEADERS" OR f STREQUAL "SOURCES")
  217. set(__filesvar "OPENCV_MODULE_${the_module}_${f}")
  218. else()
  219. list(APPEND ${__filesvar} "${f}")
  220. endif()
  221. endforeach()
  222. # the hacky way to embeed any files into the OpenCV without modification of its build system
  223. if(COMMAND ocv_get_module_external_sources)
  224. ocv_get_module_external_sources()
  225. endif()
  226. # use full paths for module to be independent from the module location
  227. ocv_convert_to_full_paths(OPENCV_MODULE_${the_module}_HEADERS)
  228. set(OPENCV_MODULE_${the_module}_HEADERS ${OPENCV_MODULE_${the_module}_HEADERS} CACHE INTERNAL "List of header files for ${the_module}")
  229. set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}")
  230. endmacro()
  231. # finds and sets headers and sources for the standard OpenCV module
  232. # Usage:
  233. # ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>)
  234. macro(ocv_glob_module_sources)
  235. # file(GLOB_RECURSE lib_srcs "src/*.cpp")
  236. # file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
  237. # file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
  238. # file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
  239. # source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
  240. # source_group("Include" FILES ${lib_hdrs})
  241. # source_group("Include\\detail" FILES ${lib_hdrs_detail})
  242. # ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} SOURCES ${lib_srcs} ${lib_int_hdrs})
  243. file(GLOB lib_srcs "*.cpp")
  244. #file(GLOB_RECURSE lib_int_hdrs "./*.hpp" "./*.h")
  245. #file(GLOB_RECURSE lib_int_hdrs "./*.hpp" "./*.h")
  246. file(GLOB lib_hdrs "*.hpp" "*.h" "*.tcc")
  247. #message(status "lib_srcs: ${lib_srcs}")
  248. #message(status "lib_hdrs: ${lib_hdrs}")
  249. source_group("Src" FILES ${lib_srcs})
  250. source_group("Include" FILES ${lib_hdrs})
  251. ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} SOURCES ${lib_srcs})
  252. endmacro()
  253. # creates OpenCV module in current folder
  254. # creates new target, configures standard dependencies, compilers flags, install rules
  255. # Usage:
  256. # ocv_create_module(<extra link dependencies>)
  257. # ocv_create_module(SKIP_LINK)
  258. macro(ocv_create_module)
  259. ##############################################
  260. ### process all subdirs #####
  261. #get list subdirs
  262. # include subdirs if != progs && != test, handle these two separately
  263. set(__path "${CMAKE_CURRENT_SOURCE_DIR}")
  264. #file(GLOB __listSubdirs RELATIVE "${__path}" "${__path}/*")
  265. SUBDIRLIST(__listSubdirs "${__path}")
  266. if(__listSubdirs)
  267. list(SORT __listSubdirs)
  268. foreach(currSubDir ${__listSubdirs})
  269. ocv_get_real_path(__subdirpath "${__path}/${currSubDir}")
  270. #message(STATUS "${currSubDir}")
  271. #message(STATUS "subdir examining: ${__subdirpath}")
  272. if(EXISTS "${__subdirpath}/CMakeLists.txt")
  273. message(STATUS "${currSubDir} has CMakeLists.txt")
  274. if ( "${currSubDir}" STREQUAL "tests" )
  275. if( NICE_BUILD_TESTS )
  276. #add tests
  277. #add_subdirectory("${__subdirpath}")
  278. else()
  279. message(STATUS "by configuration: tests/ not added")
  280. endif()
  281. elseif( "${currSubDir}" STREQUAL "progs" )
  282. if( NICE_BUILD_PROGS )
  283. #add progs
  284. add_subdirectory("${__subdirpath}")
  285. else()
  286. message(STATUS "by configuration: progs/ not added")
  287. endif()
  288. else()
  289. message(STATUS "adding subdir")
  290. add_subdirectory("${__subdirpath}")
  291. #add subdir sources to the accumulated source variable of this directory
  292. #message(STATUS "subdir-sources: ${OPENCV_MODULE_${the_module}_${currSubDir}_SOURCES}")
  293. set(OPENCV_MODULE_${the_module}_SOURCES "${OPENCV_MODULE_${the_module}_SOURCES}" "${OPENCV_MODULE_${the_module}_${currSubDir}_SOURCES}")
  294. set(OPENCV_MODULE_${the_module}_HEADERS "${OPENCV_MODULE_${the_module}_HEADERS}" "${OPENCV_MODULE_${the_module}_${currSubDir}_HEADERS}")
  295. #message(STATUS "accumulated sources of ${the_module}: ${OPENCV_MODULE_${the_module}_SOURCES}")
  296. #message(STATUS "accumulated headers of ${the_module}: ${OPENCV_MODULE_${the_module}_HEADERS}")
  297. endif()
  298. endif()
  299. endforeach()
  300. endif()
  301. ##################################################
  302. #add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
  303. # message(STATUS "linking source files of ${the_module}: ${OPENCV_MODULE_${the_module}_SOURCES}")
  304. # message(STATUS "linking header files of ${the_module}: ${OPENCV_MODULE_${the_module}_HEADERS}")
  305. add_library(${the_module} ${NICE_BUILD_LIBS_STATIC_SHARED} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
  306. if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
  307. target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
  308. endif()
  309. #jojo add_dependencies(opencv_modules ${the_module})
  310. if(ENABLE_SOLUTION_FOLDERS)
  311. set_target_properties(${the_module} PROPERTIES FOLDER "modules")
  312. endif()
  313. # message(STATUS "LIBRARY_OUTPUT_PATH: ${LIBRARY_OUTPUT_PATH}")
  314. #message(STATUS "EXECUTABLE_OUTPUT_PATH: ${EXECUTABLE_OUTPUT_PATH}")
  315. set_target_properties(${the_module} PROPERTIES
  316. OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
  317. DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
  318. ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
  319. RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
  320. INSTALL_NAME_DIR lib
  321. )
  322. # For dynamic link numbering convenions
  323. if(NOT ANDROID)
  324. # Android SDK build scripts can include only .so files into final .apk
  325. # As result we should not set version properties for Android
  326. set_target_properties(${the_module} PROPERTIES
  327. VERSION ${OPENCV_VERSION}
  328. SOVERSION ${OPENCV_SOVERSION}
  329. )
  330. endif()
  331. if(BUILD_SHARED_LIBS)
  332. if(MSVC)
  333. set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
  334. else()
  335. add_definitions(-DCVAPI_EXPORTS)
  336. endif()
  337. endif()
  338. if(MSVC)
  339. if(CMAKE_CROSSCOMPILING)
  340. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
  341. endif()
  342. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
  343. endif()
  344. install(TARGETS ${the_module}
  345. RUNTIME DESTINATION bin COMPONENT main
  346. LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
  347. ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
  348. )
  349. # only "public" headers need to be installed
  350. if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
  351. foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
  352. string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
  353. if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$")
  354. install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main)
  355. endif()
  356. endforeach()
  357. endif()
  358. endmacro()
  359. # opencv precompiled headers macro (can add pch to modules and tests)
  360. # this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work
  361. # Usage:
  362. # ocv_add_precompiled_headers(${the_module})
  363. macro(ocv_add_precompiled_headers the_target)
  364. if("${the_target}" MATCHES "^opencv_test_.*$")
  365. SET(pch_path "test/test_")
  366. elseif("${the_target}" MATCHES "^opencv_perf_.*$")
  367. SET(pch_path "perf/perf_")
  368. else()
  369. SET(pch_path "src/")
  370. endif()
  371. set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.hpp")
  372. if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}")
  373. if(CMAKE_GENERATOR MATCHES Visual)
  374. set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.cpp")
  375. add_native_precompiled_header(${the_target} ${pch_header})
  376. elseif(CMAKE_GENERATOR MATCHES Xcode)
  377. add_native_precompiled_header(${the_target} ${pch_header})
  378. elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES "Makefiles|Ninja")
  379. add_precompiled_header(${the_target} ${pch_header})
  380. endif()
  381. endif()
  382. unset(pch_header)
  383. unset(pch_path)
  384. unset(${the_target}_pch)
  385. endmacro()