You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3077 lines
126 KiB

  1. # - cotire (compile time reducer)
  2. #
  3. # See the cotire manual for usage hints.
  4. #
  5. #=============================================================================
  6. # Copyright 2012-2013 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. if (NOT CMAKE_SCRIPT_MODE_FILE)
  35. cmake_policy(PUSH)
  36. endif()
  37. # we need the CMake variables CMAKE_SCRIPT_MODE_FILE and CMAKE_ARGV available since 2.8.5
  38. # we need APPEND_STRING option for set_property available since 2.8.6
  39. cmake_minimum_required(VERSION 2.8.6)
  40. if (NOT CMAKE_SCRIPT_MODE_FILE)
  41. cmake_policy(POP)
  42. endif()
  43. set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}")
  44. set (COTIRE_CMAKE_MODULE_VERSION "1.3.1")
  45. include(CMakeParseArguments)
  46. function (cotire_determine_compiler_version _language _versionPrefix)
  47. if (NOT ${_versionPrefix}_VERSION)
  48. if (MSVC)
  49. # use CMake's predefined version variable for MSVC, if available
  50. if (DEFINED MSVC_VERSION)
  51. set (${_versionPrefix}_VERSION "${MSVC_VERSION}")
  52. else()
  53. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  54. unset (ENV{VS_UNICODE_OUTPUT})
  55. string (STRIP "${CMAKE_${_language}_COMPILER_ARG1}" _compilerArg1)
  56. execute_process (COMMAND ${CMAKE_${_language}_COMPILER} ${_compilerArg1}
  57. ERROR_VARIABLE _versionLine OUTPUT_QUIET TIMEOUT 10)
  58. string (REGEX REPLACE ".*Version *([0-9]+(\\.[0-9]+)*).*" "\\1"
  59. ${_versionPrefix}_VERSION "${_versionLine}")
  60. endif()
  61. else()
  62. # use CMake's predefined compiler version variable (available since CMake 2.8.8)
  63. if (DEFINED CMAKE_${_language}_COMPILER_VERSION)
  64. set (${_versionPrefix}_VERSION "${CMAKE_${_language}_COMPILER_VERSION}")
  65. else()
  66. # assume GCC like command line interface
  67. string (STRIP "${CMAKE_${_language}_COMPILER_ARG1}" _compilerArg1)
  68. execute_process (COMMAND ${CMAKE_${_language}_COMPILER} ${_compilerArg1} "-dumpversion"
  69. OUTPUT_VARIABLE ${_versionPrefix}_VERSION
  70. OUTPUT_STRIP_TRAILING_WHITESPACE TIMEOUT 10)
  71. endif()
  72. endif()
  73. if (${_versionPrefix}_VERSION)
  74. set (${_versionPrefix}_VERSION "${${_versionPrefix}_VERSION}" CACHE INTERNAL "${_language} compiler version")
  75. endif()
  76. set (${_versionPrefix}_VERSION "${${_versionPrefix}_VERSION}" PARENT_SCOPE)
  77. if (COTIRE_DEBUG)
  78. message (STATUS "${CMAKE_${_language}_COMPILER} version ${${_versionPrefix}_VERSION}")
  79. endif()
  80. endif()
  81. endfunction()
  82. function (cotire_get_source_file_extension _sourceFile _extVar)
  83. # get_filename_component returns extension from first occurrence of . in file name
  84. # this function computes the extension from last occurrence of . in file name
  85. string (FIND "${_sourceFile}" "." _index REVERSE)
  86. if (_index GREATER -1)
  87. math (EXPR _index "${_index} + 1")
  88. string (SUBSTRING "${_sourceFile}" ${_index} -1 _sourceExt)
  89. else()
  90. set (_sourceExt "")
  91. endif()
  92. set (${_extVar} "${_sourceExt}" PARENT_SCOPE)
  93. endfunction()
  94. macro (cotire_check_is_path_relative_to _path _isRelativeVar)
  95. set (${_isRelativeVar} FALSE)
  96. if (IS_ABSOLUTE "${_path}")
  97. foreach (_dir ${ARGN})
  98. file (RELATIVE_PATH _relPath "${_dir}" "${_path}")
  99. if (NOT _relPath OR (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\."))
  100. set (${_isRelativeVar} TRUE)
  101. break()
  102. endif()
  103. endforeach()
  104. endif()
  105. endmacro()
  106. function (cotire_filter_language_source_files _language _sourceFilesVar _excludedSourceFilesVar _cotiredSourceFilesVar)
  107. set (_sourceFiles "")
  108. set (_excludedSourceFiles "")
  109. set (_cotiredSourceFiles "")
  110. if (CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  111. set (_languageExtensions "${CMAKE_${_language}_SOURCE_FILE_EXTENSIONS}")
  112. else()
  113. set (_languageExtensions "")
  114. endif()
  115. if (CMAKE_${_language}_IGNORE_EXTENSIONS)
  116. set (_ignoreExtensions "${CMAKE_${_language}_IGNORE_EXTENSIONS}")
  117. else()
  118. set (_ignoreExtensions "")
  119. endif()
  120. if (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS)
  121. set (_excludeExtensions "${COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS}")
  122. else()
  123. set (_excludeExtensions "")
  124. endif()
  125. if (COTIRE_DEBUG)
  126. message (STATUS "${_language} source file extensions: ${_languageExtensions}")
  127. message (STATUS "${_language} ignore extensions: ${_ignoreExtensions}")
  128. message (STATUS "${_language} exclude extensions: ${_excludeExtensions}")
  129. endif()
  130. foreach (_sourceFile ${ARGN})
  131. get_source_file_property(_sourceIsHeaderOnly "${_sourceFile}" HEADER_FILE_ONLY)
  132. get_source_file_property(_sourceIsExternal "${_sourceFile}" EXTERNAL_OBJECT)
  133. get_source_file_property(_sourceIsSymbolic "${_sourceFile}" SYMBOLIC)
  134. get_source_file_property(_sourceLanguage "${_sourceFile}" LANGUAGE)
  135. set (_sourceIsFiltered FALSE)
  136. if (NOT _sourceIsHeaderOnly AND NOT _sourceIsExternal AND NOT _sourceIsSymbolic)
  137. cotire_get_source_file_extension("${_sourceFile}" _sourceExt)
  138. if (_sourceExt)
  139. list (FIND _ignoreExtensions "${_sourceExt}" _ignoreIndex)
  140. if (_ignoreIndex LESS 0)
  141. list (FIND _excludeExtensions "${_sourceExt}" _excludeIndex)
  142. if (_excludeIndex GREATER -1)
  143. list (APPEND _excludedSourceFiles "${_sourceFile}")
  144. else()
  145. list (FIND _languageExtensions "${_sourceExt}" _sourceIndex)
  146. if (_sourceIndex GREATER -1)
  147. set (_sourceIsFiltered TRUE)
  148. elseif ("${_sourceLanguage}" STREQUAL "${_language}")
  149. # add to excluded sources, if file is not ignored and has correct language without having the correct extension
  150. list (APPEND _excludedSourceFiles "${_sourceFile}")
  151. endif()
  152. endif()
  153. endif()
  154. endif()
  155. endif()
  156. if (COTIRE_DEBUG)
  157. message (STATUS "${_sourceFile} filtered=${_sourceIsFiltered} language=${_sourceLanguage} header=${_sourceIsHeaderOnly}")
  158. endif()
  159. if (_sourceIsFiltered)
  160. get_source_file_property(_sourceIsExcluded "${_sourceFile}" COTIRE_EXCLUDED)
  161. get_source_file_property(_sourceIsCotired "${_sourceFile}" COTIRE_TARGET)
  162. get_source_file_property(_sourceCompileFlags "${_sourceFile}" COMPILE_FLAGS)
  163. if (COTIRE_DEBUG)
  164. message (STATUS "${_sourceFile} excluded=${_sourceIsExcluded} cotired=${_sourceIsCotired}")
  165. endif()
  166. if (_sourceIsCotired)
  167. list (APPEND _cotiredSourceFiles "${_sourceFile}")
  168. elseif (_sourceIsExcluded OR _sourceCompileFlags)
  169. list (APPEND _excludedSourceFiles "${_sourceFile}")
  170. else()
  171. list (APPEND _sourceFiles "${_sourceFile}")
  172. endif()
  173. endif()
  174. endforeach()
  175. if (COTIRE_DEBUG)
  176. message (STATUS "All: ${ARGN}")
  177. message (STATUS "${_language}: ${_sourceFiles}")
  178. message (STATUS "Excluded: ${_excludedSourceFiles}")
  179. message (STATUS "Cotired: ${_cotiredSourceFiles}")
  180. endif()
  181. set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE)
  182. set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE)
  183. set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE)
  184. endfunction()
  185. function (cotire_get_objects_with_property_on _filteredObjectsVar _property _type)
  186. set (_filteredObjects "")
  187. foreach (_object ${ARGN})
  188. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  189. if (_isSet)
  190. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  191. if (_propertyValue)
  192. list (APPEND _filteredObjects "${_object}")
  193. endif()
  194. endif()
  195. endforeach()
  196. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  197. endfunction()
  198. function (cotire_get_objects_with_property_off _filteredObjectsVar _property _type)
  199. set (_filteredObjects "")
  200. foreach (_object ${ARGN})
  201. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  202. if (_isSet)
  203. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  204. if (NOT _propertyValue)
  205. list (APPEND _filteredObjects "${_object}")
  206. endif()
  207. endif()
  208. endforeach()
  209. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  210. endfunction()
  211. function (cotire_get_source_file_property_values _valuesVar _property)
  212. set (_values "")
  213. foreach (_sourceFile ${ARGN})
  214. get_source_file_property(_propertyValue "${_sourceFile}" ${_property})
  215. if (_propertyValue)
  216. list (APPEND _values "${_propertyValue}")
  217. endif()
  218. endforeach()
  219. set (${_valuesVar} ${_values} PARENT_SCOPE)
  220. endfunction()
  221. function (cotrie_resolve_config_properites _configurations _propertiesVar)
  222. set (_properties "")
  223. foreach (_property ${ARGN})
  224. if ("${_property}" MATCHES "<CONFIG>")
  225. foreach (_config ${_configurations})
  226. string (TOUPPER "${_config}" _upperConfig)
  227. string (REPLACE "<CONFIG>" "${_upperConfig}" _configProperty "${_property}")
  228. list (APPEND _properties ${_configProperty})
  229. endforeach()
  230. else()
  231. list (APPEND _properties ${_property})
  232. endif()
  233. endforeach()
  234. set (${_propertiesVar} ${_properties} PARENT_SCOPE)
  235. endfunction()
  236. function (cotrie_copy_set_properites _configurations _type _source _target)
  237. cotrie_resolve_config_properites("${_configurations}" _properties ${ARGN})
  238. foreach (_property ${_properties})
  239. get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET)
  240. if (_isSet)
  241. get_property(_propertyValue ${_type} ${_source} PROPERTY ${_property})
  242. set_property(${_type} ${_target} PROPERTY ${_property} "${_propertyValue}")
  243. endif()
  244. endforeach()
  245. endfunction()
  246. function (cotire_filter_compile_flags _language _flagFilter _matchedOptionsVar _unmatchedOptionsVar)
  247. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  248. set (_flagPrefix "[/-]")
  249. else()
  250. set (_flagPrefix "--?")
  251. endif()
  252. set (_optionFlag "")
  253. set (_matchedOptions "")
  254. set (_unmatchedOptions "")
  255. foreach (_compileFlag ${ARGN})
  256. if (_compileFlag)
  257. if (_optionFlag AND NOT "${_compileFlag}" MATCHES "^${_flagPrefix}")
  258. # option with separate argument
  259. list (APPEND _matchedOptions "${_compileFlag}")
  260. set (_optionFlag "")
  261. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$")
  262. # remember option
  263. set (_optionFlag "${CMAKE_MATCH_2}")
  264. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})(.+)$")
  265. # option with joined argument
  266. list (APPEND _matchedOptions "${CMAKE_MATCH_3}")
  267. set (_optionFlag "")
  268. else()
  269. # flush remembered option
  270. if (_optionFlag)
  271. list (APPEND _matchedOptions "${_optionFlag}")
  272. set (_optionFlag "")
  273. endif()
  274. # add to unfiltered options
  275. list (APPEND _unmatchedOptions "${_compileFlag}")
  276. endif()
  277. endif()
  278. endforeach()
  279. if (_optionFlag)
  280. list (APPEND _matchedOptions "${_optionFlag}")
  281. endif()
  282. if (COTIRE_DEBUG)
  283. message (STATUS "Filter ${_flagFilter}")
  284. if (_matchedOptions)
  285. message (STATUS "Matched ${_matchedOptions}")
  286. endif()
  287. if (_unmatchedOptions)
  288. message (STATUS "Unmatched ${_unmatchedOptions}")
  289. endif()
  290. endif()
  291. set (${_matchedOptionsVar} ${_matchedOptions} PARENT_SCOPE)
  292. set (${_unmatchedOptionsVar} ${_unmatchedOptions} PARENT_SCOPE)
  293. endfunction()
  294. function (cotire_get_target_compile_flags _config _language _directory _target _flagsVar)
  295. string (TOUPPER "${_config}" _upperConfig)
  296. # collect options from CMake language variables
  297. set (_compileFlags "")
  298. if (CMAKE_${_language}_FLAGS)
  299. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS}")
  300. endif()
  301. if (CMAKE_${_language}_FLAGS_${_upperConfig})
  302. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS_${_upperConfig}}")
  303. endif()
  304. if (_target)
  305. # add option from CMake target type variable
  306. get_target_property(_targetType ${_target} TYPE)
  307. if (CMAKE_VERSION VERSION_LESS "2.8.9")
  308. set (_PIC_Policy "OLD")
  309. else()
  310. # handle POSITION_INDEPENDENT_CODE property introduced with CMake 2.8.9 if policy CMP0018 is turned on
  311. cmake_policy(GET CMP0018 _PIC_Policy)
  312. endif()
  313. if (COTIRE_DEBUG)
  314. message(STATUS "CMP0018=${_PIC_Policy}, CMAKE_POLICY_DEFAULT_CMP0018=${CMAKE_POLICY_DEFAULT_CMP0018}")
  315. endif()
  316. if (_PIC_Policy STREQUAL "NEW")
  317. # NEW behavior: honor the POSITION_INDEPENDENT_CODE target property
  318. get_target_property(_targetPIC ${_target} POSITION_INDEPENDENT_CODE)
  319. if (_targetPIC)
  320. if (_targetType STREQUAL "EXECUTABLE")
  321. if (CMAKE_${_targetType}_${_language}_FLAGS)
  322. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_COMPILE_OPTIONS_PIE}")
  323. else()
  324. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_COMPILE_OPTIONS_PIC}")
  325. endif()
  326. endif()
  327. endif()
  328. else()
  329. # OLD behavior or policy not set: use the value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS
  330. if (_targetType STREQUAL "MODULE_LIBRARY")
  331. # flags variable for module library uses different name SHARED_MODULE
  332. # (e.g., CMAKE_SHARED_MODULE_C_FLAGS)
  333. set (_targetType SHARED_MODULE)
  334. endif()
  335. if (CMAKE_${_targetType}_${_language}_FLAGS)
  336. set (_compileFlags "${_compileFlags} ${CMAKE_${_targetType}_${_language}_FLAGS}")
  337. endif()
  338. endif()
  339. endif()
  340. if (_directory)
  341. # add_definitions may have been used to add flags to the compiler command
  342. get_directory_property(_dirDefinitions DIRECTORY "${_directory}" DEFINITIONS)
  343. if (_dirDefinitions)
  344. set (_compileFlags "${_compileFlags} ${_dirDefinitions}")
  345. endif()
  346. endif()
  347. if (_target)
  348. # add target compile options
  349. get_target_property(_targetflags ${_target} COMPILE_FLAGS)
  350. if (_targetflags)
  351. set (_compileFlags "${_compileFlags} ${_targetflags}")
  352. endif()
  353. endif()
  354. if (UNIX)
  355. separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}")
  356. elseif(WIN32)
  357. separate_arguments(_compileFlags WINDOWS_COMMAND "${_compileFlags}")
  358. else()
  359. separate_arguments(_compileFlags)
  360. endif()
  361. # platform specific flags
  362. if (APPLE)
  363. get_target_property(_architectures ${_target} OSX_ARCHITECTURES_${_upperConfig})
  364. if (NOT _architectures)
  365. get_target_property(_architectures ${_target} OSX_ARCHITECTURES)
  366. endif()
  367. foreach (_arch ${_architectures})
  368. list (APPEND _compileFlags "-arch" "${_arch}")
  369. endforeach()
  370. if (CMAKE_OSX_SYSROOT AND CMAKE_OSX_SYSROOT_DEFAULT AND CMAKE_${_language}_HAS_ISYSROOT)
  371. if (NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "${CMAKE_OSX_SYSROOT_DEFAULT}")
  372. list (APPEND _compileFlags "-isysroot" "${CMAKE_OSX_SYSROOT}")
  373. endif()
  374. endif()
  375. if (CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG)
  376. list (APPEND _compileFlags "${CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}")
  377. endif()
  378. endif()
  379. if (COTIRE_DEBUG AND _compileFlags)
  380. message (STATUS "Target ${_target} compile flags ${_compileFlags}")
  381. endif()
  382. set (${_flagsVar} ${_compileFlags} PARENT_SCOPE)
  383. endfunction()
  384. function (cotire_get_target_include_directories _config _language _targetSourceDir _targetBinaryDir _target _includeDirsVar)
  385. set (_includeDirs "")
  386. # default include dirs
  387. if (CMAKE_INCLUDE_CURRENT_DIR)
  388. list (APPEND _includeDirs "${_targetBinaryDir}")
  389. list (APPEND _includeDirs "${_targetSourceDir}")
  390. endif()
  391. # parse additional include directories from target compile flags
  392. cotire_get_target_compile_flags("${_config}" "${_language}" "${_targetSourceDir}" "${_target}" _targetFlags)
  393. cotire_filter_compile_flags("${_language}" "I" _dirs _ignore ${_targetFlags})
  394. if (_dirs)
  395. list (APPEND _includeDirs ${_dirs})
  396. endif()
  397. # target include directories
  398. get_directory_property(_dirs DIRECTORY "${_targetSourceDir}" INCLUDE_DIRECTORIES)
  399. if (_target)
  400. get_target_property(_targetDirs ${_target} INCLUDE_DIRECTORIES)
  401. if (_targetDirs)
  402. list (APPEND _dirs ${_targetDirs})
  403. list (REMOVE_DUPLICATES _dirs)
  404. endif()
  405. endif()
  406. list (LENGTH _includeDirs _projectInsertIndex)
  407. foreach (_dir ${_dirs})
  408. if (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE)
  409. cotire_check_is_path_relative_to("${_dir}" _isRelative "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
  410. if (_isRelative)
  411. list (LENGTH _includeDirs _len)
  412. if (_len EQUAL _projectInsertIndex)
  413. list (APPEND _includeDirs "${_dir}")
  414. else()
  415. list (INSERT _includeDirs _projectInsertIndex "${_dir}")
  416. endif()
  417. math (EXPR _projectInsertIndex "${_projectInsertIndex} + 1")
  418. else()
  419. list (APPEND _includeDirs "${_dir}")
  420. endif()
  421. else()
  422. list (APPEND _includeDirs "${_dir}")
  423. endif()
  424. endforeach()
  425. list (REMOVE_DUPLICATES _includeDirs)
  426. if (CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES)
  427. list (REMOVE_ITEM _includeDirs ${CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES})
  428. endif()
  429. if (COTIRE_DEBUG AND _includeDirs)
  430. message (STATUS "Target ${_target} include dirs ${_includeDirs}")
  431. endif()
  432. set (${_includeDirsVar} ${_includeDirs} PARENT_SCOPE)
  433. endfunction()
  434. macro (cotire_make_C_identifier _identifierVar _str)
  435. # mimic CMake SystemTools::MakeCindentifier behavior
  436. if ("${_str}" MATCHES "^[0-9].+$")
  437. set (_str "_${str}")
  438. endif()
  439. string (REGEX REPLACE "[^a-zA-Z0-9]" "_" ${_identifierVar} "${_str}")
  440. endmacro()
  441. function (cotire_get_target_export_symbol _target _exportSymbolVar)
  442. set (_exportSymbol "")
  443. get_target_property(_targetType ${_target} TYPE)
  444. get_target_property(_enableExports ${_target} ENABLE_EXPORTS)
  445. if (_targetType MATCHES "(SHARED|MODULE)_LIBRARY" OR
  446. (_targetType STREQUAL "EXECUTABLE" AND _enableExports))
  447. get_target_property(_exportSymbol ${_target} DEFINE_SYMBOL)
  448. if (NOT _exportSymbol)
  449. set (_exportSymbol "${_target}_EXPORTS")
  450. endif()
  451. cotire_make_C_identifier(_exportSymbol "${_exportSymbol}")
  452. endif()
  453. set (${_exportSymbolVar} ${_exportSymbol} PARENT_SCOPE)
  454. endfunction()
  455. function (cotire_get_target_compile_definitions _config _language _directory _target _definitionsVar)
  456. string (TOUPPER "${_config}" _upperConfig)
  457. set (_configDefinitions "")
  458. # CMAKE_INTDIR for multi-configuration build systems
  459. if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
  460. list (APPEND _configDefinitions "CMAKE_INTDIR=\"${_config}\"")
  461. endif()
  462. # target export define symbol
  463. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  464. if (_defineSymbol)
  465. list (APPEND _configDefinitions "${_defineSymbol}")
  466. endif()
  467. # directory compile definitions
  468. get_directory_property(_definitions DIRECTORY "${_directory}" COMPILE_DEFINITIONS)
  469. if (_definitions)
  470. list (APPEND _configDefinitions ${_definitions})
  471. endif()
  472. get_directory_property(_definitions DIRECTORY "${_directory}" COMPILE_DEFINITIONS_${_upperConfig})
  473. if (_definitions)
  474. list (APPEND _configDefinitions ${_definitions})
  475. endif()
  476. # target compile definitions
  477. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS)
  478. if (_definitions)
  479. list (APPEND _configDefinitions ${_definitions})
  480. endif()
  481. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS_${_upperConfig})
  482. if (_definitions)
  483. list (APPEND _configDefinitions ${_definitions})
  484. endif()
  485. # parse additional compile definitions from target compile flags
  486. # and don't look at directory compile definitions, which we already handled
  487. cotire_get_target_compile_flags("${_config}" "${_language}" "" "${_target}" _targetFlags)
  488. cotire_filter_compile_flags("${_language}" "D" _definitions _ignore ${_targetFlags})
  489. if (_definitions)
  490. list (APPEND _configDefinitions ${_definitions})
  491. endif()
  492. list (REMOVE_DUPLICATES _configDefinitions)
  493. if (COTIRE_DEBUG AND _configDefinitions)
  494. message (STATUS "Target ${_target} compile definitions ${_configDefinitions}")
  495. endif()
  496. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  497. endfunction()
  498. function (cotire_get_target_compiler_flags _config _language _directory _target _compilerFlagsVar)
  499. # parse target compile flags omitting compile definitions and include directives
  500. cotire_get_target_compile_flags("${_config}" "${_language}" "${_directory}" "${_target}" _targetFlags)
  501. cotire_filter_compile_flags("${_language}" "[ID]" _ignore _compilerFlags ${_targetFlags})
  502. if (COTIRE_DEBUG AND _compileFlags)
  503. message (STATUS "Target ${_target} compiler flags ${_compileFlags}")
  504. endif()
  505. set (${_compilerFlagsVar} ${_compilerFlags} PARENT_SCOPE)
  506. endfunction()
  507. function (cotire_add_sys_root_paths _pathsVar)
  508. if (APPLE)
  509. if (CMAKE_OSX_SYSROOT AND CMAKE_${_language}_HAS_ISYSROOT)
  510. foreach (_path IN LISTS ${_pathsVar})
  511. if (IS_ABSOLUTE "${_path}")
  512. get_filename_component(_path "${CMAKE_OSX_SYSROOT}/${_path}" ABSOLUTE)
  513. if (EXISTS "${_path}")
  514. list (APPEND ${_pathsVar} "${_path}")
  515. endif()
  516. endif()
  517. endforeach()
  518. endif()
  519. endif()
  520. set (${_pathsVar} ${${_pathsVar}} PARENT_SCOPE)
  521. if (COTIRE_DEBUG)
  522. message (STATUS "${_pathsVar}=${${_pathsVar}}")
  523. endif()
  524. endfunction()
  525. function (cotire_get_source_extra_properties _sourceFile _pattern _resultVar)
  526. set (_extraProperties ${ARGN})
  527. set (_result "")
  528. if (_extraProperties)
  529. list (FIND _extraProperties "${_sourceFile}" _index)
  530. if (_index GREATER -1)
  531. math (EXPR _index "${_index} + 1")
  532. list (LENGTH _extraProperties _len)
  533. math (EXPR _len "${_len} - 1")
  534. foreach (_index RANGE ${_index} ${_len})
  535. list (GET _extraProperties ${_index} _value)
  536. if ("${_value}" MATCHES "${_pattern}")
  537. list (APPEND _result "${_value}")
  538. else()
  539. break()
  540. endif()
  541. endforeach()
  542. endif()
  543. endif()
  544. set (${_resultVar} ${_result} PARENT_SCOPE)
  545. endfunction()
  546. function (cotire_get_source_compile_definitions _config _language _sourceFile _definitionsVar)
  547. set (_compileDefinitions "")
  548. if (NOT CMAKE_SCRIPT_MODE_FILE)
  549. string (TOUPPER "${_config}" _upperConfig)
  550. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS)
  551. if (_definitions)
  552. list (APPEND _compileDefinitions ${_definitions})
  553. endif()
  554. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS_${_upperConfig})
  555. if (_definitions)
  556. list (APPEND _compileDefinitions ${_definitions})
  557. endif()
  558. endif()
  559. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+(=.*)?$" _definitions ${ARGN})
  560. if (_definitions)
  561. list (APPEND _compileDefinitions ${_definitions})
  562. endif()
  563. if (COTIRE_DEBUG AND _compileDefinitions)
  564. message (STATUS "Source ${_sourceFile} compile definitions ${_compileDefinitions}")
  565. endif()
  566. set (${_definitionsVar} ${_compileDefinitions} PARENT_SCOPE)
  567. endfunction()
  568. function (cotire_get_source_files_compile_definitions _config _language _definitionsVar)
  569. set (_configDefinitions "")
  570. foreach (_sourceFile ${ARGN})
  571. cotire_get_source_compile_definitions("${_config}" "${_language}" "${_sourceFile}" _sourceDefinitions)
  572. if (_sourceDefinitions)
  573. list (APPEND _configDefinitions "${_sourceFile}" ${_sourceDefinitions} "-")
  574. endif()
  575. endforeach()
  576. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  577. endfunction()
  578. function (cotire_get_source_undefs _sourceFile _property _sourceUndefsVar)
  579. set (_sourceUndefs "")
  580. if (NOT CMAKE_SCRIPT_MODE_FILE)
  581. get_source_file_property(_undefs "${_sourceFile}" ${_property})
  582. if (_undefs)
  583. list (APPEND _sourceUndefs ${_undefs})
  584. endif()
  585. endif()
  586. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+$" _undefs ${ARGN})
  587. if (_undefs)
  588. list (APPEND _sourceUndefs ${_undefs})
  589. endif()
  590. if (COTIRE_DEBUG AND _sourceUndefs)
  591. message (STATUS "Source ${_sourceFile} ${_property} undefs ${_sourceUndefs}")
  592. endif()
  593. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  594. endfunction()
  595. function (cotire_get_source_files_undefs _property _sourceUndefsVar)
  596. set (_sourceUndefs "")
  597. foreach (_sourceFile ${ARGN})
  598. cotire_get_source_undefs("${_sourceFile}" ${_property} _undefs)
  599. if (_undefs)
  600. list (APPEND _sourceUndefs "${_sourceFile}" ${_undefs} "-")
  601. endif()
  602. endforeach()
  603. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  604. endfunction()
  605. macro (cotire_set_cmd_to_prologue _cmdVar)
  606. set (${_cmdVar} "${CMAKE_COMMAND}")
  607. list (APPEND ${_cmdVar} "-DCOTIRE_BUILD_TYPE:STRING=$<CONFIGURATION>")
  608. if (COTIRE_VERBOSE)
  609. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=ON")
  610. elseif("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  611. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=$(VERBOSE)")
  612. endif()
  613. endmacro()
  614. function (cotire_init_compile_cmd _cmdVar _language _compilerExe _compilerArg1)
  615. if (NOT _compilerExe)
  616. set (_compilerExe "${CMAKE_${_language}_COMPILER")
  617. endif()
  618. if (NOT _compilerArg1)
  619. set (_compilerArg1 ${CMAKE_${_language}_COMPILER_ARG1})
  620. endif()
  621. string (STRIP "${_compilerArg1}" _compilerArg1)
  622. set (${_cmdVar} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
  623. endfunction()
  624. macro (cotire_add_definitions_to_cmd _cmdVar _language)
  625. foreach (_definition ${ARGN})
  626. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  627. list (APPEND ${_cmdVar} "/D${_definition}")
  628. else()
  629. list (APPEND ${_cmdVar} "-D${_definition}")
  630. endif()
  631. endforeach()
  632. endmacro()
  633. macro (cotire_add_includes_to_cmd _cmdVar _language)
  634. foreach (_include ${ARGN})
  635. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  636. file (TO_NATIVE_PATH "${_include}" _include)
  637. list (APPEND ${_cmdVar} "/I${_include}")
  638. else()
  639. list (APPEND ${_cmdVar} "-I${_include}")
  640. endif()
  641. endforeach()
  642. endmacro()
  643. macro (cotire_add_compile_flags_to_cmd _cmdVar)
  644. foreach (_flag ${ARGN})
  645. list (APPEND ${_cmdVar} "${_flag}")
  646. endforeach()
  647. endmacro()
  648. function (cotire_check_file_up_to_date _fileIsUpToDateVar _file)
  649. set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
  650. set (_triggerFile "")
  651. foreach (_dependencyFile ${ARGN})
  652. if (EXISTS "${_dependencyFile}" AND "${_dependencyFile}" IS_NEWER_THAN "${_file}")
  653. set (_triggerFile "${_dependencyFile}")
  654. break()
  655. endif()
  656. endforeach()
  657. get_filename_component(_fileName "${_file}" NAME)
  658. if (EXISTS "${_file}")
  659. if (_triggerFile)
  660. if (COTIRE_VERBOSE)
  661. message (STATUS "${_fileName} update triggered by ${_triggerFile} change.")
  662. endif()
  663. else()
  664. if (COTIRE_VERBOSE)
  665. message (STATUS "${_fileName} is up-to-date.")
  666. endif()
  667. set (${_fileIsUpToDateVar} TRUE PARENT_SCOPE)
  668. endif()
  669. else()
  670. if (COTIRE_VERBOSE)
  671. message (STATUS "${_fileName} does not exist yet.")
  672. endif()
  673. endif()
  674. endfunction()
  675. macro (cotire_find_closest_relative_path _headerFile _includeDirs _relPathVar)
  676. set (${_relPathVar} "")
  677. foreach (_includeDir ${_includeDirs})
  678. if (IS_DIRECTORY "${_includeDir}")
  679. file (RELATIVE_PATH _relPath "${_includeDir}" "${_headerFile}")
  680. if (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.")
  681. string (LENGTH "${${_relPathVar}}" _closestLen)
  682. string (LENGTH "${_relPath}" _relLen)
  683. if (_closestLen EQUAL 0 OR _relLen LESS _closestLen)
  684. set (${_relPathVar} "${_relPath}")
  685. endif()
  686. endif()
  687. elseif ("${_includeDir}" STREQUAL "${_headerFile}")
  688. # if path matches exactly, return short non-empty string
  689. set (${_relPathVar} "1")
  690. break()
  691. endif()
  692. endforeach()
  693. endmacro()
  694. macro (cotire_check_header_file_location _headerFile _insideIncudeDirs _outsideIncudeDirs _headerIsInside)
  695. # check header path against ignored and honored include directories
  696. cotire_find_closest_relative_path("${_headerFile}" "${_insideIncudeDirs}" _insideRelPath)
  697. if (_insideRelPath)
  698. # header is inside, but could be become outside if there is a shorter outside match
  699. cotire_find_closest_relative_path("${_headerFile}" "${_outsideIncudeDirs}" _outsideRelPath)
  700. if (_outsideRelPath)
  701. string (LENGTH "${_insideRelPath}" _insideRelPathLen)
  702. string (LENGTH "${_outsideRelPath}" _outsideRelPathLen)
  703. if (_outsideRelPathLen LESS _insideRelPathLen)
  704. set (${_headerIsInside} FALSE)
  705. else()
  706. set (${_headerIsInside} TRUE)
  707. endif()
  708. else()
  709. set (${_headerIsInside} TRUE)
  710. endif()
  711. else()
  712. # header is outside
  713. set (${_headerIsInside} FALSE)
  714. endif()
  715. endmacro()
  716. macro (cotire_check_ignore_header_file_path _headerFile _headerIsIgnoredVar)
  717. if (NOT EXISTS "${_headerFile}")
  718. set (${_headerIsIgnoredVar} TRUE)
  719. elseif (IS_DIRECTORY "${_headerFile}")
  720. set (${_headerIsIgnoredVar} TRUE)
  721. elseif ("${_headerFile}" MATCHES "\\.\\.|[_-]fixed" AND "${_headerFile}" MATCHES "\\.h$")
  722. # heuristic: ignore C headers with embedded parent directory references or "-fixed" or "_fixed" in path
  723. # these often stem from using GCC #include_next tricks, which may break the precompiled header compilation
  724. # with the error message "error: no include path in which to search for header.h"
  725. set (${_headerIsIgnoredVar} TRUE)
  726. else()
  727. set (${_headerIsIgnoredVar} FALSE)
  728. endif()
  729. endmacro()
  730. macro (cotire_check_ignore_header_file_ext _headerFile _ignoreExtensionsVar _headerIsIgnoredVar)
  731. # check header file extension
  732. cotire_get_source_file_extension("${_headerFile}" _headerFileExt)
  733. set (${_headerIsIgnoredVar} FALSE)
  734. if (_headerFileExt)
  735. list (FIND ${_ignoreExtensionsVar} "${_headerFileExt}" _index)
  736. if (_index GREATER -1)
  737. set (${_headerIsIgnoredVar} TRUE)
  738. endif()
  739. endif()
  740. endmacro()
  741. macro (cotire_parse_line _line _headerFileVar _headerDepthVar)
  742. if (MSVC)
  743. # cl.exe /showIncludes output looks different depending on the language pack used, e.g.:
  744. # English: "Note: including file: C:\directory\file"
  745. # German: "Hinweis: Einlesen der Datei: C:\directory\file"
  746. # We use a very general regular expression, relying on the presence of the : characters
  747. if ("${_line}" MATCHES ":( +)([^:]+:[^:]+)$")
  748. # Visual Studio compiler output
  749. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  750. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" ABSOLUTE)
  751. else()
  752. set (${_headerFileVar} "")
  753. set (${_headerDepthVar} 0)
  754. endif()
  755. else()
  756. if ("${_line}" MATCHES "^(\\.+) (.*)$")
  757. # GCC like output
  758. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  759. if (IS_ABSOLUTE "${CMAKE_MATCH_2}")
  760. set (${_headerFileVar} "${CMAKE_MATCH_2}")
  761. else()
  762. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" REALPATH)
  763. endif()
  764. else()
  765. set (${_headerFileVar} "")
  766. set (${_headerDepthVar} 0)
  767. endif()
  768. endif()
  769. endmacro()
  770. function (cotire_parse_includes _language _scanOutput _ignoredIncudeDirs _honoredIncudeDirs _ignoredExtensions _selectedIncludesVar _unparsedLinesVar)
  771. if (WIN32)
  772. # prevent CMake macro invocation errors due to backslash characters in Windows paths
  773. string (REPLACE "\\" "/" _scanOutput "${_scanOutput}")
  774. endif()
  775. # canonize slashes
  776. string (REPLACE "//" "/" _scanOutput "${_scanOutput}")
  777. # prevent semicolon from being interpreted as a line separator
  778. string (REPLACE ";" "\\;" _scanOutput "${_scanOutput}")
  779. # then separate lines
  780. string (REGEX REPLACE "\n" ";" _scanOutput "${_scanOutput}")
  781. list (LENGTH _scanOutput _len)
  782. # remove duplicate lines to speed up parsing
  783. list (REMOVE_DUPLICATES _scanOutput)
  784. list (LENGTH _scanOutput _uniqueLen)
  785. if (COTIRE_VERBOSE)
  786. message (STATUS "Scanning ${_uniqueLen} unique lines of ${_len} for includes")
  787. if (_ignoredExtensions)
  788. message (STATUS "Ignored extensions: ${_ignoredExtensions}")
  789. endif()
  790. if (_ignoredIncudeDirs)
  791. message (STATUS "Ignored paths: ${_ignoredIncudeDirs}")
  792. endif()
  793. if (_honoredIncudeDirs)
  794. message (STATUS "Included paths: ${_honoredIncudeDirs}")
  795. endif()
  796. endif()
  797. set (_sourceFiles ${ARGN})
  798. set (_selectedIncludes "")
  799. set (_unparsedLines "")
  800. # stack keeps track of inside/outside project status of processed header files
  801. set (_headerIsInsideStack "")
  802. foreach (_line IN LISTS _scanOutput)
  803. if (_line)
  804. cotire_parse_line("${_line}" _headerFile _headerDepth)
  805. if (_headerFile)
  806. cotire_check_header_file_location("${_headerFile}" "${_ignoredIncudeDirs}" "${_honoredIncudeDirs}" _headerIsInside)
  807. if (COTIRE_DEBUG)
  808. message (STATUS "${_headerDepth}: ${_headerFile} ${_headerIsInside}")
  809. endif()
  810. # update stack
  811. list (LENGTH _headerIsInsideStack _stackLen)
  812. if (_headerDepth GREATER _stackLen)
  813. math (EXPR _stackLen "${_stackLen} + 1")
  814. foreach (_index RANGE ${_stackLen} ${_headerDepth})
  815. list (APPEND _headerIsInsideStack ${_headerIsInside})
  816. endforeach()
  817. else()
  818. foreach (_index RANGE ${_headerDepth} ${_stackLen})
  819. list (REMOVE_AT _headerIsInsideStack -1)
  820. endforeach()
  821. list (APPEND _headerIsInsideStack ${_headerIsInside})
  822. endif()
  823. if (COTIRE_DEBUG)
  824. message (STATUS "${_headerIsInsideStack}")
  825. endif()
  826. # header is a candidate if it is outside project
  827. if (NOT _headerIsInside)
  828. # get parent header file's inside/outside status
  829. if (_headerDepth GREATER 1)
  830. math (EXPR _index "${_headerDepth} - 2")
  831. list (GET _headerIsInsideStack ${_index} _parentHeaderIsInside)
  832. else()
  833. set (_parentHeaderIsInside TRUE)
  834. endif()
  835. # select header file if parent header file is inside project
  836. # (e.g., a project header file that includes a standard header file)
  837. if (_parentHeaderIsInside)
  838. cotire_check_ignore_header_file_path("${_headerFile}" _headerIsIgnored)
  839. if (NOT _headerIsIgnored)
  840. cotire_check_ignore_header_file_ext("${_headerFile}" _ignoredExtensions _headerIsIgnored)
  841. if (NOT _headerIsIgnored)
  842. list (APPEND _selectedIncludes "${_headerFile}")
  843. else()
  844. # fix header's inside status on stack, it is ignored by extension now
  845. list (REMOVE_AT _headerIsInsideStack -1)
  846. list (APPEND _headerIsInsideStack TRUE)
  847. endif()
  848. endif()
  849. if (COTIRE_DEBUG)
  850. message (STATUS "${_headerFile} ${_ignoredExtensions} ${_headerIsIgnored}")
  851. endif()
  852. endif()
  853. endif()
  854. else()
  855. if (MSVC)
  856. # for cl.exe do not keep unparsed lines which solely consist of a source file name
  857. string (FIND "${_sourceFiles}" "${_line}" _index)
  858. if (_index LESS 0)
  859. list (APPEND _unparsedLines "${_line}")
  860. endif()
  861. else()
  862. list (APPEND _unparsedLines "${_line}")
  863. endif()
  864. endif()
  865. endif()
  866. endforeach()
  867. list (REMOVE_DUPLICATES _selectedIncludes)
  868. set (${_selectedIncludesVar} ${_selectedIncludes} PARENT_SCOPE)
  869. set (${_unparsedLinesVar} ${_unparsedLines} PARENT_SCOPE)
  870. endfunction()
  871. function (cotire_scan_includes _includesVar)
  872. set(_options "")
  873. set(_oneValueArgs COMPILER_ID COMPILER_EXECUTABLE COMPILER_VERSION LANGUAGE UNPARSED_LINES)
  874. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS)
  875. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  876. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  877. if (NOT _option_LANGUAGE)
  878. set (_option_LANGUAGE "CXX")
  879. endif()
  880. if (NOT _option_COMPILER_ID)
  881. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  882. endif()
  883. set (_cmd "${_option_COMPILER_EXECUTABLE}" ${_option_COMPILER_ARG1})
  884. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  885. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  886. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  887. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_INCLUDE_DIRECTORIES})
  888. cotire_add_makedep_flags("${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}" _cmd)
  889. # only consider existing source files for scanning
  890. set (_existingSourceFiles "")
  891. foreach (_sourceFile ${_sourceFiles})
  892. if (EXISTS "${_sourceFile}")
  893. list (APPEND _existingSourceFiles "${_sourceFile}")
  894. endif()
  895. endforeach()
  896. if (NOT _existingSourceFiles)
  897. set (${_includesVar} "" PARENT_SCOPE)
  898. return()
  899. endif()
  900. list (APPEND _cmd ${_existingSourceFiles})
  901. if (COTIRE_VERBOSE)
  902. message (STATUS "execute_process: ${_cmd}")
  903. endif()
  904. if (_option_COMPILER_ID MATCHES "MSVC")
  905. if (COTIRE_DEBUG)
  906. message (STATUS "clearing VS_UNICODE_OUTPUT")
  907. endif()
  908. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  909. unset (ENV{VS_UNICODE_OUTPUT})
  910. endif()
  911. execute_process(COMMAND ${_cmd} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  912. RESULT_VARIABLE _result OUTPUT_QUIET ERROR_VARIABLE _output)
  913. if (_result)
  914. message (STATUS "Result ${_result} scanning includes of ${_existingSourceFiles}.")
  915. endif()
  916. cotire_parse_includes(
  917. "${_option_LANGUAGE}" "${_output}"
  918. "${_option_IGNORE_PATH}" "${_option_INCLUDE_PATH}"
  919. "${_option_IGNORE_EXTENSIONS}"
  920. _includes _unparsedLines
  921. ${_sourceFiles})
  922. set (${_includesVar} ${_includes} PARENT_SCOPE)
  923. if (_option_UNPARSED_LINES)
  924. set (${_option_UNPARSED_LINES} ${_unparsedLines} PARENT_SCOPE)
  925. endif()
  926. endfunction()
  927. macro (cotire_append_undefs _contentsVar)
  928. set (_undefs ${ARGN})
  929. if (_undefs)
  930. list (REMOVE_DUPLICATES _undefs)
  931. foreach (_definition ${_undefs})
  932. list (APPEND ${_contentsVar} "#undef ${_definition}")
  933. endforeach()
  934. endif()
  935. endmacro()
  936. macro (cotire_comment_str _language _commentText _commentVar)
  937. if ("${_language}" STREQUAL "CMAKE")
  938. set (${_commentVar} "# ${_commentText}")
  939. else()
  940. set (${_commentVar} "/* ${_commentText} */")
  941. endif()
  942. endmacro()
  943. function (cotire_write_file _language _file _contents _force)
  944. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  945. cotire_comment_str("${_language}" "${_moduleName} ${COTIRE_CMAKE_MODULE_VERSION} generated file" _header1)
  946. cotire_comment_str("${_language}" "${_file}" _header2)
  947. set (_contents "${_header1}\n${_header2}\n${_contents}")
  948. if (COTIRE_DEBUG)
  949. message (STATUS "${_contents}")
  950. endif()
  951. if (_force OR NOT EXISTS "${_file}")
  952. file (WRITE "${_file}" "${_contents}")
  953. else()
  954. file (READ "${_file}" _oldContents)
  955. if (NOT "${_oldContents}" STREQUAL "${_contents}")
  956. file (WRITE "${_file}" "${_contents}")
  957. else()
  958. if (COTIRE_DEBUG)
  959. message (STATUS "${_file} unchanged")
  960. endif()
  961. endif()
  962. endif()
  963. endfunction()
  964. function (cotire_generate_unity_source _unityFile)
  965. set(_options "")
  966. set(_oneValueArgs LANGUAGE)
  967. set(_multiValueArgs
  968. DEPENDS SOURCES_COMPILE_DEFINITIONS
  969. PRE_UNDEFS SOURCES_PRE_UNDEFS POST_UNDEFS SOURCES_POST_UNDEFS PROLOGUE EPILOGUE)
  970. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  971. if (_option_DEPENDS)
  972. cotire_check_file_up_to_date(_unityFileIsUpToDate "${_unityFile}" ${_option_DEPENDS})
  973. if (_unityFileIsUpToDate)
  974. return()
  975. endif()
  976. endif()
  977. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  978. if (NOT _option_PRE_UNDEFS)
  979. set (_option_PRE_UNDEFS "")
  980. endif()
  981. if (NOT _option_SOURCES_PRE_UNDEFS)
  982. set (_option_SOURCES_PRE_UNDEFS "")
  983. endif()
  984. if (NOT _option_POST_UNDEFS)
  985. set (_option_POST_UNDEFS "")
  986. endif()
  987. if (NOT _option_SOURCES_POST_UNDEFS)
  988. set (_option_SOURCES_POST_UNDEFS "")
  989. endif()
  990. set (_contents "")
  991. if (_option_PROLOGUE)
  992. list (APPEND _contents ${_option_PROLOGUE})
  993. endif()
  994. if (_option_LANGUAGE AND _sourceFiles)
  995. if ("${_option_LANGUAGE}" STREQUAL "CXX")
  996. list (APPEND _contents "#ifdef __cplusplus")
  997. elseif ("${_option_LANGUAGE}" STREQUAL "C")
  998. list (APPEND _contents "#ifndef __cplusplus")
  999. endif()
  1000. endif()
  1001. set (_compileUndefinitions "")
  1002. foreach (_sourceFile ${_sourceFiles})
  1003. cotire_get_source_compile_definitions(
  1004. "${_option_CONFIGURATION}" "${_option_LANGUAGE}" "${_sourceFile}" _compileDefinitions
  1005. ${_option_SOURCES_COMPILE_DEFINITIONS})
  1006. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_PRE_UNDEFS _sourcePreUndefs ${_option_SOURCES_PRE_UNDEFS})
  1007. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_POST_UNDEFS _sourcePostUndefs ${_option_SOURCES_POST_UNDEFS})
  1008. if (_option_PRE_UNDEFS)
  1009. list (APPEND _compileUndefinitions ${_option_PRE_UNDEFS})
  1010. endif()
  1011. if (_sourcePreUndefs)
  1012. list (APPEND _compileUndefinitions ${_sourcePreUndefs})
  1013. endif()
  1014. if (_compileUndefinitions)
  1015. cotire_append_undefs(_contents ${_compileUndefinitions})
  1016. set (_compileUndefinitions "")
  1017. endif()
  1018. if (_sourcePostUndefs)
  1019. list (APPEND _compileUndefinitions ${_sourcePostUndefs})
  1020. endif()
  1021. if (_option_POST_UNDEFS)
  1022. list (APPEND _compileUndefinitions ${_option_POST_UNDEFS})
  1023. endif()
  1024. foreach (_definition ${_compileDefinitions})
  1025. if ("${_definition}" MATCHES "^([a-zA-Z0-9_]+)=(.+)$")
  1026. list (APPEND _contents "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
  1027. list (INSERT _compileUndefinitions 0 "${CMAKE_MATCH_1}")
  1028. else()
  1029. list (APPEND _contents "#define ${_definition}")
  1030. list (INSERT _compileUndefinitions 0 "${_definition}")
  1031. endif()
  1032. endforeach()
  1033. get_filename_component(_sourceFile "${_sourceFile}" ABSOLUTE)
  1034. if (WIN32)
  1035. file (TO_NATIVE_PATH "${_sourceFile}" _sourceFile)
  1036. endif()
  1037. list (APPEND _contents "#include \"${_sourceFile}\"")
  1038. endforeach()
  1039. if (_compileUndefinitions)
  1040. cotire_append_undefs(_contents ${_compileUndefinitions})
  1041. set (_compileUndefinitions "")
  1042. endif()
  1043. if (_option_LANGUAGE AND _sourceFiles)
  1044. list (APPEND _contents "#endif")
  1045. endif()
  1046. if (_option_EPILOGUE)
  1047. list (APPEND _contents ${_option_EPILOGUE})
  1048. endif()
  1049. list (APPEND _contents "")
  1050. string (REPLACE ";" "\n" _contents "${_contents}")
  1051. if (COTIRE_VERBOSE)
  1052. message ("${_contents}")
  1053. endif()
  1054. cotire_write_file("${_option_LANGUAGE}" "${_unityFile}" "${_contents}" TRUE)
  1055. endfunction()
  1056. function (cotire_generate_prefix_header _prefixFile)
  1057. set(_options "")
  1058. set(_oneValueArgs LANGUAGE COMPILER_EXECUTABLE COMPILER_ID COMPILER_VERSION)
  1059. set(_multiValueArgs DEPENDS COMPILE_DEFINITIONS COMPILE_FLAGS
  1060. INCLUDE_DIRECTORIES IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS)
  1061. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1062. if (_option_DEPENDS)
  1063. cotire_check_file_up_to_date(_prefixFileIsUpToDate "${_prefixFile}" ${_option_DEPENDS})
  1064. if (_prefixFileIsUpToDate)
  1065. return()
  1066. endif()
  1067. endif()
  1068. set (_epilogue "")
  1069. if (_option_COMPILER_ID MATCHES "Intel")
  1070. # Intel compiler requires hdrstop pragma to stop generating PCH file
  1071. set (_epilogue "#pragma hdrstop")
  1072. endif()
  1073. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1074. cotire_scan_includes(_selectedHeaders ${_sourceFiles}
  1075. LANGUAGE "${_option_LANGUAGE}"
  1076. COMPILER_EXECUTABLE "${_option_COMPILER_EXECUTABLE}"
  1077. COMPILER_ID "${_option_COMPILER_ID}"
  1078. COMPILER_VERSION "${_option_COMPILER_VERSION}"
  1079. COMPILE_DEFINITIONS ${_option_COMPILE_DEFINITIONS}
  1080. COMPILE_FLAGS ${_option_COMPILE_FLAGS}
  1081. INCLUDE_DIRECTORIES ${_option_INCLUDE_DIRECTORIES}
  1082. IGNORE_PATH ${_option_IGNORE_PATH}
  1083. INCLUDE_PATH ${_option_INCLUDE_PATH}
  1084. IGNORE_EXTENSIONS ${_option_IGNORE_EXTENSIONS}
  1085. UNPARSED_LINES _unparsedLines)
  1086. cotire_generate_unity_source("${_prefixFile}" EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders})
  1087. set (_unparsedLinesFile "${_prefixFile}.log")
  1088. if (_unparsedLines)
  1089. if (COTIRE_VERBOSE OR NOT _selectedHeaders)
  1090. list (LENGTH _unparsedLines _skippedLineCount)
  1091. file (RELATIVE_PATH _unparsedLinesFileRelPath "${CMAKE_BINARY_DIR}" "${_unparsedLinesFile}")
  1092. message (STATUS "${_skippedLineCount} line(s) skipped, see ${_unparsedLinesFileRelPath}")
  1093. endif()
  1094. string (REPLACE ";" "\n" _unparsedLines "${_unparsedLines}")
  1095. endif()
  1096. file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}\n")
  1097. endfunction()
  1098. function (cotire_add_makedep_flags _language _compilerID _compilerVersion _flagsVar)
  1099. set (_flags ${${_flagsVar}})
  1100. if (_compilerID MATCHES "MSVC")
  1101. # cl.exe options used
  1102. # /nologo suppresses display of sign-on banner
  1103. # /TC treat all files named on the command line as C source files
  1104. # /TP treat all files named on the command line as C++ source files
  1105. # /EP preprocess to stdout without #line directives
  1106. # /showIncludes list include files
  1107. set (_sourceFileTypeC "/TC")
  1108. set (_sourceFileTypeCXX "/TP")
  1109. if (_flags)
  1110. # append to list
  1111. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /showIncludes)
  1112. else()
  1113. # return as a flag string
  1114. set (_flags "${_sourceFileType${_language}} /EP /showIncludes")
  1115. endif()
  1116. elseif (_compilerID MATCHES "GNU")
  1117. # GCC options used
  1118. # -H print the name of each header file used
  1119. # -E invoke preprocessor
  1120. # -fdirectives-only do not expand macros, requires GCC >= 4.3
  1121. if (_flags)
  1122. # append to list
  1123. list (APPEND _flags -H -E)
  1124. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1125. list (APPEND _flags "-fdirectives-only")
  1126. endif()
  1127. else()
  1128. # return as a flag string
  1129. set (_flags "-H -E")
  1130. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1131. set (_flags "${_flags} -fdirectives-only")
  1132. endif()
  1133. endif()
  1134. elseif (_compilerID MATCHES "Clang")
  1135. # Clang options used
  1136. # -H print the name of each header file used
  1137. # -E invoke preprocessor
  1138. if (_flags)
  1139. # append to list
  1140. list (APPEND _flags -H -E)
  1141. else()
  1142. # return as a flag string
  1143. set (_flags "-H -E")
  1144. endif()
  1145. elseif (_compilerID MATCHES "Intel")
  1146. if (WIN32)
  1147. # Windows Intel options used
  1148. # /nologo do not display compiler version information
  1149. # /QH display the include file order
  1150. # /EP preprocess to stdout, omitting #line directives
  1151. # /TC process all source or unrecognized file types as C source files
  1152. # /TP process all source or unrecognized file types as C++ source files
  1153. set (_sourceFileTypeC "/TC")
  1154. set (_sourceFileTypeCXX "/TP")
  1155. if (_flags)
  1156. # append to list
  1157. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /QH)
  1158. else()
  1159. # return as a flag string
  1160. set (_flags "${_sourceFileType${_language}} /EP /QH")
  1161. endif()
  1162. else()
  1163. # Linux / Mac OS X Intel options used
  1164. # -H print the name of each header file used
  1165. # -EP preprocess to stdout, omitting #line directives
  1166. # -Kc++ process all source or unrecognized file types as C++ source files
  1167. if (_flags)
  1168. # append to list
  1169. if ("${_language}" STREQUAL "CXX")
  1170. list (APPEND _flags -Kc++)
  1171. endif()
  1172. list (APPEND _flags -H -EP)
  1173. else()
  1174. # return as a flag string
  1175. if ("${_language}" STREQUAL "CXX")
  1176. set (_flags "-Kc++ ")
  1177. endif()
  1178. set (_flags "${_flags}-H -EP")
  1179. endif()
  1180. endif()
  1181. else()
  1182. message (FATAL_ERROR "Unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1183. endif()
  1184. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1185. endfunction()
  1186. function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersion _prefixFile _pchFile _hostFile _flagsVar)
  1187. set (_flags ${${_flagsVar}})
  1188. if (_compilerID MATCHES "MSVC")
  1189. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1190. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1191. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1192. # cl.exe options used
  1193. # /Yc creates a precompiled header file
  1194. # /Fp specifies precompiled header binary file name
  1195. # /FI forces inclusion of file
  1196. # /TC treat all files named on the command line as C source files
  1197. # /TP treat all files named on the command line as C++ source files
  1198. # /Zs syntax check only
  1199. set (_sourceFileTypeC "/TC")
  1200. set (_sourceFileTypeCXX "/TP")
  1201. if (_flags)
  1202. # append to list
  1203. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1204. "/Yc${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
  1205. else()
  1206. # return as a flag string
  1207. set (_flags "/Yc\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1208. endif()
  1209. elseif (_compilerID MATCHES "GNU|Clang")
  1210. # GCC / Clang options used
  1211. # -x specify the source language
  1212. # -c compile but do not link
  1213. # -o place output in file
  1214. set (_xLanguage_C "c-header")
  1215. set (_xLanguage_CXX "c++-header")
  1216. if (_flags)
  1217. # append to list
  1218. list (APPEND _flags "-x" "${_xLanguage_${_language}}" "-c" "${_prefixFile}" -o "${_pchFile}")
  1219. else()
  1220. # return as a flag string
  1221. set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"")
  1222. endif()
  1223. elseif (_compilerID MATCHES "Intel")
  1224. if (WIN32)
  1225. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1226. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1227. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1228. # Windows Intel options used
  1229. # /nologo do not display compiler version information
  1230. # /Yc create a precompiled header (PCH) file
  1231. # /Fp specify a path or file name for precompiled header files
  1232. # /FI tells the preprocessor to include a specified file name as the header file
  1233. # /TC process all source or unrecognized file types as C source files
  1234. # /TP process all source or unrecognized file types as C++ source files
  1235. # /Zs syntax check only
  1236. # /Qwd673 disable warning 673 (the initial sequence of preprocessing directives is not compatible with those of precompiled header file)
  1237. set (_sourceFileTypeC "/TC")
  1238. set (_sourceFileTypeCXX "/TP")
  1239. if (_flags)
  1240. # append to list
  1241. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1242. "/Yc" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}" "/Qwd673")
  1243. else()
  1244. # return as a flag string
  1245. set (_flags "/Yc /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\" /Qwd673")
  1246. endif()
  1247. else()
  1248. # Linux / Mac OS X Intel options used
  1249. # -pch-dir location for precompiled header files
  1250. # -pch-create name of the precompiled header (PCH) to create
  1251. # -Kc++ process all source or unrecognized file types as C++ source files
  1252. # -fsyntax-only check only for correct syntax
  1253. # -wd673 disable warning 673 (the initial sequence of preprocessing directives is not compatible with those of precompiled header file)
  1254. get_filename_component(_pchDir "${_pchFile}" PATH)
  1255. get_filename_component(_pchName "${_pchFile}" NAME)
  1256. set (_xLanguage_C "c-header")
  1257. set (_xLanguage_CXX "c++-header")
  1258. if (_flags)
  1259. # append to list
  1260. if ("${_language}" STREQUAL "CXX")
  1261. list (APPEND _flags -Kc++)
  1262. endif()
  1263. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-create" "${_pchName}" "-wd673" "-fsyntax-only" "${_hostFile}")
  1264. else()
  1265. # return as a flag string
  1266. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-create \"${_pchName}\" -wd673")
  1267. endif()
  1268. endif()
  1269. else()
  1270. message (FATAL_ERROR "Unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1271. endif()
  1272. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1273. endfunction()
  1274. function (cotire_add_pch_inclusion_flags _language _compilerID _compilerVersion _prefixFile _pchFile _flagsVar)
  1275. set (_flags ${${_flagsVar}})
  1276. if (_compilerID MATCHES "MSVC")
  1277. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1278. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1279. # cl.exe options used
  1280. # /Yu uses a precompiled header file during build
  1281. # /Fp specifies precompiled header binary file name
  1282. # /FI forces inclusion of file
  1283. if (_flags)
  1284. # append to list
  1285. list (APPEND _flags "/Yu${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
  1286. else()
  1287. # return as a flag string
  1288. set (_flags "/Yu\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1289. endif()
  1290. elseif (_compilerID MATCHES "GNU")
  1291. # GCC options used
  1292. # -include process include file as the first line of the primary source file
  1293. # -Winvalid-pch warns if precompiled header is found but cannot be used
  1294. if (_flags)
  1295. # append to list
  1296. list (APPEND _flags "-include" "${_prefixFile}" "-Winvalid-pch")
  1297. else()
  1298. # return as a flag string
  1299. set (_flags "-include \"${_prefixFile}\" -Winvalid-pch")
  1300. endif()
  1301. elseif (_compilerID MATCHES "Clang")
  1302. # Clang options used
  1303. # -include process include file as the first line of the primary source file
  1304. # -Qunused-arguments don't emit warning for unused driver arguments
  1305. if (_flags)
  1306. # append to list
  1307. list (APPEND _flags "-include" "${_prefixFile}" "-Qunused-arguments")
  1308. else()
  1309. # return as a flag string
  1310. set (_flags "-include \"${_prefixFile}\" -Qunused-arguments")
  1311. endif()
  1312. elseif (_compilerID MATCHES "Intel")
  1313. if (WIN32)
  1314. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1315. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1316. # Windows Intel options used
  1317. # /Yu use a precompiled header (PCH) file
  1318. # /Fp specify a path or file name for precompiled header files
  1319. # /FI tells the preprocessor to include a specified file name as the header file
  1320. # /Qwd673 disable warning 673 (the initial sequence of preprocessing directives is not compatible with those of precompiled header file)
  1321. if (_flags)
  1322. # append to list
  1323. list (APPEND _flags "/Yu" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" "/Qwd673")
  1324. else()
  1325. # return as a flag string
  1326. set (_flags "/Yu /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\" /Qwd673")
  1327. endif()
  1328. else()
  1329. # Linux / Mac OS X Intel options used
  1330. # -pch-dir location for precompiled header files
  1331. # -pch-use name of the precompiled header (PCH) to use
  1332. # -include process include file as the first line of the primary source file
  1333. # -wd673 disable warning 673 (the initial sequence of preprocessing directives is not compatible with those of precompiled header file)
  1334. get_filename_component(_pchDir "${_pchFile}" PATH)
  1335. get_filename_component(_pchName "${_pchFile}" NAME)
  1336. if (_flags)
  1337. # append to list
  1338. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-use" "${_pchName}" "-wd673")
  1339. else()
  1340. # return as a flag string
  1341. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-use \"${_pchName}\" -wd673")
  1342. endif()
  1343. endif()
  1344. else()
  1345. message (FATAL_ERROR "Unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1346. endif()
  1347. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1348. endfunction()
  1349. function (cotire_precompile_prefix_header _prefixFile _pchFile _hostFile)
  1350. set(_options "")
  1351. set(_oneValueArgs COMPILER_EXECUTABLE COMPILER_ID COMPILER_VERSION LANGUAGE)
  1352. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES)
  1353. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1354. if (NOT _option_LANGUAGE)
  1355. set (_option_LANGUAGE "CXX")
  1356. endif()
  1357. if (NOT _option_COMPILER_ID)
  1358. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1359. endif()
  1360. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  1361. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  1362. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  1363. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_INCLUDE_DIRECTORIES})
  1364. cotire_add_pch_compilation_flags(
  1365. "${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}"
  1366. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _cmd)
  1367. if (COTIRE_VERBOSE)
  1368. message (STATUS "execute_process: ${_cmd}")
  1369. endif()
  1370. if (_option_COMPILER_ID MATCHES "MSVC")
  1371. if (COTIRE_DEBUG)
  1372. message (STATUS "clearing VS_UNICODE_OUTPUT")
  1373. endif()
  1374. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  1375. unset (ENV{VS_UNICODE_OUTPUT})
  1376. endif()
  1377. execute_process(COMMAND ${_cmd} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE _result)
  1378. if (_result)
  1379. message (FATAL_ERROR "Error ${_result} precompiling ${_prefixFile}.")
  1380. endif()
  1381. endfunction()
  1382. function (cotire_check_precompiled_header_support _language _targetSourceDir _target _msgVar)
  1383. set (_unsupportedCompilerVersionMsg
  1384. "Precompiled headers not supported for ${_language} compiler ${CMAKE_${_language}_COMPILER_ID} version ${COTIRE_${_language}_COMPILER_VERSION}.")
  1385. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  1386. # supported since Visual Studio C++ 6.0
  1387. # and CMake does not support an earlier version
  1388. set (${_msgVar} "" PARENT_SCOPE)
  1389. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU")
  1390. # GCC PCH support requires version >= 3.4
  1391. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1392. if ("${COTIRE_${_language}_COMPILER_VERSION}" MATCHES ".+" AND
  1393. "${COTIRE_${_language}_COMPILER_VERSION}" VERSION_LESS "3.4.0")
  1394. set (${_msgVar} "${_unsupportedCompilerVersionMsg}" PARENT_SCOPE)
  1395. else()
  1396. set (${_msgVar} "" PARENT_SCOPE)
  1397. endif()
  1398. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang")
  1399. # all Clang versions have PCH support
  1400. set (${_msgVar} "" PARENT_SCOPE)
  1401. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  1402. # Intel PCH support requires version >= 8.0.0
  1403. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1404. if ("${COTIRE_${_language}_COMPILER_VERSION}" MATCHES ".+" AND
  1405. "${COTIRE_${_language}_COMPILER_VERSION}" VERSION_LESS "8.0.0")
  1406. set (${_msgVar} "${_unsupportedCompilerVersionMsg}" PARENT_SCOPE)
  1407. else()
  1408. set (${_msgVar} "" PARENT_SCOPE)
  1409. endif()
  1410. else()
  1411. set (${_msgVar} "Unsupported ${_language} compiler ${CMAKE_${_language}_COMPILER_ID}." PARENT_SCOPE)
  1412. endif()
  1413. if (APPLE)
  1414. # PCH compilation not supported by GCC / Clang for multi-architecture builds (e.g., i386, x86_64)
  1415. if (CMAKE_CONFIGURATION_TYPES)
  1416. set (_configs ${CMAKE_CONFIGURATION_TYPES})
  1417. elseif (CMAKE_BUILD_TYPE)
  1418. set (_configs ${CMAKE_BUILD_TYPE})
  1419. else()
  1420. set (_configs "None")
  1421. endif()
  1422. foreach (_config ${_configs})
  1423. cotire_get_target_compile_flags("${_config}" "${_language}" "${_targetSourceDir}" "${_target}" _targetFlags)
  1424. cotire_filter_compile_flags("${_language}" "arch" _architectures _ignore ${_targetFlags})
  1425. list (LENGTH _architectures _numberOfArchitectures)
  1426. if (_numberOfArchitectures GREATER 1)
  1427. string (REPLACE ";" ", " _architectureStr "${_architectures}")
  1428. set (${_msgVar}
  1429. "Precompiled headers not supported on Darwin for multi-architecture builds (${_architectureStr})."
  1430. PARENT_SCOPE)
  1431. break()
  1432. endif()
  1433. endforeach()
  1434. endif()
  1435. endfunction()
  1436. macro (cotire_get_intermediate_dir _cotireDir)
  1437. get_filename_component(${_cotireDir} "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${COTIRE_INTDIR}" ABSOLUTE)
  1438. endmacro()
  1439. function (cotire_make_untiy_source_file_paths _language _target _maxIncludes _unityFilesVar)
  1440. set (_sourceFiles ${ARGN})
  1441. list (LENGTH _sourceFiles _numberOfSources)
  1442. set (_unityFileExt_C ".c")
  1443. set (_unityFileExt_CXX ".cxx")
  1444. if (NOT DEFINED _unityFileExt_${_language})
  1445. set (${_unityFileVar} "" PARENT_SCOPE)
  1446. return()
  1447. endif()
  1448. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1449. cotire_get_intermediate_dir(_baseDir)
  1450. set (_startIndex 0)
  1451. set (_index 0)
  1452. set (_unityFiles "")
  1453. foreach (_sourceFile ${_sourceFiles})
  1454. get_source_file_property(_startNew "${_sourceFile}" COTIRE_START_NEW_UNITY_SOURCE)
  1455. math (EXPR _unityFileCount "${_index} - ${_startIndex}")
  1456. if (_startNew OR (_maxIncludes GREATER 0 AND NOT _unityFileCount LESS _maxIncludes))
  1457. if (_index GREATER 0)
  1458. math (EXPR _endIndex "${_index} - 1")
  1459. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1460. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1461. endif()
  1462. set (_startIndex ${_index})
  1463. endif()
  1464. math (EXPR _index "${_index} + 1")
  1465. endforeach()
  1466. if (_startIndex EQUAL 0)
  1467. set (_unityFileName "${_unityFileBaseName}${_unityFileExt_${_language}}")
  1468. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1469. elseif (_startIndex LESS _numberOfSources)
  1470. math (EXPR _endIndex "${_index} - 1")
  1471. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1472. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1473. endif()
  1474. set (${_unityFilesVar} ${_unityFiles} PARENT_SCOPE)
  1475. if (COTIRE_DEBUG)
  1476. message(STATUS "${_unityFiles}")
  1477. endif()
  1478. endfunction()
  1479. function (cotire_make_prefix_file_name _language _target _prefixFileBaseNameVar _prefixFileNameVar)
  1480. set (_prefixFileExt_C ".h")
  1481. set (_prefixFileExt_CXX ".hxx")
  1482. if (NOT _language)
  1483. set (_prefixFileBaseName "${_target}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1484. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_C}")
  1485. elseif (DEFINED _prefixFileExt_${_language})
  1486. set (_prefixFileBaseName "${_target}_${_language}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1487. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_${_language}}")
  1488. else()
  1489. set (_prefixFileBaseName "")
  1490. set (_prefixFileName "")
  1491. endif()
  1492. set (${_prefixFileBaseNameVar} "${_prefixFileBaseName}" PARENT_SCOPE)
  1493. set (${_prefixFileNameVar} "${_prefixFileName}" PARENT_SCOPE)
  1494. endfunction()
  1495. function (cotire_make_prefix_file_path _language _target _prefixFileVar)
  1496. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  1497. set (${_prefixFileVar} "" PARENT_SCOPE)
  1498. if (_prefixFileName)
  1499. if (NOT _language)
  1500. set (_language "C")
  1501. endif()
  1502. if (MSVC OR CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang|Intel")
  1503. cotire_get_intermediate_dir(_baseDir)
  1504. set (${_prefixFileVar} "${_baseDir}/${_prefixFileName}" PARENT_SCOPE)
  1505. endif()
  1506. endif()
  1507. endfunction()
  1508. function (cotire_make_pch_file_path _language _targetSourceDir _target _pchFileVar)
  1509. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  1510. set (${_pchFileVar} "" PARENT_SCOPE)
  1511. if (_prefixFileBaseName AND _prefixFileName)
  1512. cotire_check_precompiled_header_support("${_language}" "${_targetSourceDir}" "${_target}" _msg)
  1513. if (NOT _msg)
  1514. if (XCODE)
  1515. # For Xcode, we completely hand off the compilation of the prefix header to the IDE
  1516. return()
  1517. endif()
  1518. cotire_get_intermediate_dir(_baseDir)
  1519. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  1520. # MSVC uses the extension .pch added to the prefix header base name
  1521. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pch" PARENT_SCOPE)
  1522. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  1523. # GCC / Clang look for a precompiled header corresponding to the prefix header with the extension .gch appended
  1524. set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.gch" PARENT_SCOPE)
  1525. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  1526. # Intel uses the extension .pchi added to the prefix header base name
  1527. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pchi" PARENT_SCOPE)
  1528. endif()
  1529. endif()
  1530. endif()
  1531. endfunction()
  1532. function (cotire_select_unity_source_files _unityFile _sourcesVar)
  1533. set (_sourceFiles ${ARGN})
  1534. if (_sourceFiles AND "${_unityFile}" MATCHES "${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}_([0-9]+)_([0-9]+)")
  1535. set (_startIndex ${CMAKE_MATCH_1})
  1536. set (_endIndex ${CMAKE_MATCH_2})
  1537. list (LENGTH _sourceFiles _numberOfSources)
  1538. if (NOT _startIndex LESS _numberOfSources)
  1539. math (EXPR _startIndex "${_numberOfSources} - 1")
  1540. endif()
  1541. if (NOT _endIndex LESS _numberOfSources)
  1542. math (EXPR _endIndex "${_numberOfSources} - 1")
  1543. endif()
  1544. set (_files "")
  1545. foreach (_index RANGE ${_startIndex} ${_endIndex})
  1546. list (GET _sourceFiles ${_index} _file)
  1547. list (APPEND _files "${_file}")
  1548. endforeach()
  1549. else()
  1550. set (_files ${_sourceFiles})
  1551. endif()
  1552. set (${_sourcesVar} ${_files} PARENT_SCOPE)
  1553. endfunction()
  1554. function (cotire_get_unity_source_dependencies _language _target _dependencySourcesVar)
  1555. set (_dependencySources "")
  1556. # depend on target's generated source files
  1557. cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${ARGN})
  1558. if (_generatedSources)
  1559. # but omit all generated source files that have the COTIRE_EXCLUDED property set to true
  1560. cotire_get_objects_with_property_on(_excludedGeneratedSources COTIRE_EXCLUDED SOURCE ${_generatedSources})
  1561. if (_excludedGeneratedSources)
  1562. list (REMOVE_ITEM _generatedSources ${_excludedGeneratedSources})
  1563. endif()
  1564. # and omit all generated source files that have the COTIRE_DEPENDENCY property set to false explicitly
  1565. cotire_get_objects_with_property_off(_excludedNonDependencySources COTIRE_DEPENDENCY SOURCE ${_generatedSources})
  1566. if (_excludedNonDependencySources)
  1567. list (REMOVE_ITEM _generatedSources ${_excludedNonDependencySources})
  1568. endif()
  1569. if (_generatedSources)
  1570. list (APPEND _dependencySources ${_generatedSources})
  1571. endif()
  1572. endif()
  1573. if (COTIRE_DEBUG AND _dependencySources)
  1574. message (STATUS "${_language} ${_target} unity source depends on ${_dependencySources}")
  1575. endif()
  1576. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  1577. endfunction()
  1578. function (cotire_get_prefix_header_dependencies _language _target _dependencySourcesVar)
  1579. # depend on target source files marked with custom COTIRE_DEPENDENCY property
  1580. set (_dependencySources "")
  1581. cotire_get_objects_with_property_on(_dependencySources COTIRE_DEPENDENCY SOURCE ${ARGN})
  1582. if (COTIRE_DEBUG AND _dependencySources)
  1583. message (STATUS "${_language} ${_target} prefix header DEPENDS ${_dependencySources}")
  1584. endif()
  1585. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  1586. endfunction()
  1587. function (cotire_generate_target_script _language _configurations _targetSourceDir _targetBinaryDir _target _targetScriptVar)
  1588. set (COTIRE_TARGET_SOURCES ${ARGN})
  1589. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  1590. set (_targetCotireScript "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${_language}_${_moduleName}")
  1591. cotire_get_prefix_header_dependencies(${_language} ${_target} COTIRE_TARGET_PREFIX_DEPENDS ${COTIRE_TARGET_SOURCES})
  1592. cotire_get_unity_source_dependencies(${_language} ${_target} COTIRE_TARGET_UNITY_DEPENDS ${COTIRE_TARGET_SOURCES})
  1593. # set up variables to be configured
  1594. set (COTIRE_TARGET_LANGUAGE "${_language}")
  1595. cotire_determine_compiler_version("${COTIRE_TARGET_LANGUAGE}" COTIRE_${_language}_COMPILER)
  1596. get_target_property(COTIRE_TARGET_IGNORE_PATH ${_target} COTIRE_PREFIX_HEADER_IGNORE_PATH)
  1597. cotire_add_sys_root_paths(COTIRE_TARGET_IGNORE_PATH)
  1598. get_target_property(COTIRE_TARGET_INCLUDE_PATH ${_target} COTIRE_PREFIX_HEADER_INCLUDE_PATH)
  1599. cotire_add_sys_root_paths(COTIRE_TARGET_INCLUDE_PATH)
  1600. get_target_property(COTIRE_TARGET_PRE_UNDEFS ${_target} COTIRE_UNITY_SOURCE_PRE_UNDEFS)
  1601. get_target_property(COTIRE_TARGET_POST_UNDEFS ${_target} COTIRE_UNITY_SOURCE_POST_UNDEFS)
  1602. get_target_property(COTIRE_TARGET_MAXIMUM_NUMBER_OF_INCLUDES ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  1603. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_PRE_UNDEFS COTIRE_TARGET_SOURCES_PRE_UNDEFS ${COTIRE_TARGET_SOURCES})
  1604. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_POST_UNDEFS COTIRE_TARGET_SOURCES_POST_UNDEFS ${COTIRE_TARGET_SOURCES})
  1605. set (COTIRE_TARGET_CONFIGURATION_TYPES "${_configurations}")
  1606. foreach (_config ${_configurations})
  1607. string (TOUPPER "${_config}" _upperConfig)
  1608. cotire_get_target_include_directories(
  1609. "${_config}" "${_language}" "${_targetSourceDir}" "${_targetBinaryDir}" "${_target}" COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig})
  1610. cotire_get_target_compile_definitions(
  1611. "${_config}" "${_language}" "${_targetSourceDir}" "${_target}" COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig})
  1612. cotire_get_target_compiler_flags(
  1613. "${_config}" "${_language}" "${_targetSourceDir}" "${_target}" COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig})
  1614. cotire_get_source_files_compile_definitions(
  1615. "${_config}" "${_language}" COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig} ${COTIRE_TARGET_SOURCES})
  1616. endforeach()
  1617. get_cmake_property(_vars VARIABLES)
  1618. string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+" _matchVars "${_vars}")
  1619. # remove COTIRE_VERBOSE which is passed as a CMake define on command line
  1620. list (REMOVE_ITEM _matchVars COTIRE_VERBOSE)
  1621. set (_contents "")
  1622. foreach (_var IN LISTS _matchVars ITEMS
  1623. MSVC CMAKE_GENERATOR CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES
  1624. CMAKE_${_language}_COMPILER_ID CMAKE_${_language}_COMPILER CMAKE_${_language}_COMPILER_ARG1
  1625. CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  1626. if (DEFINED ${_var})
  1627. string (REPLACE "\"" "\\\"" _value "${${_var}}")
  1628. set (_contents "${_contents}set (${_var} \"${_value}\")\n")
  1629. endif()
  1630. endforeach()
  1631. cotire_write_file("CMAKE" "${_targetCotireScript}" "${_contents}" FALSE)
  1632. set (${_targetScriptVar} "${_targetCotireScript}" PARENT_SCOPE)
  1633. endfunction()
  1634. function (cotire_setup_pch_file_compilation _language _targetBinaryDir _targetScript _prefixFile _pchFile)
  1635. set (_sourceFiles ${ARGN})
  1636. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  1637. # for Visual Studio and Intel, we attach the precompiled header compilation to the first source file
  1638. # the remaining files include the precompiled header, see cotire_setup_prefix_file_inclusion
  1639. if (_sourceFiles)
  1640. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1641. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1642. list (GET _sourceFiles 0 _hostFile)
  1643. set (_flags "")
  1644. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1645. cotire_add_pch_compilation_flags(
  1646. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${COTIRE_${_language}_COMPILER_VERSION}"
  1647. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _flags)
  1648. set_property (SOURCE ${_hostFile} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  1649. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_OUTPUTS "${_pchFile}")
  1650. # make first source file depend on prefix header
  1651. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
  1652. endif()
  1653. elseif ("${CMAKE_GENERATOR}" MATCHES "Makefiles|Ninja")
  1654. # for makefile based generator, we add a custom command to precompile the prefix header
  1655. if (_targetScript)
  1656. cotire_set_cmd_to_prologue(_cmds)
  1657. list (GET _sourceFiles 0 _hostFile)
  1658. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "precompile" "${_targetScript}" "${_prefixFile}" "${_pchFile}" "${_hostFile}")
  1659. file (RELATIVE_PATH _pchFileRelPath "${CMAKE_BINARY_DIR}" "${_pchFile}")
  1660. if (COTIRE_DEBUG)
  1661. message (STATUS "add_custom_command: OUTPUT ${_pchFile} ${_cmds} DEPENDS ${_prefixFile} IMPLICIT_DEPENDS ${_language} ${_prefixFile}")
  1662. endif()
  1663. set_property (SOURCE "${_pchFile}" PROPERTY GENERATED TRUE)
  1664. add_custom_command(OUTPUT "${_pchFile}"
  1665. COMMAND ${_cmds}
  1666. DEPENDS "${_prefixFile}"
  1667. IMPLICIT_DEPENDS ${_language} "${_prefixFile}"
  1668. WORKING_DIRECTORY "${_targetSourceDir}"
  1669. COMMENT "Building ${_language} precompiled header ${_pchFileRelPath}" VERBATIM)
  1670. endif()
  1671. endif()
  1672. endfunction()
  1673. function (cotire_setup_prefix_file_inclusion _language _target _wholeTarget _prefixFile _pchFile)
  1674. set (_sourceFiles ${ARGN})
  1675. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  1676. # for Visual Studio and Intel, we include the precompiled header in all but the first source file
  1677. # the first source file does the precompiled header compilation, see cotire_setup_pch_file_compilation
  1678. list (LENGTH _sourceFiles _numberOfSourceFiles)
  1679. if (_numberOfSourceFiles GREATER 1)
  1680. # mark sources as cotired to prevent them from being used in another cotired target
  1681. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  1682. list (REMOVE_AT _sourceFiles 0)
  1683. set (_flags "")
  1684. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1685. cotire_add_pch_inclusion_flags(
  1686. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${COTIRE_${_language}_COMPILER_VERSION}"
  1687. "${_prefixFile}" "${_pchFile}" _flags)
  1688. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  1689. # make source files depend on precompiled header
  1690. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  1691. endif()
  1692. elseif ("${CMAKE_GENERATOR}" MATCHES "Makefiles|Ninja")
  1693. if (NOT _wholeTarget)
  1694. # for makefile based generator, we force the inclusion of the prefix header for a subset
  1695. # of the source files, if this is a multi-language target or has excluded files
  1696. set (_flags "")
  1697. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1698. cotire_add_pch_inclusion_flags(
  1699. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${COTIRE_${_language}_COMPILER_VERSION}"
  1700. "${_prefixFile}" "${_pchFile}" _flags)
  1701. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  1702. # mark sources as cotired to prevent them from being used in another cotired target
  1703. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  1704. endif()
  1705. # make source files depend on precompiled header
  1706. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  1707. endif()
  1708. endfunction()
  1709. function (cotire_get_first_set_property_value _propertyValueVar _type _object)
  1710. set (_properties ${ARGN})
  1711. foreach (_property ${_properties})
  1712. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  1713. if (_propertyValue)
  1714. set (${_propertyValueVar} ${_propertyValue} PARENT_SCOPE)
  1715. return()
  1716. endif()
  1717. endforeach()
  1718. set (${_propertyValueVar} "" PARENT_SCOPE)
  1719. endfunction()
  1720. function (cotire_setup_target_pch_usage _languages _targetSourceDir _target _wholeTarget)
  1721. if (XCODE)
  1722. # for Xcode, we attach a pre-build action to generate the unity sources and prefix headers
  1723. # if necessary, we also generate a single prefix header which includes all language specific prefix headers
  1724. set (_prefixFiles "")
  1725. foreach (_language ${_languages})
  1726. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  1727. if (_prefixFile)
  1728. list (APPEND _prefixFiles "${_prefixFile}")
  1729. endif()
  1730. endforeach()
  1731. set (_cmds ${ARGN})
  1732. list (LENGTH _prefixFiles _numberOfPrefixFiles)
  1733. if (_numberOfPrefixFiles GREATER 1)
  1734. cotire_make_prefix_file_path("" ${_target} _prefixHeader)
  1735. cotire_setup_combine_command("${_targetSourceDir}" "" "${_prefixHeader}" "${_prefixFiles}" _cmds)
  1736. else()
  1737. set (_prefixHeader "${_prefixFiles}")
  1738. endif()
  1739. if (COTIRE_DEBUG)
  1740. message (STATUS "add_custom_command: TARGET ${_target} PRE_BUILD ${_cmds}")
  1741. endif()
  1742. add_custom_command(TARGET "${_target}"
  1743. PRE_BUILD ${_cmds}
  1744. WORKING_DIRECTORY "${_targetSourceDir}"
  1745. COMMENT "Updating target ${_target} prefix headers" VERBATIM)
  1746. # make Xcode precompile the generated prefix header with ProcessPCH and ProcessPCH++
  1747. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
  1748. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${_prefixHeader}")
  1749. elseif ("${CMAKE_GENERATOR}" MATCHES "Makefiles|Ninja")
  1750. # for makefile based generator, we force inclusion of the prefix header for all target source files
  1751. # if this is a single-language target without any excluded files
  1752. if (_wholeTarget)
  1753. set (_language "${_languages}")
  1754. # for Visual Studio and Intel, precompiled header inclusion is always done on the source file level
  1755. # see cotire_setup_prefix_file_inclusion
  1756. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  1757. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  1758. get_property(_pchFile TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER)
  1759. set (_flags "")
  1760. cotire_determine_compiler_version("${_language}" COTIRE_${_language}_COMPILER)
  1761. cotire_add_pch_inclusion_flags(
  1762. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${COTIRE_${_language}_COMPILER_VERSION}"
  1763. "${_prefixFile}" "${_pchFile}" _flags)
  1764. set_property (TARGET ${_target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  1765. endif()
  1766. endif()
  1767. endif()
  1768. endfunction()
  1769. function (cotire_setup_unity_generation_commands _language _targetSourceDir _target _targetScript _unityFiles _cmdsVar)
  1770. set (_dependencySources "")
  1771. cotire_get_unity_source_dependencies(${_language} ${_target} _dependencySources ${ARGN})
  1772. foreach (_unityFile ${_unityFiles})
  1773. file (RELATIVE_PATH _unityFileRelPath "${CMAKE_BINARY_DIR}" "${_unityFile}")
  1774. set_property (SOURCE "${_unityFile}" PROPERTY GENERATED TRUE)
  1775. # set up compiled unity source dependencies
  1776. # this ensures that missing source files are generated before the unity file is compiled
  1777. if (COTIRE_DEBUG AND _dependencySources)
  1778. message (STATUS "${_unityFile} OBJECT_DEPENDS ${_dependencySources}")
  1779. endif()
  1780. if (_dependencySources)
  1781. set_property (SOURCE "${_unityFile}" PROPERTY OBJECT_DEPENDS ${_dependencySources})
  1782. endif()
  1783. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  1784. # unity file compilation results in potentially huge object file, thus use /bigobj by default unter MSVC and Windows Intel
  1785. set_property (SOURCE "${_unityFile}" APPEND_STRING PROPERTY COMPILE_FLAGS "/bigobj")
  1786. endif()
  1787. cotire_set_cmd_to_prologue(_unityCmd)
  1788. list (APPEND _unityCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "unity" "${_targetScript}" "${_unityFile}")
  1789. if (COTIRE_DEBUG)
  1790. message (STATUS "add_custom_command: OUTPUT ${_unityFile} COMMAND ${_unityCmd} DEPENDS ${_targetScript}")
  1791. endif()
  1792. add_custom_command(
  1793. OUTPUT "${_unityFile}"
  1794. COMMAND ${_unityCmd}
  1795. DEPENDS "${_targetScript}"
  1796. COMMENT "Generating ${_language} unity source ${_unityFileRelPath}"
  1797. WORKING_DIRECTORY "${_targetSourceDir}" VERBATIM)
  1798. list (APPEND ${_cmdsVar} COMMAND ${_unityCmd})
  1799. endforeach()
  1800. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  1801. endfunction()
  1802. function (cotire_setup_prefix_generation_command _language _target _targetSourceDir _targetScript _prefixFile _unityFiles _cmdsVar)
  1803. set (_sourceFiles ${ARGN})
  1804. list (LENGTH _unityFiles _numberOfUnityFiles)
  1805. if (_numberOfUnityFiles GREATER 1)
  1806. # create a joint unity file from all unity file segments
  1807. cotire_make_untiy_source_file_paths(${_language} ${_target} 0 _unityFile ${_unityFiles})
  1808. cotire_setup_combine_command("${_targetSourceDir}" "${_targetScript}" "${_unityFile}" "${_unityFiles}" ${_cmdsVar})
  1809. else()
  1810. set (_unityFile "${_unityFiles}")
  1811. endif()
  1812. file (RELATIVE_PATH _prefixFileRelPath "${CMAKE_BINARY_DIR}" "${_prefixFile}")
  1813. set (_dependencySources "")
  1814. cotire_get_prefix_header_dependencies(${_language} ${_target} _dependencySources ${_sourceFiles})
  1815. cotire_set_cmd_to_prologue(_prefixCmd)
  1816. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "prefix" "${_targetScript}" "${_prefixFile}" "${_unityFile}")
  1817. set_property (SOURCE "${_prefixFile}" PROPERTY GENERATED TRUE)
  1818. if (COTIRE_DEBUG)
  1819. message (STATUS "add_custom_command: OUTPUT ${_prefixFile} COMMAND ${_prefixCmd} DEPENDS ${_targetScript} ${_unityFile} ${_dependencySources}")
  1820. endif()
  1821. add_custom_command(
  1822. OUTPUT "${_prefixFile}" "${_prefixFile}.log"
  1823. COMMAND ${_prefixCmd}
  1824. DEPENDS "${_targetScript}" "${_unityFile}" ${_dependencySources}
  1825. COMMENT "Generating ${_language} prefix header ${_prefixFileRelPath}"
  1826. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
  1827. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  1828. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  1829. endfunction()
  1830. function (cotire_setup_combine_command _sourceDir _targetScript _joinedFile _files _cmdsVar)
  1831. set (_filesPaths "")
  1832. foreach (_file ${_files})
  1833. if (IS_ABSOLUTE "${_file}")
  1834. set (_filePath "${_file}")
  1835. else()
  1836. get_filename_component(_filePath "${_sourceDir}/${_file}" ABSOLUTE)
  1837. endif()
  1838. file (RELATIVE_PATH _fileRelPath "${CMAKE_BINARY_DIR}" "${_filePath}")
  1839. if (NOT IS_ABSOLUTE "${_fileRelPath}" AND NOT "${_fileRelPath}" MATCHES "^\\.\\.")
  1840. list (APPEND _filesPaths "${_fileRelPath}")
  1841. else()
  1842. list (APPEND _filesPaths "${_filePath}")
  1843. endif()
  1844. endforeach()
  1845. cotire_set_cmd_to_prologue(_prefixCmd)
  1846. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "combine")
  1847. if (_targetScript)
  1848. list (APPEND _prefixCmd "${_targetScript}")
  1849. endif()
  1850. list (APPEND _prefixCmd "${_joinedFile}" ${_filesPaths})
  1851. if (COTIRE_DEBUG)
  1852. message (STATUS "add_custom_command: OUTPUT ${_joinedFile} COMMAND ${_prefixCmd} DEPENDS ${_files}")
  1853. endif()
  1854. set_property (SOURCE "${_joinedFile}" PROPERTY GENERATED TRUE)
  1855. file (RELATIVE_PATH _joinedFileRelPath "${CMAKE_BINARY_DIR}" "${_joinedFile}")
  1856. add_custom_command(
  1857. OUTPUT "${_joinedFile}"
  1858. COMMAND ${_prefixCmd}
  1859. DEPENDS ${_files}
  1860. COMMENT "Generating ${_joinedFileRelPath}"
  1861. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
  1862. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  1863. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  1864. endfunction()
  1865. function (cotire_init_cotire_target_properties _target)
  1866. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER SET)
  1867. if (NOT _isSet)
  1868. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER TRUE)
  1869. endif()
  1870. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD SET)
  1871. if (NOT _isSet)
  1872. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD TRUE)
  1873. endif()
  1874. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN SET)
  1875. if (NOT _isSet)
  1876. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN FALSE)
  1877. endif()
  1878. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH SET)
  1879. if (NOT _isSet)
  1880. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_SOURCE_DIR}")
  1881. cotire_check_is_path_relative_to("${CMAKE_BINARY_DIR}" _isRelative "${CMAKE_SOURCE_DIR}")
  1882. if (NOT _isRelative)
  1883. set_property(TARGET ${_target} APPEND PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_BINARY_DIR}")
  1884. endif()
  1885. endif()
  1886. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH SET)
  1887. if (NOT _isSet)
  1888. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH "")
  1889. endif()
  1890. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS SET)
  1891. if (NOT _isSet)
  1892. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS "")
  1893. endif()
  1894. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS SET)
  1895. if (NOT _isSet)
  1896. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS "")
  1897. endif()
  1898. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES SET)
  1899. if (NOT _isSet)
  1900. if (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  1901. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES}")
  1902. else()
  1903. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "")
  1904. endif()
  1905. endif()
  1906. endfunction()
  1907. function (cotire_make_target_message _target _languages _disableMsg _targetMsgVar)
  1908. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  1909. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  1910. string (REPLACE ";" " " _languagesStr "${_languages}")
  1911. string (REPLACE ";" ", " _excludedStr "${ARGN}")
  1912. set (_targetMsg "")
  1913. if (NOT _languages)
  1914. set (_targetMsg "Target ${_target} cannot be cotired.")
  1915. if (_disableMsg)
  1916. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  1917. endif()
  1918. elseif (NOT _targetUsePCH AND NOT _targetAddSCU)
  1919. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build and precompiled header.")
  1920. if (_disableMsg)
  1921. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  1922. endif()
  1923. elseif (NOT _targetUsePCH)
  1924. if (_allExcludedSourceFiles)
  1925. set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr} without precompiled header.")
  1926. else()
  1927. set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header.")
  1928. endif()
  1929. if (_disableMsg)
  1930. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  1931. endif()
  1932. elseif (NOT _targetAddSCU)
  1933. if (_allExcludedSourceFiles)
  1934. set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr} without unity build.")
  1935. else()
  1936. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build.")
  1937. endif()
  1938. else()
  1939. if (_allExcludedSourceFiles)
  1940. set (_targetMsg "${_languagesStr} target ${_target} cotired excluding files ${_excludedStr}.")
  1941. else()
  1942. set (_targetMsg "${_languagesStr} target ${_target} cotired.")
  1943. endif()
  1944. endif()
  1945. set (${_targetMsgVar} "${_targetMsg}" PARENT_SCOPE)
  1946. endfunction()
  1947. function (cotire_choose_target_languages _targetSourceDir _target _targetLanguagesVar)
  1948. set (_languages ${ARGN})
  1949. set (_allSourceFiles "")
  1950. set (_allExcludedSourceFiles "")
  1951. set (_allCotiredSourceFiles "")
  1952. set (_targetLanguages "")
  1953. get_target_property(_targetType ${_target} TYPE)
  1954. get_target_property(_targetSourceFiles ${_target} SOURCES)
  1955. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  1956. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  1957. set (_disableMsg "")
  1958. foreach (_language ${_languages})
  1959. get_target_property(_prefixHeader ${_target} COTIRE_${_language}_PREFIX_HEADER)
  1960. get_target_property(_unityBuildFile ${_target} COTIRE_${_language}_UNITY_SOURCE)
  1961. if (_prefixHeader OR _unityBuildFile)
  1962. message (WARNING "Target ${_target} has already been cotired.")
  1963. set (${_targetLanguagesVar} "" PARENT_SCOPE)
  1964. return()
  1965. endif()
  1966. if (_targetUsePCH AND "${_language}" STREQUAL "C" OR "${_language}" STREQUAL "CXX")
  1967. cotire_check_precompiled_header_support("${_language}" "${_targetSourceDir}" "${_target}" _disableMsg)
  1968. if (_disableMsg)
  1969. set (_targetUsePCH FALSE)
  1970. endif()
  1971. endif()
  1972. set (_sourceFiles "")
  1973. set (_excludedSources "")
  1974. set (_cotiredSources "")
  1975. cotire_filter_language_source_files(${_language} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  1976. if (_sourceFiles OR _excludedSources OR _cotiredSources)
  1977. list (APPEND _targetLanguages ${_language})
  1978. endif()
  1979. if (_sourceFiles)
  1980. list (APPEND _allSourceFiles ${_sourceFiles})
  1981. endif()
  1982. if (_excludedSources)
  1983. list (APPEND _allExcludedSourceFiles ${_excludedSources})
  1984. endif()
  1985. if (_cotiredSources)
  1986. list (APPEND _allCotiredSourceFiles ${_cotiredSources})
  1987. endif()
  1988. endforeach()
  1989. set (_targetMsgLevel STATUS)
  1990. if (NOT _targetLanguages)
  1991. string (REPLACE ";" " or " _languagesStr "${_languages}")
  1992. set (_disableMsg "No ${_languagesStr} source files.")
  1993. set (_targetUsePCH FALSE)
  1994. set (_targetAddSCU FALSE)
  1995. endif()
  1996. if (_targetUsePCH)
  1997. list (LENGTH _allSourceFiles _numberOfSources)
  1998. if (_numberOfSources LESS ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  1999. set (_disableMsg "Too few applicable sources.")
  2000. set (_targetUsePCH FALSE)
  2001. elseif (_allCotiredSourceFiles)
  2002. cotire_get_source_file_property_values(_cotireTargets COTIRE_TARGET ${_allCotiredSourceFiles})
  2003. list (REMOVE_DUPLICATES _cotireTargets)
  2004. string (REPLACE ";" ", " _cotireTargetsStr "${_cotireTargets}")
  2005. set (_disableMsg "Target sources already include a precompiled header for target(s) ${_cotireTargets}.")
  2006. set (_disableMsg "${_disableMsg} Set target property COTIRE_ENABLE_PRECOMPILED_HEADER to FALSE for targets ${_target},")
  2007. set (_disableMsg "${_disableMsg} ${_cotireTargetsStr} to get a workable build system.")
  2008. set (_targetMsgLevel SEND_ERROR)
  2009. set (_targetUsePCH FALSE)
  2010. elseif (XCODE AND _allExcludedSourceFiles)
  2011. # for Xcode, we cannot apply the precompiled header to individual sources, only to the whole target
  2012. set (_disableMsg "Exclusion of source files not supported for generator Xcode.")
  2013. set (_targetUsePCH FALSE)
  2014. elseif (XCODE AND "${_targetType}" STREQUAL "OBJECT_LIBRARY")
  2015. # for Xcode, we cannot apply the required PRE_BUILD action to generate the prefix header to an OBJECT_LIBRARY target
  2016. set (_disableMsg "Required PRE_BUILD action not supported for OBJECT_LIBRARY targets for generator Xcode.")
  2017. set (_targetUsePCH FALSE)
  2018. endif()
  2019. endif()
  2020. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER ${_targetUsePCH})
  2021. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD ${_targetAddSCU})
  2022. cotire_make_target_message(${_target} "${_targetLanguages}" "${_disableMsg}" _targetMsg ${_allExcludedSourceFiles})
  2023. if (_targetMsg)
  2024. if (NOT DEFINED COTIREMSG_${_target})
  2025. set (COTIREMSG_${_target} "")
  2026. endif()
  2027. if (COTIRE_VERBOSE OR NOT "${_targetMsgLevel}" STREQUAL "STATUS" OR
  2028. NOT "${COTIREMSG_${_target}}" STREQUAL "${_targetMsg}")
  2029. # cache message to avoid redundant messages on re-configure
  2030. set (COTIREMSG_${_target} "${_targetMsg}" CACHE INTERNAL "${_target} cotire message.")
  2031. message (${_targetMsgLevel} "${_targetMsg}")
  2032. endif()
  2033. endif()
  2034. set (${_targetLanguagesVar} ${_targetLanguages} PARENT_SCOPE)
  2035. endfunction()
  2036. function (cotire_process_target_language _language _configurations _targetSourceDir _targetBinaryDir _target _wholeTargetVar _cmdsVar)
  2037. set (${_cmdsVar} "" PARENT_SCOPE)
  2038. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2039. set (_sourceFiles "")
  2040. set (_excludedSources "")
  2041. set (_cotiredSources "")
  2042. cotire_filter_language_source_files(${_language} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2043. if (NOT _sourceFiles)
  2044. return()
  2045. endif()
  2046. set (_wholeTarget ${${_wholeTargetVar}})
  2047. set (_cmds "")
  2048. # check for user provided unity source file list
  2049. get_property(_unitySourceFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE_INIT)
  2050. if (NOT _unitySourceFiles)
  2051. set (_unitySourceFiles ${_sourceFiles} ${_cotiredSources})
  2052. endif()
  2053. cotire_generate_target_script(
  2054. ${_language} "${_configurations}" "${_targetSourceDir}" "${_targetBinaryDir}" ${_target} _targetScript ${_unitySourceFiles})
  2055. get_target_property(_maxIncludes ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  2056. if (NOT _maxIncludes)
  2057. set (_maxIncludes 0)
  2058. endif()
  2059. cotire_make_untiy_source_file_paths(${_language} ${_target} ${_maxIncludes} _unityFiles ${_unitySourceFiles})
  2060. if (NOT _unityFiles)
  2061. return()
  2062. endif()
  2063. cotire_setup_unity_generation_commands(
  2064. ${_language} "${_targetSourceDir}" ${_target} "${_targetScript}" "${_unityFiles}" _cmds ${_unitySourceFiles})
  2065. cotire_make_prefix_file_path(${_language} ${_target} _prefixFile)
  2066. if (_prefixFile)
  2067. # check for user provided prefix header files
  2068. get_property(_prefixHeaderFiles TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
  2069. if (_prefixHeaderFiles)
  2070. cotire_setup_combine_command("${_targetSourceDir}" "${_targetScript}" "${_prefixFile}" "${_prefixHeaderFiles}" _cmds)
  2071. else()
  2072. cotire_setup_prefix_generation_command(
  2073. ${_language} ${_target} "${_targetSourceDir}" "${_targetScript}" "${_prefixFile}" "${_unityFiles}" _cmds ${_unitySourceFiles})
  2074. endif()
  2075. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2076. if (_targetUsePCH)
  2077. cotire_make_pch_file_path(${_language} "${_targetSourceDir}" ${_target} _pchFile)
  2078. if (_pchFile)
  2079. cotire_setup_pch_file_compilation(
  2080. ${_language} "${_targetBinaryDir}" "${_targetScript}" "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2081. if (_excludedSources)
  2082. set (_wholeTarget FALSE)
  2083. endif()
  2084. cotire_setup_prefix_file_inclusion(
  2085. ${_language} ${_target} ${_wholeTarget} "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2086. endif()
  2087. endif()
  2088. endif()
  2089. # mark target as cotired for language
  2090. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE "${_unityFiles}")
  2091. if (_prefixFile)
  2092. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER "${_prefixFile}")
  2093. if (_targetUsePCH AND _pchFile)
  2094. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER "${_pchFile}")
  2095. endif()
  2096. endif()
  2097. set (${_wholeTargetVar} ${_wholeTarget} PARENT_SCOPE)
  2098. set (${_cmdsVar} ${_cmds} PARENT_SCOPE)
  2099. endfunction()
  2100. function (cotire_setup_clean_target _target)
  2101. set (_cleanTargetName "${_target}${COTIRE_CLEAN_TARGET_SUFFIX}")
  2102. if (NOT TARGET "${_cleanTargetName}")
  2103. cotire_set_cmd_to_prologue(_cmds)
  2104. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" ABSOLUTE)
  2105. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${_outputDir}" "${COTIRE_INTDIR}" "${_target}")
  2106. add_custom_target(${_cleanTargetName} COMMAND ${_cmds} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  2107. COMMENT "Cleaning up target ${_target} cotire generated files" VERBATIM)
  2108. cotire_init_target("${_cleanTargetName}")
  2109. endif()
  2110. endfunction()
  2111. function (cotire_setup_pch_target _languages _configurations _target)
  2112. if ("${CMAKE_GENERATOR}" MATCHES "Makefiles|Ninja")
  2113. # for makefile based generators, we add a custom target to trigger the generation of the cotire related files
  2114. set (_dependsFiles "")
  2115. foreach (_language ${_languages})
  2116. set (_props COTIRE_${_language}_PREFIX_HEADER COTIRE_${_language}_UNITY_SOURCE)
  2117. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2118. # Visual Studio and Intel only create precompiled header as a side effect
  2119. list (INSERT _props 0 COTIRE_${_language}_PRECOMPILED_HEADER)
  2120. endif()
  2121. cotire_get_first_set_property_value(_dependsFile TARGET ${_target} ${_props})
  2122. if (_dependsFile)
  2123. list (APPEND _dependsFiles "${_dependsFile}")
  2124. endif()
  2125. endforeach()
  2126. if (_dependsFiles)
  2127. set (_pchTargetName "${_target}${COTIRE_PCH_TARGET_SUFFIX}")
  2128. add_custom_target("${_pchTargetName}" DEPENDS ${_dependsFiles})
  2129. cotire_init_target("${_pchTargetName}")
  2130. cotire_add_to_pch_all_target(${_pchTargetName})
  2131. endif()
  2132. else()
  2133. # for other generators, we add the "clean all" target to clean up the precompiled header
  2134. cotire_setup_clean_all_target()
  2135. endif()
  2136. endfunction()
  2137. function (cotire_setup_unity_build_target _languages _configurations _targetSourceDir _target)
  2138. get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME)
  2139. if (NOT _unityTargetName)
  2140. set (_unityTargetName "${_target}${COTIRE_UNITY_BUILD_TARGET_SUFFIX}")
  2141. endif()
  2142. # determine unity target sub type
  2143. get_target_property(_targetType ${_target} TYPE)
  2144. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2145. get_target_property(_isWin32 ${_target} WIN32_EXECUTABLE)
  2146. get_target_property(_isMacOSX_Bundle ${_target} MACOSX_BUNDLE)
  2147. if (_isWin32)
  2148. set (_unityTargetSubType WIN32)
  2149. elseif (_isMacOSX_Bundle)
  2150. set (_unityTargetSubType MACOSX_BUNDLE)
  2151. else()
  2152. set (_unityTargetSubType "")
  2153. endif()
  2154. elseif (_targetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  2155. set (_unityTargetSubType "${CMAKE_MATCH_1}")
  2156. else()
  2157. message (WARNING "Unknown target type ${_targetType}.")
  2158. return()
  2159. endif()
  2160. # determine unity target sources
  2161. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2162. set (_unityTargetSources ${_targetSourceFiles})
  2163. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2164. foreach (_language ${_languages})
  2165. get_property(_unityFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE)
  2166. if (_unityFiles)
  2167. # remove source files that are included in the unity source
  2168. set (_sourceFiles "")
  2169. set (_excludedSources "")
  2170. set (_cotiredSources "")
  2171. cotire_filter_language_source_files(${_language} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2172. if (_sourceFiles OR _cotiredSources)
  2173. list (REMOVE_ITEM _unityTargetSources ${_sourceFiles} ${_cotiredSources})
  2174. endif()
  2175. # if cotire is applied to a target which has not been added in the current source dir,
  2176. # non-existing files cannot be referenced from the unity build target (this is a CMake restriction)
  2177. if (NOT "${_targetSourceDir}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  2178. set (_nonExistingFiles "")
  2179. foreach (_file ${_unityTargetSources})
  2180. if (NOT EXISTS "${_file}")
  2181. list (APPEND _nonExistingFiles "${_file}")
  2182. endif()
  2183. endforeach()
  2184. if (_nonExistingFiles)
  2185. if (COTIRE_VERBOSE)
  2186. message (STATUS "removing non-existing ${_nonExistingFiles} from ${_unityTargetName}")
  2187. endif()
  2188. list (REMOVE_ITEM _unityTargetSources ${_nonExistingFiles})
  2189. endif()
  2190. endif()
  2191. # add unity source files instead
  2192. list (APPEND _unityTargetSources ${_unityFiles})
  2193. # make unity files use precompiled header if there are multiple unity files
  2194. list (LENGTH _unityFiles _numberOfUnityFiles)
  2195. if (_targetUsePCH AND _numberOfUnityFiles GREATER ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  2196. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2197. get_property(_pchFile TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER)
  2198. if (_prefixFile AND _pchFile)
  2199. cotire_setup_pch_file_compilation(
  2200. ${_language} "${_targetBinaryDir}" "" "${_prefixFile}" "${_pchFile}" ${_unityFiles})
  2201. cotire_setup_prefix_file_inclusion(
  2202. ${_language} ${_target} FALSE "${_prefixFile}" "${_pchFile}" ${_unityFiles})
  2203. # add the prefix header to unity target sources
  2204. list (APPEND _unityTargetSources "${_prefixFile}")
  2205. endif()
  2206. endif()
  2207. endif()
  2208. endforeach()
  2209. if (COTIRE_DEBUG)
  2210. message (STATUS "add ${_targetType} ${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources}")
  2211. endif()
  2212. # generate unity target
  2213. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2214. add_executable(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2215. else()
  2216. add_library(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2217. endif()
  2218. set (_outputDirProperties
  2219. ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>
  2220. LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_<CONFIG>
  2221. RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_<CONFIG>)
  2222. # copy output location properties
  2223. if (COTIRE_UNITY_OUTPUT_DIRECTORY)
  2224. set (_setDefaultOutputDir TRUE)
  2225. if (IS_ABSOLUTE "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2226. set (_outputDir "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2227. else()
  2228. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties})
  2229. cotrie_resolve_config_properites("${_configurations}" _properties ${_outputDirProperties})
  2230. foreach (_property ${_properties})
  2231. get_property(_outputDir TARGET ${_target} PROPERTY ${_property})
  2232. if (_outputDir)
  2233. get_filename_component(_outputDir "${_outputDir}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2234. set_property(TARGET ${_target} PROPERTY ${_property} "${_outputDir}")
  2235. set (_setDefaultOutputDir FALSE)
  2236. endif()
  2237. endforeach()
  2238. if (_setDefaultOutputDir)
  2239. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2240. endif()
  2241. endif()
  2242. if (_setDefaultOutputDir)
  2243. set_target_properties(${_unityTargetName} PROPERTIES
  2244. ARCHIVE_OUTPUT_DIRECTORY "${_outputDir}"
  2245. LIBRARY_OUTPUT_DIRECTORY "${_outputDir}"
  2246. RUNTIME_OUTPUT_DIRECTORY "${_outputDir}")
  2247. endif()
  2248. else()
  2249. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties})
  2250. endif()
  2251. # copy output name
  2252. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2253. ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_<CONFIG>
  2254. LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_<CONFIG>
  2255. OUTPUT_NAME OUTPUT_NAME_<CONFIG>
  2256. RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_<CONFIG>
  2257. PREFIX <CONFIG>_POSTFIX SUFFIX)
  2258. # copy compile stuff
  2259. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2260. COMPILE_DEFINITIONS COMPILE_DEFINITIONS_<CONFIG>
  2261. COMPILE_FLAGS Fortran_FORMAT
  2262. INCLUDE_DIRECTORIES
  2263. INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
  2264. POSITION_INDEPENDENT_CODE)
  2265. # copy link stuff
  2266. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2267. BUILD_WITH_INSTALL_RPATH INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH SKIP_BUILD_RPATH
  2268. LINKER_LANGUAGE LINK_DEPENDS
  2269. LINK_FLAGS LINK_FLAGS_<CONFIG>
  2270. LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_<CONFIG>
  2271. LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_<CONFIG>
  2272. LINK_SEARCH_START_STATIC LINK_SEARCH_END_STATIC
  2273. STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_<CONFIG>
  2274. NO_SONAME SOVERSION VERSION)
  2275. # copy Qt stuff
  2276. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2277. AUTOMOC AUTOMOC_MOC_OPTIONS)
  2278. # copy cmake stuff
  2279. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2280. IMPLICIT_DEPENDS_INCLUDE_TRANSFORM RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK)
  2281. # copy platform stuff
  2282. if (APPLE)
  2283. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2284. BUNDLE BUNDLE_EXTENSION FRAMEWORK INSTALL_NAME_DIR MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST
  2285. OSX_ARCHITECTURES OSX_ARCHITECTURES_<CONFIG> PRIVATE_HEADER PUBLIC_HEADER RESOURCE)
  2286. elseif (WIN32)
  2287. cotrie_copy_set_properites("${_configurations}" TARGET ${_target} ${_unityTargetName}
  2288. GNUtoMS
  2289. PDB_NAME PDB_NAME_<CONFIG> PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_<CONFIG>
  2290. VS_DOTNET_REFERENCES VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_KEYWORD
  2291. VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER
  2292. VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES)
  2293. endif()
  2294. # use output name from original target
  2295. get_target_property(_targetOutputName ${_unityTargetName} OUTPUT_NAME)
  2296. if (NOT _targetOutputName)
  2297. set_property(TARGET ${_unityTargetName} PROPERTY OUTPUT_NAME "${_target}")
  2298. endif()
  2299. # use export symbol from original target
  2300. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  2301. if (_defineSymbol)
  2302. set_property(TARGET ${_unityTargetName} PROPERTY DEFINE_SYMBOL "${_defineSymbol}")
  2303. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2304. set_property(TARGET ${_unityTargetName} PROPERTY ENABLE_EXPORTS TRUE)
  2305. endif()
  2306. endif()
  2307. cotire_init_target(${_unityTargetName})
  2308. cotire_add_to_unity_all_target(${_unityTargetName})
  2309. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_TARGET_NAME "${_unityTargetName}")
  2310. endfunction(cotire_setup_unity_build_target)
  2311. function (cotire_target _target)
  2312. set(_options "")
  2313. set(_oneValueArgs SOURCE_DIR BINARY_DIR)
  2314. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  2315. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  2316. if (NOT _option_SOURCE_DIR)
  2317. set (_option_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  2318. endif()
  2319. if (NOT _option_BINARY_DIR)
  2320. set (_option_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  2321. endif()
  2322. if (NOT _option_LANGUAGES)
  2323. get_property (_option_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
  2324. endif()
  2325. if (NOT _option_CONFIGURATIONS)
  2326. if (CMAKE_CONFIGURATION_TYPES)
  2327. set (_option_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
  2328. elseif (CMAKE_BUILD_TYPE)
  2329. set (_option_CONFIGURATIONS "${CMAKE_BUILD_TYPE}")
  2330. else()
  2331. set (_option_CONFIGURATIONS "None")
  2332. endif()
  2333. endif()
  2334. # trivial checks
  2335. get_target_property(_imported ${_target} IMPORTED)
  2336. if (_imported)
  2337. message (WARNING "Imported target ${_target} cannot be cotired.")
  2338. return()
  2339. endif()
  2340. # check if target needs to be cotired for build type
  2341. # when using configuration types, the test is performed at build time
  2342. cotire_init_cotire_target_properties(${_target})
  2343. if (NOT CMAKE_CONFIGURATION_TYPES)
  2344. if (CMAKE_BUILD_TYPE)
  2345. list (FIND _option_CONFIGURATIONS "${CMAKE_BUILD_TYPE}" _index)
  2346. else()
  2347. list (FIND _option_CONFIGURATIONS "None" _index)
  2348. endif()
  2349. if (_index EQUAL -1)
  2350. if (COTIRE_DEBUG)
  2351. message (STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} not cotired (${_option_CONFIGURATIONS})")
  2352. endif()
  2353. return()
  2354. endif()
  2355. endif()
  2356. # choose languages that apply to the target
  2357. cotire_choose_target_languages("${_option_SOURCE_DIR}" "${_target}" _targetLanguages ${_option_LANGUAGES})
  2358. if (NOT _targetLanguages)
  2359. return()
  2360. endif()
  2361. list (LENGTH _targetLanguages _numberOfLanguages)
  2362. if (_numberOfLanguages GREATER 1)
  2363. set (_wholeTarget FALSE)
  2364. else()
  2365. set (_wholeTarget TRUE)
  2366. endif()
  2367. set (_cmds "")
  2368. foreach (_language ${_targetLanguages})
  2369. cotire_process_target_language("${_language}" "${_option_CONFIGURATIONS}"
  2370. "${_option_SOURCE_DIR}" "${_option_BINARY_DIR}" ${_target} _wholeTarget _cmd)
  2371. if (_cmd)
  2372. list (APPEND _cmds ${_cmd})
  2373. endif()
  2374. endforeach()
  2375. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  2376. if (_targetAddSCU)
  2377. cotire_setup_unity_build_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" "${_option_SOURCE_DIR}" ${_target})
  2378. endif()
  2379. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2380. if (_targetUsePCH)
  2381. cotire_setup_target_pch_usage("${_targetLanguages}" "${_option_SOURCE_DIR}" ${_target} ${_wholeTarget} ${_cmds})
  2382. cotire_setup_pch_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" ${_target})
  2383. endif()
  2384. get_target_property(_targetAddCleanTarget ${_target} COTIRE_ADD_CLEAN)
  2385. if (_targetAddCleanTarget)
  2386. cotire_setup_clean_target(${_target})
  2387. endif()
  2388. endfunction()
  2389. function (cotire_cleanup _binaryDir _cotireIntermediateDirName _targetName)
  2390. if (_targetName)
  2391. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/${_targetName}*.*")
  2392. else()
  2393. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/*.*")
  2394. endif()
  2395. # filter files in intermediate directory
  2396. set (_filesToRemove "")
  2397. foreach (_file ${_cotireFiles})
  2398. get_filename_component(_dir "${_file}" PATH)
  2399. get_filename_component(_dirName "${_dir}" NAME)
  2400. if ("${_dirName}" STREQUAL "${_cotireIntermediateDirName}")
  2401. list (APPEND _filesToRemove "${_file}")
  2402. endif()
  2403. endforeach()
  2404. if (_filesToRemove)
  2405. if (COTIRE_VERBOSE)
  2406. message (STATUS "removing ${_filesToRemove}")
  2407. endif()
  2408. file (REMOVE ${_filesToRemove})
  2409. endif()
  2410. endfunction()
  2411. function (cotire_init_target _targetName)
  2412. if (COTIRE_TARGETS_FOLDER)
  2413. set_target_properties(${_targetName} PROPERTIES FOLDER "${COTIRE_TARGETS_FOLDER}")
  2414. endif()
  2415. if (MSVC_IDE)
  2416. set_target_properties(${_targetName} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
  2417. endif()
  2418. endfunction()
  2419. function (cotire_add_to_pch_all_target _pchTargetName)
  2420. set (_targetName "${COTIRE_PCH_ALL_TARGET_NAME}")
  2421. if (NOT TARGET "${_targetName}")
  2422. add_custom_target("${_targetName}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
  2423. cotire_init_target("${_targetName}")
  2424. endif()
  2425. cotire_setup_clean_all_target()
  2426. add_dependencies(${_targetName} ${_pchTargetName})
  2427. endfunction()
  2428. function (cotire_add_to_unity_all_target _unityTargetName)
  2429. set (_targetName "${COTIRE_UNITY_BUILD_ALL_TARGET_NAME}")
  2430. if (NOT TARGET "${_targetName}")
  2431. add_custom_target("${_targetName}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" VERBATIM)
  2432. cotire_init_target("${_targetName}")
  2433. endif()
  2434. cotire_setup_clean_all_target()
  2435. add_dependencies(${_targetName} ${_unityTargetName})
  2436. endfunction()
  2437. function (cotire_setup_clean_all_target)
  2438. set (_targetName "${COTIRE_CLEAN_ALL_TARGET_NAME}")
  2439. if (NOT TARGET "${_targetName}")
  2440. cotire_set_cmd_to_prologue(_cmds)
  2441. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${CMAKE_BINARY_DIR}" "${COTIRE_INTDIR}")
  2442. add_custom_target(${_targetName} COMMAND ${_cmds}
  2443. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMENT "Cleaning up all cotire generated files" VERBATIM)
  2444. cotire_init_target("${_targetName}")
  2445. endif()
  2446. endfunction()
  2447. function (cotire)
  2448. set(_options "")
  2449. set(_oneValueArgs SOURCE_DIR BINARY_DIR)
  2450. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  2451. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  2452. set (_targets ${_option_UNPARSED_ARGUMENTS})
  2453. if (NOT _option_SOURCE_DIR)
  2454. set (_option_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  2455. endif()
  2456. if (NOT _option_BINARY_DIR)
  2457. set (_option_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  2458. endif()
  2459. foreach (_target ${_targets})
  2460. if (TARGET ${_target})
  2461. cotire_target(${_target} LANGUAGES ${_option_LANGUAGES} CONFIGURATIONS ${_option_CONFIGURATIONS}
  2462. SOURCE_DIR "${_option_SOURCE_DIR}" BINARY_DIR "${_option_BINARY_DIR}")
  2463. else()
  2464. message (WARNING "${_target} is not a target")
  2465. endif()
  2466. endforeach()
  2467. endfunction()
  2468. if (CMAKE_SCRIPT_MODE_FILE)
  2469. # cotire is being run in script mode
  2470. # locate -P on command args
  2471. set (COTIRE_ARGC -1)
  2472. foreach (_index RANGE ${CMAKE_ARGC})
  2473. if (COTIRE_ARGC GREATER -1)
  2474. set (COTIRE_ARGV${COTIRE_ARGC} "${CMAKE_ARGV${_index}}")
  2475. math (EXPR COTIRE_ARGC "${COTIRE_ARGC} + 1")
  2476. elseif ("${CMAKE_ARGV${_index}}" STREQUAL "-P")
  2477. set (COTIRE_ARGC 0)
  2478. endif()
  2479. endforeach()
  2480. # include target script if available
  2481. if ("${COTIRE_ARGV2}" MATCHES "\\.cmake$")
  2482. include("${COTIRE_ARGV2}")
  2483. endif()
  2484. if (COTIRE_DEBUG)
  2485. message (STATUS "${COTIRE_ARGV0} ${COTIRE_ARGV1} ${COTIRE_ARGV2} ${COTIRE_ARGV3} ${COTIRE_ARGV4} ${COTIRE_ARGV5}")
  2486. endif()
  2487. if (WIN32)
  2488. # for MSVC, compiler IDs may not always be set correctly
  2489. if (MSVC)
  2490. set (CMAKE_C_COMPILER_ID "MSVC")
  2491. set (CMAKE_CXX_COMPILER_ID "MSVC")
  2492. endif()
  2493. endif()
  2494. if (NOT COTIRE_BUILD_TYPE)
  2495. set (COTIRE_BUILD_TYPE "None")
  2496. endif()
  2497. string (TOUPPER "${COTIRE_BUILD_TYPE}" _upperConfig)
  2498. set (_includeDirs ${COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig}})
  2499. set (_compileDefinitions ${COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig}})
  2500. set (_compileFlags ${COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig}})
  2501. # check if target has been cotired for actual build type COTIRE_BUILD_TYPE
  2502. list (FIND COTIRE_TARGET_CONFIGURATION_TYPES "${COTIRE_BUILD_TYPE}" _index)
  2503. if (_index GREATER -1)
  2504. set (_sources ${COTIRE_TARGET_SOURCES})
  2505. set (_sourcesDefinitions ${COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig}})
  2506. else()
  2507. if (COTIRE_DEBUG)
  2508. message (STATUS "COTIRE_BUILD_TYPE=${COTIRE_BUILD_TYPE} not cotired (${COTIRE_TARGET_CONFIGURATION_TYPES})")
  2509. endif()
  2510. set (_sources "")
  2511. set (_sourcesDefinitions "")
  2512. endif()
  2513. set (_targetPreUndefs ${COTIRE_TARGET_PRE_UNDEFS})
  2514. set (_targetPostUndefs ${COTIRE_TARGET_POST_UNDEFS})
  2515. set (_sourcesPreUndefs ${COTIRE_TARGET_SOURCES_PRE_UNDEFS})
  2516. set (_sourcesPostUndefs ${COTIRE_TARGET_SOURCES_POST_UNDEFS})
  2517. if ("${COTIRE_ARGV1}" STREQUAL "unity")
  2518. cotire_select_unity_source_files("${COTIRE_ARGV3}" _sources ${_sources})
  2519. cotire_generate_unity_source(
  2520. "${COTIRE_ARGV3}" ${_sources}
  2521. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  2522. DEPENDS "${COTIRE_ARGV0}" "${COTIRE_ARGV2}"
  2523. SOURCES_COMPILE_DEFINITIONS ${_sourcesDefinitions}
  2524. PRE_UNDEFS ${_targetPreUndefs}
  2525. POST_UNDEFS ${_targetPostUndefs}
  2526. SOURCES_PRE_UNDEFS ${_sourcesPreUndefs}
  2527. SOURCES_POST_UNDEFS ${_sourcesPostUndefs})
  2528. elseif ("${COTIRE_ARGV1}" STREQUAL "prefix")
  2529. set (_files "")
  2530. foreach (_index RANGE 4 ${COTIRE_ARGC})
  2531. if (COTIRE_ARGV${_index})
  2532. list (APPEND _files "${COTIRE_ARGV${_index}}")
  2533. endif()
  2534. endforeach()
  2535. cotire_generate_prefix_header(
  2536. "${COTIRE_ARGV3}" ${_files}
  2537. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  2538. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  2539. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  2540. COMPILER_VERSION "${COTIRE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  2541. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  2542. DEPENDS "${COTIRE_ARGV0}" "${COTIRE_ARGV4}" ${COTIRE_TARGET_PREFIX_DEPENDS}
  2543. IGNORE_PATH "${COTIRE_TARGET_IGNORE_PATH};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH}"
  2544. INCLUDE_PATH ${COTIRE_TARGET_INCLUDE_PATH}
  2545. IGNORE_EXTENSIONS "${CMAKE_${COTIRE_TARGET_LANGUAGE}_SOURCE_FILE_EXTENSIONS};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS}"
  2546. INCLUDE_DIRECTORIES ${_includeDirs}
  2547. COMPILE_DEFINITIONS ${_compileDefinitions}
  2548. COMPILE_FLAGS ${_compileFlags})
  2549. elseif ("${COTIRE_ARGV1}" STREQUAL "precompile")
  2550. set (_files "")
  2551. foreach (_index RANGE 5 ${COTIRE_ARGC})
  2552. if (COTIRE_ARGV${_index})
  2553. list (APPEND _files "${COTIRE_ARGV${_index}}")
  2554. endif()
  2555. endforeach()
  2556. cotire_precompile_prefix_header(
  2557. "${COTIRE_ARGV3}" "${COTIRE_ARGV4}" "${COTIRE_ARGV5}"
  2558. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  2559. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  2560. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  2561. COMPILER_VERSION "${COTIRE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  2562. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  2563. INCLUDE_DIRECTORIES ${_includeDirs}
  2564. COMPILE_DEFINITIONS ${_compileDefinitions}
  2565. COMPILE_FLAGS ${_compileFlags})
  2566. elseif ("${COTIRE_ARGV1}" STREQUAL "combine")
  2567. if (COTIRE_TARGET_LANGUAGE)
  2568. set (_startIndex 3)
  2569. else()
  2570. set (_startIndex 2)
  2571. endif()
  2572. set (_files "")
  2573. foreach (_index RANGE ${_startIndex} ${COTIRE_ARGC})
  2574. if (COTIRE_ARGV${_index})
  2575. list (APPEND _files "${COTIRE_ARGV${_index}}")
  2576. endif()
  2577. endforeach()
  2578. if (COTIRE_TARGET_LANGUAGE)
  2579. cotire_generate_unity_source(${_files} LANGUAGE "${COTIRE_TARGET_LANGUAGE}")
  2580. else()
  2581. cotire_generate_unity_source(${_files})
  2582. endif()
  2583. elseif ("${COTIRE_ARGV1}" STREQUAL "cleanup")
  2584. cotire_cleanup("${COTIRE_ARGV2}" "${COTIRE_ARGV3}" "${COTIRE_ARGV4}")
  2585. else()
  2586. message (FATAL_ERROR "Unknown cotire command \"${COTIRE_ARGV1}\".")
  2587. endif()
  2588. else()
  2589. # cotire is being run in include mode
  2590. # set up all variable and property definitions
  2591. unset (COTIRE_C_COMPILER_VERSION CACHE)
  2592. unset (COTIRE_CXX_COMPILER_VERSION CACHE)
  2593. if (NOT DEFINED COTIRE_DEBUG_INIT)
  2594. if (DEFINED COTIRE_DEBUG)
  2595. set (COTIRE_DEBUG_INIT ${COTIRE_DEBUG})
  2596. else()
  2597. set (COTIRE_DEBUG_INIT FALSE)
  2598. endif()
  2599. endif()
  2600. option (COTIRE_DEBUG "Enable cotire debugging output?" ${COTIRE_DEBUG_INIT})
  2601. if (NOT DEFINED COTIRE_VERBOSE_INIT)
  2602. if (DEFINED COTIRE_VERBOSE)
  2603. set (COTIRE_VERBOSE_INIT ${COTIRE_VERBOSE})
  2604. else()
  2605. set (COTIRE_VERBOSE_INIT FALSE)
  2606. endif()
  2607. endif()
  2608. option (COTIRE_VERBOSE "Enable cotire verbose output?" ${COTIRE_VERBOSE_INIT})
  2609. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS "inc;inl;ipp" CACHE STRING
  2610. "Ignore headers with the listed file extensions from the generated prefix header.")
  2611. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH "" CACHE STRING
  2612. "Ignore headers from these directories when generating the prefix header.")
  2613. set (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS "m;mm" CACHE STRING
  2614. "Ignore sources with the listed file extensions from the generated unity source.")
  2615. set (COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES "3" CACHE STRING
  2616. "Minimum number of sources in target required to enable use of precompiled header.")
  2617. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES "" CACHE STRING
  2618. "Maximum number of source files to include in a single unity source file.")
  2619. if (NOT COTIRE_PREFIX_HEADER_FILENAME_SUFFIX)
  2620. set (COTIRE_PREFIX_HEADER_FILENAME_SUFFIX "_prefix")
  2621. endif()
  2622. if (NOT COTIRE_UNITY_SOURCE_FILENAME_SUFFIX)
  2623. set (COTIRE_UNITY_SOURCE_FILENAME_SUFFIX "_unity")
  2624. endif()
  2625. if (NOT COTIRE_INTDIR)
  2626. set (COTIRE_INTDIR "cotire")
  2627. endif()
  2628. if (NOT COTIRE_PCH_ALL_TARGET_NAME)
  2629. set (COTIRE_PCH_ALL_TARGET_NAME "all_pch")
  2630. endif()
  2631. if (NOT COTIRE_UNITY_BUILD_ALL_TARGET_NAME)
  2632. set (COTIRE_UNITY_BUILD_ALL_TARGET_NAME "all_unity")
  2633. endif()
  2634. if (NOT COTIRE_CLEAN_ALL_TARGET_NAME)
  2635. set (COTIRE_CLEAN_ALL_TARGET_NAME "clean_cotire")
  2636. endif()
  2637. if (NOT COTIRE_CLEAN_TARGET_SUFFIX)
  2638. set (COTIRE_CLEAN_TARGET_SUFFIX "_clean_cotire")
  2639. endif()
  2640. if (NOT COTIRE_PCH_TARGET_SUFFIX)
  2641. set (COTIRE_PCH_TARGET_SUFFIX "_pch")
  2642. endif()
  2643. if (NOT COTIRE_UNITY_BUILD_TARGET_SUFFIX)
  2644. set (COTIRE_UNITY_BUILD_TARGET_SUFFIX "_unity")
  2645. endif()
  2646. if (NOT DEFINED COTIRE_TARGETS_FOLDER)
  2647. set (COTIRE_TARGETS_FOLDER "cotire")
  2648. endif()
  2649. if (NOT DEFINED COTIRE_UNITY_OUTPUT_DIRECTORY)
  2650. if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
  2651. # generated Ninja build files do not work if the unity target produces the same output file as the cotired target
  2652. set (COTIRE_UNITY_OUTPUT_DIRECTORY "unity")
  2653. else()
  2654. set (COTIRE_UNITY_OUTPUT_DIRECTORY "")
  2655. endif()
  2656. endif()
  2657. # define cotire cache variables
  2658. define_property(
  2659. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH"
  2660. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  2661. FULL_DOCS
  2662. "The variable can be set to a semicolon separated list of include directories."
  2663. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  2664. "If not defined, defaults to empty list."
  2665. )
  2666. define_property(
  2667. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS"
  2668. BRIEF_DOCS "Ignore includes with the listed file extensions from the generated prefix header."
  2669. FULL_DOCS
  2670. "The variable can be set to a semicolon separated list of file extensions."
  2671. "If a header file extension matches one in the list, it will be excluded from the generated prefix header."
  2672. "Includes with an extension in CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS are always ignored."
  2673. "If not defined, defaults to inc;inl;ipp."
  2674. )
  2675. define_property(
  2676. CACHED_VARIABLE PROPERTY "COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS"
  2677. BRIEF_DOCS "Exclude sources with the listed file extensions from the generated unity source."
  2678. FULL_DOCS
  2679. "The variable can be set to a semicolon separated list of file extensions."
  2680. "If a source file extension matches one in the list, it will be excluded from the generated unity source file."
  2681. "Source files with an extension in CMAKE_<LANG>_IGNORE_EXTENSIONS are always excluded."
  2682. "If not defined, defaults to m;mm."
  2683. )
  2684. define_property(
  2685. CACHED_VARIABLE PROPERTY "COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES"
  2686. BRIEF_DOCS "Minimum number of sources in target required to enable use of precompiled header."
  2687. FULL_DOCS
  2688. "The variable can be set to an integer > 0."
  2689. "If a target contains less than that number of source files, cotire will not enable the use of the precompiled header for the target."
  2690. "If not defined, defaults to 3."
  2691. )
  2692. define_property(
  2693. CACHED_VARIABLE PROPERTY "COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES"
  2694. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  2695. FULL_DOCS
  2696. "This may be set to an integer > 0."
  2697. "If a target contains more than that number of source files, cotire will create multiple unity source files for it."
  2698. "If not set, cotire will only create a single unity source file."
  2699. "Is use to initialize the target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  2700. "Defaults to empty."
  2701. )
  2702. # define cotire directory properties
  2703. define_property(
  2704. DIRECTORY PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER"
  2705. BRIEF_DOCS "Modify build command of cotired targets added in this directory to make use of the generated precompiled header."
  2706. FULL_DOCS
  2707. "See target property COTIRE_ENABLE_PRECOMPILED_HEADER."
  2708. )
  2709. define_property(
  2710. DIRECTORY PROPERTY "COTIRE_ADD_UNITY_BUILD"
  2711. BRIEF_DOCS "Add a new target that performs a unity build for cotired targets added in this directory."
  2712. FULL_DOCS
  2713. "See target property COTIRE_ADD_UNITY_BUILD."
  2714. )
  2715. define_property(
  2716. DIRECTORY PROPERTY "COTIRE_ADD_CLEAN"
  2717. BRIEF_DOCS "Add a new target that cleans all cotire generated files for cotired targets added in this directory."
  2718. FULL_DOCS
  2719. "See target property COTIRE_ADD_CLEAN."
  2720. )
  2721. define_property(
  2722. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH"
  2723. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  2724. FULL_DOCS
  2725. "See target property COTIRE_PREFIX_HEADER_IGNORE_PATH."
  2726. )
  2727. define_property(
  2728. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH"
  2729. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  2730. FULL_DOCS
  2731. "See target property COTIRE_PREFIX_HEADER_INCLUDE_PATH."
  2732. )
  2733. define_property(
  2734. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  2735. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each source file."
  2736. FULL_DOCS
  2737. "See target property COTIRE_UNITY_SOURCE_PRE_UNDEFS."
  2738. )
  2739. define_property(
  2740. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  2741. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each source file."
  2742. FULL_DOCS
  2743. "See target property COTIRE_UNITY_SOURCE_POST_UNDEFS."
  2744. )
  2745. define_property(
  2746. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES"
  2747. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  2748. FULL_DOCS
  2749. "See target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  2750. )
  2751. # define cotire target properties
  2752. define_property(
  2753. TARGET PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER" INHERITED
  2754. BRIEF_DOCS "Modify this target's build command to make use of the generated precompiled header."
  2755. FULL_DOCS
  2756. "If this property is set to TRUE, cotire will modify the build command to make use of the generated precompiled header."
  2757. "Irrespective of the value of this property, cotire will setup custom commands to generate the unity source and prefix header for the target."
  2758. "For makefile based generators cotire will also set up a custom target to manually invoke the generation of the precompiled header."
  2759. "The target name will be set to this target's name with the suffix _pch appended."
  2760. "Inherited from directory."
  2761. "Defaults to TRUE."
  2762. )
  2763. define_property(
  2764. TARGET PROPERTY "COTIRE_ADD_UNITY_BUILD" INHERITED
  2765. BRIEF_DOCS "Add a new target that performs a unity build for this target."
  2766. FULL_DOCS
  2767. "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."
  2768. "Most of the relevant target properties will be copied from this target to the new unity build target."
  2769. "Target dependencies and linked libraries have to be manually set up for the new unity build target."
  2770. "The unity target name will be set to this target's name with the suffix _unity appended."
  2771. "Inherited from directory."
  2772. "Defaults to TRUE."
  2773. )
  2774. define_property(
  2775. TARGET PROPERTY "COTIRE_ADD_CLEAN" INHERITED
  2776. BRIEF_DOCS "Add a new target that cleans all cotire generated files for this target."
  2777. FULL_DOCS
  2778. "If this property is set to TRUE, cotire creates a new target that clean all files (unity source, prefix header, precompiled header)."
  2779. "The clean target name will be set to this target's name with the suffix _clean_cotire appended."
  2780. "Inherited from directory."
  2781. "Defaults to FALSE."
  2782. )
  2783. define_property(
  2784. TARGET PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH" INHERITED
  2785. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  2786. FULL_DOCS
  2787. "The property can be set to a list of directories."
  2788. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  2789. "Inherited from directory."
  2790. "If not set, this property is initialized to \${CMAKE_SOURCE_DIR};\${CMAKE_BINARY_DIR}."
  2791. )
  2792. define_property(
  2793. TARGET PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH" INHERITED
  2794. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  2795. FULL_DOCS
  2796. "The property can be set to a list of directories."
  2797. "If a header file is found in one of these directories or sub-directories, it will be included in the generated prefix header."
  2798. "If a header file is both selected by COTIRE_PREFIX_HEADER_IGNORE_PATH and COTIRE_PREFIX_HEADER_INCLUDE_PATH,"
  2799. "the option which yields the closer relative path match wins."
  2800. "Inherited from directory."
  2801. "If not set, this property is initialized to the empty list."
  2802. )
  2803. define_property(
  2804. TARGET PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS" INHERITED
  2805. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each target source file."
  2806. FULL_DOCS
  2807. "This may be set to a semicolon-separated list of preprocessor symbols."
  2808. "cotire will add corresponding #undef directives to the generated unit source file before each target source file."
  2809. "Inherited from directory."
  2810. "Defaults to empty string."
  2811. )
  2812. define_property(
  2813. TARGET PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS" INHERITED
  2814. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each target source file."
  2815. FULL_DOCS
  2816. "This may be set to a semicolon-separated list of preprocessor symbols."
  2817. "cotire will add corresponding #undef directives to the generated unit source file after each target source file."
  2818. "Inherited from directory."
  2819. "Defaults to empty string."
  2820. )
  2821. define_property(
  2822. TARGET PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES" INHERITED
  2823. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  2824. FULL_DOCS
  2825. "This may be set to an integer > 0."
  2826. "If a target contains more than that number of source files, cotire will create multiple unity build files for it."
  2827. "If not set, cotire will only create a single unity source file."
  2828. "Inherited from directory."
  2829. "Defaults to empty."
  2830. )
  2831. define_property(
  2832. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE_INIT"
  2833. BRIEF_DOCS "User provided unity source file to be used instead of the automatically generated one."
  2834. FULL_DOCS
  2835. "If set, cotire will only add the given file(s) to the generated unity source file."
  2836. "If not set, cotire will add all the target source files to the generated unity source file."
  2837. "The property can be set to a user provided unity source file."
  2838. "Defaults to empty."
  2839. )
  2840. define_property(
  2841. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER_INIT"
  2842. BRIEF_DOCS "User provided prefix header file to be used instead of the automatically generated one."
  2843. FULL_DOCS
  2844. "If set, cotire will add the given header file(s) to the generated prefix header file."
  2845. "If not set, cotire will generate a prefix header by tracking the header files included by the unity source file."
  2846. "The property can be set to a user provided prefix header file (e.g., stdafx.h)."
  2847. "Defaults to empty."
  2848. )
  2849. define_property(
  2850. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE"
  2851. BRIEF_DOCS "Read-only property. The generated <LANG> unity source file(s)."
  2852. FULL_DOCS
  2853. "cotire sets this property to the path of the generated <LANG> single computation unit source file for the target."
  2854. "Defaults to empty string."
  2855. )
  2856. define_property(
  2857. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER"
  2858. BRIEF_DOCS "Read-only property. The generated <LANG> prefix header file."
  2859. FULL_DOCS
  2860. "cotire sets this property to the full path of the generated <LANG> language prefix header for the target."
  2861. "Defaults to empty string."
  2862. )
  2863. define_property(
  2864. TARGET PROPERTY "COTIRE_<LANG>_PRECOMPILED_HEADER"
  2865. BRIEF_DOCS "Read-only property. The generated <LANG> precompiled header file."
  2866. FULL_DOCS
  2867. "cotire sets this property to the full path of the generated <LANG> language precompiled header binary for the target."
  2868. "Defaults to empty string."
  2869. )
  2870. define_property(
  2871. TARGET PROPERTY "COTIRE_UNITY_TARGET_NAME"
  2872. BRIEF_DOCS "The name of the generated unity build target corresponding to this target."
  2873. FULL_DOCS
  2874. "This property can be set to the desired name of the unity target that will be created by cotire."
  2875. "If not set, the unity target name will be set to this target's name with the suffix _unity appended."
  2876. "After this target has been processed by cotire, the property is set to the actual name of the generated unity target."
  2877. "Defaults to empty string."
  2878. )
  2879. # define cotire source properties
  2880. define_property(
  2881. SOURCE PROPERTY "COTIRE_EXCLUDED"
  2882. BRIEF_DOCS "Do not modify source file's build command."
  2883. FULL_DOCS
  2884. "If this property is set to TRUE, the source file's build command will not be modified to make use of the precompiled header."
  2885. "The source file will also be excluded from the generated unity source file."
  2886. "Source files that have their COMPILE_FLAGS property set will be excluded by default."
  2887. "Defaults to FALSE."
  2888. )
  2889. define_property(
  2890. SOURCE PROPERTY "COTIRE_DEPENDENCY"
  2891. BRIEF_DOCS "Add this source file to dependencies of the automatically generated prefix header file."
  2892. FULL_DOCS
  2893. "If this property is set to TRUE, the source file is added to dependencies of the generated prefix header file."
  2894. "If the file is modified, cotire will re-generate the prefix header source upon build."
  2895. "Defaults to FALSE."
  2896. )
  2897. define_property(
  2898. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  2899. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of this source file."
  2900. FULL_DOCS
  2901. "This may be set to a semicolon-separated list of preprocessor symbols."
  2902. "cotire will add corresponding #undef directives to the generated unit source file before this file is included."
  2903. "Defaults to empty string."
  2904. )
  2905. define_property(
  2906. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  2907. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of this source file."
  2908. FULL_DOCS
  2909. "This may be set to a semicolon-separated list of preprocessor symbols."
  2910. "cotire will add corresponding #undef directives to the generated unit source file after this file is included."
  2911. "Defaults to empty string."
  2912. )
  2913. define_property(
  2914. SOURCE PROPERTY "COTIRE_START_NEW_UNITY_SOURCE"
  2915. BRIEF_DOCS "Start a new unity source file which includes this source file as the first one."
  2916. FULL_DOCS
  2917. "If this property is set to TRUE, cotire will complete the current unity file and start a new one."
  2918. "The new unity source file will include this source file as the first one."
  2919. "This property essentially works as a separator for unity source files."
  2920. "Defaults to FALSE."
  2921. )
  2922. define_property(
  2923. SOURCE PROPERTY "COTIRE_TARGET"
  2924. BRIEF_DOCS "Read-only property. Mark this source file as cotired for the given target."
  2925. FULL_DOCS
  2926. "cotire sets this property to the name of target, that the source file's build command has been altered for."
  2927. "Defaults to empty string."
  2928. )
  2929. endif()