Tue, 15 Mar 2022 18:56:02 +0200
Add missing svg icon
7 | 1 | # - cotire (compile time reducer) |
2 | # | |
3 | # See the cotire manual for usage hints. | |
4 | # | |
5 | #============================================================================= | |
6 | # Copyright 2012-2018 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 | # call cmake_minimum_required, but prevent modification of the CMake policy stack in include mode | |
36 | # cmake_minimum_required also sets the policy version as a side effect, which we have to avoid | |
37 | if (NOT CMAKE_SCRIPT_MODE_FILE) | |
38 | cmake_policy(PUSH) | |
39 | endif() | |
40 | cmake_minimum_required(VERSION 2.8.12) | |
41 | if (NOT CMAKE_SCRIPT_MODE_FILE) | |
42 | cmake_policy(POP) | |
43 | endif() | |
44 | ||
45 | set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}") | |
46 | set (COTIRE_CMAKE_MODULE_VERSION "1.8.0") | |
47 | ||
48 | # activate select policies | |
49 | if (POLICY CMP0025) | |
50 | # Compiler id for Apple Clang is now AppleClang | |
51 | cmake_policy(SET CMP0025 NEW) | |
52 | endif() | |
53 | ||
54 | if (POLICY CMP0026) | |
55 | # disallow use of the LOCATION target property | |
56 | cmake_policy(SET CMP0026 NEW) | |
57 | endif() | |
58 | ||
59 | if (POLICY CMP0038) | |
60 | # targets may not link directly to themselves | |
61 | cmake_policy(SET CMP0038 NEW) | |
62 | endif() | |
63 | ||
64 | if (POLICY CMP0039) | |
65 | # utility targets may not have link dependencies | |
66 | cmake_policy(SET CMP0039 NEW) | |
67 | endif() | |
68 | ||
69 | if (POLICY CMP0040) | |
70 | # target in the TARGET signature of add_custom_command() must exist | |
71 | cmake_policy(SET CMP0040 NEW) | |
72 | endif() | |
73 | ||
74 | if (POLICY CMP0045) | |
75 | # error on non-existent target in get_target_property | |
76 | cmake_policy(SET CMP0045 NEW) | |
77 | endif() | |
78 | ||
79 | if (POLICY CMP0046) | |
80 | # error on non-existent dependency in add_dependencies | |
81 | cmake_policy(SET CMP0046 NEW) | |
82 | endif() | |
83 | ||
84 | if (POLICY CMP0049) | |
85 | # do not expand variables in target source entries | |
86 | cmake_policy(SET CMP0049 NEW) | |
87 | endif() | |
88 | ||
89 | if (POLICY CMP0050) | |
90 | # disallow add_custom_command SOURCE signatures | |
91 | cmake_policy(SET CMP0050 NEW) | |
92 | endif() | |
93 | ||
94 | if (POLICY CMP0051) | |
95 | # include TARGET_OBJECTS expressions in a target's SOURCES property | |
96 | cmake_policy(SET CMP0051 NEW) | |
97 | endif() | |
98 | ||
99 | if (POLICY CMP0053) | |
100 | # simplify variable reference and escape sequence evaluation | |
101 | cmake_policy(SET CMP0053 NEW) | |
102 | endif() | |
103 | ||
104 | if (POLICY CMP0054) | |
105 | # only interpret if() arguments as variables or keywords when unquoted | |
106 | cmake_policy(SET CMP0054 NEW) | |
107 | endif() | |
108 | ||
109 | if (POLICY CMP0055) | |
110 | # strict checking for break() command | |
111 | cmake_policy(SET CMP0055 NEW) | |
112 | endif() | |
113 | ||
114 | include(CMakeParseArguments) | |
115 | include(ProcessorCount) | |
116 | ||
117 | function (cotire_get_configuration_types _configsVar) | |
118 | set (_configs "") | |
119 | if (CMAKE_CONFIGURATION_TYPES) | |
120 | list (APPEND _configs ${CMAKE_CONFIGURATION_TYPES}) | |
121 | endif() | |
122 | if (CMAKE_BUILD_TYPE) | |
123 | list (APPEND _configs "${CMAKE_BUILD_TYPE}") | |
124 | endif() | |
125 | if (_configs) | |
126 | list (REMOVE_DUPLICATES _configs) | |
127 | set (${_configsVar} ${_configs} PARENT_SCOPE) | |
128 | else() | |
129 | set (${_configsVar} "None" PARENT_SCOPE) | |
130 | endif() | |
131 | endfunction() | |
132 | ||
133 | function (cotire_get_source_file_extension _sourceFile _extVar) | |
134 | # get_filename_component returns extension from first occurrence of . in file name | |
135 | # this function computes the extension from last occurrence of . in file name | |
136 | string (FIND "${_sourceFile}" "." _index REVERSE) | |
137 | if (_index GREATER -1) | |
138 | math (EXPR _index "${_index} + 1") | |
139 | string (SUBSTRING "${_sourceFile}" ${_index} -1 _sourceExt) | |
140 | else() | |
141 | set (_sourceExt "") | |
142 | endif() | |
143 | set (${_extVar} "${_sourceExt}" PARENT_SCOPE) | |
144 | endfunction() | |
145 | ||
146 | macro (cotire_check_is_path_relative_to _path _isRelativeVar) | |
147 | set (${_isRelativeVar} FALSE) | |
148 | if (IS_ABSOLUTE "${_path}") | |
149 | foreach (_dir ${ARGN}) | |
150 | file (RELATIVE_PATH _relPath "${_dir}" "${_path}") | |
151 | if (NOT _relPath OR (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.")) | |
152 | set (${_isRelativeVar} TRUE) | |
153 | break() | |
154 | endif() | |
155 | endforeach() | |
156 | endif() | |
157 | endmacro() | |
158 | ||
159 | function (cotire_filter_language_source_files _language _target _sourceFilesVar _excludedSourceFilesVar _cotiredSourceFilesVar) | |
160 | if (CMAKE_${_language}_SOURCE_FILE_EXTENSIONS) | |
161 | set (_languageExtensions "${CMAKE_${_language}_SOURCE_FILE_EXTENSIONS}") | |
162 | else() | |
163 | set (_languageExtensions "") | |
164 | endif() | |
165 | if (CMAKE_${_language}_IGNORE_EXTENSIONS) | |
166 | set (_ignoreExtensions "${CMAKE_${_language}_IGNORE_EXTENSIONS}") | |
167 | else() | |
168 | set (_ignoreExtensions "") | |
169 | endif() | |
170 | if (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS) | |
171 | set (_excludeExtensions "${COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS}") | |
172 | else() | |
173 | set (_excludeExtensions "") | |
174 | endif() | |
175 | if (COTIRE_DEBUG AND _languageExtensions) | |
176 | message (STATUS "${_language} source file extensions: ${_languageExtensions}") | |
177 | endif() | |
178 | if (COTIRE_DEBUG AND _ignoreExtensions) | |
179 | message (STATUS "${_language} ignore extensions: ${_ignoreExtensions}") | |
180 | endif() | |
181 | if (COTIRE_DEBUG AND _excludeExtensions) | |
182 | message (STATUS "${_language} exclude extensions: ${_excludeExtensions}") | |
183 | endif() | |
184 | if (CMAKE_VERSION VERSION_LESS "3.1.0") | |
185 | set (_allSourceFiles ${ARGN}) | |
186 | else() | |
187 | # as of CMake 3.1 target sources may contain generator expressions | |
188 | # since we cannot obtain required property information about source files added | |
189 | # through generator expressions at configure time, we filter them out | |
190 | string (GENEX_STRIP "${ARGN}" _allSourceFiles) | |
191 | endif() | |
192 | set (_filteredSourceFiles "") | |
193 | set (_excludedSourceFiles "") | |
194 | foreach (_sourceFile ${_allSourceFiles}) | |
195 | get_source_file_property(_sourceIsHeaderOnly "${_sourceFile}" HEADER_FILE_ONLY) | |
196 | get_source_file_property(_sourceIsExternal "${_sourceFile}" EXTERNAL_OBJECT) | |
197 | get_source_file_property(_sourceIsSymbolic "${_sourceFile}" SYMBOLIC) | |
198 | if (NOT _sourceIsHeaderOnly AND NOT _sourceIsExternal AND NOT _sourceIsSymbolic) | |
199 | cotire_get_source_file_extension("${_sourceFile}" _sourceExt) | |
200 | if (_sourceExt) | |
201 | list (FIND _ignoreExtensions "${_sourceExt}" _ignoreIndex) | |
202 | if (_ignoreIndex LESS 0) | |
203 | list (FIND _excludeExtensions "${_sourceExt}" _excludeIndex) | |
204 | if (_excludeIndex GREATER -1) | |
205 | list (APPEND _excludedSourceFiles "${_sourceFile}") | |
206 | else() | |
207 | list (FIND _languageExtensions "${_sourceExt}" _sourceIndex) | |
208 | if (_sourceIndex GREATER -1) | |
209 | # consider source file unless it is excluded explicitly | |
210 | get_source_file_property(_sourceIsExcluded "${_sourceFile}" COTIRE_EXCLUDED) | |
211 | if (_sourceIsExcluded) | |
212 | list (APPEND _excludedSourceFiles "${_sourceFile}") | |
213 | else() | |
214 | list (APPEND _filteredSourceFiles "${_sourceFile}") | |
215 | endif() | |
216 | else() | |
217 | get_source_file_property(_sourceLanguage "${_sourceFile}" LANGUAGE) | |
218 | if ("${_sourceLanguage}" STREQUAL "${_language}") | |
219 | # add to excluded sources, if file is not ignored and has correct language without having the correct extension | |
220 | list (APPEND _excludedSourceFiles "${_sourceFile}") | |
221 | endif() | |
222 | endif() | |
223 | endif() | |
224 | endif() | |
225 | endif() | |
226 | endif() | |
227 | endforeach() | |
228 | # separate filtered source files from already cotired ones | |
229 | # the COTIRE_TARGET property of a source file may be set while a target is being processed by cotire | |
230 | set (_sourceFiles "") | |
231 | set (_cotiredSourceFiles "") | |
232 | foreach (_sourceFile ${_filteredSourceFiles}) | |
233 | get_source_file_property(_sourceIsCotired "${_sourceFile}" COTIRE_TARGET) | |
234 | if (_sourceIsCotired) | |
235 | list (APPEND _cotiredSourceFiles "${_sourceFile}") | |
236 | else() | |
237 | get_source_file_property(_sourceCompileFlags "${_sourceFile}" COMPILE_FLAGS) | |
238 | if (_sourceCompileFlags) | |
239 | # add to excluded sources, if file has custom compile flags | |
240 | list (APPEND _excludedSourceFiles "${_sourceFile}") | |
241 | else() | |
242 | get_source_file_property(_sourceCompileOptions "${_sourceFile}" COMPILE_OPTIONS) | |
243 | if (_sourceCompileOptions) | |
244 | # add to excluded sources, if file has list of custom compile options | |
245 | list (APPEND _excludedSourceFiles "${_sourceFile}") | |
246 | else() | |
247 | list (APPEND _sourceFiles "${_sourceFile}") | |
248 | endif() | |
249 | endif() | |
250 | endif() | |
251 | endforeach() | |
252 | if (COTIRE_DEBUG) | |
253 | if (_sourceFiles) | |
254 | message (STATUS "Filtered ${_target} ${_language} sources: ${_sourceFiles}") | |
255 | endif() | |
256 | if (_excludedSourceFiles) | |
257 | message (STATUS "Excluded ${_target} ${_language} sources: ${_excludedSourceFiles}") | |
258 | endif() | |
259 | if (_cotiredSourceFiles) | |
260 | message (STATUS "Cotired ${_target} ${_language} sources: ${_cotiredSourceFiles}") | |
261 | endif() | |
262 | endif() | |
263 | set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE) | |
264 | set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE) | |
265 | set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE) | |
266 | endfunction() | |
267 | ||
268 | function (cotire_get_objects_with_property_on _filteredObjectsVar _property _type) | |
269 | set (_filteredObjects "") | |
270 | foreach (_object ${ARGN}) | |
271 | get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET) | |
272 | if (_isSet) | |
273 | get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property}) | |
274 | if (_propertyValue) | |
275 | list (APPEND _filteredObjects "${_object}") | |
276 | endif() | |
277 | endif() | |
278 | endforeach() | |
279 | set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE) | |
280 | endfunction() | |
281 | ||
282 | function (cotire_get_objects_with_property_off _filteredObjectsVar _property _type) | |
283 | set (_filteredObjects "") | |
284 | foreach (_object ${ARGN}) | |
285 | get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET) | |
286 | if (_isSet) | |
287 | get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property}) | |
288 | if (NOT _propertyValue) | |
289 | list (APPEND _filteredObjects "${_object}") | |
290 | endif() | |
291 | endif() | |
292 | endforeach() | |
293 | set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE) | |
294 | endfunction() | |
295 | ||
296 | function (cotire_get_source_file_property_values _valuesVar _property) | |
297 | set (_values "") | |
298 | foreach (_sourceFile ${ARGN}) | |
299 | get_source_file_property(_propertyValue "${_sourceFile}" ${_property}) | |
300 | if (_propertyValue) | |
301 | list (APPEND _values "${_propertyValue}") | |
302 | endif() | |
303 | endforeach() | |
304 | set (${_valuesVar} ${_values} PARENT_SCOPE) | |
305 | endfunction() | |
306 | ||
307 | function (cotire_resolve_config_properties _configurations _propertiesVar) | |
308 | set (_properties "") | |
309 | foreach (_property ${ARGN}) | |
310 | if ("${_property}" MATCHES "<CONFIG>") | |
311 | foreach (_config ${_configurations}) | |
312 | string (TOUPPER "${_config}" _upperConfig) | |
313 | string (REPLACE "<CONFIG>" "${_upperConfig}" _configProperty "${_property}") | |
314 | list (APPEND _properties ${_configProperty}) | |
315 | endforeach() | |
316 | else() | |
317 | list (APPEND _properties ${_property}) | |
318 | endif() | |
319 | endforeach() | |
320 | set (${_propertiesVar} ${_properties} PARENT_SCOPE) | |
321 | endfunction() | |
322 | ||
323 | function (cotire_copy_set_properties _configurations _type _source _target) | |
324 | cotire_resolve_config_properties("${_configurations}" _properties ${ARGN}) | |
325 | foreach (_property ${_properties}) | |
326 | get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET) | |
327 | if (_isSet) | |
328 | get_property(_propertyValue ${_type} ${_source} PROPERTY ${_property}) | |
329 | set_property(${_type} ${_target} PROPERTY ${_property} "${_propertyValue}") | |
330 | endif() | |
331 | endforeach() | |
332 | endfunction() | |
333 | ||
334 | function (cotire_get_target_usage_requirements _target _config _targetRequirementsVar) | |
335 | set (_targetRequirements "") | |
336 | get_target_property(_librariesToProcess ${_target} LINK_LIBRARIES) | |
337 | while (_librariesToProcess) | |
338 | # remove from head | |
339 | list (GET _librariesToProcess 0 _library) | |
340 | list (REMOVE_AT _librariesToProcess 0) | |
341 | if (_library MATCHES "^\\$<\\$<CONFIG:${_config}>:([A-Za-z0-9_:-]+)>$") | |
342 | set (_library "${CMAKE_MATCH_1}") | |
343 | elseif (_config STREQUAL "None" AND _library MATCHES "^\\$<\\$<CONFIG:>:([A-Za-z0-9_:-]+)>$") | |
344 | set (_library "${CMAKE_MATCH_1}") | |
345 | endif() | |
346 | if (TARGET ${_library}) | |
347 | list (FIND _targetRequirements ${_library} _index) | |
348 | if (_index LESS 0) | |
349 | list (APPEND _targetRequirements ${_library}) | |
350 | # BFS traversal of transitive libraries | |
351 | get_target_property(_libraries ${_library} INTERFACE_LINK_LIBRARIES) | |
352 | if (_libraries) | |
353 | list (APPEND _librariesToProcess ${_libraries}) | |
354 | list (REMOVE_DUPLICATES _librariesToProcess) | |
355 | endif() | |
356 | endif() | |
357 | endif() | |
358 | endwhile() | |
359 | set (${_targetRequirementsVar} ${_targetRequirements} PARENT_SCOPE) | |
360 | endfunction() | |
361 | ||
362 | function (cotire_filter_compile_flags _language _flagFilter _matchedOptionsVar _unmatchedOptionsVar) | |
363 | if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel") | |
364 | set (_flagPrefix "[/-]") | |
365 | else() | |
366 | set (_flagPrefix "--?") | |
367 | endif() | |
368 | set (_optionFlag "") | |
369 | set (_matchedOptions "") | |
370 | set (_unmatchedOptions "") | |
371 | foreach (_compileFlag ${ARGN}) | |
372 | if (_compileFlag) | |
373 | if (_optionFlag AND NOT "${_compileFlag}" MATCHES "^${_flagPrefix}") | |
374 | # option with separate argument | |
375 | list (APPEND _matchedOptions "${_compileFlag}") | |
376 | set (_optionFlag "") | |
377 | elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$") | |
378 | # remember option | |
379 | set (_optionFlag "${CMAKE_MATCH_2}") | |
380 | elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})(.+)$") | |
381 | # option with joined argument | |
382 | list (APPEND _matchedOptions "${CMAKE_MATCH_3}") | |
383 | set (_optionFlag "") | |
384 | else() | |
385 | # flush remembered option | |
386 | if (_optionFlag) | |
387 | list (APPEND _matchedOptions "${_optionFlag}") | |
388 | set (_optionFlag "") | |
389 | endif() | |
390 | # add to unfiltered options | |
391 | list (APPEND _unmatchedOptions "${_compileFlag}") | |
392 | endif() | |
393 | endif() | |
394 | endforeach() | |
395 | if (_optionFlag) | |
396 | list (APPEND _matchedOptions "${_optionFlag}") | |
397 | endif() | |
398 | if (COTIRE_DEBUG AND _matchedOptions) | |
399 | message (STATUS "Filter ${_flagFilter} matched: ${_matchedOptions}") | |
400 | endif() | |
401 | if (COTIRE_DEBUG AND _unmatchedOptions) | |
402 | message (STATUS "Filter ${_flagFilter} unmatched: ${_unmatchedOptions}") | |
403 | endif() | |
404 | set (${_matchedOptionsVar} ${_matchedOptions} PARENT_SCOPE) | |
405 | set (${_unmatchedOptionsVar} ${_unmatchedOptions} PARENT_SCOPE) | |
406 | endfunction() | |
407 | ||
408 | function (cotire_is_target_supported _target _isSupportedVar) | |
409 | if (NOT TARGET "${_target}") | |
410 | set (${_isSupportedVar} FALSE PARENT_SCOPE) | |
411 | return() | |
412 | endif() | |
413 | get_target_property(_imported ${_target} IMPORTED) | |
414 | if (_imported) | |
415 | set (${_isSupportedVar} FALSE PARENT_SCOPE) | |
416 | return() | |
417 | endif() | |
418 | get_target_property(_targetType ${_target} TYPE) | |
419 | if (NOT _targetType MATCHES "EXECUTABLE|(STATIC|SHARED|MODULE|OBJECT)_LIBRARY") | |
420 | set (${_isSupportedVar} FALSE PARENT_SCOPE) | |
421 | return() | |
422 | endif() | |
423 | set (${_isSupportedVar} TRUE PARENT_SCOPE) | |
424 | endfunction() | |
425 | ||
426 | function (cotire_get_target_compile_flags _config _language _target _flagsVar) | |
427 | string (TOUPPER "${_config}" _upperConfig) | |
428 | # collect options from CMake language variables | |
429 | set (_compileFlags "") | |
430 | if (CMAKE_${_language}_FLAGS) | |
431 | set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS}") | |
432 | endif() | |
433 | if (CMAKE_${_language}_FLAGS_${_upperConfig}) | |
434 | set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS_${_upperConfig}}") | |
435 | endif() | |
436 | if (_target) | |
437 | # add target compile flags | |
438 | get_target_property(_targetflags ${_target} COMPILE_FLAGS) | |
439 | if (_targetflags) | |
440 | set (_compileFlags "${_compileFlags} ${_targetflags}") | |
441 | endif() | |
442 | endif() | |
443 | if (UNIX) | |
444 | separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}") | |
445 | elseif(WIN32) | |
446 | separate_arguments(_compileFlags WINDOWS_COMMAND "${_compileFlags}") | |
447 | else() | |
448 | separate_arguments(_compileFlags) | |
449 | endif() | |
450 | # target compile options | |
451 | if (_target) | |
452 | get_target_property(_targetOptions ${_target} COMPILE_OPTIONS) | |
453 | if (_targetOptions) | |
454 | list (APPEND _compileFlags ${_targetOptions}) | |
455 | endif() | |
456 | endif() | |
457 | # interface compile options from linked library targets | |
458 | if (_target) | |
459 | set (_linkedTargets "") | |
460 | cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets) | |
461 | foreach (_linkedTarget ${_linkedTargets}) | |
462 | get_target_property(_targetOptions ${_linkedTarget} INTERFACE_COMPILE_OPTIONS) | |
463 | if (_targetOptions) | |
464 | list (APPEND _compileFlags ${_targetOptions}) | |
465 | endif() | |
466 | endforeach() | |
467 | endif() | |
468 | # handle language standard properties | |
469 | if (CMAKE_${_language}_STANDARD_DEFAULT) | |
470 | # used compiler supports language standard levels | |
471 | if (_target) | |
472 | get_target_property(_targetLanguageStandard ${_target} ${_language}_STANDARD) | |
473 | if (_targetLanguageStandard) | |
474 | set (_type "EXTENSION") | |
475 | get_property(_isSet TARGET ${_target} PROPERTY ${_language}_EXTENSIONS SET) | |
476 | if (_isSet) | |
477 | get_target_property(_targetUseLanguageExtensions ${_target} ${_language}_EXTENSIONS) | |
478 | if (NOT _targetUseLanguageExtensions) | |
479 | set (_type "STANDARD") | |
480 | endif() | |
481 | endif() | |
482 | if (CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION) | |
483 | list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION}") | |
484 | endif() | |
485 | endif() | |
486 | endif() | |
487 | endif() | |
488 | # handle the POSITION_INDEPENDENT_CODE target property | |
489 | if (_target) | |
490 | get_target_property(_targetPIC ${_target} POSITION_INDEPENDENT_CODE) | |
491 | if (_targetPIC) | |
492 | get_target_property(_targetType ${_target} TYPE) | |
493 | if (_targetType STREQUAL "EXECUTABLE" AND CMAKE_${_language}_COMPILE_OPTIONS_PIE) | |
494 | list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIE}") | |
495 | elseif (CMAKE_${_language}_COMPILE_OPTIONS_PIC) | |
496 | list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIC}") | |
497 | endif() | |
498 | endif() | |
499 | endif() | |
500 | # handle visibility target properties | |
501 | if (_target) | |
502 | get_target_property(_targetVisibility ${_target} ${_language}_VISIBILITY_PRESET) | |
503 | if (_targetVisibility AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY) | |
504 | list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY}${_targetVisibility}") | |
505 | endif() | |
506 | get_target_property(_targetVisibilityInlines ${_target} VISIBILITY_INLINES_HIDDEN) | |
507 | if (_targetVisibilityInlines AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN) | |
508 | list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}") | |
509 | endif() | |
510 | endif() | |
511 | # platform specific flags | |
512 | if (APPLE) | |
513 | get_target_property(_architectures ${_target} OSX_ARCHITECTURES_${_upperConfig}) | |
514 | if (NOT _architectures) | |
515 | get_target_property(_architectures ${_target} OSX_ARCHITECTURES) | |
516 | endif() | |
517 | if (_architectures) | |
518 | foreach (_arch ${_architectures}) | |
519 | list (APPEND _compileFlags "-arch" "${_arch}") | |
520 | endforeach() | |
521 | endif() | |
522 | if (CMAKE_OSX_SYSROOT) | |
523 | if (CMAKE_${_language}_SYSROOT_FLAG) | |
524 | list (APPEND _compileFlags "${CMAKE_${_language}_SYSROOT_FLAG}" "${CMAKE_OSX_SYSROOT}") | |
525 | else() | |
526 | list (APPEND _compileFlags "-isysroot" "${CMAKE_OSX_SYSROOT}") | |
527 | endif() | |
528 | endif() | |
529 | if (CMAKE_OSX_DEPLOYMENT_TARGET) | |
530 | if (CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG) | |
531 | list (APPEND _compileFlags "${CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}") | |
532 | else() | |
533 | list (APPEND _compileFlags "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") | |
534 | endif() | |
535 | endif() | |
536 | endif() | |
537 | if (COTIRE_DEBUG AND _compileFlags) | |
538 | message (STATUS "Target ${_target} compile flags: ${_compileFlags}") | |
539 | endif() | |
540 | set (${_flagsVar} ${_compileFlags} PARENT_SCOPE) | |
541 | endfunction() | |
542 | ||
543 | function (cotire_get_target_include_directories _config _language _target _includeDirsVar _systemIncludeDirsVar) | |
544 | set (_includeDirs "") | |
545 | set (_systemIncludeDirs "") | |
546 | # default include dirs | |
547 | if (CMAKE_INCLUDE_CURRENT_DIR) | |
548 | list (APPEND _includeDirs "${CMAKE_CURRENT_BINARY_DIR}") | |
549 | list (APPEND _includeDirs "${CMAKE_CURRENT_SOURCE_DIR}") | |
550 | endif() | |
551 | set (_targetFlags "") | |
552 | cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags) | |
553 | # parse additional include directories from target compile flags | |
554 | if (CMAKE_INCLUDE_FLAG_${_language}) | |
555 | string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag) | |
556 | string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}") | |
557 | if (_includeFlag) | |
558 | set (_dirs "") | |
559 | cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags}) | |
560 | if (_dirs) | |
561 | list (APPEND _includeDirs ${_dirs}) | |
562 | endif() | |
563 | endif() | |
564 | endif() | |
565 | # parse additional system include directories from target compile flags | |
566 | if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language}) | |
567 | string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag) | |
568 | string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}") | |
569 | if (_includeFlag) | |
570 | set (_dirs "") | |
571 | cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags}) | |
572 | if (_dirs) | |
573 | list (APPEND _systemIncludeDirs ${_dirs}) | |
574 | endif() | |
575 | endif() | |
576 | endif() | |
577 | # target include directories | |
578 | get_directory_property(_dirs DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" INCLUDE_DIRECTORIES) | |
579 | if (_target) | |
580 | get_target_property(_targetDirs ${_target} INCLUDE_DIRECTORIES) | |
581 | if (_targetDirs) | |
582 | list (APPEND _dirs ${_targetDirs}) | |
583 | endif() | |
584 | get_target_property(_targetDirs ${_target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) | |
585 | if (_targetDirs) | |
586 | list (APPEND _systemIncludeDirs ${_targetDirs}) | |
587 | endif() | |
588 | endif() | |
589 | # interface include directories from linked library targets | |
590 | if (_target) | |
591 | set (_linkedTargets "") | |
592 | cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets) | |
593 | foreach (_linkedTarget ${_linkedTargets}) | |
594 | get_target_property(_linkedTargetType ${_linkedTarget} TYPE) | |
595 | if (CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE AND NOT CMAKE_VERSION VERSION_LESS "3.4.0" AND | |
596 | _linkedTargetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY") | |
597 | # CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE refers to CMAKE_CURRENT_BINARY_DIR and CMAKE_CURRENT_SOURCE_DIR | |
598 | # at the time, when the target was created. These correspond to the target properties BINARY_DIR and SOURCE_DIR | |
599 | # which are only available with CMake 3.4 or later. | |
600 | get_target_property(_targetDirs ${_linkedTarget} BINARY_DIR) | |
601 | if (_targetDirs) | |
602 | list (APPEND _dirs ${_targetDirs}) | |
603 | endif() | |
604 | get_target_property(_targetDirs ${_linkedTarget} SOURCE_DIR) | |
605 | if (_targetDirs) | |
606 | list (APPEND _dirs ${_targetDirs}) | |
607 | endif() | |
608 | endif() | |
609 | get_target_property(_targetDirs ${_linkedTarget} INTERFACE_INCLUDE_DIRECTORIES) | |
610 | if (_targetDirs) | |
611 | list (APPEND _dirs ${_targetDirs}) | |
612 | endif() | |
613 | get_target_property(_targetDirs ${_linkedTarget} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) | |
614 | if (_targetDirs) | |
615 | list (APPEND _systemIncludeDirs ${_targetDirs}) | |
616 | endif() | |
617 | endforeach() | |
618 | endif() | |
619 | if (dirs) | |
620 | list (REMOVE_DUPLICATES _dirs) | |
621 | endif() | |
622 | list (LENGTH _includeDirs _projectInsertIndex) | |
623 | foreach (_dir ${_dirs}) | |
624 | if (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE) | |
625 | cotire_check_is_path_relative_to("${_dir}" _isRelative "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}") | |
626 | if (_isRelative) | |
627 | list (LENGTH _includeDirs _len) | |
628 | if (_len EQUAL _projectInsertIndex) | |
629 | list (APPEND _includeDirs "${_dir}") | |
630 | else() | |
631 | list (INSERT _includeDirs _projectInsertIndex "${_dir}") | |
632 | endif() | |
633 | math (EXPR _projectInsertIndex "${_projectInsertIndex} + 1") | |
634 | else() | |
635 | list (APPEND _includeDirs "${_dir}") | |
636 | endif() | |
637 | else() | |
638 | list (APPEND _includeDirs "${_dir}") | |
639 | endif() | |
640 | endforeach() | |
641 | list (REMOVE_DUPLICATES _includeDirs) | |
642 | list (REMOVE_DUPLICATES _systemIncludeDirs) | |
643 | if (CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES) | |
644 | list (REMOVE_ITEM _includeDirs ${CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES}) | |
645 | endif() | |
646 | if (WIN32 AND NOT MINGW) | |
647 | # convert Windows paths in include directories to CMake paths | |
648 | if (_includeDirs) | |
649 | set (_paths "") | |
650 | foreach (_dir ${_includeDirs}) | |
651 | file (TO_CMAKE_PATH "${_dir}" _path) | |
652 | list (APPEND _paths "${_path}") | |
653 | endforeach() | |
654 | set (_includeDirs ${_paths}) | |
655 | endif() | |
656 | if (_systemIncludeDirs) | |
657 | set (_paths "") | |
658 | foreach (_dir ${_systemIncludeDirs}) | |
659 | file (TO_CMAKE_PATH "${_dir}" _path) | |
660 | list (APPEND _paths "${_path}") | |
661 | endforeach() | |
662 | set (_systemIncludeDirs ${_paths}) | |
663 | endif() | |
664 | endif() | |
665 | if (COTIRE_DEBUG AND _includeDirs) | |
666 | message (STATUS "Target ${_target} include dirs: ${_includeDirs}") | |
667 | endif() | |
668 | set (${_includeDirsVar} ${_includeDirs} PARENT_SCOPE) | |
669 | if (COTIRE_DEBUG AND _systemIncludeDirs) | |
670 | message (STATUS "Target ${_target} system include dirs: ${_systemIncludeDirs}") | |
671 | endif() | |
672 | set (${_systemIncludeDirsVar} ${_systemIncludeDirs} PARENT_SCOPE) | |
673 | endfunction() | |
674 | ||
675 | function (cotire_get_target_export_symbol _target _exportSymbolVar) | |
676 | set (_exportSymbol "") | |
677 | get_target_property(_targetType ${_target} TYPE) | |
678 | get_target_property(_enableExports ${_target} ENABLE_EXPORTS) | |
679 | if (_targetType MATCHES "(SHARED|MODULE)_LIBRARY" OR | |
680 | (_targetType STREQUAL "EXECUTABLE" AND _enableExports)) | |
681 | get_target_property(_exportSymbol ${_target} DEFINE_SYMBOL) | |
682 | if (NOT _exportSymbol) | |
683 | set (_exportSymbol "${_target}_EXPORTS") | |
684 | endif() | |
685 | string (MAKE_C_IDENTIFIER "${_exportSymbol}" _exportSymbol) | |
686 | endif() | |
687 | set (${_exportSymbolVar} ${_exportSymbol} PARENT_SCOPE) | |
688 | endfunction() | |
689 | ||
690 | function (cotire_get_target_compile_definitions _config _language _target _definitionsVar) | |
691 | string (TOUPPER "${_config}" _upperConfig) | |
692 | set (_configDefinitions "") | |
693 | # CMAKE_INTDIR for multi-configuration build systems | |
694 | if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") | |
695 | list (APPEND _configDefinitions "CMAKE_INTDIR=\"${_config}\"") | |
696 | endif() | |
697 | # target export define symbol | |
698 | cotire_get_target_export_symbol("${_target}" _defineSymbol) | |
699 | if (_defineSymbol) | |
700 | list (APPEND _configDefinitions "${_defineSymbol}") | |
701 | endif() | |
702 | # directory compile definitions | |
703 | get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS) | |
704 | if (_definitions) | |
705 | list (APPEND _configDefinitions ${_definitions}) | |
706 | endif() | |
707 | get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS_${_upperConfig}) | |
708 | if (_definitions) | |
709 | list (APPEND _configDefinitions ${_definitions}) | |
710 | endif() | |
711 | # target compile definitions | |
712 | get_target_property(_definitions ${_target} COMPILE_DEFINITIONS) | |
713 | if (_definitions) | |
714 | list (APPEND _configDefinitions ${_definitions}) | |
715 | endif() | |
716 | get_target_property(_definitions ${_target} COMPILE_DEFINITIONS_${_upperConfig}) | |
717 | if (_definitions) | |
718 | list (APPEND _configDefinitions ${_definitions}) | |
719 | endif() | |
720 | # interface compile definitions from linked library targets | |
721 | set (_linkedTargets "") | |
722 | cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets) | |
723 | foreach (_linkedTarget ${_linkedTargets}) | |
724 | get_target_property(_definitions ${_linkedTarget} INTERFACE_COMPILE_DEFINITIONS) | |
725 | if (_definitions) | |
726 | list (APPEND _configDefinitions ${_definitions}) | |
727 | endif() | |
728 | endforeach() | |
729 | # parse additional compile definitions from target compile flags | |
730 | # and do not look at directory compile definitions, which we already handled | |
731 | set (_targetFlags "") | |
732 | cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags) | |
733 | cotire_filter_compile_flags("${_language}" "D" _definitions _ignore ${_targetFlags}) | |
734 | if (_definitions) | |
735 | list (APPEND _configDefinitions ${_definitions}) | |
736 | endif() | |
737 | list (REMOVE_DUPLICATES _configDefinitions) | |
738 | if (COTIRE_DEBUG AND _configDefinitions) | |
739 | message (STATUS "Target ${_target} compile definitions: ${_configDefinitions}") | |
740 | endif() | |
741 | set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE) | |
742 | endfunction() | |
743 | ||
744 | function (cotire_get_target_compiler_flags _config _language _target _compilerFlagsVar) | |
745 | # parse target compile flags omitting compile definitions and include directives | |
746 | set (_targetFlags "") | |
747 | cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags) | |
748 | set (_flagFilter "D") | |
749 | if (CMAKE_INCLUDE_FLAG_${_language}) | |
750 | string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag) | |
751 | string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}") | |
752 | if (_includeFlag) | |
753 | set (_flagFilter "${_flagFilter}|${_includeFlag}") | |
754 | endif() | |
755 | endif() | |
756 | if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language}) | |
757 | string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag) | |
758 | string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}") | |
759 | if (_includeFlag) | |
760 | set (_flagFilter "${_flagFilter}|${_includeFlag}") | |
761 | endif() | |
762 | endif() | |
763 | set (_compilerFlags "") | |
764 | cotire_filter_compile_flags("${_language}" "${_flagFilter}" _ignore _compilerFlags ${_targetFlags}) | |
765 | if (COTIRE_DEBUG AND _compilerFlags) | |
766 | message (STATUS "Target ${_target} compiler flags: ${_compilerFlags}") | |
767 | endif() | |
768 | set (${_compilerFlagsVar} ${_compilerFlags} PARENT_SCOPE) | |
769 | endfunction() | |
770 | ||
771 | function (cotire_add_sys_root_paths _pathsVar) | |
772 | if (APPLE) | |
773 | if (CMAKE_OSX_SYSROOT AND CMAKE_${_language}_HAS_ISYSROOT) | |
774 | foreach (_path IN LISTS ${_pathsVar}) | |
775 | if (IS_ABSOLUTE "${_path}") | |
776 | get_filename_component(_path "${CMAKE_OSX_SYSROOT}/${_path}" ABSOLUTE) | |
777 | if (EXISTS "${_path}") | |
778 | list (APPEND ${_pathsVar} "${_path}") | |
779 | endif() | |
780 | endif() | |
781 | endforeach() | |
782 | endif() | |
783 | endif() | |
784 | set (${_pathsVar} ${${_pathsVar}} PARENT_SCOPE) | |
785 | endfunction() | |
786 | ||
787 | function (cotire_get_source_extra_properties _sourceFile _pattern _resultVar) | |
788 | set (_extraProperties ${ARGN}) | |
789 | set (_result "") | |
790 | if (_extraProperties) | |
791 | list (FIND _extraProperties "${_sourceFile}" _index) | |
792 | if (_index GREATER -1) | |
793 | math (EXPR _index "${_index} + 1") | |
794 | list (LENGTH _extraProperties _len) | |
795 | math (EXPR _len "${_len} - 1") | |
796 | foreach (_index RANGE ${_index} ${_len}) | |
797 | list (GET _extraProperties ${_index} _value) | |
798 | if (_value MATCHES "${_pattern}") | |
799 | list (APPEND _result "${_value}") | |
800 | else() | |
801 | break() | |
802 | endif() | |
803 | endforeach() | |
804 | endif() | |
805 | endif() | |
806 | set (${_resultVar} ${_result} PARENT_SCOPE) | |
807 | endfunction() | |
808 | ||
809 | function (cotire_get_source_compile_definitions _config _language _sourceFile _definitionsVar) | |
810 | set (_compileDefinitions "") | |
811 | if (NOT CMAKE_SCRIPT_MODE_FILE) | |
812 | string (TOUPPER "${_config}" _upperConfig) | |
813 | get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS) | |
814 | if (_definitions) | |
815 | list (APPEND _compileDefinitions ${_definitions}) | |
816 | endif() | |
817 | get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS_${_upperConfig}) | |
818 | if (_definitions) | |
819 | list (APPEND _compileDefinitions ${_definitions}) | |
820 | endif() | |
821 | endif() | |
822 | cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+(=.*)?$" _definitions ${ARGN}) | |
823 | if (_definitions) | |
824 | list (APPEND _compileDefinitions ${_definitions}) | |
825 | endif() | |
826 | if (COTIRE_DEBUG AND _compileDefinitions) | |
827 | message (STATUS "Source ${_sourceFile} compile definitions: ${_compileDefinitions}") | |
828 | endif() | |
829 | set (${_definitionsVar} ${_compileDefinitions} PARENT_SCOPE) | |
830 | endfunction() | |
831 | ||
832 | function (cotire_get_source_files_compile_definitions _config _language _definitionsVar) | |
833 | set (_configDefinitions "") | |
834 | foreach (_sourceFile ${ARGN}) | |
835 | cotire_get_source_compile_definitions("${_config}" "${_language}" "${_sourceFile}" _sourceDefinitions) | |
836 | if (_sourceDefinitions) | |
837 | list (APPEND _configDefinitions "${_sourceFile}" ${_sourceDefinitions} "-") | |
838 | endif() | |
839 | endforeach() | |
840 | set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE) | |
841 | endfunction() | |
842 | ||
843 | function (cotire_get_source_undefs _sourceFile _property _sourceUndefsVar) | |
844 | set (_sourceUndefs "") | |
845 | if (NOT CMAKE_SCRIPT_MODE_FILE) | |
846 | get_source_file_property(_undefs "${_sourceFile}" ${_property}) | |
847 | if (_undefs) | |
848 | list (APPEND _sourceUndefs ${_undefs}) | |
849 | endif() | |
850 | endif() | |
851 | cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+$" _undefs ${ARGN}) | |
852 | if (_undefs) | |
853 | list (APPEND _sourceUndefs ${_undefs}) | |
854 | endif() | |
855 | if (COTIRE_DEBUG AND _sourceUndefs) | |
856 | message (STATUS "Source ${_sourceFile} ${_property} undefs: ${_sourceUndefs}") | |
857 | endif() | |
858 | set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE) | |
859 | endfunction() | |
860 | ||
861 | function (cotire_get_source_files_undefs _property _sourceUndefsVar) | |
862 | set (_sourceUndefs "") | |
863 | foreach (_sourceFile ${ARGN}) | |
864 | cotire_get_source_undefs("${_sourceFile}" ${_property} _undefs) | |
865 | if (_undefs) | |
866 | list (APPEND _sourceUndefs "${_sourceFile}" ${_undefs} "-") | |
867 | endif() | |
868 | endforeach() | |
869 | set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE) | |
870 | endfunction() | |
871 | ||
872 | macro (cotire_set_cmd_to_prologue _cmdVar) | |
873 | set (${_cmdVar} "${CMAKE_COMMAND}") | |
874 | if (COTIRE_DEBUG) | |
875 | list (APPEND ${_cmdVar} "--warn-uninitialized") | |
876 | endif() | |
877 | list (APPEND ${_cmdVar} "-DCOTIRE_BUILD_TYPE:STRING=$<CONFIGURATION>") | |
878 | if (XCODE) | |
879 | list (APPEND ${_cmdVar} "-DXCODE:BOOL=TRUE") | |
880 | endif() | |
881 | if (COTIRE_VERBOSE) | |
882 | list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=ON") | |
883 | elseif("${CMAKE_GENERATOR}" MATCHES "Makefiles") | |
884 | list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=$(VERBOSE)") | |
885 | endif() | |
886 | endmacro() | |
887 | ||
888 | function (cotire_init_compile_cmd _cmdVar _language _compilerLauncher _compilerExe _compilerArg1) | |
889 | if (NOT _compilerLauncher) | |
890 | set (_compilerLauncher ${CMAKE_${_language}_COMPILER_LAUNCHER}) | |
891 | endif() | |
892 | if (NOT _compilerExe) | |
893 | set (_compilerExe "${CMAKE_${_language}_COMPILER}") | |
894 | endif() | |
895 | if (NOT _compilerArg1) | |
896 | set (_compilerArg1 ${CMAKE_${_language}_COMPILER_ARG1}) | |
897 | endif() | |
898 | if (WIN32) | |
899 | file (TO_NATIVE_PATH "${_compilerExe}" _compilerExe) | |
900 | endif() | |
901 | string (STRIP "${_compilerArg1}" _compilerArg1) | |
902 | if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja") | |
903 | # compiler launcher is only supported for Makefile and Ninja | |
904 | set (${_cmdVar} ${_compilerLauncher} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE) | |
905 | else() | |
906 | set (${_cmdVar} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE) | |
907 | endif() | |
908 | endfunction() | |
909 | ||
910 | macro (cotire_add_definitions_to_cmd _cmdVar _language) | |
911 | foreach (_definition ${ARGN}) | |
912 | if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel") | |
913 | list (APPEND ${_cmdVar} "/D${_definition}") | |
914 | else() | |
915 | list (APPEND ${_cmdVar} "-D${_definition}") | |
916 | endif() | |
917 | endforeach() | |
918 | endmacro() | |
919 | ||
920 | function (cotire_add_includes_to_cmd _cmdVar _language _includesVar _systemIncludesVar) | |
921 | set (_includeDirs ${${_includesVar}} ${${_systemIncludesVar}}) | |
922 | if (_includeDirs) | |
923 | list (REMOVE_DUPLICATES _includeDirs) | |
924 | foreach (_include ${_includeDirs}) | |
925 | if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel") | |
926 | file (TO_NATIVE_PATH "${_include}" _include) | |
927 | list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}") | |
928 | else() | |
929 | set (_index -1) | |
930 | if ("${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" MATCHES ".+") | |
931 | list (FIND ${_systemIncludesVar} "${_include}" _index) | |
932 | endif() | |
933 | if (_index GREATER -1) | |
934 | list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}") | |
935 | else() | |
936 | list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}") | |
937 | endif() | |
938 | endif() | |
939 | endforeach() | |
940 | endif() | |
941 | set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE) | |
942 | endfunction() | |
943 | ||
944 | function (cotire_add_frameworks_to_cmd _cmdVar _language _includesVar _systemIncludesVar) | |
945 | if (APPLE) | |
946 | set (_frameworkDirs "") | |
947 | foreach (_include ${${_includesVar}}) | |
948 | if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$") | |
949 | get_filename_component(_frameworkDir "${_include}" DIRECTORY) | |
950 | list (APPEND _frameworkDirs "${_frameworkDir}") | |
951 | endif() | |
952 | endforeach() | |
953 | set (_systemFrameworkDirs "") | |
954 | foreach (_include ${${_systemIncludesVar}}) | |
955 | if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$") | |
956 | get_filename_component(_frameworkDir "${_include}" DIRECTORY) | |
957 | list (APPEND _systemFrameworkDirs "${_frameworkDir}") | |
958 | endif() | |
959 | endforeach() | |
960 | if (_systemFrameworkDirs) | |
961 | list (APPEND _frameworkDirs ${_systemFrameworkDirs}) | |
962 | endif() | |
963 | if (_frameworkDirs) | |
964 | list (REMOVE_DUPLICATES _frameworkDirs) | |
965 | foreach (_frameworkDir ${_frameworkDirs}) | |
966 | set (_index -1) | |
967 | if ("${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}" MATCHES ".+") | |
968 | list (FIND _systemFrameworkDirs "${_frameworkDir}" _index) | |
969 | endif() | |
970 | if (_index GREATER -1) | |
971 | list (APPEND ${_cmdVar} "${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}") | |
972 | else() | |
973 | list (APPEND ${_cmdVar} "${CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}") | |
974 | endif() | |
975 | endforeach() | |
976 | endif() | |
977 | endif() | |
978 | set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE) | |
979 | endfunction() | |
980 | ||
981 | macro (cotire_add_compile_flags_to_cmd _cmdVar) | |
982 | foreach (_flag ${ARGN}) | |
983 | list (APPEND ${_cmdVar} "${_flag}") | |
984 | endforeach() | |
985 | endmacro() | |
986 | ||
987 | function (cotire_check_file_up_to_date _fileIsUpToDateVar _file) | |
988 | if (EXISTS "${_file}") | |
989 | set (_triggerFile "") | |
990 | foreach (_dependencyFile ${ARGN}) | |
991 | if (EXISTS "${_dependencyFile}") | |
992 | # IS_NEWER_THAN returns TRUE if both files have the same timestamp | |
993 | # thus we do the comparison in both directions to exclude ties | |
994 | if ("${_dependencyFile}" IS_NEWER_THAN "${_file}" AND | |
995 | NOT "${_file}" IS_NEWER_THAN "${_dependencyFile}") | |
996 | set (_triggerFile "${_dependencyFile}") | |
997 | break() | |
998 | endif() | |
999 | endif() | |
1000 | endforeach() | |
1001 | if (_triggerFile) | |
1002 | if (COTIRE_VERBOSE) | |
1003 | get_filename_component(_fileName "${_file}" NAME) | |
1004 | message (STATUS "${_fileName} update triggered by ${_triggerFile} change.") | |
1005 | endif() | |
1006 | set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE) | |
1007 | else() | |
1008 | if (COTIRE_VERBOSE) | |
1009 | get_filename_component(_fileName "${_file}" NAME) | |
1010 | message (STATUS "${_fileName} is up-to-date.") | |
1011 | endif() | |
1012 | set (${_fileIsUpToDateVar} TRUE PARENT_SCOPE) | |
1013 | endif() | |
1014 | else() | |
1015 | if (COTIRE_VERBOSE) | |
1016 | get_filename_component(_fileName "${_file}" NAME) | |
1017 | message (STATUS "${_fileName} does not exist yet.") | |
1018 | endif() | |
1019 | set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE) | |
1020 | endif() | |
1021 | endfunction() | |
1022 | ||
1023 | macro (cotire_find_closest_relative_path _headerFile _includeDirs _relPathVar) | |
1024 | set (${_relPathVar} "") | |
1025 | foreach (_includeDir ${_includeDirs}) | |
1026 | if (IS_DIRECTORY "${_includeDir}") | |
1027 | file (RELATIVE_PATH _relPath "${_includeDir}" "${_headerFile}") | |
1028 | if (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.") | |
1029 | string (LENGTH "${${_relPathVar}}" _closestLen) | |
1030 | string (LENGTH "${_relPath}" _relLen) | |
1031 | if (_closestLen EQUAL 0 OR _relLen LESS _closestLen) | |
1032 | set (${_relPathVar} "${_relPath}") | |
1033 | endif() | |
1034 | endif() | |
1035 | elseif ("${_includeDir}" STREQUAL "${_headerFile}") | |
1036 | # if path matches exactly, return short non-empty string | |
1037 | set (${_relPathVar} "1") | |
1038 | break() | |
1039 | endif() | |
1040 | endforeach() | |
1041 | endmacro() | |
1042 | ||
1043 | macro (cotire_check_header_file_location _headerFile _insideIncludeDirs _outsideIncludeDirs _headerIsInside) | |
1044 | # check header path against ignored and honored include directories | |
1045 | cotire_find_closest_relative_path("${_headerFile}" "${_insideIncludeDirs}" _insideRelPath) | |
1046 | if (_insideRelPath) | |
1047 | # header is inside, but could be become outside if there is a shorter outside match | |
1048 | cotire_find_closest_relative_path("${_headerFile}" "${_outsideIncludeDirs}" _outsideRelPath) | |
1049 | if (_outsideRelPath) | |
1050 | string (LENGTH "${_insideRelPath}" _insideRelPathLen) | |
1051 | string (LENGTH "${_outsideRelPath}" _outsideRelPathLen) | |
1052 | if (_outsideRelPathLen LESS _insideRelPathLen) | |
1053 | set (${_headerIsInside} FALSE) | |
1054 | else() | |
1055 | set (${_headerIsInside} TRUE) | |
1056 | endif() | |
1057 | else() | |
1058 | set (${_headerIsInside} TRUE) | |
1059 | endif() | |
1060 | else() | |
1061 | # header is outside | |
1062 | set (${_headerIsInside} FALSE) | |
1063 | endif() | |
1064 | endmacro() | |
1065 | ||
1066 | macro (cotire_check_ignore_header_file_path _headerFile _headerIsIgnoredVar) | |
1067 | if (NOT EXISTS "${_headerFile}") | |
1068 | set (${_headerIsIgnoredVar} TRUE) | |
1069 | elseif (IS_DIRECTORY "${_headerFile}") | |
1070 | set (${_headerIsIgnoredVar} TRUE) | |
1071 | elseif ("${_headerFile}" MATCHES "\\.\\.|[_-]fixed" AND "${_headerFile}" MATCHES "\\.h$") | |
1072 | # heuristic: ignore C headers with embedded parent directory references or "-fixed" or "_fixed" in path | |
1073 | # these often stem from using GCC #include_next tricks, which may break the precompiled header compilation | |
1074 | # with the error message "error: no include path in which to search for header.h" | |
1075 | set (${_headerIsIgnoredVar} TRUE) | |
1076 | else() | |
1077 | set (${_headerIsIgnoredVar} FALSE) | |
1078 | endif() | |
1079 | endmacro() | |
1080 | ||
1081 | macro (cotire_check_ignore_header_file_ext _headerFile _ignoreExtensionsVar _headerIsIgnoredVar) | |
1082 | # check header file extension | |
1083 | cotire_get_source_file_extension("${_headerFile}" _headerFileExt) | |
1084 | set (${_headerIsIgnoredVar} FALSE) | |
1085 | if (_headerFileExt) | |
1086 | list (FIND ${_ignoreExtensionsVar} "${_headerFileExt}" _index) | |
1087 | if (_index GREATER -1) | |
1088 | set (${_headerIsIgnoredVar} TRUE) | |
1089 | endif() | |
1090 | endif() | |
1091 | endmacro() | |
1092 | ||
1093 | macro (cotire_parse_line _line _headerFileVar _headerDepthVar) | |
1094 | if (MSVC) | |
1095 | # cl.exe /showIncludes produces different output, depending on the language pack used, e.g.: | |
1096 | # English: "Note: including file: C:\directory\file" | |
1097 | # German: "Hinweis: Einlesen der Datei: C:\directory\file" | |
1098 | # We use a very general regular expression, relying on the presence of the : characters | |
1099 | if (_line MATCHES "( +)([a-zA-Z]:[^:]+)$") | |
1100 | string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar}) | |
1101 | get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" ABSOLUTE) | |
1102 | else() | |
1103 | set (${_headerFileVar} "") | |
1104 | set (${_headerDepthVar} 0) | |
1105 | endif() | |
1106 | else() | |
1107 | if (_line MATCHES "^(\\.+) (.*)$") | |
1108 | # GCC like output | |
1109 | string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar}) | |
1110 | if (IS_ABSOLUTE "${CMAKE_MATCH_2}") | |
1111 | set (${_headerFileVar} "${CMAKE_MATCH_2}") | |
1112 | else() | |
1113 | get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" REALPATH) | |
1114 | endif() | |
1115 | else() | |
1116 | set (${_headerFileVar} "") | |
1117 | set (${_headerDepthVar} 0) | |
1118 | endif() | |
1119 | endif() | |
1120 | endmacro() | |
1121 | ||
1122 | function (cotire_parse_includes _language _scanOutput _ignoredIncludeDirs _honoredIncludeDirs _ignoredExtensions _selectedIncludesVar _unparsedLinesVar) | |
1123 | if (WIN32) | |
1124 | # prevent CMake macro invocation errors due to backslash characters in Windows paths | |
1125 | string (REPLACE "\\" "/" _scanOutput "${_scanOutput}") | |
1126 | endif() | |
1127 | # canonize slashes | |
1128 | string (REPLACE "//" "/" _scanOutput "${_scanOutput}") | |
1129 | # prevent semicolon from being interpreted as a line separator | |
1130 | string (REPLACE ";" "\\;" _scanOutput "${_scanOutput}") | |
1131 | # then separate lines | |
1132 | string (REGEX REPLACE "\n" ";" _scanOutput "${_scanOutput}") | |
1133 | list (LENGTH _scanOutput _len) | |
1134 | # remove duplicate lines to speed up parsing | |
1135 | list (REMOVE_DUPLICATES _scanOutput) | |
1136 | list (LENGTH _scanOutput _uniqueLen) | |
1137 | if (COTIRE_VERBOSE OR COTIRE_DEBUG) | |
1138 | message (STATUS "Scanning ${_uniqueLen} unique lines of ${_len} for includes") | |
1139 | if (_ignoredExtensions) | |
1140 | message (STATUS "Ignored extensions: ${_ignoredExtensions}") | |
1141 | endif() | |
1142 | if (_ignoredIncludeDirs) | |
1143 | message (STATUS "Ignored paths: ${_ignoredIncludeDirs}") | |
1144 | endif() | |
1145 | if (_honoredIncludeDirs) | |
1146 | message (STATUS "Included paths: ${_honoredIncludeDirs}") | |
1147 | endif() | |
1148 | endif() | |
1149 | set (_sourceFiles ${ARGN}) | |
1150 | set (_selectedIncludes "") | |
1151 | set (_unparsedLines "") | |
1152 | # stack keeps track of inside/outside project status of processed header files | |
1153 | set (_headerIsInsideStack "") | |
1154 | foreach (_line IN LISTS _scanOutput) | |
1155 | if (_line) | |
1156 | cotire_parse_line("${_line}" _headerFile _headerDepth) | |
1157 | if (_headerFile) | |
1158 | cotire_check_header_file_location("${_headerFile}" "${_ignoredIncludeDirs}" "${_honoredIncludeDirs}" _headerIsInside) | |
1159 | if (COTIRE_DEBUG) | |
1160 | message (STATUS "${_headerDepth}: ${_headerFile} ${_headerIsInside}") | |
1161 | endif() | |
1162 | # update stack | |
1163 | list (LENGTH _headerIsInsideStack _stackLen) | |
1164 | if (_headerDepth GREATER _stackLen) | |
1165 | math (EXPR _stackLen "${_stackLen} + 1") | |
1166 | foreach (_index RANGE ${_stackLen} ${_headerDepth}) | |
1167 | list (APPEND _headerIsInsideStack ${_headerIsInside}) | |
1168 | endforeach() | |
1169 | else() | |
1170 | foreach (_index RANGE ${_headerDepth} ${_stackLen}) | |
1171 | list (REMOVE_AT _headerIsInsideStack -1) | |
1172 | endforeach() | |
1173 | list (APPEND _headerIsInsideStack ${_headerIsInside}) | |
1174 | endif() | |
1175 | if (COTIRE_DEBUG) | |
1176 | message (STATUS "${_headerIsInsideStack}") | |
1177 | endif() | |
1178 | # header is a candidate if it is outside project | |
1179 | if (NOT _headerIsInside) | |
1180 | # get parent header file's inside/outside status | |
1181 | if (_headerDepth GREATER 1) | |
1182 | math (EXPR _index "${_headerDepth} - 2") | |
1183 | list (GET _headerIsInsideStack ${_index} _parentHeaderIsInside) | |
1184 | else() | |
1185 | set (_parentHeaderIsInside TRUE) | |
1186 | endif() | |
1187 | # select header file if parent header file is inside project | |
1188 | # (e.g., a project header file that includes a standard header file) | |
1189 | if (_parentHeaderIsInside) | |
1190 | cotire_check_ignore_header_file_path("${_headerFile}" _headerIsIgnored) | |
1191 | if (NOT _headerIsIgnored) | |
1192 | cotire_check_ignore_header_file_ext("${_headerFile}" _ignoredExtensions _headerIsIgnored) | |
1193 | if (NOT _headerIsIgnored) | |
1194 | list (APPEND _selectedIncludes "${_headerFile}") | |
1195 | else() | |
1196 | # fix header's inside status on stack, it is ignored by extension now | |
1197 | list (REMOVE_AT _headerIsInsideStack -1) | |
1198 | list (APPEND _headerIsInsideStack TRUE) | |
1199 | endif() | |
1200 | endif() | |
1201 | if (COTIRE_DEBUG) | |
1202 | message (STATUS "${_headerFile} ${_ignoredExtensions} ${_headerIsIgnored}") | |
1203 | endif() | |
1204 | endif() | |
1205 | endif() | |
1206 | else() | |
1207 | if (MSVC) | |
1208 | # for cl.exe do not keep unparsed lines which solely consist of a source file name | |
1209 | string (FIND "${_sourceFiles}" "${_line}" _index) | |
1210 | if (_index LESS 0) | |
1211 | list (APPEND _unparsedLines "${_line}") | |
1212 | endif() | |
1213 | else() | |
1214 | list (APPEND _unparsedLines "${_line}") | |
1215 | endif() | |
1216 | endif() | |
1217 | endif() | |
1218 | endforeach() | |
1219 | list (REMOVE_DUPLICATES _selectedIncludes) | |
1220 | set (${_selectedIncludesVar} ${_selectedIncludes} PARENT_SCOPE) | |
1221 | set (${_unparsedLinesVar} ${_unparsedLines} PARENT_SCOPE) | |
1222 | endfunction() | |
1223 | ||
1224 | function (cotire_scan_includes _includesVar) | |
1225 | set(_options "") | |
1226 | set(_oneValueArgs COMPILER_ID COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_VERSION LANGUAGE UNPARSED_LINES SCAN_RESULT) | |
1227 | set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES | |
1228 | IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER) | |
1229 | cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) | |
1230 | set (_sourceFiles ${_option_UNPARSED_ARGUMENTS}) | |
1231 | if (NOT _option_LANGUAGE) | |
1232 | set (_option_LANGUAGE "CXX") | |
1233 | endif() | |
1234 | if (NOT _option_COMPILER_ID) | |
1235 | set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}") | |
1236 | endif() | |
1237 | if (NOT _option_COMPILER_VERSION) | |
1238 | set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}") | |
1239 | endif() | |
1240 | cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}") | |
1241 | cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS}) | |
1242 | cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS}) | |
1243 | cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES) | |
1244 | cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES) | |
1245 | cotire_add_makedep_flags("${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}" _cmd) | |
1246 | # only consider existing source files for scanning | |
1247 | set (_existingSourceFiles "") | |
1248 | foreach (_sourceFile ${_sourceFiles}) | |
1249 | if (EXISTS "${_sourceFile}") | |
1250 | list (APPEND _existingSourceFiles "${_sourceFile}") | |
1251 | endif() | |
1252 | endforeach() | |
1253 | if (NOT _existingSourceFiles) | |
1254 | set (${_includesVar} "" PARENT_SCOPE) | |
1255 | return() | |
1256 | endif() | |
1257 | # add source files to be scanned | |
1258 | if (WIN32) | |
1259 | foreach (_sourceFile ${_existingSourceFiles}) | |
1260 | file (TO_NATIVE_PATH "${_sourceFile}" _sourceFileNative) | |
1261 | list (APPEND _cmd "${_sourceFileNative}") | |
1262 | endforeach() | |
1263 | else() | |
1264 | list (APPEND _cmd ${_existingSourceFiles}) | |
1265 | endif() | |
1266 | if (COTIRE_VERBOSE) | |
1267 | message (STATUS "execute_process: ${_cmd}") | |
1268 | endif() | |
1269 | if (MSVC_IDE OR _option_COMPILER_ID MATCHES "MSVC") | |
1270 | # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared | |
1271 | unset (ENV{VS_UNICODE_OUTPUT}) | |
1272 |