From b0996a3fa223370edcdb40a1d8b66d1a3a734daf Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 26 Oct 2016 16:11:01 -0400 Subject: Features: Add meta-features requesting awareness of a particular standard A common use case of `target_compile_features` is simply to specify that the compiler should be run in a mode that is aware of e.g. C++11. Some projects simply specify a particular C++11-only feature to request this. Provide a first-class way to do this by naming features after the corresponding language standard. Record them as always available in the corresponding standard level so that requesting them always ensures that standard (or higher) is used. --- Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst | 9 +++++++++ Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst | 9 +++++++++ Modules/Compiler/MSVC-CXX.cmake | 5 +++++ Modules/Internal/FeatureTesting.cmake | 2 ++ Source/cmake.h | 6 ++++++ Tests/CompileFeatures/CMakeLists.txt | 2 ++ 6 files changed, 33 insertions(+) diff --git a/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst index e8f4d2a..00a5104 100644 --- a/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst +++ b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst @@ -14,6 +14,15 @@ compile features and a list of supported compilers. The features known to this version of CMake are: +``cxx_std_98`` + Compiler mode is aware of C++ 98. + +``cxx_std_11`` + Compiler mode is aware of C++ 11. + +``cxx_std_14`` + Compiler mode is aware of C++ 14. + ``cxx_aggregate_default_initializers`` Aggregate default initializers, as defined in N3605_. diff --git a/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst b/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst index a08af00..3707fef 100644 --- a/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst +++ b/Help/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst @@ -13,6 +13,15 @@ compile features and a list of supported compilers. The features known to this version of CMake are: +``c_std_90`` + Compiler mode is aware of C 90. + +``c_std_99`` + Compiler mode is aware of C 99. + +``c_std_11`` + Compiler mode is aware of C 11. + ``c_function_prototypes`` Function prototypes, as defined in ``ISO/IEC 9899:1990``. diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake index 82f15bd..f103832 100644 --- a/Modules/Compiler/MSVC-CXX.cmake +++ b/Modules/Compiler/MSVC-CXX.cmake @@ -6,6 +6,11 @@ endif() macro(cmake_record_cxx_compile_features) if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) + list(APPEND CMAKE_CXX_COMPILE_FEATURES + cxx_std_98 + cxx_std_11 + cxx_std_14 + ) _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES) endif() endmacro() diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake index e94246e..50b8526 100644 --- a/Modules/Internal/FeatureTesting.cmake +++ b/Modules/Internal/FeatureTesting.cmake @@ -60,9 +60,11 @@ macro(_record_compiler_features lang compile_flags feature_list) endmacro() macro(_record_compiler_features_c std) + list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std}) _record_compiler_features(C "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES) endmacro() macro(_record_compiler_features_cxx std) + list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std}) _record_compiler_features(CXX "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES) endmacro() diff --git a/Source/cmake.h b/Source/cmake.h index cd00c61..6e8d9c8 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -535,12 +535,18 @@ private: } #define FOR_EACH_C_FEATURE(F) \ + F(c_std_90) \ + F(c_std_99) \ + F(c_std_11) \ F(c_function_prototypes) \ F(c_restrict) \ F(c_static_assert) \ F(c_variadic_macros) #define FOR_EACH_CXX_FEATURE(F) \ + F(cxx_std_98) \ + F(cxx_std_11) \ + F(cxx_std_14) \ F(cxx_aggregate_default_initializers) \ F(cxx_alias_templates) \ F(cxx_alignas) \ diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 9f08523..9986de0 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -23,10 +23,12 @@ macro(run_test feature lang) endmacro() get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES) +list(REMOVE_ITEM c_features c_std_90 c_std_99 c_std_11) foreach(feature ${c_features}) run_test(${feature} C) endforeach() get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES) +list(REMOVE_ITEM cxx_features cxx_std_98 cxx_std_11 cxx_std_14) foreach(feature ${cxx_features}) run_test(${feature} CXX) endforeach() -- cgit v0.12