From 0d641fcfad232a6981f587a8ee077dcf08432843 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 9 Apr 2019 08:43:14 -0400 Subject: Tests: Remove outdated portion of CompileFeatures genex test The genex part of the test verifies that `$` evaluates as expected. It does not need to actually try using code with the associated features, as that is tested separately. --- Tests/CompileFeatures/genex_test.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp index 4539789..53dce62 100644 --- a/Tests/CompileFeatures/genex_test.cpp +++ b/Tests/CompileFeatures/genex_test.cpp @@ -31,17 +31,6 @@ # if !EXPECT_OVERRIDE_CONTROL # error "Expect no override control feature" # endif - -struct A -{ - virtual int getA() { return 7; } -}; - -struct B final : A -{ - int getA() override { return 42; } -}; - #endif #if !HAVE_AUTO_TYPE -- cgit v0.12 From 646fb1a646a3b860e983f3d030dfd223c761d49f Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 27 Mar 2019 15:44:37 -0400 Subject: CompileFeatures: memoize C++ compilers with full language level support Previously compilers that had full support for a language standard level were still verified every time a new build directory was created. Now we record this information and insert the correct granular compile features instead of doing a `try_compile`. --- Modules/Compiler/CMakeCommonCompilerMacros.cmake | 35 ++++++++++++++++++++---- Modules/Internal/FeatureTesting.cmake | 4 +++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Modules/Compiler/CMakeCommonCompilerMacros.cmake b/Modules/Compiler/CMakeCommonCompilerMacros.cmake index 9c62e10..96537f8 100644 --- a/Modules/Compiler/CMakeCommonCompilerMacros.cmake +++ b/Modules/Compiler/CMakeCommonCompilerMacros.cmake @@ -94,18 +94,43 @@ endmacro() macro(cmake_record_cxx_compile_features) set(_result 0) if(_result EQUAL 0 AND DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION) - _record_compiler_features_cxx(20) + if(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT) + _has_compiler_features_cxx(20) + else() + _record_compiler_features_cxx(20) + endif() + unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT) endif() if(_result EQUAL 0 AND DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION) - _record_compiler_features_cxx(17) + if(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT) + _has_compiler_features_cxx(17) + else() + _record_compiler_features_cxx(17) + endif() + unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT) endif() if(_result EQUAL 0 AND DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION) - _record_compiler_features_cxx(14) + if(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT) + _has_compiler_features_cxx(14) + else() + _record_compiler_features_cxx(14) + endif() + unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT) endif() if(_result EQUAL 0 AND DEFINED CMAKE_CXX11_STANDARD_COMPILE_OPTION) - _record_compiler_features_cxx(11) + if(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT) + _has_compiler_features_cxx(11) + else() + _record_compiler_features_cxx(11) + endif() + unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT) endif() if(_result EQUAL 0 AND DEFINED CMAKE_CXX98_STANDARD_COMPILE_OPTION) - _record_compiler_features_cxx(98) + if(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT) + _has_compiler_features_cxx(98) + else() + _record_compiler_features_cxx(98) + endif() + unset(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT) endif() endmacro() diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake index f7b3e96..75be473 100644 --- a/Modules/Internal/FeatureTesting.cmake +++ b/Modules/Internal/FeatureTesting.cmake @@ -99,3 +99,7 @@ macro(_has_compiler_features_c std) list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std}) _has_compiler_features(C ${std} "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES) endmacro() +macro(_has_compiler_features_cxx std) + list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std}) + _has_compiler_features(CXX ${std} "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES) +endmacro() -- cgit v0.12 From b0f46c48f6e3efc0481d7c573f67cc76dfa5b2fd Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 6 Mar 2019 12:28:00 -0500 Subject: CompileFeatures: Now able to presume full language level support Previously compilers that only supported the meta-level flags would not have any of the granular features listed. Now we presume that they have full support and enable all the features. Update granular feature tests to skip the actual compilation checks for the presumed features. --- Modules/Compiler/Cray-CXX.cmake | 3 +++ Modules/Compiler/PGI-CXX.cmake | 4 ++++ Modules/Compiler/XL-CXX.cmake | 2 ++ Modules/Compiler/XLClang-CXX.cmake | 3 +++ Tests/CompileFeatures/CMakeLists.txt | 24 +++++++++++++--------- .../WriteCompilerDetectionHeader/CMakeLists.txt | 12 +++++++---- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Modules/Compiler/Cray-CXX.cmake b/Modules/Compiler/Cray-CXX.cmake index 85a3167..38c8b1e 100644 --- a/Modules/Compiler/Cray-CXX.cmake +++ b/Modules/Compiler/Cray-CXX.cmake @@ -10,13 +10,16 @@ string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG") if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1) set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -h conform) set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -h gnu) + set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.4) set(CMAKE_CXX11_STANDARD_COMPILE_OPTION -h std=c++11) set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -h std=c++11,gnu) + set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) endif() if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.6) set(CMAKE_CXX14_STANDARD_COMPILE_OPTION -h std=c++14) set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -h std=c++14,gnu) + set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) endif () endif () diff --git a/Modules/Compiler/PGI-CXX.cmake b/Modules/Compiler/PGI-CXX.cmake index 35076bb..c77de36 100644 --- a/Modules/Compiler/PGI-CXX.cmake +++ b/Modules/Compiler/PGI-CXX.cmake @@ -6,15 +6,19 @@ string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.10) set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -A) set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION --gnu_extensions) + set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.10) set(CMAKE_CXX11_STANDARD_COMPILE_OPTION --c++11 -A) set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION --c++11 --gnu_extensions) + set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.7) set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14 -A) set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION --c++14 --gnu_extensions) + set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.1) set(CMAKE_CXX17_STANDARD_COMPILE_OPTION --c++17 -A) set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION --c++17 --gnu_extensions) + set(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT ON) endif() endif() endif() diff --git a/Modules/Compiler/XL-CXX.cmake b/Modules/Compiler/XL-CXX.cmake index 0026b4a..ec3f1f8 100644 --- a/Modules/Compiler/XL-CXX.cmake +++ b/Modules/Compiler/XL-CXX.cmake @@ -16,6 +16,8 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) endif() set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") + set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) endif () __compiler_check_default_language_standard(CXX 10.1 98) diff --git a/Modules/Compiler/XLClang-CXX.cmake b/Modules/Compiler/XLClang-CXX.cmake index f535ebc..03c7c7b 100644 --- a/Modules/Compiler/XLClang-CXX.cmake +++ b/Modules/Compiler/XLClang-CXX.cmake @@ -4,13 +4,16 @@ __compiler_xlclang(CXX) if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x") set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x") + set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2) set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") + set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) endif () endif() diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 6ccdcc3..2dd8917 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -15,17 +15,21 @@ macro(run_test feature lang) endif() endmacro() -get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES) -list(FILTER c_features EXCLUDE REGEX "^c_std_[0-9][0-9]") -foreach(feature ${c_features}) - run_test(${feature} C) -endforeach() +if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$") + get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES) + list(FILTER c_features EXCLUDE REGEX "^c_std_[0-9][0-9]") + foreach(feature ${c_features}) + run_test(${feature} C) + endforeach() +endif() -get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES) -list(FILTER cxx_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]") -foreach(feature ${cxx_features}) - run_test(${feature} CXX) -endforeach() +if(NOT CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$") + get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES) + list(FILTER cxx_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]") + foreach(feature ${cxx_features}) + run_test(${feature} CXX) + endforeach() +endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index b584e16..cffef5a 100644 --- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -52,8 +52,10 @@ endmacro() # detailed features tables, not just meta-features if (CMAKE_C_COMPILE_FEATURES) - set(C_expected_features ${CMAKE_C_COMPILE_FEATURES}) - list(FILTER C_expected_features EXCLUDE REGEX "^c_std_[0-9][0-9]") + if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$") + set(C_expected_features ${CMAKE_C_COMPILE_FEATURES}) + list(FILTER C_expected_features EXCLUDE REGEX "^c_std_[0-9][0-9]") + endif() endif() if (C_expected_features) string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" COMPILER_VERSION_MAJOR "${CMAKE_C_COMPILER_VERSION}") @@ -93,8 +95,10 @@ if (C_expected_features) endif() if (CMAKE_CXX_COMPILE_FEATURES) - set(CXX_expected_features ${CMAKE_CXX_COMPILE_FEATURES}) - list(FILTER CXX_expected_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]") + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$") + set(CXX_expected_features ${CMAKE_CXX_COMPILE_FEATURES}) + list(FILTER CXX_expected_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]") + endif() endif() if (NOT CXX_expected_features) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" -- cgit v0.12 From 613ac56e508be666e2b6fcf42a6502055bf0764c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 5 Mar 2019 15:25:24 -0500 Subject: Add a test to verify meta-feature parity with granular features --- Tests/RunCMake/CMakeLists.txt | 3 +++ Tests/RunCMake/MetaCompileFeatures/C.cmake | 27 ++++++++++++++++++++++ Tests/RunCMake/MetaCompileFeatures/CMakeLists.txt | 3 +++ Tests/RunCMake/MetaCompileFeatures/CXX.cmake | 27 ++++++++++++++++++++++ .../MetaCompileFeatures/RunCMakeTest.cmake | 4 ++++ Tests/RunCMake/MetaCompileFeatures/a.c | 0 Tests/RunCMake/MetaCompileFeatures/a.cxx | 0 7 files changed, 64 insertions(+) create mode 100644 Tests/RunCMake/MetaCompileFeatures/C.cmake create mode 100644 Tests/RunCMake/MetaCompileFeatures/CMakeLists.txt create mode 100644 Tests/RunCMake/MetaCompileFeatures/CXX.cmake create mode 100644 Tests/RunCMake/MetaCompileFeatures/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/MetaCompileFeatures/a.c create mode 100644 Tests/RunCMake/MetaCompileFeatures/a.cxx diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index afa8df7..68411d6 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -192,6 +192,9 @@ add_RunCMake_test(GoogleTest) # Note: does not actually depend on Google Test add_RunCMake_test(TargetPropertyGeneratorExpressions) add_RunCMake_test(Languages) add_RunCMake_test(LinkStatic) +if(CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$") + add_RunCMake_test(MetaCompileFeatures) +endif() add_RunCMake_test(ObjectLibrary) add_RunCMake_test(ParseImplicitIncludeInfo) if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF") diff --git a/Tests/RunCMake/MetaCompileFeatures/C.cmake b/Tests/RunCMake/MetaCompileFeatures/C.cmake new file mode 100644 index 0000000..3bb6181 --- /dev/null +++ b/Tests/RunCMake/MetaCompileFeatures/C.cmake @@ -0,0 +1,27 @@ + +enable_language(C) + +function(check_language_feature_flags lang level) + if(CMAKE_${lang}${level}_STANDARD_COMPILE_OPTION) + #this property is an internal implementation detail of CMake + get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES) + list(LENGTH known_features len) + if(len LESS 1) + message(FATAL_ERROR "unable to find known features of ${lang}${level}") + endif() + + string(TOLOWER ${lang} lang_lower) + set(known_name ${lang_lower}${level}_known_features) + set(meta_name ${lang_lower}${level}_meta_feature) + + add_library(${known_name} STATIC a.c) + target_compile_features(${known_name} PUBLIC ${known_features}) + add_library(${meta_name} STATIC a.c) + target_compile_features(${meta_name} PUBLIC ${lang_lower}_std_${level}) + endif() +endfunction() + + +check_language_feature_flags(C 90) +check_language_feature_flags(C 99) +check_language_feature_flags(C 11) diff --git a/Tests/RunCMake/MetaCompileFeatures/CMakeLists.txt b/Tests/RunCMake/MetaCompileFeatures/CMakeLists.txt new file mode 100644 index 0000000..3e470a2 --- /dev/null +++ b/Tests/RunCMake/MetaCompileFeatures/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.14) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/MetaCompileFeatures/CXX.cmake b/Tests/RunCMake/MetaCompileFeatures/CXX.cmake new file mode 100644 index 0000000..ef3b9d4 --- /dev/null +++ b/Tests/RunCMake/MetaCompileFeatures/CXX.cmake @@ -0,0 +1,27 @@ + +enable_language(CXX) + +function(check_language_feature_flags lang level) + if(CMAKE_${lang}${level}_STANDARD_COMPILE_OPTION) + #this property is an internal implementation detail of CMake + get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES) + list(LENGTH known_features len) + if(len LESS 1) + message(FATAL_ERROR "unable to find known features of ${lang}${level}") + endif() + + string(TOLOWER ${lang} lang_lower) + set(known_name ${lang_lower}${level}_known_features) + set(meta_name ${lang_lower}${level}_meta_feature) + + add_library(${known_name} STATIC a.cxx) + target_compile_features(${known_name} PUBLIC ${known_features}) + add_library(${meta_name} STATIC a.cxx) + target_compile_features(${meta_name} PUBLIC ${lang_lower}_std_${level}) + endif() +endfunction() + + +check_language_feature_flags(CXX 98) +check_language_feature_flags(CXX 11) +check_language_feature_flags(CXX 14) diff --git a/Tests/RunCMake/MetaCompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/MetaCompileFeatures/RunCMakeTest.cmake new file mode 100644 index 0000000..009cde4 --- /dev/null +++ b/Tests/RunCMake/MetaCompileFeatures/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(C) +run_cmake(CXX) diff --git a/Tests/RunCMake/MetaCompileFeatures/a.c b/Tests/RunCMake/MetaCompileFeatures/a.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/MetaCompileFeatures/a.cxx b/Tests/RunCMake/MetaCompileFeatures/a.cxx new file mode 100644 index 0000000..e69de29 -- cgit v0.12