2 macro(_record_compiler_features lang compile_flags feature_list)
3 include("${CMAKE_ROOT}/Modules/Compiler/${CMAKE_${lang}_COMPILER_ID}-${lang}-FeatureTests.cmake" OPTIONAL)
5 string(TOLOWER ${lang} lang_lc)
6 file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
8 const char features[] = {\"\\n\"\n")
10 get_property(known_features GLOBAL PROPERTY CMAKE_${lang}_KNOWN_FEATURES)
12 foreach(feature ${known_features})
13 if (_cmake_feature_test_${feature})
14 if (${_cmake_feature_test_${feature}} STREQUAL 1)
15 set(_feature_condition "\"1\" ")
17 set(_feature_condition "#if ${_cmake_feature_test_${feature}}\n\"1\"\n#else\n\"0\"\n#endif\n")
19 string(APPEND _content
20 "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n")
23 string(APPEND _content
24 "\n};\n\nint main(int argc, char** argv) { (void)argv; return features[argc]; }\n")
26 if(CMAKE_${lang}_LINK_WITH_STANDARD_COMPILE_OPTION)
27 # This toolchain requires use of the language standard flag
28 # when linking in order to use the matching standard library.
29 set(compile_flags_for_link "${compile_flags}")
31 set(compile_flags_for_link "")
34 try_compile(CMAKE_${lang}_FEATURE_TEST
35 SOURCE_FROM_VAR "feature_tests.${lang_lc}" _content
36 COMPILE_DEFINITIONS "${compile_flags}"
37 LINK_LIBRARIES "${compile_flags_for_link}"
38 OUTPUT_VARIABLE _output
39 COPY_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
40 COPY_FILE_ERROR _copy_error
42 if(CMAKE_${lang}_FEATURE_TEST AND NOT _copy_error)
47 unset(CMAKE_${lang}_FEATURE_TEST CACHE)
48 unset(compile_flags_for_link)
51 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
52 "\n\nDetecting ${lang} [${compile_flags}] compiler features compiled with the following output:\n${_output}\n\n")
53 if(EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
54 file(STRINGS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin"
55 features REGEX "${lang}_FEATURE:.*")
56 foreach(info ${features})
57 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
58 " Feature record: ${info}\n")
59 string(REPLACE "${lang}_FEATURE:" "" info ${info})
60 string(SUBSTRING ${info} 0 1 has_feature)
62 string(REGEX REPLACE "^1" "" feature ${info})
63 list(APPEND ${feature_list} ${feature})
68 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
69 "Detecting ${lang} [${compile_flags}] compiler features failed to compile with the following output:\n${_output}\n${_copy_error}\n\n")
73 macro(_record_compiler_features_c std)
74 list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std})
76 get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_C${std}_KNOWN_FEATURES)
77 if(lang_level_has_features)
78 _record_compiler_features(C "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
80 unset(lang_level_has_features)
83 macro(_record_compiler_features_cxx std)
84 list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std})
86 get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_CXX${std}_KNOWN_FEATURES)
87 if(lang_level_has_features)
88 _record_compiler_features(CXX "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
90 unset(lang_level_has_features)
93 macro(_record_compiler_features_cuda std)
94 list(APPEND CMAKE_CUDA${std}_COMPILE_FEATURES cuda_std_${std})
96 get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_CUDA${std}_KNOWN_FEATURES)
97 if(lang_level_has_features)
98 _record_compiler_features(CUDA "${CMAKE_CUDA${std}_STANDARD_COMPILE_OPTION}" CMAKE_CUDA${std}_COMPILE_FEATURES)
100 unset(lang_level_has_features)
103 macro(_record_compiler_features_hip std)
104 list(APPEND CMAKE_HIP${std}_COMPILE_FEATURES hip_std_${std})
106 get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_HIP${std}_KNOWN_FEATURES)
107 if(lang_level_has_features)
108 _record_compiler_features(HIP "${CMAKE_HIP${std}_STANDARD_COMPILE_OPTION}" CMAKE_HIP${std}_COMPILE_FEATURES)
110 unset(lang_level_has_features)
113 macro(_has_compiler_features lang level compile_flags feature_list)
114 # presume all known features are supported
115 get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES)
116 list(APPEND ${feature_list} ${known_features})
119 macro(_has_compiler_features_c std)
120 list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std})
121 _has_compiler_features(C ${std} "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
123 macro(_has_compiler_features_cxx std)
124 list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std})
125 _has_compiler_features(CXX ${std} "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
127 macro(_has_compiler_features_cuda std)
128 list(APPEND CMAKE_CUDA${std}_COMPILE_FEATURES cuda_std_${std})
129 _has_compiler_features(CUDA ${std} "${CMAKE_CUDA${std}_STANDARD_COMPILE_OPTION}" CMAKE_CUDA${std}_COMPILE_FEATURES)
131 macro(_has_compiler_features_hip std)
132 list(APPEND CMAKE_HIP${std}_COMPILE_FEATURES hip_std_${std})
133 _has_compiler_features(HIP ${std} "${CMAKE_HIP${std}_STANDARD_COMPILE_OPTION}" CMAKE_HIP${std}_COMPILE_FEATURES)