Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

3828 řádky
156 KiB

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