diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-10-17 09:47:29 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2014-04-07 14:48:44 (GMT) |
commit | faeddf64f21b592a5663803ca8accdf9f4b73c29 (patch) | |
tree | 532605f328c1297d89a84999c1fe93a25378cfde /Modules/Internal | |
parent | 913394af249d6b1892a6e609d2abfed001fa1dc4 (diff) | |
download | CMake-faeddf64f21b592a5663803ca8accdf9f4b73c29.zip CMake-faeddf64f21b592a5663803ca8accdf9f4b73c29.tar.gz CMake-faeddf64f21b592a5663803ca8accdf9f4b73c29.tar.bz2 |
project: Add infrastructure for recording CXX compiler features
Add a feature test using the compiler macros and the preprocessor to
determine available features.
Add a CMAKE_CXX_COMPILE_FEATURES variable which contains all features
known to the loaded compiler, and a CMAKE_CXX_KNOWN_FEATURES variable
containing all features known to CMake. Add language standard specific
variables for internal use to determine the standard-specific compile
flags to use.
This will be extended to other languages in the future. Follow-up
commits will add features which will be recorded by the feature test.
Diffstat (limited to 'Modules/Internal')
-rw-r--r-- | Modules/Internal/FeatureTesting.cmake | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake new file mode 100644 index 0000000..92d262c --- /dev/null +++ b/Modules/Internal/FeatureTesting.cmake @@ -0,0 +1,57 @@ + +macro(record_compiler_features lang compile_flags feature_list) + include("${CMAKE_ROOT}/Modules/Compiler/${CMAKE_${lang}_COMPILER_ID}-${lang}-FeatureTests.cmake" OPTIONAL) + + string(TOLOWER ${lang} lang_lc) + file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin") + file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" " + extern const char features[] = {\"\"\n") + foreach(feature ${CMAKE_${lang}_KNOWN_FEATURES}) + if (_cmake_feature_test_${feature}) + if (${_cmake_feature_test_${feature}} STREQUAL 1) + set(_feature_condition "\"1\" ") + else() + set(_feature_condition "#if ${_cmake_feature_test_${feature}}\n\"1\"\n#else\n\"0\"\n#endif\n") + endif() + file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n") + endif() + endforeach() + file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" + "\n};\n\nint main(int, char **) { return 0; }\n") + + try_compile(CMAKE_${lang}_FEATURE_TEST + ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" + COMPILE_DEFINITIONS "${compile_flags}" + OUTPUT_VARIABLE _output + COPY_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin" + COPY_FILE_ERROR _copy_error + ) + if(CMAKE_${lang}_FEATURE_TEST AND NOT _copy_error) + set(_result 0) + else() + set(_result 255) + endif() + unset(CMAKE_${lang}_FEATURE_TEST CACHE) + + if (_result EQUAL 0) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "\n\nDetecting ${lang} [${compile_flags}] compiler features compiled with the following output:\n${_output}\n\n") + if(EXISTS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin") + file(STRINGS "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin" + features REGEX "${lang}_FEATURE:.*") + foreach(info ${features}) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + " Feature record: ${info}\n") + string(REPLACE "${lang}_FEATURE:" "" info ${info}) + string(SUBSTRING ${info} 0 1 has_feature) + if(has_feature) + string(REGEX REPLACE "^1" "" feature ${info}) + list(APPEND ${feature_list} ${feature}) + endif() + endforeach() + endif() + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Detecting ${lang} [${compile_flags}] compiler features failed to compile with the following output:\n${_output}\n${_copy_error}\n\n") + endif() +endmacro() |