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