Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3918 рядки
160 KiB

  1. # - cotire (compile time reducer)
  2. #
  3. # See the cotire manual for usage hints.
  4. #
  5. #=============================================================================
  6. # Copyright 2012-2016 Sascha Kratky
  7. #
  8. # Permission is hereby granted, free of charge, to any person
  9. # obtaining a copy of this software and associated documentation
  10. # files (the "Software"), to deal in the Software without
  11. # restriction, including without limitation the rights to use,
  12. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. # copies of the Software, and to permit persons to whom the
  14. # Software is furnished to do so, subject to the following
  15. # conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be
  18. # included in all copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  22. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  24. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  25. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. # OTHER DEALINGS IN THE SOFTWARE.
  28. #=============================================================================
  29. if(__COTIRE_INCLUDED)
  30. return()
  31. endif()
  32. set(__COTIRE_INCLUDED TRUE)
  33. # call cmake_minimum_required, but prevent modification of the CMake policy stack in include mode
  34. # cmake_minimum_required also sets the policy version as a side effect, which we have to avoid
  35. if (NOT CMAKE_SCRIPT_MODE_FILE)
  36. cmake_policy(PUSH)
  37. endif()
  38. cmake_minimum_required(VERSION 2.8.12)
  39. if (NOT CMAKE_SCRIPT_MODE_FILE)
  40. cmake_policy(POP)
  41. endif()
  42. set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}")
  43. set (COTIRE_CMAKE_MODULE_VERSION "1.7.9")
  44. # activate select policies
  45. if (POLICY CMP0025)
  46. # Compiler id for Apple Clang is now AppleClang
  47. cmake_policy(SET CMP0025 NEW)
  48. endif()
  49. if (POLICY CMP0026)
  50. # disallow use of the LOCATION target property
  51. cmake_policy(SET CMP0026 NEW)
  52. endif()
  53. if (POLICY CMP0038)
  54. # targets may not link directly to themselves
  55. cmake_policy(SET CMP0038 NEW)
  56. endif()
  57. if (POLICY CMP0039)
  58. # utility targets may not have link dependencies
  59. cmake_policy(SET CMP0039 NEW)
  60. endif()
  61. if (POLICY CMP0040)
  62. # target in the TARGET signature of add_custom_command() must exist
  63. cmake_policy(SET CMP0040 NEW)
  64. endif()
  65. if (POLICY CMP0045)
  66. # error on non-existent target in get_target_property
  67. cmake_policy(SET CMP0045 NEW)
  68. endif()
  69. if (POLICY CMP0046)
  70. # error on non-existent dependency in add_dependencies
  71. cmake_policy(SET CMP0046 NEW)
  72. endif()
  73. if (POLICY CMP0049)
  74. # do not expand variables in target source entries
  75. cmake_policy(SET CMP0049 NEW)
  76. endif()
  77. if (POLICY CMP0050)
  78. # disallow add_custom_command SOURCE signatures
  79. cmake_policy(SET CMP0050 NEW)
  80. endif()
  81. if (POLICY CMP0051)
  82. # include TARGET_OBJECTS expressions in a target's SOURCES property
  83. cmake_policy(SET CMP0051 NEW)
  84. endif()
  85. if (POLICY CMP0053)
  86. # simplify variable reference and escape sequence evaluation
  87. cmake_policy(SET CMP0053 NEW)
  88. endif()
  89. if (POLICY CMP0054)
  90. # only interpret if() arguments as variables or keywords when unquoted
  91. cmake_policy(SET CMP0054 NEW)
  92. endif()
  93. include(CMakeParseArguments)
  94. include(ProcessorCount)
  95. function (cotire_get_configuration_types _configsVar)
  96. set (_configs "")
  97. if (CMAKE_CONFIGURATION_TYPES)
  98. list (APPEND _configs ${CMAKE_CONFIGURATION_TYPES})
  99. endif()
  100. if (CMAKE_BUILD_TYPE)
  101. list (APPEND _configs "${CMAKE_BUILD_TYPE}")
  102. endif()
  103. if (_configs)
  104. list (REMOVE_DUPLICATES _configs)
  105. set (${_configsVar} ${_configs} PARENT_SCOPE)
  106. else()
  107. set (${_configsVar} "None" PARENT_SCOPE)
  108. endif()
  109. endfunction()
  110. function (cotire_get_source_file_extension _sourceFile _extVar)
  111. # get_filename_component returns extension from first occurrence of . in file name
  112. # this function computes the extension from last occurrence of . in file name
  113. string (FIND "${_sourceFile}" "." _index REVERSE)
  114. if (_index GREATER -1)
  115. math (EXPR _index "${_index} + 1")
  116. string (SUBSTRING "${_sourceFile}" ${_index} -1 _sourceExt)
  117. else()
  118. set (_sourceExt "")
  119. endif()
  120. set (${_extVar} "${_sourceExt}" PARENT_SCOPE)
  121. endfunction()
  122. macro (cotire_check_is_path_relative_to _path _isRelativeVar)
  123. set (${_isRelativeVar} FALSE)
  124. if (IS_ABSOLUTE "${_path}")
  125. foreach (_dir ${ARGN})
  126. file (RELATIVE_PATH _relPath "${_dir}" "${_path}")
  127. if (NOT _relPath OR (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\."))
  128. set (${_isRelativeVar} TRUE)
  129. break()
  130. endif()
  131. endforeach()
  132. endif()
  133. endmacro()
  134. function (cotire_filter_language_source_files _language _target _sourceFilesVar _excludedSourceFilesVar _cotiredSourceFilesVar)
  135. if (CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  136. set (_languageExtensions "${CMAKE_${_language}_SOURCE_FILE_EXTENSIONS}")
  137. else()
  138. set (_languageExtensions "")
  139. endif()
  140. if (CMAKE_${_language}_IGNORE_EXTENSIONS)
  141. set (_ignoreExtensions "${CMAKE_${_language}_IGNORE_EXTENSIONS}")
  142. else()
  143. set (_ignoreExtensions "")
  144. endif()
  145. if (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS)
  146. set (_excludeExtensions "${COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS}")
  147. else()
  148. set (_excludeExtensions "")
  149. endif()
  150. if (COTIRE_DEBUG AND _languageExtensions)
  151. message (STATUS "${_language} source file extensions: ${_languageExtensions}")
  152. endif()
  153. if (COTIRE_DEBUG AND _ignoreExtensions)
  154. message (STATUS "${_language} ignore extensions: ${_ignoreExtensions}")
  155. endif()
  156. if (COTIRE_DEBUG AND _excludeExtensions)
  157. message (STATUS "${_language} exclude extensions: ${_excludeExtensions}")
  158. endif()
  159. if (CMAKE_VERSION VERSION_LESS "3.1.0")
  160. set (_allSourceFiles ${ARGN})
  161. else()
  162. # as of CMake 3.1 target sources may contain generator expressions
  163. # since we cannot obtain required property information about source files added
  164. # through generator expressions at configure time, we filter them out
  165. string (GENEX_STRIP "${ARGN}" _allSourceFiles)
  166. endif()
  167. set (_filteredSourceFiles "")
  168. set (_excludedSourceFiles "")
  169. foreach (_sourceFile ${_allSourceFiles})
  170. get_source_file_property(_sourceIsHeaderOnly "${_sourceFile}" HEADER_FILE_ONLY)
  171. get_source_file_property(_sourceIsExternal "${_sourceFile}" EXTERNAL_OBJECT)
  172. get_source_file_property(_sourceIsSymbolic "${_sourceFile}" SYMBOLIC)
  173. if (NOT _sourceIsHeaderOnly AND NOT _sourceIsExternal AND NOT _sourceIsSymbolic)
  174. cotire_get_source_file_extension("${_sourceFile}" _sourceExt)
  175. if (_sourceExt)
  176. list (FIND _ignoreExtensions "${_sourceExt}" _ignoreIndex)
  177. if (_ignoreIndex LESS 0)
  178. list (FIND _excludeExtensions "${_sourceExt}" _excludeIndex)
  179. if (_excludeIndex GREATER -1)
  180. list (APPEND _excludedSourceFiles "${_sourceFile}")
  181. else()
  182. list (FIND _languageExtensions "${_sourceExt}" _sourceIndex)
  183. if (_sourceIndex GREATER -1)
  184. # consider source file unless it is excluded explicitly
  185. get_source_file_property(_sourceIsExcluded "${_sourceFile}" COTIRE_EXCLUDED)
  186. if (_sourceIsExcluded)
  187. list (APPEND _excludedSourceFiles "${_sourceFile}")
  188. else()
  189. list (APPEND _filteredSourceFiles "${_sourceFile}")
  190. endif()
  191. else()
  192. get_source_file_property(_sourceLanguage "${_sourceFile}" LANGUAGE)
  193. if ("${_sourceLanguage}" STREQUAL "${_language}")
  194. # add to excluded sources, if file is not ignored and has correct language without having the correct extension
  195. list (APPEND _excludedSourceFiles "${_sourceFile}")
  196. endif()
  197. endif()
  198. endif()
  199. endif()
  200. endif()
  201. endif()
  202. endforeach()
  203. # separate filtered source files from already cotired ones
  204. # the COTIRE_TARGET property of a source file may be set while a target is being processed by cotire
  205. set (_sourceFiles "")
  206. set (_cotiredSourceFiles "")
  207. foreach (_sourceFile ${_filteredSourceFiles})
  208. get_source_file_property(_sourceIsCotired "${_sourceFile}" COTIRE_TARGET)
  209. if (_sourceIsCotired)
  210. list (APPEND _cotiredSourceFiles "${_sourceFile}")
  211. else()
  212. get_source_file_property(_sourceCompileFlags "${_sourceFile}" COMPILE_FLAGS)
  213. if (_sourceCompileFlags)
  214. # add to excluded sources, if file has custom compile flags
  215. list (APPEND _excludedSourceFiles "${_sourceFile}")
  216. else()
  217. list (APPEND _sourceFiles "${_sourceFile}")
  218. endif()
  219. endif()
  220. endforeach()
  221. if (COTIRE_DEBUG)
  222. if (_sourceFiles)
  223. message (STATUS "Filtered ${_target} ${_language} sources: ${_sourceFiles}")
  224. endif()
  225. if (_excludedSourceFiles)
  226. message (STATUS "Excluded ${_target} ${_language} sources: ${_excludedSourceFiles}")
  227. endif()
  228. if (_cotiredSourceFiles)
  229. message (STATUS "Cotired ${_target} ${_language} sources: ${_cotiredSourceFiles}")
  230. endif()
  231. endif()
  232. set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE)
  233. set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE)
  234. set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE)
  235. endfunction()
  236. function (cotire_get_objects_with_property_on _filteredObjectsVar _property _type)
  237. set (_filteredObjects "")
  238. foreach (_object ${ARGN})
  239. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  240. if (_isSet)
  241. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  242. if (_propertyValue)
  243. list (APPEND _filteredObjects "${_object}")
  244. endif()
  245. endif()
  246. endforeach()
  247. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  248. endfunction()
  249. function (cotire_get_objects_with_property_off _filteredObjectsVar _property _type)
  250. set (_filteredObjects "")
  251. foreach (_object ${ARGN})
  252. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  253. if (_isSet)
  254. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  255. if (NOT _propertyValue)
  256. list (APPEND _filteredObjects "${_object}")
  257. endif()
  258. endif()
  259. endforeach()
  260. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  261. endfunction()
  262. function (cotire_get_source_file_property_values _valuesVar _property)
  263. set (_values "")
  264. foreach (_sourceFile ${ARGN})
  265. get_source_file_property(_propertyValue "${_sourceFile}" ${_property})
  266. if (_propertyValue)
  267. list (APPEND _values "${_propertyValue}")
  268. endif()
  269. endforeach()
  270. set (${_valuesVar} ${_values} PARENT_SCOPE)
  271. endfunction()
  272. function (cotire_resolve_config_properites _configurations _propertiesVar)
  273. set (_properties "")
  274. foreach (_property ${ARGN})
  275. if ("${_property}" MATCHES "<CONFIG>")
  276. foreach (_config ${_configurations})
  277. string (TOUPPER "${_config}" _upperConfig)
  278. string (REPLACE "<CONFIG>" "${_upperConfig}" _configProperty "${_property}")
  279. list (APPEND _properties ${_configProperty})
  280. endforeach()
  281. else()
  282. list (APPEND _properties ${_property})
  283. endif()
  284. endforeach()
  285. set (${_propertiesVar} ${_properties} PARENT_SCOPE)
  286. endfunction()
  287. function (cotire_copy_set_properites _configurations _type _source _target)
  288. cotire_resolve_config_properites("${_configurations}" _properties ${ARGN})
  289. foreach (_property ${_properties})
  290. get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET)
  291. if (_isSet)
  292. get_property(_propertyValue ${_type} ${_source} PROPERTY ${_property})
  293. set_property(${_type} ${_target} PROPERTY ${_property} "${_propertyValue}")
  294. endif()
  295. endforeach()
  296. endfunction()
  297. function (cotire_get_target_usage_requirements _target _targetRequirementsVar)
  298. set (_targetRequirements "")
  299. get_target_property(_librariesToProcess ${_target} LINK_LIBRARIES)
  300. while (_librariesToProcess)
  301. # remove from head
  302. list (GET _librariesToProcess 0 _library)
  303. list (REMOVE_AT _librariesToProcess 0)
  304. if (TARGET ${_library})
  305. list (FIND _targetRequirements ${_library} _index)
  306. if (_index LESS 0)
  307. list (APPEND _targetRequirements ${_library})
  308. # BFS traversal of transitive libraries
  309. get_target_property(_libraries ${_library} INTERFACE_LINK_LIBRARIES)
  310. if (_libraries)
  311. list (APPEND _librariesToProcess ${_libraries})
  312. list (REMOVE_DUPLICATES _librariesToProcess)
  313. endif()
  314. endif()
  315. endif()
  316. endwhile()
  317. set (${_targetRequirementsVar} ${_targetRequirements} PARENT_SCOPE)
  318. endfunction()
  319. function (cotire_filter_compile_flags _language _flagFilter _matchedOptionsVar _unmatchedOptionsVar)
  320. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  321. set (_flagPrefix "[/-]")
  322. else()
  323. set (_flagPrefix "--?")
  324. endif()
  325. set (_optionFlag "")
  326. set (_matchedOptions "")
  327. set (_unmatchedOptions "")
  328. foreach (_compileFlag ${ARGN})
  329. if (_compileFlag)
  330. if (_optionFlag AND NOT "${_compileFlag}" MATCHES "^${_flagPrefix}")
  331. # option with separate argument
  332. list (APPEND _matchedOptions "${_compileFlag}")
  333. set (_optionFlag "")
  334. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$")
  335. # remember option
  336. set (_optionFlag "${CMAKE_MATCH_2}")
  337. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})(.+)$")
  338. # option with joined argument
  339. list (APPEND _matchedOptions "${CMAKE_MATCH_3}")
  340. set (_optionFlag "")
  341. else()
  342. # flush remembered option
  343. if (_optionFlag)
  344. list (APPEND _matchedOptions "${_optionFlag}")
  345. set (_optionFlag "")
  346. endif()
  347. # add to unfiltered options
  348. list (APPEND _unmatchedOptions "${_compileFlag}")
  349. endif()
  350. endif()
  351. endforeach()
  352. if (_optionFlag)
  353. list (APPEND _matchedOptions "${_optionFlag}")
  354. endif()
  355. if (COTIRE_DEBUG AND _matchedOptions)
  356. message (STATUS "Filter ${_flagFilter} matched: ${_matchedOptions}")
  357. endif()
  358. if (COTIRE_DEBUG AND _unmatchedOptions)
  359. message (STATUS "Filter ${_flagFilter} unmatched: ${_unmatchedOptions}")
  360. endif()
  361. set (${_matchedOptionsVar} ${_matchedOptions} PARENT_SCOPE)
  362. set (${_unmatchedOptionsVar} ${_unmatchedOptions} PARENT_SCOPE)
  363. endfunction()
  364. function (cotire_is_target_supported _target _isSupportedVar)
  365. if (NOT TARGET "${_target}")
  366. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  367. return()
  368. endif()
  369. get_target_property(_imported ${_target} IMPORTED)
  370. if (_imported)
  371. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  372. return()
  373. endif()
  374. get_target_property(_targetType ${_target} TYPE)
  375. if (NOT _targetType MATCHES "EXECUTABLE|(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  376. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  377. return()
  378. endif()
  379. set (${_isSupportedVar} TRUE PARENT_SCOPE)
  380. endfunction()
  381. function (cotire_get_target_compile_flags _config _language _target _flagsVar)
  382. string (TOUPPER "${_config}" _upperConfig)
  383. # collect options from CMake language variables
  384. set (_compileFlags "")
  385. if (CMAKE_${_language}_FLAGS)
  386. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS}")
  387. endif()
  388. if (CMAKE_${_language}_FLAGS_${_upperConfig})
  389. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS_${_upperConfig}}")
  390. endif()
  391. if (_target)
  392. # add target compile flags
  393. get_target_property(_targetflags ${_target} COMPILE_FLAGS)
  394. if (_targetflags)
  395. set (_compileFlags "${_compileFlags} ${_targetflags}")
  396. endif()
  397. endif()
  398. if (UNIX)
  399. separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}")
  400. elseif(WIN32)
  401. separate_arguments(_compileFlags WINDOWS_COMMAND "${_compileFlags}")
  402. else()
  403. separate_arguments(_compileFlags)
  404. endif()
  405. # target compile options
  406. if (_target)
  407. get_target_property(_targetOptions ${_target} COMPILE_OPTIONS)
  408. if (_targetOptions)
  409. list (APPEND _compileFlags ${_targetOptions})
  410. endif()
  411. endif()
  412. # interface compile options from linked library targets
  413. if (_target)
  414. set (_linkedTargets "")
  415. cotire_get_target_usage_requirements(${_target} _linkedTargets)
  416. foreach (_linkedTarget ${_linkedTargets})
  417. get_target_property(_targetOptions ${_linkedTarget} INTERFACE_COMPILE_OPTIONS)
  418. if (_targetOptions)
  419. list (APPEND _compileFlags ${_targetOptions})
  420. endif()
  421. endforeach()
  422. endif()
  423. # handle language standard properties
  424. if (_target)
  425. get_target_property(_targetLanguageStandard ${_target} ${_language}_STANDARD)
  426. get_target_property(_targetLanguageExtensions ${_target} ${_language}_EXTENSIONS)
  427. get_target_property(_targetLanguageStandardRequired ${_target} ${_language}_STANDARD_REQUIRED)
  428. if (_targetLanguageExtensions)
  429. if (CMAKE_${_language}${_targetLanguageExtensions}_EXTENSION_COMPILE_OPTION)
  430. list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageExtensions}_EXTENSION_COMPILE_OPTION}")
  431. endif()
  432. elseif (_targetLanguageStandard)
  433. if (_targetLanguageStandardRequired)
  434. if (CMAKE_${_language}${_targetLanguageStandard}_STANDARD_COMPILE_OPTION)
  435. list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageStandard}_STANDARD_COMPILE_OPTION}")
  436. endif()
  437. else()
  438. if (CMAKE_${_language}${_targetLanguageStandard}_EXTENSION_COMPILE_OPTION)
  439. list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageStandard}_EXTENSION_COMPILE_OPTION}")
  440. endif()
  441. endif()
  442. endif()
  443. endif()
  444. # handle the POSITION_INDEPENDENT_CODE target property
  445. if (_target)
  446. get_target_property(_targetPIC ${_target} POSITION_INDEPENDENT_CODE)
  447. if (_targetPIC)
  448. get_target_property(_targetType ${_target} TYPE)
  449. if (_targetType STREQUAL "EXECUTABLE" AND CMAKE_${_language}_COMPILE_OPTIONS_PIE)
  450. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIE}")
  451. elseif (CMAKE_${_language}_COMPILE_OPTIONS_PIC)
  452. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIC}")
  453. endif()
  454. endif()
  455. endif()
  456. # handle visibility target properties
  457. if (_target)
  458. get_target_property(_targetVisibility ${_target} ${_language}_VISIBILITY_PRESET)
  459. if (_targetVisibility AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY)
  460. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY}${_targetVisibility}")
  461. endif()
  462. get_target_property(_targetVisibilityInlines ${_target} VISIBILITY_INLINES_HIDDEN)
  463. if (_targetVisibilityInlines AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN)
  464. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}")
  465. endif()
  466. endif()
  467. # platform specific flags
  468. if (APPLE)
  469. get_target_property(_architectures ${_target} OSX_ARCHITECTURES_${_upperConfig})
  470. if (NOT _architectures)
  471. get_target_property(_architectures ${_target} OSX_ARCHITECTURES)
  472. endif()
  473. if (_architectures)
  474. foreach (_arch ${_architectures})
  475. list (APPEND _compileFlags "-arch" "${_arch}")
  476. endforeach()
  477. endif()
  478. if (CMAKE_OSX_SYSROOT)
  479. if (CMAKE_${_language}_SYSROOT_FLAG)
  480. list (APPEND _compileFlags "${CMAKE_${_language}_SYSROOT_FLAG}" "${CMAKE_OSX_SYSROOT}")
  481. else()
  482. list (APPEND _compileFlags "-isysroot" "${CMAKE_OSX_SYSROOT}")
  483. endif()
  484. endif()
  485. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  486. if (CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG)
  487. list (APPEND _compileFlags "${CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}")
  488. else()
  489. list (APPEND _compileFlags "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  490. endif()
  491. endif()
  492. endif()
  493. if (COTIRE_DEBUG AND _compileFlags)
  494. message (STATUS "Target ${_target} compile flags: ${_compileFlags}")
  495. endif()
  496. set (${_flagsVar} ${_compileFlags} PARENT_SCOPE)
  497. endfunction()
  498. function (cotire_get_target_include_directories _config _language _target _includeDirsVar _systemIncludeDirsVar)
  499. set (_includeDirs "")
  500. set (_systemIncludeDirs "")
  501. # default include dirs
  502. if (CMAKE_INCLUDE_CURRENT_DIR)
  503. list (APPEND _includeDirs "${CMAKE_CURRENT_BINARY_DIR}")
  504. list (APPEND _includeDirs "${CMAKE_CURRENT_SOURCE_DIR}")
  505. endif()
  506. set (_targetFlags "")
  507. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  508. # parse additional include directories from target compile flags
  509. if (CMAKE_INCLUDE_FLAG_${_language})
  510. string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
  511. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  512. if (_includeFlag)
  513. set (_dirs "")
  514. cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
  515. if (_dirs)
  516. list (APPEND _includeDirs ${_dirs})
  517. endif()
  518. endif()
  519. endif()
  520. # parse additional system include directories from target compile flags
  521. if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
  522. string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
  523. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  524. if (_includeFlag)
  525. set (_dirs "")
  526. cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
  527. if (_dirs)
  528. list (APPEND _systemIncludeDirs ${_dirs})
  529. endif()
  530. endif()
  531. endif()
  532. # target include directories
  533. get_directory_property(_dirs DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" INCLUDE_DIRECTORIES)
  534. if (_target)
  535. get_target_property(_targetDirs ${_target} INCLUDE_DIRECTORIES)
  536. if (_targetDirs)
  537. list (APPEND _dirs ${_targetDirs})
  538. endif()
  539. get_target_property(_targetDirs ${_target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
  540. if (_targetDirs)
  541. list (APPEND _systemIncludeDirs ${_targetDirs})
  542. endif()
  543. endif()
  544. # interface include directories from linked library targets
  545. if (_target)
  546. set (_linkedTargets "")
  547. cotire_get_target_usage_requirements(${_target} _linkedTargets)
  548. foreach (_linkedTarget ${_linkedTargets})
  549. get_target_property(_linkedTargetType ${_linkedTarget} TYPE)
  550. if (CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE AND NOT CMAKE_VERSION VERSION_LESS "3.4.0" AND
  551. _linkedTargetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  552. # CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE refers to CMAKE_CURRENT_BINARY_DIR and CMAKE_CURRENT_SOURCE_DIR
  553. # at the time, when the target was created. These correspond to the target properties BINARY_DIR and SOURCE_DIR
  554. # which are only available with CMake 3.4 or later.
  555. get_target_property(_targetDirs ${_linkedTarget} BINARY_DIR)
  556. if (_targetDirs)
  557. list (APPEND _dirs ${_targetDirs})
  558. endif()
  559. get_target_property(_targetDirs ${_linkedTarget} SOURCE_DIR)
  560. if (_targetDirs)
  561. list (APPEND _dirs ${_targetDirs})
  562. endif()
  563. endif()
  564. get_target_property(_targetDirs ${_linkedTarget} INTERFACE_INCLUDE_DIRECTORIES)
  565. if (_targetDirs)
  566. list (APPEND _dirs ${_targetDirs})
  567. endif()
  568. get_target_property(_targetDirs ${_linkedTarget} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
  569. if (_targetDirs)
  570. list (APPEND _systemIncludeDirs ${_targetDirs})
  571. endif()
  572. endforeach()
  573. endif()
  574. if (dirs)
  575. list (REMOVE_DUPLICATES _dirs)
  576. endif()
  577. list (LENGTH _includeDirs _projectInsertIndex)
  578. foreach (_dir ${_dirs})
  579. if (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE)
  580. cotire_check_is_path_relative_to("${_dir}" _isRelative "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
  581. if (_isRelative)
  582. list (LENGTH _includeDirs _len)
  583. if (_len EQUAL _projectInsertIndex)
  584. list (APPEND _includeDirs "${_dir}")
  585. else()
  586. list (INSERT _includeDirs _projectInsertIndex "${_dir}")
  587. endif()
  588. math (EXPR _projectInsertIndex "${_projectInsertIndex} + 1")
  589. else()
  590. list (APPEND _includeDirs "${_dir}")
  591. endif()
  592. else()
  593. list (APPEND _includeDirs "${_dir}")
  594. endif()
  595. endforeach()
  596. list (REMOVE_DUPLICATES _includeDirs)
  597. list (REMOVE_DUPLICATES _systemIncludeDirs)
  598. if (CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES)
  599. list (REMOVE_ITEM _includeDirs ${CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES})
  600. endif()
  601. if (COTIRE_DEBUG AND _includeDirs)
  602. message (STATUS "Target ${_target} include dirs: ${_includeDirs}")
  603. endif()
  604. set (${_includeDirsVar} ${_includeDirs} PARENT_SCOPE)
  605. if (COTIRE_DEBUG AND _systemIncludeDirs)
  606. message (STATUS "Target ${_target} system include dirs: ${_systemIncludeDirs}")
  607. endif()
  608. set (${_systemIncludeDirsVar} ${_systemIncludeDirs} PARENT_SCOPE)
  609. endfunction()
  610. function (cotire_get_target_export_symbol _target _exportSymbolVar)
  611. set (_exportSymbol "")
  612. get_target_property(_targetType ${_target} TYPE)
  613. get_target_property(_enableExports ${_target} ENABLE_EXPORTS)
  614. if (_targetType MATCHES "(SHARED|MODULE)_LIBRARY" OR
  615. (_targetType STREQUAL "EXECUTABLE" AND _enableExports))
  616. get_target_property(_exportSymbol ${_target} DEFINE_SYMBOL)
  617. if (NOT _exportSymbol)
  618. set (_exportSymbol "${_target}_EXPORTS")
  619. endif()
  620. string (MAKE_C_IDENTIFIER "${_exportSymbol}" _exportSymbol)
  621. endif()
  622. set (${_exportSymbolVar} ${_exportSymbol} PARENT_SCOPE)
  623. endfunction()
  624. function (cotire_get_target_compile_definitions _config _language _target _definitionsVar)
  625. string (TOUPPER "${_config}" _upperConfig)
  626. set (_configDefinitions "")
  627. # CMAKE_INTDIR for multi-configuration build systems
  628. if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
  629. list (APPEND _configDefinitions "CMAKE_INTDIR=\"${_config}\"")
  630. endif()
  631. # target export define symbol
  632. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  633. if (_defineSymbol)
  634. list (APPEND _configDefinitions "${_defineSymbol}")
  635. endif()
  636. # directory compile definitions
  637. get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS)
  638. if (_definitions)
  639. list (APPEND _configDefinitions ${_definitions})
  640. endif()
  641. get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS_${_upperConfig})
  642. if (_definitions)
  643. list (APPEND _configDefinitions ${_definitions})
  644. endif()
  645. # target compile definitions
  646. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS)
  647. if (_definitions)
  648. list (APPEND _configDefinitions ${_definitions})
  649. endif()
  650. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS_${_upperConfig})
  651. if (_definitions)
  652. list (APPEND _configDefinitions ${_definitions})
  653. endif()
  654. # interface compile definitions from linked library targets
  655. set (_linkedTargets "")
  656. cotire_get_target_usage_requirements(${_target} _linkedTargets)
  657. foreach (_linkedTarget ${_linkedTargets})
  658. get_target_property(_definitions ${_linkedTarget} INTERFACE_COMPILE_DEFINITIONS)
  659. if (_definitions)
  660. list (APPEND _configDefinitions ${_definitions})
  661. endif()
  662. endforeach()
  663. # parse additional compile definitions from target compile flags
  664. # and don't look at directory compile definitions, which we already handled
  665. set (_targetFlags "")
  666. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  667. cotire_filter_compile_flags("${_language}" "D" _definitions _ignore ${_targetFlags})
  668. if (_definitions)
  669. list (APPEND _configDefinitions ${_definitions})
  670. endif()
  671. list (REMOVE_DUPLICATES _configDefinitions)
  672. if (COTIRE_DEBUG AND _configDefinitions)
  673. message (STATUS "Target ${_target} compile definitions: ${_configDefinitions}")
  674. endif()
  675. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  676. endfunction()
  677. function (cotire_get_target_compiler_flags _config _language _target _compilerFlagsVar)
  678. # parse target compile flags omitting compile definitions and include directives
  679. set (_targetFlags "")
  680. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  681. set (_flagFilter "D")
  682. if (CMAKE_INCLUDE_FLAG_${_language})
  683. string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
  684. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  685. if (_includeFlag)
  686. set (_flagFilter "${_flagFilter}|${_includeFlag}")
  687. endif()
  688. endif()
  689. if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
  690. string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
  691. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  692. if (_includeFlag)
  693. set (_flagFilter "${_flagFilter}|${_includeFlag}")
  694. endif()
  695. endif()
  696. set (_compilerFlags "")
  697. cotire_filter_compile_flags("${_language}" "${_flagFilter}" _ignore _compilerFlags ${_targetFlags})
  698. if (COTIRE_DEBUG AND _compilerFlags)
  699. message (STATUS "Target ${_target} compiler flags: ${_compilerFlags}")
  700. endif()
  701. set (${_compilerFlagsVar} ${_compilerFlags} PARENT_SCOPE)
  702. endfunction()
  703. function (cotire_add_sys_root_paths _pathsVar)
  704. if (APPLE)
  705. if (CMAKE_OSX_SYSROOT AND CMAKE_${_language}_HAS_ISYSROOT)
  706. foreach (_path IN LISTS ${_pathsVar})
  707. if (IS_ABSOLUTE "${_path}")
  708. get_filename_component(_path "${CMAKE_OSX_SYSROOT}/${_path}" ABSOLUTE)
  709. if (EXISTS "${_path}")
  710. list (APPEND ${_pathsVar} "${_path}")
  711. endif()
  712. endif()
  713. endforeach()
  714. endif()
  715. endif()
  716. set (${_pathsVar} ${${_pathsVar}} PARENT_SCOPE)
  717. endfunction()
  718. function (cotire_get_source_extra_properties _sourceFile _pattern _resultVar)
  719. set (_extraProperties ${ARGN})
  720. set (_result "")
  721. if (_extraProperties)
  722. list (FIND _extraProperties "${_sourceFile}" _index)
  723. if (_index GREATER -1)
  724. math (EXPR _index "${_index} + 1")
  725. list (LENGTH _extraProperties _len)
  726. math (EXPR _len "${_len} - 1")
  727. foreach (_index RANGE ${_index} ${_len})
  728. list (GET _extraProperties ${_index} _value)
  729. if (_value MATCHES "${_pattern}")
  730. list (APPEND _result "${_value}")
  731. else()
  732. break()
  733. endif()
  734. endforeach()
  735. endif()
  736. endif()
  737. set (${_resultVar} ${_result} PARENT_SCOPE)
  738. endfunction()
  739. function (cotire_get_source_compile_definitions _config _language _sourceFile _definitionsVar)
  740. set (_compileDefinitions "")
  741. if (NOT CMAKE_SCRIPT_MODE_FILE)
  742. string (TOUPPER "${_config}" _upperConfig)
  743. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS)
  744. if (_definitions)
  745. list (APPEND _compileDefinitions ${_definitions})
  746. endif()
  747. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS_${_upperConfig})
  748. if (_definitions)
  749. list (APPEND _compileDefinitions ${_definitions})
  750. endif()
  751. endif()
  752. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+(=.*)?$" _definitions ${ARGN})
  753. if (_definitions)
  754. list (APPEND _compileDefinitions ${_definitions})
  755. endif()
  756. if (COTIRE_DEBUG AND _compileDefinitions)
  757. message (STATUS "Source ${_sourceFile} compile definitions: ${_compileDefinitions}")
  758. endif()
  759. set (${_definitionsVar} ${_compileDefinitions} PARENT_SCOPE)
  760. endfunction()
  761. function (cotire_get_source_files_compile_definitions _config _language _definitionsVar)
  762. set (_configDefinitions "")
  763. foreach (_sourceFile ${ARGN})
  764. cotire_get_source_compile_definitions("${_config}" "${_language}" "${_sourceFile}" _sourceDefinitions)
  765. if (_sourceDefinitions)
  766. list (APPEND _configDefinitions "${_sourceFile}" ${_sourceDefinitions} "-")
  767. endif()
  768. endforeach()
  769. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  770. endfunction()
  771. function (cotire_get_source_undefs _sourceFile _property _sourceUndefsVar)
  772. set (_sourceUndefs "")
  773. if (NOT CMAKE_SCRIPT_MODE_FILE)
  774. get_source_file_property(_undefs "${_sourceFile}" ${_property})
  775. if (_undefs)
  776. list (APPEND _sourceUndefs ${_undefs})
  777. endif()
  778. endif()
  779. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+$" _undefs ${ARGN})
  780. if (_undefs)
  781. list (APPEND _sourceUndefs ${_undefs})
  782. endif()
  783. if (COTIRE_DEBUG AND _sourceUndefs)
  784. message (STATUS "Source ${_sourceFile} ${_property} undefs: ${_sourceUndefs}")
  785. endif()
  786. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  787. endfunction()
  788. function (cotire_get_source_files_undefs _property _sourceUndefsVar)
  789. set (_sourceUndefs "")
  790. foreach (_sourceFile ${ARGN})
  791. cotire_get_source_undefs("${_sourceFile}" ${_property} _undefs)
  792. if (_undefs)
  793. list (APPEND _sourceUndefs "${_sourceFile}" ${_undefs} "-")
  794. endif()
  795. endforeach()
  796. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  797. endfunction()
  798. macro (cotire_set_cmd_to_prologue _cmdVar)
  799. set (${_cmdVar} "${CMAKE_COMMAND}")
  800. if (COTIRE_DEBUG)
  801. list (APPEND ${_cmdVar} "--warn-uninitialized")
  802. endif()
  803. list (APPEND ${_cmdVar} "-DCOTIRE_BUILD_TYPE:STRING=$<CONFIGURATION>")
  804. if (COTIRE_VERBOSE)
  805. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=ON")
  806. elseif("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  807. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=$(VERBOSE)")
  808. endif()
  809. endmacro()
  810. function (cotire_init_compile_cmd _cmdVar _language _compilerLauncher _compilerExe _compilerArg1)
  811. if (NOT _compilerLauncher)
  812. set (_compilerLauncher ${CMAKE_${_language}_COMPILER_LAUNCHER})
  813. endif()
  814. if (NOT _compilerExe)
  815. set (_compilerExe "${CMAKE_${_language}_COMPILER}")
  816. endif()
  817. if (NOT _compilerArg1)
  818. set (_compilerArg1 ${CMAKE_${_language}_COMPILER_ARG1})
  819. endif()
  820. string (STRIP "${_compilerArg1}" _compilerArg1)
  821. if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  822. # compiler launcher is only supported for Makefile and Ninja
  823. set (${_cmdVar} ${_compilerLauncher} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
  824. else()
  825. set (${_cmdVar} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
  826. endif()
  827. endfunction()
  828. macro (cotire_add_definitions_to_cmd _cmdVar _language)
  829. foreach (_definition ${ARGN})
  830. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  831. list (APPEND ${_cmdVar} "/D${_definition}")
  832. else()
  833. list (APPEND ${_cmdVar} "-D${_definition}")
  834. endif()
  835. endforeach()
  836. endmacro()
  837. function (cotire_add_includes_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
  838. set (_includeDirs ${${_includesVar}} ${${_systemIncludesVar}})
  839. if (_includeDirs)
  840. list (REMOVE_DUPLICATES _includeDirs)
  841. foreach (_include ${_includeDirs})
  842. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  843. file (TO_NATIVE_PATH "${_include}" _include)
  844. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_${_language}_SEP}${_include}")
  845. else()
  846. set (_index -1)
  847. if ("${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" MATCHES ".+")
  848. list (FIND ${_systemIncludesVar} "${_include}" _index)
  849. endif()
  850. if (_index GREATER -1)
  851. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}${_include}")
  852. else()
  853. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_${_language}_SEP}${_include}")
  854. endif()
  855. endif()
  856. endforeach()
  857. endif()
  858. set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
  859. endfunction()
  860. function (cotire_add_frameworks_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
  861. if (APPLE)
  862. set (_frameworkDirs "")
  863. foreach (_include ${${_includesVar}})
  864. if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
  865. get_filename_component(_frameworkDir "${_include}" DIRECTORY)
  866. list (APPEND _frameworkDirs "${_frameworkDir}")
  867. endif()
  868. endforeach()
  869. set (_systemFrameworkDirs "")
  870. foreach (_include ${${_systemIncludesVar}})
  871. if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
  872. get_filename_component(_frameworkDir "${_include}" DIRECTORY)
  873. list (APPEND _systemFrameworkDirs "${_frameworkDir}")
  874. endif()
  875. endforeach()
  876. if (_systemFrameworkDirs)
  877. list (APPEND _frameworkDirs ${_systemFrameworkDirs})
  878. endif()
  879. if (_frameworkDirs)
  880. list (REMOVE_DUPLICATES _frameworkDirs)
  881. foreach (_frameworkDir ${_frameworkDirs})
  882. set (_index -1)
  883. if ("${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}" MATCHES ".+")
  884. list (FIND _systemFrameworkDirs "${_frameworkDir}" _index)
  885. endif()
  886. if (_index GREATER -1)
  887. list (APPEND ${_cmdVar} "${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
  888. else()
  889. list (APPEND ${_cmdVar} "${CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
  890. endif()
  891. endforeach()
  892. endif()
  893. endif()
  894. set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
  895. endfunction()
  896. macro (cotire_add_compile_flags_to_cmd _cmdVar)
  897. foreach (_flag ${ARGN})
  898. list (APPEND ${_cmdVar} "${_flag}")
  899. endforeach()
  900. endmacro()
  901. function (cotire_check_file_up_to_date _fileIsUpToDateVar _file)
  902. if (EXISTS "${_file}")
  903. set (_triggerFile "")
  904. foreach (_dependencyFile ${ARGN})
  905. if (EXISTS "${_dependencyFile}")
  906. # IS_NEWER_THAN returns TRUE if both files have the same timestamp
  907. # thus we do the comparison in both directions to exclude ties
  908. if ("${_dependencyFile}" IS_NEWER_THAN "${_file}" AND
  909. NOT "${_file}" IS_NEWER_THAN "${_dependencyFile}")
  910. set (_triggerFile "${_dependencyFile}")
  911. break()
  912. endif()
  913. endif()
  914. endforeach()
  915. if (_triggerFile)
  916. if (COTIRE_VERBOSE)
  917. get_filename_component(_fileName "${_file}" NAME)
  918. message (STATUS "${_fileName} update triggered by ${_triggerFile} change.")
  919. endif()
  920. set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
  921. else()
  922. if (COTIRE_VERBOSE)
  923. get_filename_component(_fileName "${_file}" NAME)
  924. message (STATUS "${_fileName} is up-to-date.")
  925. endif()
  926. set (${_fileIsUpToDateVar} TRUE PARENT_SCOPE)
  927. endif()
  928. else()
  929. if (COTIRE_VERBOSE)
  930. get_filename_component(_fileName "${_file}" NAME)
  931. message (STATUS "${_fileName} does not exist yet.")
  932. endif()
  933. set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
  934. endif()
  935. endfunction()
  936. macro (cotire_find_closest_relative_path _headerFile _includeDirs _relPathVar)
  937. set (${_relPathVar} "")
  938. foreach (_includeDir ${_includeDirs})
  939. if (IS_DIRECTORY "${_includeDir}")
  940. file (RELATIVE_PATH _relPath "${_includeDir}" "${_headerFile}")
  941. if (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.")
  942. string (LENGTH "${${_relPathVar}}" _closestLen)
  943. string (LENGTH "${_relPath}" _relLen)
  944. if (_closestLen EQUAL 0 OR _relLen LESS _closestLen)
  945. set (${_relPathVar} "${_relPath}")
  946. endif()
  947. endif()
  948. elseif ("${_includeDir}" STREQUAL "${_headerFile}")
  949. # if path matches exactly, return short non-empty string
  950. set (${_relPathVar} "1")
  951. break()
  952. endif()
  953. endforeach()
  954. endmacro()
  955. macro (cotire_check_header_file_location _headerFile _insideIncludeDirs _outsideIncludeDirs _headerIsInside)
  956. # check header path against ignored and honored include directories
  957. cotire_find_closest_relative_path("${_headerFile}" "${_insideIncludeDirs}" _insideRelPath)
  958. if (_insideRelPath)
  959. # header is inside, but could be become outside if there is a shorter outside match
  960. cotire_find_closest_relative_path("${_headerFile}" "${_outsideIncludeDirs}" _outsideRelPath)
  961. if (_outsideRelPath)
  962. string (LENGTH "${_insideRelPath}" _insideRelPathLen)
  963. string (LENGTH "${_outsideRelPath}" _outsideRelPathLen)
  964. if (_outsideRelPathLen LESS _insideRelPathLen)
  965. set (${_headerIsInside} FALSE)
  966. else()
  967. set (${_headerIsInside} TRUE)
  968. endif()
  969. else()
  970. set (${_headerIsInside} TRUE)
  971. endif()
  972. else()
  973. # header is outside
  974. set (${_headerIsInside} FALSE)
  975. endif()
  976. endmacro()
  977. macro (cotire_check_ignore_header_file_path _headerFile _headerIsIgnoredVar)
  978. if (NOT EXISTS "${_headerFile}")
  979. set (${_headerIsIgnoredVar} TRUE)
  980. elseif (IS_DIRECTORY "${_headerFile}")
  981. set (${_headerIsIgnoredVar} TRUE)
  982. elseif ("${_headerFile}" MATCHES "\\.\\.|[_-]fixed" AND "${_headerFile}" MATCHES "\\.h$")
  983. # heuristic: ignore C headers with embedded parent directory references or "-fixed" or "_fixed" in path
  984. # these often stem from using GCC #include_next tricks, which may break the precompiled header compilation
  985. # with the error message "error: no include path in which to search for header.h"
  986. set (${_headerIsIgnoredVar} TRUE)
  987. else()
  988. set (${_headerIsIgnoredVar} FALSE)
  989. endif()
  990. endmacro()
  991. macro (cotire_check_ignore_header_file_ext _headerFile _ignoreExtensionsVar _headerIsIgnoredVar)
  992. # check header file extension
  993. cotire_get_source_file_extension("${_headerFile}" _headerFileExt)
  994. set (${_headerIsIgnoredVar} FALSE)
  995. if (_headerFileExt)
  996. list (FIND ${_ignoreExtensionsVar} "${_headerFileExt}" _index)
  997. if (_index GREATER -1)
  998. set (${_headerIsIgnoredVar} TRUE)
  999. endif()
  1000. endif()
  1001. endmacro()
  1002. macro (cotire_parse_line _line _headerFileVar _headerDepthVar)
  1003. if (MSVC)
  1004. # cl.exe /showIncludes output looks different depending on the language pack used, e.g.:
  1005. # English: "Note: including file: C:\directory\file"
  1006. # German: "Hinweis: Einlesen der Datei: C:\directory\file"
  1007. # We use a very general regular expression, relying on the presence of the : characters
  1008. if (_line MATCHES "( +)([a-zA-Z]:[^:]+)$")
  1009. # Visual Studio compiler output
  1010. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  1011. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" ABSOLUTE)
  1012. else()
  1013. set (${_headerFileVar} "")
  1014. set (${_headerDepthVar} 0)
  1015. endif()
  1016. else()
  1017. if (_line MATCHES "^(\\.+) (.*)$")
  1018. # GCC like output
  1019. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  1020. if (IS_ABSOLUTE "${CMAKE_MATCH_2}")
  1021. set (${_headerFileVar} "${CMAKE_MATCH_2}")
  1022. else()
  1023. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" REALPATH)
  1024. endif()
  1025. else()
  1026. set (${_headerFileVar} "")
  1027. set (${_headerDepthVar} 0)
  1028. endif()
  1029. endif()
  1030. endmacro()
  1031. function (cotire_parse_includes _language _scanOutput _ignoredIncludeDirs _honoredIncludeDirs _ignoredExtensions _selectedIncludesVar _unparsedLinesVar)
  1032. if (WIN32)
  1033. # prevent CMake macro invocation errors due to backslash characters in Windows paths
  1034. string (REPLACE "\\" "/" _scanOutput "${_scanOutput}")
  1035. endif()
  1036. # canonize slashes
  1037. string (REPLACE "//" "/" _scanOutput "${_scanOutput}")
  1038. # prevent semicolon from being interpreted as a line separator
  1039. string (REPLACE ";" "\\;" _scanOutput "${_scanOutput}")
  1040. # then separate lines
  1041. string (REGEX REPLACE "\n" ";" _scanOutput "${_scanOutput}")
  1042. list (LENGTH _scanOutput _len)
  1043. # remove duplicate lines to speed up parsing
  1044. list (REMOVE_DUPLICATES _scanOutput)
  1045. list (LENGTH _scanOutput _uniqueLen)
  1046. if (COTIRE_VERBOSE OR COTIRE_DEBUG)
  1047. message (STATUS "Scanning ${_uniqueLen} unique lines of ${_len} for includes")
  1048. if (_ignoredExtensions)
  1049. message (STATUS "Ignored extensions: ${_ignoredExtensions}")
  1050. endif()
  1051. if (_ignoredIncludeDirs)
  1052. message (STATUS "Ignored paths: ${_ignoredIncludeDirs}")
  1053. endif()
  1054. if (_honoredIncludeDirs)
  1055. message (STATUS "Included paths: ${_honoredIncludeDirs}")
  1056. endif()
  1057. endif()
  1058. set (_sourceFiles ${ARGN})
  1059. set (_selectedIncludes "")
  1060. set (_unparsedLines "")
  1061. # stack keeps track of inside/outside project status of processed header files
  1062. set (_headerIsInsideStack "")
  1063. foreach (_line IN LISTS _scanOutput)
  1064. if (_line)
  1065. cotire_parse_line("${_line}" _headerFile _headerDepth)
  1066. if (_headerFile)
  1067. cotire_check_header_file_location("${_headerFile}" "${_ignoredIncludeDirs}" "${_honoredIncludeDirs}" _headerIsInside)
  1068. if (COTIRE_DEBUG)
  1069. message (STATUS "${_headerDepth}: ${_headerFile} ${_headerIsInside}")
  1070. endif()
  1071. # update stack
  1072. list (LENGTH _headerIsInsideStack _stackLen)
  1073. if (_headerDepth GREATER _stackLen)
  1074. math (EXPR _stackLen "${_stackLen} + 1")
  1075. foreach (_index RANGE ${_stackLen} ${_headerDepth})
  1076. list (APPEND _headerIsInsideStack ${_headerIsInside})
  1077. endforeach()
  1078. else()
  1079. foreach (_index RANGE ${_headerDepth} ${_stackLen})
  1080. list (REMOVE_AT _headerIsInsideStack -1)
  1081. endforeach()
  1082. list (APPEND _headerIsInsideStack ${_headerIsInside})
  1083. endif()
  1084. if (COTIRE_DEBUG)
  1085. message (STATUS "${_headerIsInsideStack}")
  1086. endif()
  1087. # header is a candidate if it is outside project
  1088. if (NOT _headerIsInside)
  1089. # get parent header file's inside/outside status
  1090. if (_headerDepth GREATER 1)
  1091. math (EXPR _index "${_headerDepth} - 2")
  1092. list (GET _headerIsInsideStack ${_index} _parentHeaderIsInside)
  1093. else()
  1094. set (_parentHeaderIsInside TRUE)
  1095. endif()
  1096. # select header file if parent header file is inside project
  1097. # (e.g., a project header file that includes a standard header file)
  1098. if (_parentHeaderIsInside)
  1099. cotire_check_ignore_header_file_path("${_headerFile}" _headerIsIgnored)
  1100. if (NOT _headerIsIgnored)
  1101. cotire_check_ignore_header_file_ext("${_headerFile}" _ignoredExtensions _headerIsIgnored)
  1102. if (NOT _headerIsIgnored)
  1103. list (APPEND _selectedIncludes "${_headerFile}")
  1104. else()
  1105. # fix header's inside status on stack, it is ignored by extension now
  1106. list (REMOVE_AT _headerIsInsideStack -1)
  1107. list (APPEND _headerIsInsideStack TRUE)
  1108. endif()
  1109. endif()
  1110. if (COTIRE_DEBUG)
  1111. message (STATUS "${_headerFile} ${_ignoredExtensions} ${_headerIsIgnored}")
  1112. endif()
  1113. endif()
  1114. endif()
  1115. else()
  1116. if (MSVC)
  1117. # for cl.exe do not keep unparsed lines which solely consist of a source file name
  1118. string (FIND "${_sourceFiles}" "${_line}" _index)
  1119. if (_index LESS 0)
  1120. list (APPEND _unparsedLines "${_line}")
  1121. endif()
  1122. else()
  1123. list (APPEND _unparsedLines "${_line}")
  1124. endif()
  1125. endif()
  1126. endif()
  1127. endforeach()
  1128. list (REMOVE_DUPLICATES _selectedIncludes)
  1129. set (${_selectedIncludesVar} ${_selectedIncludes} PARENT_SCOPE)
  1130. set (${_unparsedLinesVar} ${_unparsedLines} PARENT_SCOPE)
  1131. endfunction()
  1132. function (cotire_scan_includes _includesVar)
  1133. set(_options "")
  1134. set(_oneValueArgs COMPILER_ID COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_VERSION LANGUAGE UNPARSED_LINES)
  1135. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES
  1136. IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
  1137. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1138. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1139. if (NOT _option_LANGUAGE)
  1140. set (_option_LANGUAGE "CXX")
  1141. endif()
  1142. if (NOT _option_COMPILER_ID)
  1143. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1144. endif()
  1145. if (NOT _option_COMPILER_VERSION)
  1146. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1147. endif()
  1148. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  1149. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  1150. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  1151. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1152. cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1153. cotire_add_makedep_flags("${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}" _cmd)
  1154. # only consider existing source files for scanning
  1155. set (_existingSourceFiles "")
  1156. foreach (_sourceFile ${_sourceFiles})
  1157. if (EXISTS "${_sourceFile}")
  1158. list (APPEND _existingSourceFiles "${_sourceFile}")
  1159. endif()
  1160. endforeach()
  1161. if (NOT _existingSourceFiles)
  1162. set (${_includesVar} "" PARENT_SCOPE)
  1163. return()
  1164. endif()
  1165. list (APPEND _cmd ${_existingSourceFiles})
  1166. if (COTIRE_VERBOSE)
  1167. message (STATUS "execute_process: ${_cmd}")
  1168. endif()
  1169. if (_option_COMPILER_ID MATCHES "MSVC")
  1170. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  1171. unset (ENV{VS_UNICODE_OUTPUT})
  1172. endif()
  1173. execute_process(
  1174. COMMAND ${_cmd}
  1175. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  1176. RESULT_VARIABLE _result
  1177. OUTPUT_QUIET
  1178. ERROR_VARIABLE _output)
  1179. if (_result)
  1180. message (STATUS "Result ${_result} scanning includes of ${_existingSourceFiles}.")
  1181. endif()
  1182. cotire_parse_includes(
  1183. "${_option_LANGUAGE}" "${_output}"
  1184. "${_option_IGNORE_PATH}" "${_option_INCLUDE_PATH}"
  1185. "${_option_IGNORE_EXTENSIONS}"
  1186. _includes _unparsedLines
  1187. ${_sourceFiles})
  1188. if (_option_INCLUDE_PRIORITY_PATH)
  1189. set (_sortedIncludes "")
  1190. foreach (_priorityPath ${_option_INCLUDE_PRIORITY_PATH})
  1191. foreach (_include ${_includes})
  1192. string (FIND ${_include} ${_priorityPath} _position)
  1193. if (_position GREATER -1)
  1194. list (APPEND _sortedIncludes ${_include})
  1195. endif()
  1196. endforeach()
  1197. endforeach()
  1198. if (_sortedIncludes)
  1199. list (INSERT _includes 0 ${_sortedIncludes})
  1200. list (REMOVE_DUPLICATES _includes)
  1201. endif()
  1202. endif()
  1203. set (${_includesVar} ${_includes} PARENT_SCOPE)
  1204. if (_option_UNPARSED_LINES)
  1205. set (${_option_UNPARSED_LINES} ${_unparsedLines} PARENT_SCOPE)
  1206. endif()
  1207. endfunction()
  1208. macro (cotire_append_undefs _contentsVar)
  1209. set (_undefs ${ARGN})
  1210. if (_undefs)
  1211. list (REMOVE_DUPLICATES _undefs)
  1212. foreach (_definition ${_undefs})
  1213. list (APPEND ${_contentsVar} "#undef ${_definition}")
  1214. endforeach()
  1215. endif()
  1216. endmacro()
  1217. macro (cotire_comment_str _language _commentText _commentVar)
  1218. if ("${_language}" STREQUAL "CMAKE")
  1219. set (${_commentVar} "# ${_commentText}")
  1220. else()
  1221. set (${_commentVar} "/* ${_commentText} */")
  1222. endif()
  1223. endmacro()
  1224. function (cotire_write_file _language _file _contents _force)
  1225. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  1226. cotire_comment_str("${_language}" "${_moduleName} ${COTIRE_CMAKE_MODULE_VERSION} generated file" _header1)
  1227. cotire_comment_str("${_language}" "${_file}" _header2)
  1228. set (_contents "${_header1}\n${_header2}\n${_contents}")
  1229. if (COTIRE_DEBUG)
  1230. message (STATUS "${_contents}")
  1231. endif()
  1232. if (_force OR NOT EXISTS "${_file}")
  1233. file (WRITE "${_file}" "${_contents}")
  1234. else()
  1235. file (READ "${_file}" _oldContents)
  1236. if (NOT "${_oldContents}" STREQUAL "${_contents}")
  1237. file (WRITE "${_file}" "${_contents}")
  1238. else()
  1239. if (COTIRE_DEBUG)
  1240. message (STATUS "${_file} unchanged")
  1241. endif()
  1242. endif()
  1243. endif()
  1244. endfunction()
  1245. function (cotire_generate_unity_source _unityFile)
  1246. set(_options "")
  1247. set(_oneValueArgs LANGUAGE)
  1248. set(_multiValueArgs
  1249. DEPENDS SOURCES_COMPILE_DEFINITIONS
  1250. PRE_UNDEFS SOURCES_PRE_UNDEFS POST_UNDEFS SOURCES_POST_UNDEFS PROLOGUE EPILOGUE)
  1251. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1252. if (_option_DEPENDS)
  1253. cotire_check_file_up_to_date(_unityFileIsUpToDate "${_unityFile}" ${_option_DEPENDS})
  1254. if (_unityFileIsUpToDate)
  1255. return()
  1256. endif()
  1257. endif()
  1258. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1259. if (NOT _option_PRE_UNDEFS)
  1260. set (_option_PRE_UNDEFS "")
  1261. endif()
  1262. if (NOT _option_SOURCES_PRE_UNDEFS)
  1263. set (_option_SOURCES_PRE_UNDEFS "")
  1264. endif()
  1265. if (NOT _option_POST_UNDEFS)
  1266. set (_option_POST_UNDEFS "")
  1267. endif()
  1268. if (NOT _option_SOURCES_POST_UNDEFS)
  1269. set (_option_SOURCES_POST_UNDEFS "")
  1270. endif()
  1271. set (_contents "")
  1272. if (_option_PROLOGUE)
  1273. list (APPEND _contents ${_option_PROLOGUE})
  1274. endif()
  1275. if (_option_LANGUAGE AND _sourceFiles)
  1276. if ("${_option_LANGUAGE}" STREQUAL "CXX")
  1277. list (APPEND _contents "#ifdef __cplusplus")
  1278. elseif ("${_option_LANGUAGE}" STREQUAL "C")
  1279. list (APPEND _contents "#ifndef __cplusplus")
  1280. endif()
  1281. endif()
  1282. set (_compileUndefinitions "")
  1283. foreach (_sourceFile ${_sourceFiles})
  1284. cotire_get_source_compile_definitions(
  1285. "${_option_CONFIGURATION}" "${_option_LANGUAGE}" "${_sourceFile}" _compileDefinitions
  1286. ${_option_SOURCES_COMPILE_DEFINITIONS})
  1287. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_PRE_UNDEFS _sourcePreUndefs ${_option_SOURCES_PRE_UNDEFS})
  1288. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_POST_UNDEFS _sourcePostUndefs ${_option_SOURCES_POST_UNDEFS})
  1289. if (_option_PRE_UNDEFS)
  1290. list (APPEND _compileUndefinitions ${_option_PRE_UNDEFS})
  1291. endif()
  1292. if (_sourcePreUndefs)
  1293. list (APPEND _compileUndefinitions ${_sourcePreUndefs})
  1294. endif()
  1295. if (_compileUndefinitions)
  1296. cotire_append_undefs(_contents ${_compileUndefinitions})
  1297. set (_compileUndefinitions "")
  1298. endif()
  1299. if (_sourcePostUndefs)
  1300. list (APPEND _compileUndefinitions ${_sourcePostUndefs})
  1301. endif()
  1302. if (_option_POST_UNDEFS)
  1303. list (APPEND _compileUndefinitions ${_option_POST_UNDEFS})
  1304. endif()
  1305. foreach (_definition ${_compileDefinitions})
  1306. if (_definition MATCHES "^([a-zA-Z0-9_]+)=(.+)$")
  1307. list (APPEND _contents "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
  1308. list (INSERT _compileUndefinitions 0 "${CMAKE_MATCH_1}")
  1309. else()
  1310. list (APPEND _contents "#define ${_definition}")
  1311. list (INSERT _compileUndefinitions 0 "${_definition}")
  1312. endif()
  1313. endforeach()
  1314. # use absolute path as source file location
  1315. get_filename_component(_sourceFileLocation "${_sourceFile}" ABSOLUTE)
  1316. if (WIN32)
  1317. file (TO_NATIVE_PATH "${_sourceFileLocation}" _sourceFileLocation)
  1318. endif()
  1319. list (APPEND _contents "#include \"${_sourceFileLocation}\"")
  1320. endforeach()
  1321. if (_compileUndefinitions)
  1322. cotire_append_undefs(_contents ${_compileUndefinitions})
  1323. set (_compileUndefinitions "")
  1324. endif()
  1325. if (_option_LANGUAGE AND _sourceFiles)
  1326. list (APPEND _contents "#endif")
  1327. endif()
  1328. if (_option_EPILOGUE)
  1329. list (APPEND _contents ${_option_EPILOGUE})
  1330. endif()
  1331. list (APPEND _contents "")
  1332. string (REPLACE ";" "\n" _contents "${_contents}")
  1333. if (COTIRE_VERBOSE)
  1334. message ("${_contents}")
  1335. endif()
  1336. cotire_write_file("${_option_LANGUAGE}" "${_unityFile}" "${_contents}" TRUE)
  1337. endfunction()
  1338. function (cotire_generate_prefix_header _prefixFile)
  1339. set(_options "")
  1340. set(_oneValueArgs LANGUAGE COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_ID COMPILER_VERSION)
  1341. set(_multiValueArgs DEPENDS COMPILE_DEFINITIONS COMPILE_FLAGS
  1342. INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES IGNORE_PATH INCLUDE_PATH
  1343. IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
  1344. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1345. if (NOT _option_COMPILER_ID)
  1346. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1347. endif()
  1348. if (NOT _option_COMPILER_VERSION)
  1349. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1350. endif()
  1351. if (_option_DEPENDS)
  1352. cotire_check_file_up_to_date(_prefixFileIsUpToDate "${_prefixFile}" ${_option_DEPENDS})
  1353. if (_prefixFileIsUpToDate)
  1354. # create empty log file
  1355. set (_unparsedLinesFile "${_prefixFile}.log")
  1356. file (WRITE "${_unparsedLinesFile}" "")
  1357. return()
  1358. endif()
  1359. endif()
  1360. set (_prologue "")
  1361. set (_epilogue "")
  1362. if (_option_COMPILER_ID MATCHES "Clang")
  1363. set (_prologue "#pragma clang system_header")
  1364. elseif (_option_COMPILER_ID MATCHES "GNU")
  1365. set (_prologue "#pragma GCC system_header")
  1366. elseif (_option_COMPILER_ID MATCHES "MSVC")
  1367. set (_prologue "#pragma warning(push, 0)")
  1368. set (_epilogue "#pragma warning(pop)")
  1369. elseif (_option_COMPILER_ID MATCHES "Intel")
  1370. # Intel compiler requires hdrstop pragma to stop generating PCH file
  1371. set (_epilogue "#pragma hdrstop")
  1372. endif()
  1373. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1374. cotire_scan_includes(_selectedHeaders ${_sourceFiles}
  1375. LANGUAGE "${_option_LANGUAGE}"
  1376. COMPILER_LAUNCHER "${_option_COMPILER_LAUNCHER}"
  1377. COMPILER_EXECUTABLE "${_option_COMPILER_EXECUTABLE}"
  1378. COMPILER_ARG1 "${_option_COMPILER_ARG1}"
  1379. COMPILER_ID "${_option_COMPILER_ID}"
  1380. COMPILER_VERSION "${_option_COMPILER_VERSION}"
  1381. COMPILE_DEFINITIONS ${_option_COMPILE_DEFINITIONS}
  1382. COMPILE_FLAGS ${_option_COMPILE_FLAGS}
  1383. INCLUDE_DIRECTORIES ${_option_INCLUDE_DIRECTORIES}
  1384. SYSTEM_INCLUDE_DIRECTORIES ${_option_SYSTEM_INCLUDE_DIRECTORIES}
  1385. IGNORE_PATH ${_option_IGNORE_PATH}
  1386. INCLUDE_PATH ${_option_INCLUDE_PATH}
  1387. IGNORE_EXTENSIONS ${_option_IGNORE_EXTENSIONS}
  1388. INCLUDE_PRIORITY_PATH ${_option_INCLUDE_PRIORITY_PATH}
  1389. UNPARSED_LINES _unparsedLines)
  1390. cotire_generate_unity_source("${_prefixFile}"
  1391. PROLOGUE ${_prologue} EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders})
  1392. set (_unparsedLinesFile "${_prefixFile}.log")
  1393. if (_unparsedLines)
  1394. if (COTIRE_VERBOSE OR NOT _selectedHeaders)
  1395. list (LENGTH _unparsedLines _skippedLineCount)
  1396. message (STATUS "${_skippedLineCount} line(s) skipped, see ${_unparsedLinesFile}")
  1397. endif()
  1398. string (REPLACE ";" "\n" _unparsedLines "${_unparsedLines}")
  1399. endif()
  1400. file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}")
  1401. endfunction()
  1402. function (cotire_add_makedep_flags _language _compilerID _compilerVersion _flagsVar)
  1403. set (_flags ${${_flagsVar}})
  1404. if (_compilerID MATCHES "MSVC")
  1405. # cl.exe options used
  1406. # /nologo suppresses display of sign-on banner
  1407. # /TC treat all files named on the command line as C source files
  1408. # /TP treat all files named on the command line as C++ source files
  1409. # /EP preprocess to stdout without #line directives
  1410. # /showIncludes list include files
  1411. set (_sourceFileTypeC "/TC")
  1412. set (_sourceFileTypeCXX "/TP")
  1413. if (_flags)
  1414. # append to list
  1415. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /showIncludes)
  1416. else()
  1417. # return as a flag string
  1418. set (_flags "${_sourceFileType${_language}} /EP /showIncludes")
  1419. endif()
  1420. elseif (_compilerID MATCHES "GNU")
  1421. # GCC options used
  1422. # -H print the name of each header file used
  1423. # -E invoke preprocessor
  1424. # -fdirectives-only do not expand macros, requires GCC >= 4.3
  1425. if (_flags)
  1426. # append to list
  1427. list (APPEND _flags -H -E)
  1428. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1429. list (APPEND _flags "-fdirectives-only")
  1430. endif()
  1431. else()
  1432. # return as a flag string
  1433. set (_flags "-H -E")
  1434. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1435. set (_flags "${_flags} -fdirectives-only")
  1436. endif()
  1437. endif()
  1438. elseif (_compilerID MATCHES "Clang")
  1439. # Clang options used
  1440. # -H print the name of each header file used
  1441. # -E invoke preprocessor
  1442. # -fno-color-diagnostics don't prints diagnostics in color
  1443. if (_flags)
  1444. # append to list
  1445. list (APPEND _flags -H -E -fno-color-diagnostics)
  1446. else()
  1447. # return as a flag string
  1448. set (_flags "-H -E -fno-color-diagnostics")
  1449. endif()
  1450. elseif (_compilerID MATCHES "Intel")
  1451. if (WIN32)
  1452. # Windows Intel options used
  1453. # /nologo do not display compiler version information
  1454. # /QH display the include file order
  1455. # /EP preprocess to stdout, omitting #line directives
  1456. # /TC process all source or unrecognized file types as C source files
  1457. # /TP process all source or unrecognized file types as C++ source files
  1458. set (_sourceFileTypeC "/TC")
  1459. set (_sourceFileTypeCXX "/TP")
  1460. if (_flags)
  1461. # append to list
  1462. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /QH)
  1463. else()
  1464. # return as a flag string
  1465. set (_flags "${_sourceFileType${_language}} /EP /QH")
  1466. endif()
  1467. else()
  1468. # Linux / Mac OS X Intel options used
  1469. # -H print the name of each header file used
  1470. # -EP preprocess to stdout, omitting #line directives
  1471. # -Kc++ process all source or unrecognized file types as C++ source files
  1472. if (_flags)
  1473. # append to list
  1474. if ("${_language}" STREQUAL "CXX")
  1475. list (APPEND _flags -Kc++)
  1476. endif()
  1477. list (APPEND _flags -H -EP)
  1478. else()
  1479. # return as a flag string
  1480. if ("${_language}" STREQUAL "CXX")
  1481. set (_flags "-Kc++ ")
  1482. endif()
  1483. set (_flags "${_flags}-H -EP")
  1484. endif()
  1485. endif()
  1486. else()
  1487. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1488. endif()
  1489. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1490. endfunction()
  1491. function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersion _prefixFile _pchFile _hostFile _flagsVar)
  1492. set (_flags ${${_flagsVar}})
  1493. if (_compilerID MATCHES "MSVC")
  1494. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1495. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1496. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1497. # cl.exe options used
  1498. # /Yc creates a precompiled header file
  1499. # /Fp specifies precompiled header binary file name
  1500. # /FI forces inclusion of file
  1501. # /TC treat all files named on the command line as C source files
  1502. # /TP treat all files named on the command line as C++ source files
  1503. # /Zs syntax check only
  1504. # /Zm precompiled header memory allocation scaling factor
  1505. set (_sourceFileTypeC "/TC")
  1506. set (_sourceFileTypeCXX "/TP")
  1507. if (_flags)
  1508. # append to list
  1509. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1510. "/Yc${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
  1511. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1512. list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1513. endif()
  1514. else()
  1515. # return as a flag string
  1516. set (_flags "/Yc\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1517. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1518. set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1519. endif()
  1520. endif()
  1521. elseif (_compilerID MATCHES "GNU|Clang")
  1522. # GCC / Clang options used
  1523. # -x specify the source language
  1524. # -c compile but do not link
  1525. # -o place output in file
  1526. # note that we cannot use -w to suppress all warnings upon pre-compiling, because turning off a warning may
  1527. # alter compile flags as a side effect (e.g., -Wwrite-string implies -fconst-strings)
  1528. set (_xLanguage_C "c-header")
  1529. set (_xLanguage_CXX "c++-header")
  1530. if (_flags)
  1531. # append to list
  1532. list (APPEND _flags "-x" "${_xLanguage_${_language}}" "-c" "${_prefixFile}" -o "${_pchFile}")
  1533. else()
  1534. # return as a flag string
  1535. set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"")
  1536. endif()
  1537. elseif (_compilerID MATCHES "Intel")
  1538. if (WIN32)
  1539. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1540. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1541. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1542. # Windows Intel options used
  1543. # /nologo do not display compiler version information
  1544. # /Yc create a precompiled header (PCH) file
  1545. # /Fp specify a path or file name for precompiled header files
  1546. # /FI tells the preprocessor to include a specified file name as the header file
  1547. # /TC process all source or unrecognized file types as C source files
  1548. # /TP process all source or unrecognized file types as C++ source files
  1549. # /Zs syntax check only
  1550. # /Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1551. set (_sourceFileTypeC "/TC")
  1552. set (_sourceFileTypeCXX "/TP")
  1553. if (_flags)
  1554. # append to list
  1555. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1556. "/Yc" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
  1557. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1558. list (APPEND _flags "/Wpch-messages")
  1559. endif()
  1560. else()
  1561. # return as a flag string
  1562. set (_flags "/Yc /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1563. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1564. set (_flags "${_flags} /Wpch-messages")
  1565. endif()
  1566. endif()
  1567. else()
  1568. # Linux / Mac OS X Intel options used
  1569. # -pch-dir location for precompiled header files
  1570. # -pch-create name of the precompiled header (PCH) to create
  1571. # -Kc++ process all source or unrecognized file types as C++ source files
  1572. # -fsyntax-only check only for correct syntax
  1573. # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1574. get_filename_component(_pchDir "${_pchFile}" DIRECTORY)
  1575. get_filename_component(_pchName "${_pchFile}" NAME)
  1576. set (_xLanguage_C "c-header")
  1577. set (_xLanguage_CXX "c++-header")
  1578. if (_flags)
  1579. # append to list
  1580. if ("${_language}" STREQUAL "CXX")
  1581. list (APPEND _flags -Kc++)
  1582. endif()
  1583. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-create" "${_pchName}" "-fsyntax-only" "${_hostFile}")
  1584. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1585. list (APPEND _flags "-Wpch-messages")
  1586. endif()
  1587. else()
  1588. # return as a flag string
  1589. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-create \"${_pchName}\"")
  1590. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1591. set (_flags "${_flags} -Wpch-messages")
  1592. endif()
  1593. endif()
  1594. endif()
  1595. else()
  1596. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1597. endif()
  1598. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1599. endfunction()
  1600. function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerVersion _prefixFile _pchFile _flagsVar)
  1601. set (_flags ${${_flagsVar}})
  1602. if (_compilerID MATCHES "MSVC")
  1603. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1604. # cl.exe options used
  1605. # /Yu uses a precompiled header file during build
  1606. # /Fp specifies precompiled header binary file name
  1607. # /FI forces inclusion of file
  1608. # /Zm precompiled header memory allocation scaling factor
  1609. if (_pchFile)
  1610. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1611. if (_flags)
  1612. # append to list
  1613. list (APPEND _flags "/Yu${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
  1614. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1615. list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1616. endif()
  1617. else()
  1618. # return as a flag string
  1619. set (_flags "/Yu\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1620. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1621. set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1622. endif()
  1623. endif()
  1624. else()
  1625. # no precompiled header, force inclusion of prefix header
  1626. if (_flags)
  1627. # append to list
  1628. list (APPEND _flags "/FI${_prefixFileNative}")
  1629. else()
  1630. # return as a flag string
  1631. set (_flags "/FI\"${_prefixFileNative}\"")
  1632. endif()
  1633. endif()
  1634. elseif (_compilerID MATCHES "GNU")
  1635. # GCC options used
  1636. # -include process include file as the first line of the primary source file
  1637. # -Winvalid-pch warns if precompiled header is found but cannot be used
  1638. # note: ccache requires the -include flag to be used in order to process precompiled header correctly
  1639. if (_flags)
  1640. # append to list
  1641. list (APPEND _flags "-Winvalid-pch" "-include" "${_prefixFile}")
  1642. else()
  1643. # return as a flag string
  1644. set (_flags "-Winvalid-pch -include \"${_prefixFile}\"")
  1645. endif()
  1646. elseif (_compilerID MATCHES "Clang")
  1647. # Clang options used
  1648. # -include process include file as the first line of the primary source file
  1649. # -include-pch include precompiled header file
  1650. # -Qunused-arguments don't emit warning for unused driver arguments
  1651. # note: ccache requires the -include flag to be used in order to process precompiled header correctly
  1652. if (_flags)
  1653. # append to list
  1654. list (APPEND _flags "-Qunused-arguments" "-include" "${_prefixFile}")
  1655. else()
  1656. # return as a flag string
  1657. set (_flags "-Qunused-arguments -include \"${_prefixFile}\"")
  1658. endif()
  1659. elseif (_compilerID MATCHES "Intel")
  1660. if (WIN32)
  1661. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1662. # Windows Intel options used
  1663. # /Yu use a precompiled header (PCH) file
  1664. # /Fp specify a path or file name for precompiled header files
  1665. # /FI tells the preprocessor to include a specified file name as the header file
  1666. # /Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1667. if (_pchFile)
  1668. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1669. if (_flags)
  1670. # append to list
  1671. list (APPEND _flags "/Yu" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
  1672. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1673. list (APPEND _flags "/Wpch-messages")
  1674. endif()
  1675. else()
  1676. # return as a flag string
  1677. set (_flags "/Yu /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1678. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1679. set (_flags "${_flags} /Wpch-messages")
  1680. endif()
  1681. endif()
  1682. else()
  1683. # no precompiled header, force inclusion of prefix header
  1684. if (_flags)
  1685. # append to list
  1686. list (APPEND _flags "/FI${_prefixFileNative}")
  1687. else()
  1688. # return as a flag string
  1689. set (_flags "/FI\"${_prefixFileNative}\"")
  1690. endif()
  1691. endif()
  1692. else()
  1693. # Linux / Mac OS X Intel options used
  1694. # -pch-dir location for precompiled header files
  1695. # -pch-use name of the precompiled header (PCH) to use
  1696. # -include process include file as the first line of the primary source file
  1697. # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1698. if (_pchFile)
  1699. get_filename_component(_pchDir "${_pchFile}" DIRECTORY)
  1700. get_filename_component(_pchName "${_pchFile}" NAME)
  1701. if (_flags)
  1702. # append to list
  1703. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-use" "${_pchName}")
  1704. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1705. list (APPEND _flags "-Wpch-messages")
  1706. endif()
  1707. else()
  1708. # return as a flag string
  1709. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-use \"${_pchName}\"")
  1710. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1711. set (_flags "${_flags} -Wpch-messages")
  1712. endif()
  1713. endif()
  1714. else()
  1715. # no precompiled header, force inclusion of prefix header
  1716. if (_flags)
  1717. # append to list
  1718. list (APPEND _flags "-include" "${_prefixFile}")
  1719. else()
  1720. # return as a flag string
  1721. set (_flags "-include \"${_prefixFile}\"")
  1722. endif()
  1723. endif()
  1724. endif()
  1725. else()
  1726. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1727. endif()
  1728. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1729. endfunction()
  1730. function (cotire_precompile_prefix_header _prefixFile _pchFile _hostFile)
  1731. set(_options "")
  1732. set(_oneValueArgs COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_ID COMPILER_VERSION LANGUAGE)
  1733. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES SYS COMPILER_LAUNCHER)
  1734. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1735. if (NOT _option_LANGUAGE)
  1736. set (_option_LANGUAGE "CXX")
  1737. endif()
  1738. if (NOT _option_COMPILER_ID)
  1739. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1740. endif()
  1741. if (NOT _option_COMPILER_VERSION)
  1742. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1743. endif()
  1744. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  1745. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  1746. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  1747. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1748. cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1749. cotire_add_pch_compilation_flags(
  1750. "${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}"
  1751. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _cmd)
  1752. if (COTIRE_VERBOSE)
  1753. message (STATUS "execute_process: ${_cmd}")
  1754. endif()
  1755. if (_option_COMPILER_ID MATCHES "MSVC")
  1756. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  1757. unset (ENV{VS_UNICODE_OUTPUT})
  1758. endif()
  1759. execute_process(
  1760. COMMAND ${_cmd}
  1761. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  1762. RESULT_VARIABLE _result)
  1763. if (_result)
  1764. message (FATAL_ERROR "cotire: error ${_result} precompiling ${_prefixFile}.")
  1765. endif()
  1766. endfunction()
  1767. function (cotire_check_precompiled_header_support _language _target _msgVar)
  1768. set (_unsupportedCompiler
  1769. "Precompiled headers not supported for ${_language} compiler ${CMAKE_${_language}_COMPILER_ID}")
  1770. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  1771. # supported since Visual Studio C++ 6.0
  1772. # and CMake does not support an earlier version
  1773. set (${_msgVar} "" PARENT_SCOPE)
  1774. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU")
  1775. # GCC PCH support requires version >= 3.4
  1776. if ("${CMAKE_${_language}_COMPILER_VERSION}" VERSION_LESS "3.4.0")
  1777. set (${_msgVar} "${_unsupportedCompiler} version ${CMAKE_${_language}_COMPILER_VERSION}." PARENT_SCOPE)
  1778. else()
  1779. set (${_msgVar} "" PARENT_SCOPE)
  1780. endif()
  1781. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang")
  1782. # all Clang versions have PCH support
  1783. set (${_msgVar} "" PARENT_SCOPE)
  1784. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  1785. # Intel PCH support requires version >= 8.0.0
  1786. if ("${CMAKE_${_language}_COMPILER_VERSION}" VERSION_LESS "8.0.0")
  1787. set (${_msgVar} "${_unsupportedCompiler} version ${CMAKE_${_language}_COMPILER_VERSION}." PARENT_SCOPE)
  1788. else()
  1789. set (${_msgVar} "" PARENT_SCOPE)
  1790. endif()
  1791. else()
  1792. set (${_msgVar} "${_unsupportedCompiler}." PARENT_SCOPE)
  1793. endif()
  1794. get_target_property(_launcher ${_target} ${_language}_COMPILER_LAUNCHER)
  1795. if (CMAKE_${_language}_COMPILER MATCHES "ccache" OR _launcher MATCHES "ccache")
  1796. if (NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "time_macros|pch_defines")
  1797. set (${_msgVar}
  1798. "ccache requires the environment variable CCACHE_SLOPPINESS to be set to \"pch_defines,time_macros\"."
  1799. PARENT_SCOPE)
  1800. endif()
  1801. endif()
  1802. if (APPLE)
  1803. # PCH compilation not supported by GCC / Clang for multi-architecture builds (e.g., i386, x86_64)
  1804. cotire_get_configuration_types(_configs)
  1805. foreach (_config ${_configs})
  1806. set (_targetFlags "")
  1807. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  1808. cotire_filter_compile_flags("${_language}" "arch" _architectures _ignore ${_targetFlags})
  1809. list (LENGTH _architectures _numberOfArchitectures)
  1810. if (_numberOfArchitectures GREATER 1)
  1811. string (REPLACE ";" ", " _architectureStr "${_architectures}")
  1812. set (${_msgVar}
  1813. "Precompiled headers not supported on Darwin for multi-architecture builds (${_architectureStr})."
  1814. PARENT_SCOPE)
  1815. break()
  1816. endif()
  1817. endforeach()
  1818. endif()
  1819. endfunction()
  1820. macro (cotire_get_intermediate_dir _cotireDir)
  1821. # ${CMAKE_CFG_INTDIR} may reference a build-time variable when using a generator which supports configuration types
  1822. get_filename_component(${_cotireDir} "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${COTIRE_INTDIR}" ABSOLUTE)
  1823. endmacro()
  1824. macro (cotire_setup_file_extension_variables)
  1825. set (_unityFileExt_C ".c")
  1826. set (_unityFileExt_CXX ".cxx")
  1827. set (_prefixFileExt_C ".h")
  1828. set (_prefixFileExt_CXX ".hxx")
  1829. set (_prefixSourceFileExt_C ".c")
  1830. set (_prefixSourceFileExt_CXX ".cxx")
  1831. endmacro()
  1832. function (cotire_make_single_unity_source_file_path _language _target _unityFileVar)
  1833. cotire_setup_file_extension_variables()
  1834. if (NOT DEFINED _unityFileExt_${_language})
  1835. set (${_unityFileVar} "" PARENT_SCOPE)
  1836. return()
  1837. endif()
  1838. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1839. set (_unityFileName "${_unityFileBaseName}${_unityFileExt_${_language}}")
  1840. cotire_get_intermediate_dir(_baseDir)
  1841. set (_unityFile "${_baseDir}/${_unityFileName}")
  1842. set (${_unityFileVar} "${_unityFile}" PARENT_SCOPE)
  1843. endfunction()
  1844. function (cotire_make_unity_source_file_paths _language _target _maxIncludes _unityFilesVar)
  1845. cotire_setup_file_extension_variables()
  1846. if (NOT DEFINED _unityFileExt_${_language})
  1847. set (${_unityFileVar} "" PARENT_SCOPE)
  1848. return()
  1849. endif()
  1850. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1851. cotire_get_intermediate_dir(_baseDir)
  1852. set (_startIndex 0)
  1853. set (_index 0)
  1854. set (_unityFiles "")
  1855. set (_sourceFiles ${ARGN})
  1856. foreach (_sourceFile ${_sourceFiles})
  1857. get_source_file_property(_startNew "${_sourceFile}" COTIRE_START_NEW_UNITY_SOURCE)
  1858. math (EXPR _unityFileCount "${_index} - ${_startIndex}")
  1859. if (_startNew OR (_maxIncludes GREATER 0 AND NOT _unityFileCount LESS _maxIncludes))
  1860. if (_index GREATER 0)
  1861. # start new unity file segment
  1862. math (EXPR _endIndex "${_index} - 1")
  1863. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1864. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1865. endif()
  1866. set (_startIndex ${_index})
  1867. endif()
  1868. math (EXPR _index "${_index} + 1")
  1869. endforeach()
  1870. list (LENGTH _sourceFiles _numberOfSources)
  1871. if (_startIndex EQUAL 0)
  1872. # there is only a single unity file
  1873. cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFiles)
  1874. elseif (_startIndex LESS _numberOfSources)
  1875. # end with final unity file segment
  1876. math (EXPR _endIndex "${_index} - 1")
  1877. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1878. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1879. endif()
  1880. set (${_unityFilesVar} ${_unityFiles} PARENT_SCOPE)
  1881. if (COTIRE_DEBUG AND _unityFiles)
  1882. message (STATUS "unity files: ${_unityFiles}")
  1883. endif()
  1884. endfunction()
  1885. function (cotire_unity_to_prefix_file_path _language _target _unityFile _prefixFileVar)
  1886. cotire_setup_file_extension_variables()
  1887. if (NOT DEFINED _unityFileExt_${_language})
  1888. set (${_prefixFileVar} "" PARENT_SCOPE)
  1889. return()
  1890. endif()
  1891. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1892. set (_prefixFileBaseName "${_target}_${_language}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1893. string (REPLACE "${_unityFileBaseName}" "${_prefixFileBaseName}" _prefixFile "${_unityFile}")
  1894. string (REGEX REPLACE "${_unityFileExt_${_language}}$" "${_prefixFileExt_${_language}}" _prefixFile "${_prefixFile}")
  1895. set (${_prefixFileVar} "${_prefixFile}" PARENT_SCOPE)
  1896. endfunction()
  1897. function (cotire_prefix_header_to_source_file_path _language _prefixHeaderFile _prefixSourceFileVar)
  1898. cotire_setup_file_extension_variables()
  1899. if (NOT DEFINED _prefixSourceFileExt_${_language})
  1900. set (${_prefixSourceFileVar} "" PARENT_SCOPE)
  1901. return()
  1902. endif()
  1903. string (REGEX REPLACE "${_prefixFileExt_${_language}}$" "${_prefixSourceFileExt_${_language}}" _prefixSourceFile "${_prefixHeaderFile}")
  1904. set (${_prefixSourceFileVar} "${_prefixSourceFile}" PARENT_SCOPE)
  1905. endfunction()
  1906. function (cotire_make_prefix_file_name _language _target _prefixFileBaseNameVar _prefixFileNameVar)
  1907. cotire_setup_file_extension_variables()
  1908. if (NOT _language)
  1909. set (_prefixFileBaseName "${_target}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1910. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_C}")
  1911. elseif (DEFINED _prefixFileExt_${_language})
  1912. set (_prefixFileBaseName "${_target}_${_language}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1913. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_${_language}}")
  1914. else()
  1915. set (_prefixFileBaseName "")
  1916. set (_prefixFileName "")
  1917. endif()
  1918. set (${_prefixFileBaseNameVar} "${_prefixFileBaseName}" PARENT_SCOPE)
  1919. set (${_prefixFileNameVar} "${_prefixFileName}" PARENT_SCOPE)
  1920. endfunction()
  1921. function (cotire_make_prefix_file_path _language _target _prefixFileVar)
  1922. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  1923. set (${_prefixFileVar} "" PARENT_SCOPE)
  1924. if (_prefixFileName)
  1925. if (NOT _language)
  1926. set (_language "C")
  1927. endif()
  1928. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang|Intel|MSVC")
  1929. cotire_get_intermediate_dir(_baseDir)
  1930. set (${_prefixFileVar} "${_baseDir}/${_prefixFileName}" PARENT_SCOPE)
  1931. endif()
  1932. endif()
  1933. endfunction()
  1934. function (cotire_make_pch_file_path _language _target _pchFileVar)
  1935. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  1936. set (${_pchFileVar} "" PARENT_SCOPE)
  1937. if (_prefixFileBaseName AND _prefixFileName)
  1938. cotire_check_precompiled_header_support("${_language}" "${_target}" _msg)
  1939. if (NOT _msg)
  1940. if (XCODE)
  1941. # For Xcode, we completely hand off the compilation of the prefix header to the IDE
  1942. return()
  1943. endif()
  1944. cotire_get_intermediate_dir(_baseDir)
  1945. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  1946. # MSVC uses the extension .pch added to the prefix header base name
  1947. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pch" PARENT_SCOPE)
  1948. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang")
  1949. # Clang looks for a precompiled header corresponding to the prefix header with the extension .pch appended
  1950. set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.pch" PARENT_SCOPE)
  1951. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU")
  1952. # GCC looks for a precompiled header corresponding to the prefix header with the extension .gch appended
  1953. set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.gch" PARENT_SCOPE)
  1954. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  1955. # Intel uses the extension .pchi added to the prefix header base name
  1956. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pchi" PARENT_SCOPE)
  1957. endif()
  1958. endif()
  1959. endif()
  1960. endfunction()
  1961. function (cotire_select_unity_source_files _unityFile _sourcesVar)
  1962. set (_sourceFiles ${ARGN})
  1963. if (_sourceFiles AND "${_unityFile}" MATCHES "${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}_([0-9]+)_([0-9]+)")
  1964. set (_startIndex ${CMAKE_MATCH_1})
  1965. set (_endIndex ${CMAKE_MATCH_2})
  1966. list (LENGTH _sourceFiles _numberOfSources)
  1967. if (NOT _startIndex LESS _numberOfSources)
  1968. math (EXPR _startIndex "${_numberOfSources} - 1")
  1969. endif()
  1970. if (NOT _endIndex LESS _numberOfSources)
  1971. math (EXPR _endIndex "${_numberOfSources} - 1")
  1972. endif()
  1973. set (_files "")
  1974. foreach (_index RANGE ${_startIndex} ${_endIndex})
  1975. list (GET _sourceFiles ${_index} _file)
  1976. list (APPEND _files "${_file}")
  1977. endforeach()
  1978. else()
  1979. set (_files ${_sourceFiles})
  1980. endif()
  1981. set (${_sourcesVar} ${_files} PARENT_SCOPE)
  1982. endfunction()
  1983. function (cotire_get_unity_source_dependencies _language _target _dependencySourcesVar)
  1984. set (_dependencySources "")
  1985. # depend on target's generated source files
  1986. get_target_property(_targetSourceFiles ${_target} SOURCES)
  1987. cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${_targetSourceFiles})
  1988. if (_generatedSources)
  1989. # but omit all generated source files that have the COTIRE_EXCLUDED property set to true
  1990. cotire_get_objects_with_property_on(_excludedGeneratedSources COTIRE_EXCLUDED SOURCE ${_generatedSources})
  1991. if (_excludedGeneratedSources)
  1992. list (REMOVE_ITEM _generatedSources ${_excludedGeneratedSources})
  1993. endif()
  1994. # and omit all generated source files that have the COTIRE_DEPENDENCY property set to false explicitly
  1995. cotire_get_objects_with_property_off(_excludedNonDependencySources COTIRE_DEPENDENCY SOURCE ${_generatedSources})
  1996. if (_excludedNonDependencySources)
  1997. list (REMOVE_ITEM _generatedSources ${_excludedNonDependencySources})
  1998. endif()
  1999. if (_generatedSources)
  2000. list (APPEND _dependencySources ${_generatedSources})
  2001. endif()
  2002. endif()
  2003. if (COTIRE_DEBUG AND _dependencySources)
  2004. message (STATUS "${_language} ${_target} unity source dependencies: ${_dependencySources}")
  2005. endif()
  2006. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  2007. endfunction()
  2008. function (cotire_get_prefix_header_dependencies _language _target _dependencySourcesVar)
  2009. set (_dependencySources "")
  2010. # depend on target source files marked with custom COTIRE_DEPENDENCY property
  2011. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2012. cotire_get_objects_with_property_on(_dependencySources COTIRE_DEPENDENCY SOURCE ${_targetSourceFiles})
  2013. if (COTIRE_DEBUG AND _dependencySources)
  2014. message (STATUS "${_language} ${_target} prefix header dependencies: ${_dependencySources}")
  2015. endif()
  2016. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  2017. endfunction()
  2018. function (cotire_generate_target_script _language _configurations _target _targetScriptVar _targetConfigScriptVar)
  2019. set (_targetSources ${ARGN})
  2020. cotire_get_prefix_header_dependencies(${_language} ${_target} COTIRE_TARGET_PREFIX_DEPENDS ${_targetSources})
  2021. cotire_get_unity_source_dependencies(${_language} ${_target} COTIRE_TARGET_UNITY_DEPENDS ${_targetSources})
  2022. # set up variables to be configured
  2023. set (COTIRE_TARGET_LANGUAGE "${_language}")
  2024. get_target_property(COTIRE_TARGET_IGNORE_PATH ${_target} COTIRE_PREFIX_HEADER_IGNORE_PATH)
  2025. cotire_add_sys_root_paths(COTIRE_TARGET_IGNORE_PATH)
  2026. get_target_property(COTIRE_TARGET_INCLUDE_PATH ${_target} COTIRE_PREFIX_HEADER_INCLUDE_PATH)
  2027. cotire_add_sys_root_paths(COTIRE_TARGET_INCLUDE_PATH)
  2028. get_target_property(COTIRE_TARGET_PRE_UNDEFS ${_target} COTIRE_UNITY_SOURCE_PRE_UNDEFS)
  2029. get_target_property(COTIRE_TARGET_POST_UNDEFS ${_target} COTIRE_UNITY_SOURCE_POST_UNDEFS)
  2030. get_target_property(COTIRE_TARGET_MAXIMUM_NUMBER_OF_INCLUDES ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  2031. get_target_property(COTIRE_TARGET_INCLUDE_PRIORITY_PATH ${_target} COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH)
  2032. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_PRE_UNDEFS COTIRE_TARGET_SOURCES_PRE_UNDEFS ${_targetSources})
  2033. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_POST_UNDEFS COTIRE_TARGET_SOURCES_POST_UNDEFS ${_targetSources})
  2034. set (COTIRE_TARGET_CONFIGURATION_TYPES "${_configurations}")
  2035. foreach (_config ${_configurations})
  2036. string (TOUPPER "${_config}" _upperConfig)
  2037. cotire_get_target_include_directories(
  2038. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig} COTIRE_TARGET_SYSTEM_INCLUDE_DIRECTORIES_${_upperConfig})
  2039. cotire_get_target_compile_definitions(
  2040. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig})
  2041. cotire_get_target_compiler_flags(
  2042. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig})
  2043. cotire_get_source_files_compile_definitions(
  2044. "${_config}" "${_language}" COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig} ${_targetSources})
  2045. endforeach()
  2046. get_target_property(COTIRE_TARGET_${_language}_COMPILER_LAUNCHER ${_target} ${_language}_COMPILER_LAUNCHER)
  2047. # set up COTIRE_TARGET_SOURCES
  2048. set (COTIRE_TARGET_SOURCES "")
  2049. foreach (_sourceFile ${_targetSources})
  2050. get_source_file_property(_generated "${_sourceFile}" GENERATED)
  2051. if (_generated)
  2052. # use absolute paths for generated files only, retrieving the LOCATION property is an expensive operation
  2053. get_source_file_property(_sourceLocation "${_sourceFile}" LOCATION)
  2054. list (APPEND COTIRE_TARGET_SOURCES "${_sourceLocation}")
  2055. else()
  2056. list (APPEND COTIRE_TARGET_SOURCES "${_sourceFile}")
  2057. endif()
  2058. endforeach()
  2059. # copy variable definitions to cotire target script
  2060. get_cmake_property(_vars VARIABLES)
  2061. string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+" _matchVars "${_vars}")
  2062. # omit COTIRE_*_INIT variables
  2063. string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+_INIT" _initVars "${_matchVars}")
  2064. if (_initVars)
  2065. list (REMOVE_ITEM _matchVars ${_initVars})
  2066. endif()
  2067. # omit COTIRE_VERBOSE which is passed as a CMake define on command line
  2068. list (REMOVE_ITEM _matchVars COTIRE_VERBOSE)
  2069. set (_contents "")
  2070. set (_contentsHasGeneratorExpressions FALSE)
  2071. foreach (_var IN LISTS _matchVars ITEMS
  2072. XCODE MSVC CMAKE_GENERATOR CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES
  2073. CMAKE_${_language}_COMPILER_ID CMAKE_${_language}_COMPILER_VERSION
  2074. CMAKE_${_language}_COMPILER_LAUNCHER CMAKE_${_language}_COMPILER CMAKE_${_language}_COMPILER_ARG1
  2075. CMAKE_INCLUDE_FLAG_${_language} CMAKE_INCLUDE_FLAG_${_language}_SEP
  2076. CMAKE_INCLUDE_SYSTEM_FLAG_${_language}
  2077. CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG
  2078. CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG
  2079. CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  2080. if (DEFINED ${_var})
  2081. string (REPLACE "\"" "\\\"" _value "${${_var}}")
  2082. set (_contents "${_contents}set (${_var} \"${_value}\")\n")
  2083. if (NOT _contentsHasGeneratorExpressions)
  2084. if ("${_value}" MATCHES "\\$<.*>")
  2085. set (_contentsHasGeneratorExpressions TRUE)
  2086. endif()
  2087. endif()
  2088. endif()
  2089. endforeach()
  2090. # generate target script file
  2091. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  2092. set (_targetCotireScript "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${_language}_${_moduleName}")
  2093. cotire_write_file("CMAKE" "${_targetCotireScript}" "${_contents}" FALSE)
  2094. if (_contentsHasGeneratorExpressions)
  2095. # use file(GENERATE ...) to expand generator expressions in the target script at CMake generate-time
  2096. set (_configNameOrNoneGeneratorExpression "$<$<CONFIG:>:None>$<$<NOT:$<CONFIG:>>:$<CONFIGURATION>>")
  2097. set (_targetCotireConfigScript "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${_language}_${_configNameOrNoneGeneratorExpression}_${_moduleName}")
  2098. file (GENERATE OUTPUT "${_targetCotireConfigScript}" INPUT "${_targetCotireScript}")
  2099. else()
  2100. set (_targetCotireConfigScript "${_targetCotireScript}")
  2101. endif()
  2102. set (${_targetScriptVar} "${_targetCotireScript}" PARENT_SCOPE)
  2103. set (${_targetConfigScriptVar} "${_targetCotireConfigScript}" PARENT_SCOPE)
  2104. endfunction()
  2105. function (cotire_setup_pch_file_compilation _language _target _targetScript _prefixFile _pchFile _hostFile)
  2106. set (_sourceFiles ${ARGN})
  2107. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2108. # for Visual Studio and Intel, we attach the precompiled header compilation to the host file
  2109. # the remaining files include the precompiled header, see cotire_setup_pch_file_inclusion
  2110. if (_sourceFiles)
  2111. set (_flags "")
  2112. cotire_add_pch_compilation_flags(
  2113. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2114. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _flags)
  2115. set_property (SOURCE ${_hostFile} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2116. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_OUTPUTS "${_pchFile}")
  2117. # make object file generated from host file depend on prefix header
  2118. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
  2119. # mark host file as cotired to prevent it from being used in another cotired target
  2120. set_property (SOURCE ${_hostFile} PROPERTY COTIRE_TARGET "${_target}")
  2121. endif()
  2122. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2123. # for makefile based generator, we add a custom command to precompile the prefix header
  2124. if (_targetScript)
  2125. cotire_set_cmd_to_prologue(_cmds)
  2126. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "precompile" "${_targetScript}" "${_prefixFile}" "${_pchFile}" "${_hostFile}")
  2127. if (MSVC_IDE)
  2128. file (TO_NATIVE_PATH "${_pchFile}" _pchFileLogPath)
  2129. else()
  2130. file (RELATIVE_PATH _pchFileLogPath "${CMAKE_BINARY_DIR}" "${_pchFile}")
  2131. endif()
  2132. if (COTIRE_DEBUG)
  2133. message (STATUS "add_custom_command: OUTPUT ${_pchFile} ${_cmds} DEPENDS ${_prefixFile} IMPLICIT_DEPENDS ${_language} ${_prefixFile}")
  2134. endif()
  2135. set_property (SOURCE "${_pchFile}" PROPERTY GENERATED TRUE)
  2136. add_custom_command(
  2137. OUTPUT "${_pchFile}"
  2138. COMMAND ${_cmds}
  2139. DEPENDS "${_prefixFile}"
  2140. IMPLICIT_DEPENDS ${_language} "${_prefixFile}"
  2141. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2142. COMMENT "Building ${_language} precompiled header ${_pchFileLogPath}"
  2143. VERBATIM)
  2144. endif()
  2145. endif()
  2146. endfunction()
  2147. function (cotire_setup_pch_file_inclusion _language _target _wholeTarget _prefixFile _pchFile _hostFile)
  2148. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2149. # for Visual Studio and Intel, we include the precompiled header in all but the host file
  2150. # the host file does the precompiled header compilation, see cotire_setup_pch_file_compilation
  2151. set (_sourceFiles ${ARGN})
  2152. list (LENGTH _sourceFiles _numberOfSourceFiles)
  2153. if (_numberOfSourceFiles GREATER 0)
  2154. # mark sources as cotired to prevent them from being used in another cotired target
  2155. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2156. set (_flags "")
  2157. cotire_add_prefix_pch_inclusion_flags(
  2158. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2159. "${_prefixFile}" "${_pchFile}" _flags)
  2160. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2161. # make object files generated from source files depend on precompiled header
  2162. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  2163. endif()
  2164. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2165. set (_sourceFiles ${_hostFile} ${ARGN})
  2166. if (NOT _wholeTarget)
  2167. # for makefile based generator, we force the inclusion of the prefix header for a subset
  2168. # of the source files, if this is a multi-language target or has excluded files
  2169. set (_flags "")
  2170. cotire_add_prefix_pch_inclusion_flags(
  2171. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2172. "${_prefixFile}" "${_pchFile}" _flags)
  2173. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2174. # mark sources as cotired to prevent them from being used in another cotired target
  2175. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2176. endif()
  2177. # make object files generated from source files depend on precompiled header
  2178. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  2179. endif()
  2180. endfunction()
  2181. function (cotire_setup_prefix_file_inclusion _language _target _prefixFile)
  2182. set (_sourceFiles ${ARGN})
  2183. # force the inclusion of the prefix header for the given source files
  2184. set (_flags "")
  2185. set (_pchFile "")
  2186. cotire_add_prefix_pch_inclusion_flags(
  2187. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2188. "${_prefixFile}" "${_pchFile}" _flags)
  2189. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2190. # mark sources as cotired to prevent them from being used in another cotired target
  2191. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2192. # make object files generated from source files depend on prefix header
  2193. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
  2194. endfunction()
  2195. function (cotire_get_first_set_property_value _propertyValueVar _type _object)
  2196. set (_properties ${ARGN})
  2197. foreach (_property ${_properties})
  2198. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  2199. if (_propertyValue)
  2200. set (${_propertyValueVar} ${_propertyValue} PARENT_SCOPE)
  2201. return()
  2202. endif()
  2203. endforeach()
  2204. set (${_propertyValueVar} "" PARENT_SCOPE)
  2205. endfunction()
  2206. function (cotire_setup_combine_command _language _targetScript _joinedFile _cmdsVar)
  2207. set (_files ${ARGN})
  2208. set (_filesPaths "")
  2209. foreach (_file ${_files})
  2210. get_filename_component(_filePath "${_file}" ABSOLUTE)
  2211. list (APPEND _filesPaths "${_filePath}")
  2212. endforeach()
  2213. cotire_set_cmd_to_prologue(_prefixCmd)
  2214. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "combine")
  2215. if (_targetScript)
  2216. list (APPEND _prefixCmd "${_targetScript}")
  2217. endif()
  2218. list (APPEND _prefixCmd "${_joinedFile}" ${_filesPaths})
  2219. if (COTIRE_DEBUG)
  2220. message (STATUS "add_custom_command: OUTPUT ${_joinedFile} COMMAND ${_prefixCmd} DEPENDS ${_files}")
  2221. endif()
  2222. set_property (SOURCE "${_joinedFile}" PROPERTY GENERATED TRUE)
  2223. if (MSVC_IDE)
  2224. file (TO_NATIVE_PATH "${_joinedFile}" _joinedFileLogPath)
  2225. else()
  2226. file (RELATIVE_PATH _joinedFileLogPath "${CMAKE_BINARY_DIR}" "${_joinedFile}")
  2227. endif()
  2228. get_filename_component(_joinedFileBaseName "${_joinedFile}" NAME_WE)
  2229. get_filename_component(_joinedFileExt "${_joinedFile}" EXT)
  2230. if (_language AND _joinedFileBaseName MATCHES "${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}$")
  2231. set (_comment "Generating ${_language} unity source ${_joinedFileLogPath}")
  2232. elseif (_language AND _joinedFileBaseName MATCHES "${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}$")
  2233. if (_joinedFileExt MATCHES "^\\.c")
  2234. set (_comment "Generating ${_language} prefix source ${_joinedFileLogPath}")
  2235. else()
  2236. set (_comment "Generating ${_language} prefix header ${_joinedFileLogPath}")
  2237. endif()
  2238. else()
  2239. set (_comment "Generating ${_joinedFileLogPath}")
  2240. endif()
  2241. add_custom_command(
  2242. OUTPUT "${_joinedFile}"
  2243. COMMAND ${_prefixCmd}
  2244. DEPENDS ${_files}
  2245. COMMENT "${_comment}"
  2246. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  2247. VERBATIM)
  2248. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  2249. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2250. endfunction()
  2251. function (cotire_setup_target_pch_usage _languages _target _wholeTarget)
  2252. if (XCODE)
  2253. # for Xcode, we attach a pre-build action to generate the unity sources and prefix headers
  2254. set (_prefixFiles "")
  2255. foreach (_language ${_languages})
  2256. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2257. if (_prefixFile)
  2258. list (APPEND _prefixFiles "${_prefixFile}")
  2259. endif()
  2260. endforeach()
  2261. set (_cmds ${ARGN})
  2262. list (LENGTH _prefixFiles _numberOfPrefixFiles)
  2263. if (_numberOfPrefixFiles GREATER 1)
  2264. # we also generate a generic, single prefix header which includes all language specific prefix headers
  2265. set (_language "")
  2266. set (_targetScript "")
  2267. cotire_make_prefix_file_path("${_language}" ${_target} _prefixHeader)
  2268. cotire_setup_combine_command("${_language}" "${_targetScript}" "${_prefixHeader}" _cmds ${_prefixFiles})
  2269. else()
  2270. set (_prefixHeader "${_prefixFiles}")
  2271. endif()
  2272. if (COTIRE_DEBUG)
  2273. message (STATUS "add_custom_command: TARGET ${_target} PRE_BUILD ${_cmds}")
  2274. endif()
  2275. # because CMake PRE_BUILD command does not support dependencies,
  2276. # we check dependencies explicity in cotire script mode when the pre-build action is run
  2277. add_custom_command(
  2278. TARGET "${_target}"
  2279. PRE_BUILD ${_cmds}
  2280. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2281. COMMENT "Updating target ${_target} prefix headers"
  2282. VERBATIM)
  2283. # make Xcode precompile the generated prefix header with ProcessPCH and ProcessPCH++
  2284. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
  2285. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${_prefixHeader}")
  2286. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2287. # for makefile based generator, we force inclusion of the prefix header for all target source files
  2288. # if this is a single-language target without any excluded files
  2289. if (_wholeTarget)
  2290. set (_language "${_languages}")
  2291. # for Visual Studio and Intel, precompiled header inclusion is always done on the source file level
  2292. # see cotire_setup_pch_file_inclusion
  2293. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2294. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2295. if (_prefixFile)
  2296. get_property(_pchFile TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER)
  2297. set (_options COMPILE_OPTIONS)
  2298. cotire_add_prefix_pch_inclusion_flags(
  2299. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2300. "${_prefixFile}" "${_pchFile}" _options)
  2301. set_property(TARGET ${_target} APPEND PROPERTY ${_options})
  2302. endif()
  2303. endif()
  2304. endif()
  2305. endif()
  2306. endfunction()
  2307. function (cotire_setup_unity_generation_commands _language _target _targetScript _targetConfigScript _unityFiles _cmdsVar)
  2308. set (_dependencySources "")
  2309. cotire_get_unity_source_dependencies(${_language} ${_target} _dependencySources ${ARGN})
  2310. foreach (_unityFile ${_unityFiles})
  2311. set_property (SOURCE "${_unityFile}" PROPERTY GENERATED TRUE)
  2312. # set up compiled unity source dependencies via OBJECT_DEPENDS
  2313. # this ensures that missing source files are generated before the unity file is compiled
  2314. if (COTIRE_DEBUG AND _dependencySources)
  2315. message (STATUS "${_unityFile} OBJECT_DEPENDS ${_dependencySources}")
  2316. endif()
  2317. if (_dependencySources)
  2318. # the OBJECT_DEPENDS property requires a list of full paths
  2319. set (_objectDependsPaths "")
  2320. foreach (_sourceFile ${_dependencySources})
  2321. get_source_file_property(_sourceLocation "${_sourceFile}" LOCATION)
  2322. list (APPEND _objectDependsPaths "${_sourceLocation}")
  2323. endforeach()
  2324. set_property (SOURCE "${_unityFile}" PROPERTY OBJECT_DEPENDS ${_objectDependsPaths})
  2325. endif()
  2326. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2327. # unity file compilation results in potentially huge object file, thus use /bigobj by default unter MSVC and Windows Intel
  2328. set_property (SOURCE "${_unityFile}" APPEND_STRING PROPERTY COMPILE_FLAGS "/bigobj")
  2329. endif()
  2330. cotire_set_cmd_to_prologue(_unityCmd)
  2331. list (APPEND _unityCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "unity" "${_targetConfigScript}" "${_unityFile}")
  2332. if (CMAKE_VERSION VERSION_LESS "3.1.0")
  2333. set (_unityCmdDepends "${_targetScript}")
  2334. else()
  2335. # CMake 3.1.0 supports generator expressions in arguments to DEPENDS
  2336. set (_unityCmdDepends "${_targetConfigScript}")
  2337. endif()
  2338. if (MSVC_IDE)
  2339. file (TO_NATIVE_PATH "${_unityFile}" _unityFileLogPath)
  2340. else()
  2341. file (RELATIVE_PATH _unityFileLogPath "${CMAKE_BINARY_DIR}" "${_unityFile}")
  2342. endif()
  2343. if (COTIRE_DEBUG)
  2344. message (STATUS "add_custom_command: OUTPUT ${_unityFile} COMMAND ${_unityCmd} DEPENDS ${_unityCmdDepends}")
  2345. endif()
  2346. add_custom_command(
  2347. OUTPUT "${_unityFile}"
  2348. COMMAND ${_unityCmd}
  2349. DEPENDS ${_unityCmdDepends}
  2350. COMMENT "Generating ${_language} unity source ${_unityFileLogPath}"
  2351. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2352. VERBATIM)
  2353. list (APPEND ${_cmdsVar} COMMAND ${_unityCmd})
  2354. endforeach()
  2355. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2356. endfunction()
  2357. function (cotire_setup_prefix_generation_command _language _target _targetScript _prefixFile _unityFiles _cmdsVar)
  2358. set (_sourceFiles ${ARGN})
  2359. set (_dependencySources "")
  2360. cotire_get_prefix_header_dependencies(${_language} ${_target} _dependencySources ${_sourceFiles})
  2361. cotire_set_cmd_to_prologue(_prefixCmd)
  2362. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "prefix" "${_targetScript}" "${_prefixFile}" ${_unityFiles})
  2363. set_property (SOURCE "${_prefixFile}" PROPERTY GENERATED TRUE)
  2364. if (COTIRE_DEBUG)
  2365. message (STATUS "add_custom_command: OUTPUT ${_prefixFile} COMMAND ${_prefixCmd} DEPENDS ${_unityFile} ${_dependencySources}")
  2366. endif()
  2367. if (MSVC_IDE)
  2368. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileLogPath)
  2369. else()
  2370. file (RELATIVE_PATH _prefixFileLogPath "${CMAKE_BINARY_DIR}" "${_prefixFile}")
  2371. endif()
  2372. get_filename_component(_prefixFileExt "${_prefixFile}" EXT)
  2373. if (_prefixFileExt MATCHES "^\\.c")
  2374. set (_comment "Generating ${_language} prefix source ${_prefixFileLogPath}")
  2375. else()
  2376. set (_comment "Generating ${_language} prefix header ${_prefixFileLogPath}")
  2377. endif()
  2378. # prevent pre-processing errors upon generating the prefix header when a target's generated include file does not yet exist
  2379. # we do not add a file-level dependency for the target's generated files though, because we only want to depend on their existence
  2380. # thus we make the prefix header generation depend on a custom helper target which triggers the generation of the files
  2381. set (_preTargetName "${_target}${COTIRE_PCH_TARGET_SUFFIX}_pre")
  2382. if (TARGET ${_preTargetName})
  2383. # custom helper target has already been generated while processing a different language
  2384. list (APPEND _dependencySources ${_preTargetName})
  2385. else()
  2386. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2387. cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${_targetSourceFiles})
  2388. if (_generatedSources)
  2389. add_custom_target("${_preTargetName}" DEPENDS ${_generatedSources})
  2390. cotire_init_target("${_preTargetName}")
  2391. list (APPEND _dependencySources ${_preTargetName})
  2392. endif()
  2393. endif()
  2394. add_custom_command(
  2395. OUTPUT "${_prefixFile}" "${_prefixFile}.log"
  2396. COMMAND ${_prefixCmd}
  2397. DEPENDS ${_unityFiles} ${_dependencySources}
  2398. COMMENT "${_comment}"
  2399. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2400. VERBATIM)
  2401. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  2402. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2403. endfunction()
  2404. function (cotire_setup_prefix_generation_from_unity_command _language _target _targetScript _prefixFile _unityFiles _cmdsVar)
  2405. set (_sourceFiles ${ARGN})
  2406. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2407. # GNU and Clang require indirect compilation of the prefix header to make them honor the system_header pragma
  2408. cotire_prefix_header_to_source_file_path(${_language} "${_prefixFile}" _prefixSourceFile)
  2409. else()
  2410. set (_prefixSourceFile "${_prefixFile}")
  2411. endif()
  2412. cotire_setup_prefix_generation_command(
  2413. ${_language} ${_target} "${_targetScript}"
  2414. "${_prefixSourceFile}" "${_unityFiles}" ${_cmdsVar} ${_sourceFiles})
  2415. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2416. # set up generation of a prefix source file which includes the prefix header
  2417. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixFile}" _cmds ${_prefixSourceFile})
  2418. endif()
  2419. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2420. endfunction()
  2421. function (cotire_setup_prefix_generation_from_provided_command _language _target _targetScript _prefixFile _cmdsVar)
  2422. set (_prefixHeaderFiles ${ARGN})
  2423. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2424. # GNU and Clang require indirect compilation of the prefix header to make them honor the system_header pragma
  2425. cotire_prefix_header_to_source_file_path(${_language} "${_prefixFile}" _prefixSourceFile)
  2426. else()
  2427. set (_prefixSourceFile "${_prefixFile}")
  2428. endif()
  2429. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixSourceFile}" _cmds ${_prefixHeaderFiles})
  2430. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2431. # set up generation of a prefix source file which includes the prefix header
  2432. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixFile}" _cmds ${_prefixSourceFile})
  2433. endif()
  2434. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2435. endfunction()
  2436. function (cotire_init_cotire_target_properties _target)
  2437. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER SET)
  2438. if (NOT _isSet)
  2439. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER TRUE)
  2440. endif()
  2441. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD SET)
  2442. if (NOT _isSet)
  2443. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD TRUE)
  2444. endif()
  2445. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN SET)
  2446. if (NOT _isSet)
  2447. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN FALSE)
  2448. endif()
  2449. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH SET)
  2450. if (NOT _isSet)
  2451. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_SOURCE_DIR}")
  2452. cotire_check_is_path_relative_to("${CMAKE_BINARY_DIR}" _isRelative "${CMAKE_SOURCE_DIR}")
  2453. if (NOT _isRelative)
  2454. set_property(TARGET ${_target} APPEND PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_BINARY_DIR}")
  2455. endif()
  2456. endif()
  2457. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH SET)
  2458. if (NOT _isSet)
  2459. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH "")
  2460. endif()
  2461. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH SET)
  2462. if (NOT _isSet)
  2463. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH "")
  2464. endif()
  2465. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS SET)
  2466. if (NOT _isSet)
  2467. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS "")
  2468. endif()
  2469. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS SET)
  2470. if (NOT _isSet)
  2471. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS "")
  2472. endif()
  2473. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT SET)
  2474. if (NOT _isSet)
  2475. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY_UNITY")
  2476. endif()
  2477. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES SET)
  2478. if (NOT _isSet)
  2479. if (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  2480. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES}")
  2481. else()
  2482. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "")
  2483. endif()
  2484. endif()
  2485. endfunction()
  2486. function (cotire_make_target_message _target _languages _disableMsg _targetMsgVar)
  2487. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2488. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  2489. string (REPLACE ";" " " _languagesStr "${_languages}")
  2490. math (EXPR _numberOfExcludedFiles "${ARGC} - 4")
  2491. if (_numberOfExcludedFiles EQUAL 0)
  2492. set (_excludedStr "")
  2493. elseif (COTIRE_VERBOSE OR _numberOfExcludedFiles LESS 4)
  2494. string (REPLACE ";" ", " _excludedStr "excluding ${ARGN}")
  2495. else()
  2496. set (_excludedStr "excluding ${_numberOfExcludedFiles} files")
  2497. endif()
  2498. set (_targetMsg "")
  2499. if (NOT _languages)
  2500. set (_targetMsg "Target ${_target} cannot be cotired.")
  2501. if (_disableMsg)
  2502. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2503. endif()
  2504. elseif (NOT _targetUsePCH AND NOT _targetAddSCU)
  2505. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build and precompiled header.")
  2506. if (_disableMsg)
  2507. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2508. endif()
  2509. elseif (NOT _targetUsePCH)
  2510. if (_excludedStr)
  2511. set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header ${_excludedStr}.")
  2512. else()
  2513. set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header.")
  2514. endif()
  2515. if (_disableMsg)
  2516. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2517. endif()
  2518. elseif (NOT _targetAddSCU)
  2519. if (_excludedStr)
  2520. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build ${_excludedStr}.")
  2521. else()
  2522. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build.")
  2523. endif()
  2524. else()
  2525. if (_excludedStr)
  2526. set (_targetMsg "${_languagesStr} target ${_target} cotired ${_excludedStr}.")
  2527. else()
  2528. set (_targetMsg "${_languagesStr} target ${_target} cotired.")
  2529. endif()
  2530. endif()
  2531. set (${_targetMsgVar} "${_targetMsg}" PARENT_SCOPE)
  2532. endfunction()
  2533. function (cotire_choose_target_languages _target _targetLanguagesVar _wholeTargetVar)
  2534. set (_languages ${ARGN})
  2535. set (_allSourceFiles "")
  2536. set (_allExcludedSourceFiles "")
  2537. set (_allCotiredSourceFiles "")
  2538. set (_targetLanguages "")
  2539. set (_pchEligibleTargetLanguages "")
  2540. get_target_property(_targetType ${_target} TYPE)
  2541. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2542. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2543. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  2544. set (_disableMsg "")
  2545. foreach (_language ${_languages})
  2546. get_target_property(_prefixHeader ${_target} COTIRE_${_language}_PREFIX_HEADER)
  2547. get_target_property(_unityBuildFile ${_target} COTIRE_${_language}_UNITY_SOURCE)
  2548. if (_prefixHeader OR _unityBuildFile)
  2549. message (STATUS "cotire: target ${_target} has already been cotired.")
  2550. set (${_targetLanguagesVar} "" PARENT_SCOPE)
  2551. return()
  2552. endif()
  2553. if (_targetUsePCH AND "${_language}" MATCHES "^C|CXX$" AND NOT "${CMAKE_${_language}_COMPILER_ID}" STREQUAL "")
  2554. cotire_check_precompiled_header_support("${_language}" "${_target}" _disableMsg)
  2555. if (_disableMsg)
  2556. set (_targetUsePCH FALSE)
  2557. endif()
  2558. endif()
  2559. set (_sourceFiles "")
  2560. set (_excludedSources "")
  2561. set (_cotiredSources "")
  2562. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2563. if (_sourceFiles OR _excludedSources OR _cotiredSources)
  2564. list (APPEND _targetLanguages ${_language})
  2565. endif()
  2566. if (_sourceFiles)
  2567. list (APPEND _allSourceFiles ${_sourceFiles})
  2568. endif()
  2569. list (LENGTH _sourceFiles _numberOfSources)
  2570. if (NOT _numberOfSources LESS ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  2571. list (APPEND _pchEligibleTargetLanguages ${_language})
  2572. endif()
  2573. if (_excludedSources)
  2574. list (APPEND _allExcludedSourceFiles ${_excludedSources})
  2575. endif()
  2576. if (_cotiredSources)
  2577. list (APPEND _allCotiredSourceFiles ${_cotiredSources})
  2578. endif()
  2579. endforeach()
  2580. set (_targetMsgLevel STATUS)
  2581. if (NOT _targetLanguages)
  2582. string (REPLACE ";" " or " _languagesStr "${_languages}")
  2583. set (_disableMsg "No ${_languagesStr} source files.")
  2584. set (_targetUsePCH FALSE)
  2585. set (_targetAddSCU FALSE)
  2586. endif()
  2587. if (_targetUsePCH)
  2588. if (_allCotiredSourceFiles)
  2589. cotire_get_source_file_property_values(_cotireTargets COTIRE_TARGET ${_allCotiredSourceFiles})
  2590. list (REMOVE_DUPLICATES _cotireTargets)
  2591. string (REPLACE ";" ", " _cotireTargetsStr "${_cotireTargets}")
  2592. set (_disableMsg "Target sources already include a precompiled header for target(s) ${_cotireTargets}.")
  2593. set (_disableMsg "${_disableMsg} Set target property COTIRE_ENABLE_PRECOMPILED_HEADER to FALSE for targets ${_target},")
  2594. set (_disableMsg "${_disableMsg} ${_cotireTargetsStr} to get a workable build system.")
  2595. set (_targetMsgLevel SEND_ERROR)
  2596. set (_targetUsePCH FALSE)
  2597. elseif (NOT _pchEligibleTargetLanguages)
  2598. set (_disableMsg "Too few applicable sources.")
  2599. set (_targetUsePCH FALSE)
  2600. elseif (XCODE AND _allExcludedSourceFiles)
  2601. # for Xcode, we cannot apply the precompiled header to individual sources, only to the whole target
  2602. set (_disableMsg "Exclusion of source files not supported for generator Xcode.")
  2603. set (_targetUsePCH FALSE)
  2604. elseif (XCODE AND "${_targetType}" STREQUAL "OBJECT_LIBRARY")
  2605. # for Xcode, we cannot apply the required PRE_BUILD action to generate the prefix header to an OBJECT_LIBRARY target
  2606. set (_disableMsg "Required PRE_BUILD action not supported for OBJECT_LIBRARY targets for generator Xcode.")
  2607. set (_targetUsePCH FALSE)
  2608. endif()
  2609. endif()
  2610. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER ${_targetUsePCH})
  2611. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD ${_targetAddSCU})
  2612. cotire_make_target_message(${_target} "${_targetLanguages}" "${_disableMsg}" _targetMsg ${_allExcludedSourceFiles})
  2613. if (_targetMsg)
  2614. if (NOT DEFINED COTIREMSG_${_target})
  2615. set (COTIREMSG_${_target} "")
  2616. endif()
  2617. if (COTIRE_VERBOSE OR NOT "${_targetMsgLevel}" STREQUAL "STATUS" OR
  2618. NOT "${COTIREMSG_${_target}}" STREQUAL "${_targetMsg}")
  2619. # cache message to avoid redundant messages on re-configure
  2620. set (COTIREMSG_${_target} "${_targetMsg}" CACHE INTERNAL "${_target} cotire message.")
  2621. message (${_targetMsgLevel} "${_targetMsg}")
  2622. endif()
  2623. endif()
  2624. list (LENGTH _targetLanguages _numberOfLanguages)
  2625. if (_numberOfLanguages GREATER 1 OR _allExcludedSourceFiles)
  2626. set (${_wholeTargetVar} FALSE PARENT_SCOPE)
  2627. else()
  2628. set (${_wholeTargetVar} TRUE PARENT_SCOPE)
  2629. endif()
  2630. set (${_targetLanguagesVar} ${_targetLanguages} PARENT_SCOPE)
  2631. endfunction()
  2632. function (cotire_compute_unity_max_number_of_includes _target _maxIncludesVar)
  2633. set (_sourceFiles ${ARGN})
  2634. get_target_property(_maxIncludes ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  2635. if (_maxIncludes MATCHES "(-j|--parallel|--jobs) ?([0-9]*)")
  2636. set (_numberOfThreads "${CMAKE_MATCH_2}")
  2637. if (NOT _numberOfThreads)
  2638. # use all available cores
  2639. ProcessorCount(_numberOfThreads)
  2640. endif()
  2641. list (LENGTH _sourceFiles _numberOfSources)
  2642. math (EXPR _maxIncludes "(${_numberOfSources} + ${_numberOfThreads} - 1) / ${_numberOfThreads}")
  2643. elseif (NOT _maxIncludes MATCHES "[0-9]+")
  2644. set (_maxIncludes 0)
  2645. endif()
  2646. if (COTIRE_DEBUG)
  2647. message (STATUS "${_target} unity source max includes: ${_maxIncludes}")
  2648. endif()
  2649. set (${_maxIncludesVar} ${_maxIncludes} PARENT_SCOPE)
  2650. endfunction()
  2651. function (cotire_process_target_language _language _configurations _target _wholeTarget _cmdsVar)
  2652. set (${_cmdsVar} "" PARENT_SCOPE)
  2653. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2654. set (_sourceFiles "")
  2655. set (_excludedSources "")
  2656. set (_cotiredSources "")
  2657. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2658. if (NOT _sourceFiles AND NOT _cotiredSources)
  2659. return()
  2660. endif()
  2661. set (_cmds "")
  2662. # check for user provided unity source file list
  2663. get_property(_unitySourceFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE_INIT)
  2664. if (NOT _unitySourceFiles)
  2665. set (_unitySourceFiles ${_sourceFiles} ${_cotiredSources})
  2666. endif()
  2667. cotire_generate_target_script(
  2668. ${_language} "${_configurations}" ${_target} _targetScript _targetConfigScript ${_unitySourceFiles})
  2669. # set up unity files for parallel compilation
  2670. cotire_compute_unity_max_number_of_includes(${_target} _maxIncludes ${_unitySourceFiles})
  2671. cotire_make_unity_source_file_paths(${_language} ${_target} ${_maxIncludes} _unityFiles ${_unitySourceFiles})
  2672. list (LENGTH _unityFiles _numberOfUnityFiles)
  2673. if (_numberOfUnityFiles EQUAL 0)
  2674. return()
  2675. elseif (_numberOfUnityFiles GREATER 1)
  2676. cotire_setup_unity_generation_commands(
  2677. ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFiles}" _cmds ${_unitySourceFiles})
  2678. endif()
  2679. # set up single unity file for prefix header generation
  2680. cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFile)
  2681. cotire_setup_unity_generation_commands(
  2682. ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFile}" _cmds ${_unitySourceFiles})
  2683. cotire_make_prefix_file_path(${_language} ${_target} _prefixFile)
  2684. # set up prefix header
  2685. if (_prefixFile)
  2686. # check for user provided prefix header files
  2687. get_property(_prefixHeaderFiles TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
  2688. if (_prefixHeaderFiles)
  2689. cotire_setup_prefix_generation_from_provided_command(
  2690. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" _cmds ${_prefixHeaderFiles})
  2691. else()
  2692. cotire_setup_prefix_generation_from_unity_command(
  2693. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_unityFile}" _cmds ${_unitySourceFiles})
  2694. endif()
  2695. # check if selected language has enough sources at all
  2696. list (LENGTH _sourceFiles _numberOfSources)
  2697. if (_numberOfSources LESS ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  2698. set (_targetUsePCH FALSE)
  2699. else()
  2700. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2701. endif()
  2702. if (_targetUsePCH)
  2703. cotire_make_pch_file_path(${_language} ${_target} _pchFile)
  2704. if (_pchFile)
  2705. # first file in _sourceFiles is passed as the host file
  2706. cotire_setup_pch_file_compilation(
  2707. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2708. cotire_setup_pch_file_inclusion(
  2709. ${_language} ${_target} ${_wholeTarget} "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2710. endif()
  2711. elseif (_prefixHeaderFiles)
  2712. # user provided prefix header must be included unconditionally
  2713. cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_sourceFiles})
  2714. endif()
  2715. endif()
  2716. # mark target as cotired for language
  2717. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE "${_unityFiles}")
  2718. if (_prefixFile)
  2719. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER "${_prefixFile}")
  2720. if (_targetUsePCH AND _pchFile)
  2721. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER "${_pchFile}")
  2722. endif()
  2723. endif()
  2724. set (${_cmdsVar} ${_cmds} PARENT_SCOPE)
  2725. endfunction()
  2726. function (cotire_setup_clean_target _target)
  2727. set (_cleanTargetName "${_target}${COTIRE_CLEAN_TARGET_SUFFIX}")
  2728. if (NOT TARGET "${_cleanTargetName}")
  2729. cotire_set_cmd_to_prologue(_cmds)
  2730. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" ABSOLUTE)
  2731. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${_outputDir}" "${COTIRE_INTDIR}" "${_target}")
  2732. add_custom_target(${_cleanTargetName}
  2733. COMMAND ${_cmds}
  2734. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  2735. COMMENT "Cleaning up target ${_target} cotire generated files"
  2736. VERBATIM)
  2737. cotire_init_target("${_cleanTargetName}")
  2738. endif()
  2739. endfunction()
  2740. function (cotire_setup_pch_target _languages _configurations _target)
  2741. if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2742. # for makefile based generators, we add a custom target to trigger the generation of the cotire related files
  2743. set (_dependsFiles "")
  2744. foreach (_language ${_languages})
  2745. set (_props COTIRE_${_language}_PREFIX_HEADER COTIRE_${_language}_UNITY_SOURCE)
  2746. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2747. # Visual Studio and Intel only create precompiled header as a side effect
  2748. list (INSERT _props 0 COTIRE_${_language}_PRECOMPILED_HEADER)
  2749. endif()
  2750. cotire_get_first_set_property_value(_dependsFile TARGET ${_target} ${_props})
  2751. if (_dependsFile)
  2752. list (APPEND _dependsFiles "${_dependsFile}")
  2753. endif()
  2754. endforeach()
  2755. if (_dependsFiles)
  2756. set (_pchTargetName "${_target}${COTIRE_PCH_TARGET_SUFFIX}")
  2757. add_custom_target("${_pchTargetName}" DEPENDS ${_dependsFiles})
  2758. cotire_init_target("${_pchTargetName}")
  2759. cotire_add_to_pch_all_target(${_pchTargetName})
  2760. endif()
  2761. else()
  2762. # for other generators, we add the "clean all" target to clean up the precompiled header
  2763. cotire_setup_clean_all_target()
  2764. endif()
  2765. endfunction()
  2766. function (cotire_collect_unity_target_sources _target _languages _unityTargetSourcesVar)
  2767. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2768. set (_unityTargetSources ${_targetSourceFiles})
  2769. foreach (_language ${_languages})
  2770. get_property(_unityFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE)
  2771. if (_unityFiles)
  2772. # remove source files that are included in the unity source
  2773. set (_sourceFiles "")
  2774. set (_excludedSources "")
  2775. set (_cotiredSources "")
  2776. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2777. if (_sourceFiles OR _cotiredSources)
  2778. list (REMOVE_ITEM _unityTargetSources ${_sourceFiles} ${_cotiredSources})
  2779. endif()
  2780. # add unity source files instead
  2781. list (APPEND _unityTargetSources ${_unityFiles})
  2782. endif()
  2783. endforeach()
  2784. set (${_unityTargetSourcesVar} ${_unityTargetSources} PARENT_SCOPE)
  2785. endfunction()
  2786. function (cotire_setup_unity_target_pch_usage _languages _target)
  2787. foreach (_language ${_languages})
  2788. get_property(_unityFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE)
  2789. if (_unityFiles)
  2790. get_property(_userPrefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
  2791. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2792. if (_userPrefixFile AND _prefixFile)
  2793. # user provided prefix header must be included unconditionally by unity sources
  2794. cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_unityFiles})
  2795. endif()
  2796. endif()
  2797. endforeach()
  2798. endfunction()
  2799. function (cotire_setup_unity_build_target _languages _configurations _target)
  2800. get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME)
  2801. if (NOT _unityTargetName)
  2802. set (_unityTargetName "${_target}${COTIRE_UNITY_BUILD_TARGET_SUFFIX}")
  2803. endif()
  2804. # determine unity target sub type
  2805. get_target_property(_targetType ${_target} TYPE)
  2806. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2807. set (_unityTargetSubType "")
  2808. elseif (_targetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  2809. set (_unityTargetSubType "${CMAKE_MATCH_1}")
  2810. else()
  2811. message (WARNING "cotire: target ${_target} has unknown target type ${_targetType}.")
  2812. return()
  2813. endif()
  2814. # determine unity target sources
  2815. set (_unityTargetSources "")
  2816. cotire_collect_unity_target_sources(${_target} "${_languages}" _unityTargetSources)
  2817. # handle automatic Qt processing
  2818. get_target_property(_targetAutoMoc ${_target} AUTOMOC)
  2819. get_target_property(_targetAutoUic ${_target} AUTOUIC)
  2820. get_target_property(_targetAutoRcc ${_target} AUTORCC)
  2821. if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
  2822. # if the original target sources are subject to CMake's automatic Qt processing,
  2823. # also include implicitly generated <targetname>_automoc.cpp file
  2824. list (APPEND _unityTargetSources "${_target}_automoc.cpp")
  2825. set_property (SOURCE "${_target}_automoc.cpp" PROPERTY GENERATED TRUE)
  2826. endif()
  2827. # prevent AUTOMOC, AUTOUIC and AUTORCC properties from being set when the unity target is created
  2828. set (CMAKE_AUTOMOC OFF)
  2829. set (CMAKE_AUTOUIC OFF)
  2830. set (CMAKE_AUTORCC OFF)
  2831. if (COTIRE_DEBUG)
  2832. message (STATUS "add target ${_targetType} ${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources}")
  2833. endif()
  2834. # generate unity target
  2835. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2836. add_executable(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2837. else()
  2838. add_library(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2839. endif()
  2840. if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
  2841. # depend on the original target's implicity generated <targetname>_automoc target
  2842. add_dependencies(${_unityTargetName} ${_target}_automoc)
  2843. endif()
  2844. # copy output location properties
  2845. set (_outputDirProperties
  2846. ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>
  2847. LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_<CONFIG>
  2848. RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_<CONFIG>)
  2849. if (COTIRE_UNITY_OUTPUT_DIRECTORY)
  2850. set (_setDefaultOutputDir TRUE)
  2851. if (IS_ABSOLUTE "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2852. set (_outputDir "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2853. else()
  2854. # append relative COTIRE_UNITY_OUTPUT_DIRECTORY to target's actual output directory
  2855. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties})
  2856. cotire_resolve_config_properites("${_configurations}" _properties ${_outputDirProperties})
  2857. foreach (_property ${_properties})
  2858. get_property(_outputDir TARGET ${_target} PROPERTY ${_property})
  2859. if (_outputDir)
  2860. get_filename_component(_outputDir "${_outputDir}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2861. set_property(TARGET ${_unityTargetName} PROPERTY ${_property} "${_outputDir}")
  2862. set (_setDefaultOutputDir FALSE)
  2863. endif()
  2864. endforeach()
  2865. if (_setDefaultOutputDir)
  2866. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2867. endif()
  2868. endif()
  2869. if (_setDefaultOutputDir)
  2870. set_target_properties(${_unityTargetName} PROPERTIES
  2871. ARCHIVE_OUTPUT_DIRECTORY "${_outputDir}"
  2872. LIBRARY_OUTPUT_DIRECTORY "${_outputDir}"
  2873. RUNTIME_OUTPUT_DIRECTORY "${_outputDir}")
  2874. endif()
  2875. else()
  2876. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2877. ${_outputDirProperties})
  2878. endif()
  2879. # copy output name
  2880. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2881. ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_<CONFIG>
  2882. LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_<CONFIG>
  2883. OUTPUT_NAME OUTPUT_NAME_<CONFIG>
  2884. RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_<CONFIG>
  2885. PREFIX <CONFIG>_POSTFIX SUFFIX
  2886. IMPORT_PREFIX IMPORT_SUFFIX)
  2887. # copy compile stuff
  2888. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2889. COMPILE_DEFINITIONS COMPILE_DEFINITIONS_<CONFIG>
  2890. COMPILE_FLAGS COMPILE_OPTIONS
  2891. Fortran_FORMAT Fortran_MODULE_DIRECTORY
  2892. INCLUDE_DIRECTORIES
  2893. INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
  2894. POSITION_INDEPENDENT_CODE
  2895. C_COMPILER_LAUNCHER CXX_COMPILER_LAUNCHER
  2896. C_INCLUDE_WHAT_YOU_USE CXX_INCLUDE_WHAT_YOU_USE
  2897. C_VISIBILITY_PRESET CXX_VISIBILITY_PRESET VISIBILITY_INLINES_HIDDEN)
  2898. # copy compile features
  2899. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2900. C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED
  2901. CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED
  2902. COMPILE_FEATURES)
  2903. # copy interface stuff
  2904. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2905. COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN
  2906. COMPATIBLE_INTERFACE_STRING
  2907. INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS
  2908. INTERFACE_INCLUDE_DIRECTORIES INTERFACE_SOURCES
  2909. INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
  2910. INTERFACE_AUTOUIC_OPTIONS NO_SYSTEM_FROM_IMPORTED)
  2911. # copy link stuff
  2912. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2913. BUILD_WITH_INSTALL_RPATH INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH SKIP_BUILD_RPATH
  2914. LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED
  2915. LINK_FLAGS LINK_FLAGS_<CONFIG>
  2916. LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_<CONFIG>
  2917. LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_<CONFIG>
  2918. LINK_SEARCH_START_STATIC LINK_SEARCH_END_STATIC
  2919. STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_<CONFIG>
  2920. NO_SONAME SOVERSION VERSION)
  2921. # copy cmake stuff
  2922. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2923. IMPLICIT_DEPENDS_INCLUDE_TRANSFORM RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK)
  2924. # copy Apple platform specific stuff
  2925. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2926. BUNDLE BUNDLE_EXTENSION FRAMEWORK FRAMEWORK_VERSION INSTALL_NAME_DIR
  2927. MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_RPATH
  2928. OSX_ARCHITECTURES OSX_ARCHITECTURES_<CONFIG> PRIVATE_HEADER PUBLIC_HEADER RESOURCE XCTEST
  2929. IOS_INSTALL_COMBINED)
  2930. # copy Windows platform specific stuff
  2931. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2932. GNUtoMS
  2933. COMPILE_PDB_NAME COMPILE_PDB_NAME_<CONFIG>
  2934. COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>
  2935. PDB_NAME PDB_NAME_<CONFIG> PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_<CONFIG>
  2936. VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION
  2937. VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE
  2938. VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK
  2939. VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION
  2940. VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER
  2941. VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION
  2942. VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES
  2943. WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS)
  2944. # copy Android platform specific stuff
  2945. cotire_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2946. ANDROID_API ANDROID_API_MIN ANDROID_GUI
  2947. ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES
  2948. ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR
  2949. ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES
  2950. ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH
  2951. ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE)
  2952. # use output name from original target
  2953. get_target_property(_targetOutputName ${_unityTargetName} OUTPUT_NAME)
  2954. if (NOT _targetOutputName)
  2955. set_property(TARGET ${_unityTargetName} PROPERTY OUTPUT_NAME "${_target}")
  2956. endif()
  2957. # use export symbol from original target
  2958. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  2959. if (_defineSymbol)
  2960. set_property(TARGET ${_unityTargetName} PROPERTY DEFINE_SYMBOL "${_defineSymbol}")
  2961. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2962. set_property(TARGET ${_unityTargetName} PROPERTY ENABLE_EXPORTS TRUE)
  2963. endif()
  2964. endif()
  2965. cotire_init_target(${_unityTargetName})
  2966. cotire_add_to_unity_all_target(${_unityTargetName})
  2967. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_TARGET_NAME "${_unityTargetName}")
  2968. endfunction(cotire_setup_unity_build_target)
  2969. function (cotire_target _target)
  2970. set(_options "")
  2971. set(_oneValueArgs "")
  2972. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  2973. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  2974. if (NOT _option_LANGUAGES)
  2975. get_property (_option_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
  2976. endif()
  2977. if (NOT _option_CONFIGURATIONS)
  2978. cotire_get_configuration_types(_option_CONFIGURATIONS)
  2979. endif()
  2980. # check if cotire can be applied to target at all
  2981. cotire_is_target_supported(${_target} _isSupported)
  2982. if (NOT _isSupported)
  2983. get_target_property(_imported ${_target} IMPORTED)
  2984. get_target_property(_targetType ${_target} TYPE)
  2985. if (_imported)
  2986. message (WARNING "cotire: imported ${_targetType} target ${_target} cannot be cotired.")
  2987. else()
  2988. message (STATUS "cotire: ${_targetType} target ${_target} cannot be cotired.")
  2989. endif()
  2990. return()
  2991. endif()
  2992. # resolve alias
  2993. get_target_property(_aliasName ${_target} ALIASED_TARGET)
  2994. if (_aliasName)
  2995. if (COTIRE_DEBUG)
  2996. message (STATUS "${_target} is an alias. Applying cotire to aliased target ${_aliasName} instead.")
  2997. endif()
  2998. set (_target ${_aliasName})
  2999. endif()
  3000. # check if target needs to be cotired for build type
  3001. # when using configuration types, the test is performed at build time
  3002. cotire_init_cotire_target_properties(${_target})
  3003. if (NOT CMAKE_CONFIGURATION_TYPES)
  3004. if (CMAKE_BUILD_TYPE)
  3005. list (FIND _option_CONFIGURATIONS "${CMAKE_BUILD_TYPE}" _index)
  3006. else()
  3007. list (FIND _option_CONFIGURATIONS "None" _index)
  3008. endif()
  3009. if (_index EQUAL -1)
  3010. if (COTIRE_DEBUG)
  3011. message (STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} not cotired (${_option_CONFIGURATIONS})")
  3012. endif()
  3013. return()
  3014. endif()
  3015. endif()
  3016. # when not using configuration types, immediately create cotire intermediate dir
  3017. if (NOT CMAKE_CONFIGURATION_TYPES)
  3018. cotire_get_intermediate_dir(_baseDir)
  3019. file (MAKE_DIRECTORY "${_baseDir}")
  3020. endif()
  3021. # choose languages that apply to the target
  3022. cotire_choose_target_languages("${_target}" _targetLanguages _wholeTarget ${_option_LANGUAGES})
  3023. if (NOT _targetLanguages)
  3024. return()
  3025. endif()
  3026. set (_cmds "")
  3027. foreach (_language ${_targetLanguages})
  3028. cotire_process_target_language("${_language}" "${_option_CONFIGURATIONS}" ${_target} ${_wholeTarget} _cmd)
  3029. if (_cmd)
  3030. list (APPEND _cmds ${_cmd})
  3031. endif()
  3032. endforeach()
  3033. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  3034. if (_targetAddSCU)
  3035. cotire_setup_unity_build_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" ${_target})
  3036. endif()
  3037. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  3038. if (_targetUsePCH)
  3039. cotire_setup_target_pch_usage("${_targetLanguages}" ${_target} ${_wholeTarget} ${_cmds})
  3040. cotire_setup_pch_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" ${_target})
  3041. if (_targetAddSCU)
  3042. cotire_setup_unity_target_pch_usage("${_targetLanguages}" ${_target})
  3043. endif()
  3044. endif()
  3045. get_target_property(_targetAddCleanTarget ${_target} COTIRE_ADD_CLEAN)
  3046. if (_targetAddCleanTarget)
  3047. cotire_setup_clean_target(${_target})
  3048. endif()
  3049. endfunction(cotire_target)
  3050. function (cotire_map_libraries _strategy _mappedLibrariesVar)
  3051. set (_mappedLibraries "")
  3052. foreach (_library ${ARGN})
  3053. if (_library MATCHES "^\\$<LINK_ONLY:(.+)>$")
  3054. set (_libraryName "${CMAKE_MATCH_1}")
  3055. set (_linkOnly TRUE)
  3056. else()
  3057. set (_libraryName "${_library}")
  3058. set (_linkOnly FALSE)
  3059. endif()
  3060. if ("${_strategy}" MATCHES "COPY_UNITY")
  3061. cotire_is_target_supported(${_libraryName} _isSupported)
  3062. if (_isSupported)
  3063. # use target's corresponding unity target, if available
  3064. get_target_property(_libraryUnityTargetName ${_libraryName} COTIRE_UNITY_TARGET_NAME)
  3065. if (TARGET "${_libraryUnityTargetName}")
  3066. if (_linkOnly)
  3067. list (APPEND _mappedLibraries "$<LINK_ONLY:${_libraryUnityTargetName}>")
  3068. else()
  3069. list (APPEND _mappedLibraries "${_libraryUnityTargetName}")
  3070. endif()
  3071. else()
  3072. list (APPEND _mappedLibraries "${_library}")
  3073. endif()
  3074. else()
  3075. list (APPEND _mappedLibraries "${_library}")
  3076. endif()
  3077. else()
  3078. list (APPEND _mappedLibraries "${_library}")
  3079. endif()
  3080. endforeach()
  3081. list (REMOVE_DUPLICATES _mappedLibraries)
  3082. set (${_mappedLibrariesVar} ${_mappedLibraries} PARENT_SCOPE)
  3083. endfunction()
  3084. function (cotire_target_link_libraries _target)
  3085. cotire_is_target_supported(${_target} _isSupported)
  3086. if (NOT _isSupported)
  3087. return()
  3088. endif()
  3089. get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME)
  3090. if (TARGET "${_unityTargetName}")
  3091. get_target_property(_linkLibrariesStrategy ${_target} COTIRE_UNITY_LINK_LIBRARIES_INIT)
  3092. if (COTIRE_DEBUG)
  3093. message (STATUS "unity target ${_unityTargetName} link strategy: ${_linkLibrariesStrategy}")
  3094. endif()
  3095. if ("${_linkLibrariesStrategy}" MATCHES "^(COPY|COPY_UNITY)$")
  3096. get_target_property(_linkLibraries ${_target} LINK_LIBRARIES)
  3097. if (_linkLibraries)
  3098. cotire_map_libraries("${_linkLibrariesStrategy}" _unityLinkLibraries ${_linkLibraries})
  3099. set_target_properties(${_unityTargetName} PROPERTIES LINK_LIBRARIES "${_unityLinkLibraries}")
  3100. if (COTIRE_DEBUG)
  3101. message (STATUS "unity target ${_unityTargetName} link libraries: ${_unityLinkLibraries}")
  3102. endif()
  3103. endif()
  3104. get_target_property(_interfaceLinkLibraries ${_target} INTERFACE_LINK_LIBRARIES)
  3105. if (_interfaceLinkLibraries)
  3106. cotire_map_libraries("${_linkLibrariesStrategy}" _unityLinkInterfaceLibraries ${_interfaceLinkLibraries})
  3107. set_target_properties(${_unityTargetName} PROPERTIES INTERFACE_LINK_LIBRARIES "${_unityLinkInterfaceLibraries}")
  3108. if (COTIRE_DEBUG)
  3109. message (STATUS "unity target ${_unityTargetName} interface link libraries: ${_unityLinkInterfaceLibraries}")
  3110. endif()
  3111. endif()
  3112. endif()
  3113. endif()
  3114. endfunction(cotire_target_link_libraries)
  3115. function (cotire_cleanup _binaryDir _cotireIntermediateDirName _targetName)
  3116. if (_targetName)
  3117. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/${_targetName}*.*")
  3118. else()
  3119. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/*.*")
  3120. endif()
  3121. # filter files in intermediate directory
  3122. set (_filesToRemove "")
  3123. foreach (_file ${_cotireFiles})
  3124. get_filename_component(_dir "${_file}" DIRECTORY)
  3125. get_filename_component(_dirName "${_dir}" NAME)
  3126. if ("${_dirName}" STREQUAL "${_cotireIntermediateDirName}")
  3127. list (APPEND _filesToRemove "${_file}")
  3128. endif()
  3129. endforeach()
  3130. if (_filesToRemove)
  3131. if (COTIRE_VERBOSE)
  3132. message (STATUS "cleaning up ${_filesToRemove}")
  3133. endif()
  3134. file (REMOVE ${_filesToRemove})
  3135. endif()
  3136. endfunction()
  3137. function (cotire_init_target _targetName)
  3138. if (COTIRE_TARGETS_FOLDER)
  3139. set_target_properties(${_targetName} PROPERTIES FOLDER "${COTIRE_TARGETS_FOLDER}")
  3140. endif()
  3141. set_target_properties(${_targetName} PROPERTIES EXCLUDE_FROM_ALL TRUE)
  3142. if (MSVC_IDE)
  3143. set_target_properties(${_targetName} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
  3144. endif()
  3145. endfunction()
  3146. function (cotire_add_to_pch_all_target _pchTargetName)
  3147. set (_targetName "${COTIRE_PCH_ALL_TARGET_NAME}")
  3148. if (NOT TARGET "${_targetName}")
  3149. add_custom_target("${_targetName}"
  3150. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3151. VERBATIM)
  3152. cotire_init_target("${_targetName}")
  3153. endif()
  3154. cotire_setup_clean_all_target()
  3155. add_dependencies(${_targetName} ${_pchTargetName})
  3156. endfunction()
  3157. function (cotire_add_to_unity_all_target _unityTargetName)
  3158. set (_targetName "${COTIRE_UNITY_BUILD_ALL_TARGET_NAME}")
  3159. if (NOT TARGET "${_targetName}")
  3160. add_custom_target("${_targetName}"
  3161. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3162. VERBATIM)
  3163. cotire_init_target("${_targetName}")
  3164. endif()
  3165. cotire_setup_clean_all_target()
  3166. add_dependencies(${_targetName} ${_unityTargetName})
  3167. endfunction()
  3168. function (cotire_setup_clean_all_target)
  3169. set (_targetName "${COTIRE_CLEAN_ALL_TARGET_NAME}")
  3170. if (NOT TARGET "${_targetName}")
  3171. cotire_set_cmd_to_prologue(_cmds)
  3172. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${CMAKE_BINARY_DIR}" "${COTIRE_INTDIR}")
  3173. add_custom_target(${_targetName}
  3174. COMMAND ${_cmds}
  3175. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3176. COMMENT "Cleaning up all cotire generated files"
  3177. VERBATIM)
  3178. cotire_init_target("${_targetName}")
  3179. endif()
  3180. endfunction()
  3181. function (cotire)
  3182. set(_options "")
  3183. set(_oneValueArgs "")
  3184. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  3185. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  3186. set (_targets ${_option_UNPARSED_ARGUMENTS})
  3187. foreach (_target ${_targets})
  3188. if (TARGET ${_target})
  3189. cotire_target(${_target} LANGUAGES ${_option_LANGUAGES} CONFIGURATIONS ${_option_CONFIGURATIONS})
  3190. else()
  3191. message (WARNING "cotire: ${_target} is not a target.")
  3192. endif()
  3193. endforeach()
  3194. foreach (_target ${_targets})
  3195. if (TARGET ${_target})
  3196. cotire_target_link_libraries(${_target})
  3197. endif()
  3198. endforeach()
  3199. endfunction()
  3200. if (CMAKE_SCRIPT_MODE_FILE)
  3201. # cotire is being run in script mode
  3202. # locate -P on command args
  3203. set (COTIRE_ARGC -1)
  3204. foreach (_index RANGE ${CMAKE_ARGC})
  3205. if (COTIRE_ARGC GREATER -1)
  3206. set (COTIRE_ARGV${COTIRE_ARGC} "${CMAKE_ARGV${_index}}")
  3207. math (EXPR COTIRE_ARGC "${COTIRE_ARGC} + 1")
  3208. elseif ("${CMAKE_ARGV${_index}}" STREQUAL "-P")
  3209. set (COTIRE_ARGC 0)
  3210. endif()
  3211. endforeach()
  3212. # include target script if available
  3213. if ("${COTIRE_ARGV2}" MATCHES "\\.cmake$")
  3214. # the included target scripts sets up additional variables relating to the target (e.g., COTIRE_TARGET_SOURCES)
  3215. include("${COTIRE_ARGV2}")
  3216. endif()
  3217. if (COTIRE_DEBUG)
  3218. message (STATUS "${COTIRE_ARGV0} ${COTIRE_ARGV1} ${COTIRE_ARGV2} ${COTIRE_ARGV3} ${COTIRE_ARGV4} ${COTIRE_ARGV5}")
  3219. endif()
  3220. if (NOT COTIRE_BUILD_TYPE)
  3221. set (COTIRE_BUILD_TYPE "None")
  3222. endif()
  3223. string (TOUPPER "${COTIRE_BUILD_TYPE}" _upperConfig)
  3224. set (_includeDirs ${COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig}})
  3225. set (_systemIncludeDirs ${COTIRE_TARGET_SYSTEM_INCLUDE_DIRECTORIES_${_upperConfig}})
  3226. set (_compileDefinitions ${COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig}})
  3227. set (_compileFlags ${COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig}})
  3228. # check if target has been cotired for actual build type COTIRE_BUILD_TYPE
  3229. list (FIND COTIRE_TARGET_CONFIGURATION_TYPES "${COTIRE_BUILD_TYPE}" _index)
  3230. if (_index GREATER -1)
  3231. set (_sources ${COTIRE_TARGET_SOURCES})
  3232. set (_sourcesDefinitions ${COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig}})
  3233. else()
  3234. if (COTIRE_DEBUG)
  3235. message (STATUS "COTIRE_BUILD_TYPE=${COTIRE_BUILD_TYPE} not cotired (${COTIRE_TARGET_CONFIGURATION_TYPES})")
  3236. endif()
  3237. set (_sources "")
  3238. set (_sourcesDefinitions "")
  3239. endif()
  3240. set (_targetPreUndefs ${COTIRE_TARGET_PRE_UNDEFS})
  3241. set (_targetPostUndefs ${COTIRE_TARGET_POST_UNDEFS})
  3242. set (_sourcesPreUndefs ${COTIRE_TARGET_SOURCES_PRE_UNDEFS})
  3243. set (_sourcesPostUndefs ${COTIRE_TARGET_SOURCES_POST_UNDEFS})
  3244. if ("${COTIRE_ARGV1}" STREQUAL "unity")
  3245. if (XCODE)
  3246. # executing pre-build action under Xcode, check dependency on target script
  3247. set (_dependsOption DEPENDS "${COTIRE_ARGV2}")
  3248. else()
  3249. # executing custom command, no need to re-check for dependencies
  3250. set (_dependsOption "")
  3251. endif()
  3252. cotire_select_unity_source_files("${COTIRE_ARGV3}" _sources ${_sources})
  3253. cotire_generate_unity_source(
  3254. "${COTIRE_ARGV3}" ${_sources}
  3255. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3256. SOURCES_COMPILE_DEFINITIONS ${_sourcesDefinitions}
  3257. PRE_UNDEFS ${_targetPreUndefs}
  3258. POST_UNDEFS ${_targetPostUndefs}
  3259. SOURCES_PRE_UNDEFS ${_sourcesPreUndefs}
  3260. SOURCES_POST_UNDEFS ${_sourcesPostUndefs}
  3261. ${_dependsOption})
  3262. elseif ("${COTIRE_ARGV1}" STREQUAL "prefix")
  3263. if (XCODE)
  3264. # executing pre-build action under Xcode, check dependency on unity file and prefix dependencies
  3265. set (_dependsOption DEPENDS "${COTIRE_ARGV4}" ${COTIRE_TARGET_PREFIX_DEPENDS})
  3266. else()
  3267. # executing custom command, no need to re-check for dependencies
  3268. set (_dependsOption "")
  3269. endif()
  3270. set (_files "")
  3271. foreach (_index RANGE 4 ${COTIRE_ARGC})
  3272. if (COTIRE_ARGV${_index})
  3273. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3274. endif()
  3275. endforeach()
  3276. cotire_generate_prefix_header(
  3277. "${COTIRE_ARGV3}" ${_files}
  3278. COMPILER_LAUNCHER "${COTIRE_TARGET_${COTIRE_TARGET_LANGUAGE}_COMPILER_LAUNCHER}"
  3279. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  3280. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  3281. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  3282. COMPILER_VERSION "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  3283. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3284. IGNORE_PATH "${COTIRE_TARGET_IGNORE_PATH};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH}"
  3285. INCLUDE_PATH ${COTIRE_TARGET_INCLUDE_PATH}
  3286. IGNORE_EXTENSIONS "${CMAKE_${COTIRE_TARGET_LANGUAGE}_SOURCE_FILE_EXTENSIONS};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS}"
  3287. INCLUDE_PRIORITY_PATH ${COTIRE_TARGET_INCLUDE_PRIORITY_PATH}
  3288. INCLUDE_DIRECTORIES ${_includeDirs}
  3289. SYSTEM_INCLUDE_DIRECTORIES ${_systemIncludeDirs}
  3290. COMPILE_DEFINITIONS ${_compileDefinitions}
  3291. COMPILE_FLAGS ${_compileFlags}
  3292. ${_dependsOption})
  3293. elseif ("${COTIRE_ARGV1}" STREQUAL "precompile")
  3294. set (_files "")
  3295. foreach (_index RANGE 5 ${COTIRE_ARGC})
  3296. if (COTIRE_ARGV${_index})
  3297. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3298. endif()
  3299. endforeach()
  3300. cotire_precompile_prefix_header(
  3301. "${COTIRE_ARGV3}" "${COTIRE_ARGV4}" "${COTIRE_ARGV5}"
  3302. COMPILER_LAUNCHER "${COTIRE_TARGET_${COTIRE_TARGET_LANGUAGE}_COMPILER_LAUNCHER}"
  3303. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  3304. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  3305. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  3306. COMPILER_VERSION "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  3307. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3308. INCLUDE_DIRECTORIES ${_includeDirs}
  3309. SYSTEM_INCLUDE_DIRECTORIES ${_systemIncludeDirs}
  3310. COMPILE_DEFINITIONS ${_compileDefinitions}
  3311. COMPILE_FLAGS ${_compileFlags})
  3312. elseif ("${COTIRE_ARGV1}" STREQUAL "combine")
  3313. if (COTIRE_TARGET_LANGUAGE)
  3314. set (_combinedFile "${COTIRE_ARGV3}")
  3315. set (_startIndex 4)
  3316. else()
  3317. set (_combinedFile "${COTIRE_ARGV2}")
  3318. set (_startIndex 3)
  3319. endif()
  3320. set (_files "")
  3321. foreach (_index RANGE ${_startIndex} ${COTIRE_ARGC})
  3322. if (COTIRE_ARGV${_index})
  3323. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3324. endif()
  3325. endforeach()
  3326. if (XCODE)
  3327. # executing pre-build action under Xcode, check dependency on files to be combined
  3328. set (_dependsOption DEPENDS ${_files})
  3329. else()
  3330. # executing custom command, no need to re-check for dependencies
  3331. set (_dependsOption "")
  3332. endif()
  3333. if (COTIRE_TARGET_LANGUAGE)
  3334. cotire_generate_unity_source(
  3335. "${_combinedFile}" ${_files}
  3336. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3337. ${_dependsOption})
  3338. else()
  3339. cotire_generate_unity_source("${_combinedFile}" ${_files} ${_dependsOption})
  3340. endif()
  3341. elseif ("${COTIRE_ARGV1}" STREQUAL "cleanup")
  3342. cotire_cleanup("${COTIRE_ARGV2}" "${COTIRE_ARGV3}" "${COTIRE_ARGV4}")
  3343. else()
  3344. message (FATAL_ERROR "cotire: unknown command \"${COTIRE_ARGV1}\".")
  3345. endif()
  3346. else()
  3347. # cotire is being run in include mode
  3348. # set up all variable and property definitions
  3349. if (NOT DEFINED COTIRE_DEBUG_INIT)
  3350. if (DEFINED COTIRE_DEBUG)
  3351. set (COTIRE_DEBUG_INIT ${COTIRE_DEBUG})
  3352. else()
  3353. set (COTIRE_DEBUG_INIT FALSE)
  3354. endif()
  3355. endif()
  3356. option (COTIRE_DEBUG "Enable cotire debugging output?" ${COTIRE_DEBUG_INIT})
  3357. if (NOT DEFINED COTIRE_VERBOSE_INIT)
  3358. if (DEFINED COTIRE_VERBOSE)
  3359. set (COTIRE_VERBOSE_INIT ${COTIRE_VERBOSE})
  3360. else()
  3361. set (COTIRE_VERBOSE_INIT FALSE)
  3362. endif()
  3363. endif()
  3364. option (COTIRE_VERBOSE "Enable cotire verbose output?" ${COTIRE_VERBOSE_INIT})
  3365. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS "inc;inl;ipp" CACHE STRING
  3366. "Ignore headers with the listed file extensions from the generated prefix header.")
  3367. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH "" CACHE STRING
  3368. "Ignore headers from these directories when generating the prefix header.")
  3369. set (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS "m;mm" CACHE STRING
  3370. "Ignore sources with the listed file extensions from the generated unity source.")
  3371. set (COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES "3" CACHE STRING
  3372. "Minimum number of sources in target required to enable use of precompiled header.")
  3373. if (NOT DEFINED COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT)
  3374. if (DEFINED COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  3375. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT ${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES})
  3376. elseif ("${CMAKE_GENERATOR}" MATCHES "JOM|Ninja|Visual Studio")
  3377. # enable parallelization for generators that run multiple jobs by default
  3378. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT "-j")
  3379. else()
  3380. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT "0")
  3381. endif()
  3382. endif()
  3383. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES "${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT}" CACHE STRING
  3384. "Maximum number of source files to include in a single unity source file.")
  3385. if (NOT COTIRE_PREFIX_HEADER_FILENAME_SUFFIX)
  3386. set (COTIRE_PREFIX_HEADER_FILENAME_SUFFIX "_prefix")
  3387. endif()
  3388. if (NOT COTIRE_UNITY_SOURCE_FILENAME_SUFFIX)
  3389. set (COTIRE_UNITY_SOURCE_FILENAME_SUFFIX "_unity")
  3390. endif()
  3391. if (NOT COTIRE_INTDIR)
  3392. set (COTIRE_INTDIR "cotire")
  3393. endif()
  3394. if (NOT COTIRE_PCH_ALL_TARGET_NAME)
  3395. set (COTIRE_PCH_ALL_TARGET_NAME "all_pch")
  3396. endif()
  3397. if (NOT COTIRE_UNITY_BUILD_ALL_TARGET_NAME)
  3398. set (COTIRE_UNITY_BUILD_ALL_TARGET_NAME "all_unity")
  3399. endif()
  3400. if (NOT COTIRE_CLEAN_ALL_TARGET_NAME)
  3401. set (COTIRE_CLEAN_ALL_TARGET_NAME "clean_cotire")
  3402. endif()
  3403. if (NOT COTIRE_CLEAN_TARGET_SUFFIX)
  3404. set (COTIRE_CLEAN_TARGET_SUFFIX "_clean_cotire")
  3405. endif()
  3406. if (NOT COTIRE_PCH_TARGET_SUFFIX)
  3407. set (COTIRE_PCH_TARGET_SUFFIX "_pch")
  3408. endif()
  3409. if (MSVC)
  3410. # MSVC default PCH memory scaling factor of 100 percent (75 MB) is too small for template heavy C++ code
  3411. # use a bigger default factor of 170 percent (128 MB)
  3412. if (NOT DEFINED COTIRE_PCH_MEMORY_SCALING_FACTOR)
  3413. set (COTIRE_PCH_MEMORY_SCALING_FACTOR "170")
  3414. endif()
  3415. endif()
  3416. if (NOT COTIRE_UNITY_BUILD_TARGET_SUFFIX)
  3417. set (COTIRE_UNITY_BUILD_TARGET_SUFFIX "_unity")
  3418. endif()
  3419. if (NOT DEFINED COTIRE_TARGETS_FOLDER)
  3420. set (COTIRE_TARGETS_FOLDER "cotire")
  3421. endif()
  3422. if (NOT DEFINED COTIRE_UNITY_OUTPUT_DIRECTORY)
  3423. if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
  3424. # generated Ninja build files do not work if the unity target produces the same output file as the cotired target
  3425. set (COTIRE_UNITY_OUTPUT_DIRECTORY "unity")
  3426. else()
  3427. set (COTIRE_UNITY_OUTPUT_DIRECTORY "")
  3428. endif()
  3429. endif()
  3430. # define cotire cache variables
  3431. define_property(
  3432. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH"
  3433. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3434. FULL_DOCS
  3435. "The variable can be set to a semicolon separated list of include directories."
  3436. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  3437. "If not defined, defaults to empty list."
  3438. )
  3439. define_property(
  3440. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS"
  3441. BRIEF_DOCS "Ignore includes with the listed file extensions from the generated prefix header."
  3442. FULL_DOCS
  3443. "The variable can be set to a semicolon separated list of file extensions."
  3444. "If a header file extension matches one in the list, it will be excluded from the generated prefix header."
  3445. "Includes with an extension in CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS are always ignored."
  3446. "If not defined, defaults to inc;inl;ipp."
  3447. )
  3448. define_property(
  3449. CACHED_VARIABLE PROPERTY "COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS"
  3450. BRIEF_DOCS "Exclude sources with the listed file extensions from the generated unity source."
  3451. FULL_DOCS
  3452. "The variable can be set to a semicolon separated list of file extensions."
  3453. "If a source file extension matches one in the list, it will be excluded from the generated unity source file."
  3454. "Source files with an extension in CMAKE_<LANG>_IGNORE_EXTENSIONS are always excluded."
  3455. "If not defined, defaults to m;mm."
  3456. )
  3457. define_property(
  3458. CACHED_VARIABLE PROPERTY "COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES"
  3459. BRIEF_DOCS "Minimum number of sources in target required to enable use of precompiled header."
  3460. FULL_DOCS
  3461. "The variable can be set to an integer > 0."
  3462. "If a target contains less than that number of source files, cotire will not enable the use of the precompiled header for the target."
  3463. "If not defined, defaults to 3."
  3464. )
  3465. define_property(
  3466. CACHED_VARIABLE PROPERTY "COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES"
  3467. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3468. FULL_DOCS
  3469. "This may be set to an integer >= 0."
  3470. "If 0, cotire will only create a single unity source file."
  3471. "If a target contains more than that number of source files, cotire will create multiple unity source files for it."
  3472. "Can be set to \"-j\" to optimize the count of unity source files for the number of available processor cores."
  3473. "Can be set to \"-j jobs\" to optimize the number of unity source files for the given number of simultaneous jobs."
  3474. "Is used to initialize the target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  3475. "Defaults to \"-j\" for the generators Visual Studio, JOM or Ninja. Defaults to 0 otherwise."
  3476. )
  3477. # define cotire directory properties
  3478. define_property(
  3479. DIRECTORY PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER"
  3480. BRIEF_DOCS "Modify build command of cotired targets added in this directory to make use of the generated precompiled header."
  3481. FULL_DOCS
  3482. "See target property COTIRE_ENABLE_PRECOMPILED_HEADER."
  3483. )
  3484. define_property(
  3485. DIRECTORY PROPERTY "COTIRE_ADD_UNITY_BUILD"
  3486. BRIEF_DOCS "Add a new target that performs a unity build for cotired targets added in this directory."
  3487. FULL_DOCS
  3488. "See target property COTIRE_ADD_UNITY_BUILD."
  3489. )
  3490. define_property(
  3491. DIRECTORY PROPERTY "COTIRE_ADD_CLEAN"
  3492. BRIEF_DOCS "Add a new target that cleans all cotire generated files for cotired targets added in this directory."
  3493. FULL_DOCS
  3494. "See target property COTIRE_ADD_CLEAN."
  3495. )
  3496. define_property(
  3497. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH"
  3498. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3499. FULL_DOCS
  3500. "See target property COTIRE_PREFIX_HEADER_IGNORE_PATH."
  3501. )
  3502. define_property(
  3503. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH"
  3504. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  3505. FULL_DOCS
  3506. "See target property COTIRE_PREFIX_HEADER_INCLUDE_PATH."
  3507. )
  3508. define_property(
  3509. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH"
  3510. BRIEF_DOCS "Header paths matching one of these directories are put at the top of the prefix header."
  3511. FULL_DOCS
  3512. "See target property COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH."
  3513. )
  3514. define_property(
  3515. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  3516. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each source file."
  3517. FULL_DOCS
  3518. "See target property COTIRE_UNITY_SOURCE_PRE_UNDEFS."
  3519. )
  3520. define_property(
  3521. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  3522. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each source file."
  3523. FULL_DOCS
  3524. "See target property COTIRE_UNITY_SOURCE_POST_UNDEFS."
  3525. )
  3526. define_property(
  3527. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES"
  3528. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3529. FULL_DOCS
  3530. "See target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  3531. )
  3532. define_property(
  3533. DIRECTORY PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT"
  3534. BRIEF_DOCS "Define strategy for setting up the unity target's link libraries."
  3535. FULL_DOCS
  3536. "See target property COTIRE_UNITY_LINK_LIBRARIES_INIT."
  3537. )
  3538. # define cotire target properties
  3539. define_property(
  3540. TARGET PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER" INHERITED
  3541. BRIEF_DOCS "Modify this target's build command to make use of the generated precompiled header."
  3542. FULL_DOCS
  3543. "If this property is set to TRUE, cotire will modify the build command to make use of the generated precompiled header."
  3544. "Irrespective of the value of this property, cotire will setup custom commands to generate the unity source and prefix header for the target."
  3545. "For makefile based generators cotire will also set up a custom target to manually invoke the generation of the precompiled header."
  3546. "The target name will be set to this target's name with the suffix _pch appended."
  3547. "Inherited from directory."
  3548. "Defaults to TRUE."
  3549. )
  3550. define_property(
  3551. TARGET PROPERTY "COTIRE_ADD_UNITY_BUILD" INHERITED
  3552. BRIEF_DOCS "Add a new target that performs a unity build for this target."
  3553. FULL_DOCS
  3554. "If this property is set to TRUE, cotire creates a new target of the same type that uses the generated unity source file instead of the target sources."
  3555. "Most of the relevant target properties will be copied from this target to the new unity build target."
  3556. "Target dependencies and linked libraries have to be manually set up for the new unity build target."
  3557. "The unity target name will be set to this target's name with the suffix _unity appended."
  3558. "Inherited from directory."
  3559. "Defaults to TRUE."
  3560. )
  3561. define_property(
  3562. TARGET PROPERTY "COTIRE_ADD_CLEAN" INHERITED
  3563. BRIEF_DOCS "Add a new target that cleans all cotire generated files for this target."
  3564. FULL_DOCS
  3565. "If this property is set to TRUE, cotire creates a new target that clean all files (unity source, prefix header, precompiled header)."
  3566. "The clean target name will be set to this target's name with the suffix _clean_cotire appended."
  3567. "Inherited from directory."
  3568. "Defaults to FALSE."
  3569. )
  3570. define_property(
  3571. TARGET PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH" INHERITED
  3572. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3573. FULL_DOCS
  3574. "The property can be set to a list of directories."
  3575. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  3576. "Inherited from directory."
  3577. "If not set, this property is initialized to \${CMAKE_SOURCE_DIR};\${CMAKE_BINARY_DIR}."
  3578. )
  3579. define_property(
  3580. TARGET PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH" INHERITED
  3581. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  3582. FULL_DOCS
  3583. "The property can be set to a list of directories."
  3584. "If a header file is found in one of these directories or sub-directories, it will be included in the generated prefix header."
  3585. "If a header file is both selected by COTIRE_PREFIX_HEADER_IGNORE_PATH and COTIRE_PREFIX_HEADER_INCLUDE_PATH,"
  3586. "the option which yields the closer relative path match wins."
  3587. "Inherited from directory."
  3588. "If not set, this property is initialized to the empty list."
  3589. )
  3590. define_property(
  3591. TARGET PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH" INHERITED
  3592. BRIEF_DOCS "Header paths matching one of these directories are put at the top of prefix header."
  3593. FULL_DOCS
  3594. "The property can be set to a list of directories."
  3595. "Header file paths matching one of these directories will be inserted at the beginning of the generated prefix header."
  3596. "Header files are sorted according to the order of the directories in the property."
  3597. "If not set, this property is initialized to the empty list."
  3598. )
  3599. define_property(
  3600. TARGET PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS" INHERITED
  3601. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each target source file."
  3602. FULL_DOCS
  3603. "This may be set to a semicolon-separated list of preprocessor symbols."
  3604. "cotire will add corresponding #undef directives to the generated unit source file before each target source file."
  3605. "Inherited from directory."
  3606. "Defaults to empty string."
  3607. )
  3608. define_property(
  3609. TARGET PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS" INHERITED
  3610. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each target source file."
  3611. FULL_DOCS
  3612. "This may be set to a semicolon-separated list of preprocessor symbols."
  3613. "cotire will add corresponding #undef directives to the generated unit source file after each target source file."
  3614. "Inherited from directory."
  3615. "Defaults to empty string."
  3616. )
  3617. define_property(
  3618. TARGET PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES" INHERITED
  3619. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3620. FULL_DOCS
  3621. "This may be set to an integer > 0."
  3622. "If a target contains more than that number of source files, cotire will create multiple unity build files for it."
  3623. "If not set, cotire will only create a single unity source file."
  3624. "Inherited from directory."
  3625. "Defaults to empty."
  3626. )
  3627. define_property(
  3628. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE_INIT"
  3629. BRIEF_DOCS "User provided unity source file to be used instead of the automatically generated one."
  3630. FULL_DOCS
  3631. "If set, cotire will only add the given file(s) to the generated unity source file."
  3632. "If not set, cotire will add all the target source files to the generated unity source file."
  3633. "The property can be set to a user provided unity source file."
  3634. "Defaults to empty."
  3635. )
  3636. define_property(
  3637. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER_INIT"
  3638. BRIEF_DOCS "User provided prefix header file to be used instead of the automatically generated one."
  3639. FULL_DOCS
  3640. "If set, cotire will add the given header file(s) to the generated prefix header file."
  3641. "If not set, cotire will generate a prefix header by tracking the header files included by the unity source file."
  3642. "The property can be set to a user provided prefix header file (e.g., stdafx.h)."
  3643. "Defaults to empty."
  3644. )
  3645. define_property(
  3646. TARGET PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT" INHERITED
  3647. BRIEF_DOCS "Define strategy for setting up unity target's link libraries."
  3648. FULL_DOCS
  3649. "If this property is empty or set to NONE, the generated unity target's link libraries have to be set up manually."
  3650. "If this property is set to COPY, the unity target's link libraries will be copied from this target."
  3651. "If this property is set to COPY_UNITY, the unity target's link libraries will be copied from this target with considering existing unity targets."
  3652. "Inherited from directory."
  3653. "Defaults to empty."
  3654. )
  3655. define_property(
  3656. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE"
  3657. BRIEF_DOCS "Read-only property. The generated <LANG> unity source file(s)."
  3658. FULL_DOCS
  3659. "cotire sets this property to the path of the generated <LANG> single computation unit source file for the target."
  3660. "Defaults to empty string."
  3661. )
  3662. define_property(
  3663. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER"
  3664. BRIEF_DOCS "Read-only property. The generated <LANG> prefix header file."
  3665. FULL_DOCS
  3666. "cotire sets this property to the full path of the generated <LANG> language prefix header for the target."
  3667. "Defaults to empty string."
  3668. )
  3669. define_property(
  3670. TARGET PROPERTY "COTIRE_<LANG>_PRECOMPILED_HEADER"
  3671. BRIEF_DOCS "Read-only property. The generated <LANG> precompiled header file."
  3672. FULL_DOCS
  3673. "cotire sets this property to the full path of the generated <LANG> language precompiled header binary for the target."
  3674. "Defaults to empty string."
  3675. )
  3676. define_property(
  3677. TARGET PROPERTY "COTIRE_UNITY_TARGET_NAME"
  3678. BRIEF_DOCS "The name of the generated unity build target corresponding to this target."
  3679. FULL_DOCS
  3680. "This property can be set to the desired name of the unity target that will be created by cotire."
  3681. "If not set, the unity target name will be set to this target's name with the suffix _unity appended."
  3682. "After this target has been processed by cotire, the property is set to the actual name of the generated unity target."
  3683. "Defaults to empty string."
  3684. )
  3685. # define cotire source properties
  3686. define_property(
  3687. SOURCE PROPERTY "COTIRE_EXCLUDED"
  3688. BRIEF_DOCS "Do not modify source file's build command."
  3689. FULL_DOCS
  3690. "If this property is set to TRUE, the source file's build command will not be modified to make use of the precompiled header."
  3691. "The source file will also be excluded from the generated unity source file."
  3692. "Source files that have their COMPILE_FLAGS property set will be excluded by default."
  3693. "Defaults to FALSE."
  3694. )
  3695. define_property(
  3696. SOURCE PROPERTY "COTIRE_DEPENDENCY"
  3697. BRIEF_DOCS "Add this source file to dependencies of the automatically generated prefix header file."
  3698. FULL_DOCS
  3699. "If this property is set to TRUE, the source file is added to dependencies of the generated prefix header file."
  3700. "If the file is modified, cotire will re-generate the prefix header source upon build."
  3701. "Defaults to FALSE."
  3702. )
  3703. define_property(
  3704. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  3705. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of this source file."
  3706. FULL_DOCS
  3707. "This may be set to a semicolon-separated list of preprocessor symbols."
  3708. "cotire will add corresponding #undef directives to the generated unit source file before this file is included."
  3709. "Defaults to empty string."
  3710. )
  3711. define_property(
  3712. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  3713. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of this source file."
  3714. FULL_DOCS
  3715. "This may be set to a semicolon-separated list of preprocessor symbols."
  3716. "cotire will add corresponding #undef directives to the generated unit source file after this file is included."
  3717. "Defaults to empty string."
  3718. )
  3719. define_property(
  3720. SOURCE PROPERTY "COTIRE_START_NEW_UNITY_SOURCE"
  3721. BRIEF_DOCS "Start a new unity source file which includes this source file as the first one."
  3722. FULL_DOCS
  3723. "If this property is set to TRUE, cotire will complete the current unity file and start a new one."
  3724. "The new unity source file will include this source file as the first one."
  3725. "This property essentially works as a separator for unity source files."
  3726. "Defaults to FALSE."
  3727. )
  3728. define_property(
  3729. SOURCE PROPERTY "COTIRE_TARGET"
  3730. BRIEF_DOCS "Read-only property. Mark this source file as cotired for the given target."
  3731. FULL_DOCS
  3732. "cotire sets this property to the name of target, that the source file's build command has been altered for."
  3733. "Defaults to empty string."
  3734. )
  3735. message (STATUS "cotire ${COTIRE_CMAKE_MODULE_VERSION} loaded.")
  3736. endif()