NiceModules.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS} CACHE INTERNAL "Required dependencies of ${full_modname} module")
  111. set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS} CACHE INTERNAL "Optional dependencies of ${full_modname} module")
  112. endmacro()
  113. # declare new OpenCV module in current folder
  114. # Usage:
  115. # ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
  116. # Example:
  117. # ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_gpu)
  118. macro(ocv_add_module _name)
  119. #string(TOLOWER "${_name}" name)
  120. #string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
  121. #set(the_module opencv_${name})
  122. #-----
  123. get_filename_component(currDirName ${CMAKE_CURRENT_SOURCE_DIR} NAME )
  124. set(the_module "${the_module}_${currDirName}")
  125. #----
  126. # the first pass - collect modules info, the second pass - create targets
  127. if(OPENCV_INITIAL_PASS)
  128. #guard agains redefinition
  129. if(";${OPENCV_MODULES_BUILD};${OPENCV_MODULES_DISABLED_USER};" MATCHES ";${the_module};")
  130. message(FATAL_ERROR "Redefinition of the ${the_module} module.
  131. at: ${CMAKE_CURRENT_SOURCE_DIR}
  132. previously defined at: ${OPENCV_MODULE_${the_module}_LOCATION}
  133. ")
  134. endif()
  135. if(NOT DEFINED the_description)
  136. set(the_description "The ${name} OpenCV module")
  137. endif()
  138. if(NOT DEFINED BUILD_${the_module}_INIT)
  139. set(BUILD_${the_module}_INIT ON)
  140. endif()
  141. # create option to enable/disable this module
  142. # option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${BUILD_${the_module}_INIT})
  143. # remember the module details
  144. set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module")
  145. set(OPENCV_MODULE_${the_module}_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources")
  146. # parse list of dependencies
  147. if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
  148. set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The cathegory of the module")
  149. set(__ocv_argn__ ${ARGN})
  150. list(REMOVE_AT __ocv_argn__ 0)
  151. ocv_add_dependencies(${the_module} ${__ocv_argn__})
  152. unset(__ocv_argn__)
  153. else()
  154. set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The cathegory of the module")
  155. ocv_add_dependencies(${the_module} ${ARGN})
  156. if(BUILD_${the_module})
  157. set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
  158. endif()
  159. endif()
  160. # add self to the world dependencies
  161. 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)
  162. ocv_add_dependencies(opencv_world OPTIONAL ${the_module})
  163. endif()
  164. if(BUILD_${the_module})
  165. set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build")
  166. else()
  167. set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
  168. endif()
  169. # TODO: add submodules if any
  170. # stop processing of current file
  171. # return()
  172. else(OPENCV_INITIAL_PASS)
  173. if(NOT BUILD_${the_module})
  174. return() # extra protection from redefinition
  175. endif()
  176. project(${the_module})
  177. endif(OPENCV_INITIAL_PASS)
  178. endmacro()
  179. # setup include paths for the list of passed modules
  180. macro(ocv_include_modules)
  181. foreach(d ${ARGN})
  182. if(d MATCHES "^opencv_" AND HAVE_${d})
  183. # message(STATUS "${OPENCV_MODULE_${d}_LOCATION}")
  184. if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
  185. ocv_include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
  186. endif()
  187. elseif(EXISTS "${d}")
  188. ocv_include_directories("${d}")
  189. endif()
  190. endforeach()
  191. endmacro()
  192. # setup include path for OpenCV headers for specified module
  193. # ocv_module_include_directories(<extra include directories/extra include modules>)
  194. macro(ocv_module_include_directories)
  195. # ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include"
  196. # "${OPENCV_MODULE_${the_module}_LOCATION}/src"
  197. # "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
  198. # )
  199. ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/"
  200. "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
  201. )
  202. ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN})
  203. endmacro()
  204. # sets header and source files for the current module
  205. # NB: all files specified as headers will be installed
  206. # Usage:
  207. # ocv_set_module_sources([HEADERS] <list of files> [SOURCES] <list of files>)
  208. macro(ocv_set_module_sources)
  209. #opencv: set(OPENCV_MODULE_${the_module}_HEADERS "" )
  210. #opencv: set(OPENCV_MODULE_${the_module}_SOURCES "" )
  211. set(OPENCV_MODULE_${the_module}_HEADERS "" PARENT_SCOPE)
  212. set(OPENCV_MODULE_${the_module}_SOURCES "" PARENT_SCOPE)
  213. foreach(f "HEADERS" ${ARGN})
  214. if(f STREQUAL "HEADERS" OR f STREQUAL "SOURCES")
  215. set(__filesvar "OPENCV_MODULE_${the_module}_${f}")
  216. else()
  217. list(APPEND ${__filesvar} "${f}")
  218. endif()
  219. endforeach()
  220. # the hacky way to embeed any files into the OpenCV without modification of its build system
  221. if(COMMAND ocv_get_module_external_sources)
  222. ocv_get_module_external_sources()
  223. endif()
  224. # use full paths for module to be independent from the module location
  225. ocv_convert_to_full_paths(OPENCV_MODULE_${the_module}_HEADERS)
  226. set(OPENCV_MODULE_${the_module}_HEADERS ${OPENCV_MODULE_${the_module}_HEADERS} CACHE INTERNAL "List of header files for ${the_module}")
  227. set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}")
  228. endmacro()
  229. # finds and sets headers and sources for the standard OpenCV module
  230. # Usage:
  231. # ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>)
  232. macro(ocv_glob_module_sources)
  233. # file(GLOB_RECURSE lib_srcs "src/*.cpp")
  234. # file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
  235. # file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
  236. # file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
  237. # source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
  238. # source_group("Include" FILES ${lib_hdrs})
  239. # source_group("Include\\detail" FILES ${lib_hdrs_detail})
  240. # ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} SOURCES ${lib_srcs} ${lib_int_hdrs})
  241. file(GLOB lib_srcs "*.cpp")
  242. #file(GLOB_RECURSE lib_int_hdrs "./*.hpp" "./*.h")
  243. #file(GLOB_RECURSE lib_int_hdrs "./*.hpp" "./*.h")
  244. file(GLOB lib_hdrs "*.hpp" "*.h" "*.tcc")
  245. #message(status "lib_srcs: ${lib_srcs}")
  246. #message(status "lib_hdrs: ${lib_hdrs}")
  247. source_group("Src" FILES ${lib_srcs})
  248. source_group("Include" FILES ${lib_hdrs})
  249. ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} SOURCES ${lib_srcs})
  250. endmacro()
  251. # creates OpenCV module in current folder
  252. # creates new target, configures standard dependencies, compilers flags, install rules
  253. # Usage:
  254. # ocv_create_module(<extra link dependencies>)
  255. # ocv_create_module(SKIP_LINK)
  256. macro(ocv_create_module)
  257. ##############################################
  258. ### process all subdirs #####
  259. #get list subdirs
  260. # include subdirs if != progs && != test, handle these two separately
  261. set(__path "${CMAKE_CURRENT_SOURCE_DIR}")
  262. #file(GLOB __listSubdirs RELATIVE "${__path}" "${__path}/*")
  263. SUBDIRLIST(__listSubdirs "${__path}")
  264. if(__listSubdirs)
  265. list(SORT __listSubdirs)
  266. foreach(currSubDir ${__listSubdirs})
  267. ocv_get_real_path(__subdirpath "${__path}/${currSubDir}")
  268. #message(STATUS "${currSubDir}")
  269. #message(STATUS "subdir examining: ${__subdirpath}")
  270. if(EXISTS "${__subdirpath}/CMakeLists.txt")
  271. message(STATUS "${currSubDir} has CMakeLists.txt")
  272. if ( "${currSubDir}" STREQUAL "tests" )
  273. if( NICE_BUILD_TESTS )
  274. #add tests
  275. #add_subdirectory("${__subdirpath}")
  276. else()
  277. message(STATUS "by configuration: tests/ not added")
  278. endif()
  279. elseif( "${currSubDir}" STREQUAL "progs" )
  280. if( NICE_BUILD_PROGS )
  281. #add progs
  282. add_subdirectory("${__subdirpath}")
  283. else()
  284. message(STATUS "by configuration: progs/ not added")
  285. endif()
  286. else()
  287. message(STATUS "adding subdir")
  288. add_subdirectory("${__subdirpath}")
  289. #add subdir sources to the accumulated source variable of this directory
  290. #message(STATUS "subdir-sources: ${OPENCV_MODULE_${the_module}_${currSubDir}_SOURCES}")
  291. set(OPENCV_MODULE_${the_module}_SOURCES "${OPENCV_MODULE_${the_module}_SOURCES}" "${OPENCV_MODULE_${the_module}_${currSubDir}_SOURCES}")
  292. set(OPENCV_MODULE_${the_module}_HEADERS "${OPENCV_MODULE_${the_module}_HEADERS}" "${OPENCV_MODULE_${the_module}_${currSubDir}_HEADERS}")
  293. #message(STATUS "accumulated sources of ${the_module}: ${OPENCV_MODULE_${the_module}_SOURCES}")
  294. #message(STATUS "accumulated headers of ${the_module}: ${OPENCV_MODULE_${the_module}_HEADERS}")
  295. endif()
  296. endif()
  297. endforeach()
  298. endif()
  299. ##################################################
  300. #add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
  301. # message(STATUS "linking source files of ${the_module}: ${OPENCV_MODULE_${the_module}_SOURCES}")
  302. # message(STATUS "linking header files of ${the_module}: ${OPENCV_MODULE_${the_module}_HEADERS}")
  303. add_library(${the_module} ${NICE_BUILD_LIBS_STATIC_SHARED} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
  304. if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
  305. target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
  306. endif()
  307. #jojo add_dependencies(opencv_modules ${the_module})
  308. if(ENABLE_SOLUTION_FOLDERS)
  309. set_target_properties(${the_module} PROPERTIES FOLDER "modules")
  310. endif()
  311. # message(STATUS "LIBRARY_OUTPUT_PATH: ${LIBRARY_OUTPUT_PATH}")
  312. #message(STATUS "EXECUTABLE_OUTPUT_PATH: ${EXECUTABLE_OUTPUT_PATH}")
  313. set_target_properties(${the_module} PROPERTIES
  314. OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
  315. DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
  316. ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
  317. RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
  318. INSTALL_NAME_DIR lib
  319. )
  320. # For dynamic link numbering convenions
  321. if(NOT ANDROID)
  322. # Android SDK build scripts can include only .so files into final .apk
  323. # As result we should not set version properties for Android
  324. set_target_properties(${the_module} PROPERTIES
  325. VERSION ${OPENCV_VERSION}
  326. SOVERSION ${OPENCV_SOVERSION}
  327. )
  328. endif()
  329. if(BUILD_SHARED_LIBS)
  330. if(MSVC)
  331. set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
  332. else()
  333. add_definitions(-DCVAPI_EXPORTS)
  334. endif()
  335. endif()
  336. if(MSVC)
  337. if(CMAKE_CROSSCOMPILING)
  338. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
  339. endif()
  340. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
  341. endif()
  342. install(TARGETS ${the_module}
  343. RUNTIME DESTINATION bin COMPONENT main
  344. LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
  345. ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
  346. )
  347. # only "public" headers need to be installed
  348. if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
  349. foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
  350. string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
  351. if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$")
  352. install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main)
  353. endif()
  354. endforeach()
  355. endif()
  356. endmacro()
  357. # opencv precompiled headers macro (can add pch to modules and tests)
  358. # this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work
  359. # Usage:
  360. # ocv_add_precompiled_headers(${the_module})
  361. macro(ocv_add_precompiled_headers the_target)
  362. if("${the_target}" MATCHES "^opencv_test_.*$")
  363. SET(pch_path "test/test_")
  364. elseif("${the_target}" MATCHES "^opencv_perf_.*$")
  365. SET(pch_path "perf/perf_")
  366. else()
  367. SET(pch_path "src/")
  368. endif()
  369. set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.hpp")
  370. if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}")
  371. if(CMAKE_GENERATOR MATCHES Visual)
  372. set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.cpp")
  373. add_native_precompiled_header(${the_target} ${pch_header})
  374. elseif(CMAKE_GENERATOR MATCHES Xcode)
  375. add_native_precompiled_header(${the_target} ${pch_header})
  376. elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES "Makefiles|Ninja")
  377. add_precompiled_header(${the_target} ${pch_header})
  378. endif()
  379. endif()
  380. unset(pch_header)
  381. unset(pch_path)
  382. unset(${the_target}_pch)
  383. endmacro()