From f5bf9d431166250257d4ff2716f74668b1fce16b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 21 Oct 2013 16:59:40 +0200 Subject: [PATCH 1/6] Tests: Make CompileFeature tests use highest standard known. Remove the use of check_cxx_source_compiles which is now just getting in the way. Blacklist the cxx_alignof feature in the test with GNU 4.7. The test file compiles, but it is documented as available first in GNU 4.8. --- Modules/Compiler/GNU-CXX-FeatureTests.cmake | 2 ++ Tests/CompileFeatures/CMakeLists.txt | 22 ++++++++++++++++++--- Tests/CompileFeatures/feature_test.cpp | 10 ++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 Tests/CompileFeatures/feature_test.cpp diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake index 5edb69ec1..0694927d9 100644 --- a/Modules/Compiler/GNU-CXX-FeatureTests.cmake +++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake @@ -8,6 +8,8 @@ set(_cmake_feature_test_cxx_decltype_incomplete_return_types "${GNU481_CXX11}") set(_cmake_feature_test_cxx_reference_qualified_functions "${GNU481_CXX11}") set(GNU48_CXX11 "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L") set(_cmake_feature_test_cxx_alignas "${GNU48_CXX11}") +# The alignof feature works with GNU 4.7 and -std=c++11, but it is documented +# as available with GNU 4.8, so treat that as true. set(_cmake_feature_test_cxx_alignof "${GNU48_CXX11}") set(_cmake_feature_test_cxx_attributes "${GNU48_CXX11}") set(_cmake_feature_test_cxx_inheriting_constructors "${GNU48_CXX11}") diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 274c5ba0c..925f75780 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -27,13 +27,29 @@ foreach(feature ${cxx_features}) run_test(${feature} CXX) endforeach() +if (CMAKE_CXX_COMPILER_ID STREQUAL GNU + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + list(REMOVE_ITEM CXX_non_features + cxx_alignof + ) +endif() + if (CMAKE_CXX_COMPILE_FEATURES) - include(CheckCXXSourceCompiles) foreach(feature ${CXX_non_features}) - check_cxx_source_compiles("#include \"${CMAKE_CURRENT_SOURCE_DIR}/${feature}.cpp\"\nint main() { return 0; }\n" ${feature}_works) + message("Testing feature : ${feature}") + try_compile(${feature}_works + "${CMAKE_CURRENT_BINARY_DIR}/${feature}_test" + "${CMAKE_CURRENT_SOURCE_DIR}/feature_test.cpp" + COMPILE_DEFINITIONS "-DTEST=${CMAKE_CURRENT_SOURCE_DIR}/${feature}.cpp" + CMAKE_FLAGS "-DCMAKE_CXX_STANDARD=11" + OUTPUT_VARIABLE OUTPUT + ) if (${feature}_works) message(SEND_ERROR - "Feature ${feature} expected not to work for ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}. Update the supported features or blacklist it.") + "Feature ${feature} expected not to work for ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}. +Update the supported features or blacklist it.\n${OUTPUT}") + else() + message("Testing feature : ${feature} -- Fails, as expected.") endif() endforeach() endif() diff --git a/Tests/CompileFeatures/feature_test.cpp b/Tests/CompileFeatures/feature_test.cpp new file mode 100644 index 000000000..4406c16e2 --- /dev/null +++ b/Tests/CompileFeatures/feature_test.cpp @@ -0,0 +1,10 @@ + +#define STRINGIFY_IMPL(X) #X +#define STRINGIFY(X) STRINGIFY_IMPL(X) + +#include STRINGIFY(TEST) + +int main() +{ + return 0; +} From 6a9fdbeb48eb16a0f7082329f0d0840bf0c0a98c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 9 May 2014 17:27:55 +0200 Subject: [PATCH 2/6] Test: Parameterize the language in the CompileFeature test. --- Tests/CompileFeatures/CMakeLists.txt | 42 +++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 925f75780..adf50d54e 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -34,25 +34,29 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL GNU ) endif() -if (CMAKE_CXX_COMPILE_FEATURES) - foreach(feature ${CXX_non_features}) - message("Testing feature : ${feature}") - try_compile(${feature}_works - "${CMAKE_CURRENT_BINARY_DIR}/${feature}_test" - "${CMAKE_CURRENT_SOURCE_DIR}/feature_test.cpp" - COMPILE_DEFINITIONS "-DTEST=${CMAKE_CURRENT_SOURCE_DIR}/${feature}.cpp" - CMAKE_FLAGS "-DCMAKE_CXX_STANDARD=11" - OUTPUT_VARIABLE OUTPUT - ) - if (${feature}_works) - message(SEND_ERROR - "Feature ${feature} expected not to work for ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}. -Update the supported features or blacklist it.\n${OUTPUT}") - else() - message("Testing feature : ${feature} -- Fails, as expected.") - endif() - endforeach() -endif() +set(CXX_ext cpp) +set(CXX_standard_flag 11) +foreach(lang CXX) + if (CMAKE_${lang}_COMPILE_FEATURES) + foreach(feature ${${lang}_non_features}) + message("Testing feature : ${feature}") + try_compile(${feature}_works + "${CMAKE_CURRENT_BINARY_DIR}/${feature}_test" + "${CMAKE_CURRENT_SOURCE_DIR}/feature_test.${${lang}_ext}" + COMPILE_DEFINITIONS "-DTEST=${CMAKE_CURRENT_SOURCE_DIR}/${feature}.${${lang}_ext}" + CMAKE_FLAGS "-DCMAKE_${lang}_STANDARD=${${lang}_standard_flag}" + OUTPUT_VARIABLE OUTPUT + ) + if (${feature}_works) + message(SEND_ERROR + "Feature ${feature} expected not to work for ${lang} ${CMAKE_${lang}_COMPILER_ID}-${CMAKE_${lang}_COMPILER_VERSION}. + Update the supported features or blacklist it.\n${OUTPUT}") + else() + message("Testing feature : ${feature} -- Fails, as expected.") + endif() + endforeach() + endif() +endforeach() add_executable(CompileFeatures main.cpp) set_property(TARGET CompileFeatures From 5109b0428d0145da4b71464f6c2aa51aca19cb52 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 10 May 2014 08:58:49 +0200 Subject: [PATCH 3/6] Features: Fix GNU 4.8.1 version test. --- Modules/Compiler/GNU-CXX-FeatureTests.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake index 0694927d9..64ddc59d7 100644 --- a/Modules/Compiler/GNU-CXX-FeatureTests.cmake +++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake @@ -3,7 +3,7 @@ set(_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407") # Introduced in GCC 4.8.1 -set(GNU481_CXX11 "((__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __GNUC_PATCHLEVEL__ >= 1) && __cplusplus >= 201103L") +set(GNU481_CXX11 "((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40801) && __cplusplus >= 201103L") set(_cmake_feature_test_cxx_decltype_incomplete_return_types "${GNU481_CXX11}") set(_cmake_feature_test_cxx_reference_qualified_functions "${GNU481_CXX11}") set(GNU48_CXX11 "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L") From e2f09aff12fe0188c032f814aeb5f8f8bd577246 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 10 May 2014 09:07:05 +0200 Subject: [PATCH 4/6] CMakeConfigurableFile: Remove excess newline. --- Modules/CMakeConfigurableFile.in | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/CMakeConfigurableFile.in b/Modules/CMakeConfigurableFile.in index 4cf74a12b..df2c382e9 100644 --- a/Modules/CMakeConfigurableFile.in +++ b/Modules/CMakeConfigurableFile.in @@ -1,2 +1 @@ @CMAKE_CONFIGURABLE_FILE_CONTENT@ - From eb638c75cc43be338391f9a12f23570e7dfcd48d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 10 May 2014 13:05:46 +0200 Subject: [PATCH 5/6] Tests: Make CompileFeatures feature list lang-specific. --- Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 6 +++--- Tests/RunCMake/CompileFeatures/generate_feature_list.cmake | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index f083751c2..bb4e0f904 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -10,11 +10,11 @@ run_cmake(NotAFeature_OriginDebug_target_compile_features) run_cmake(generate_feature_list) file(READ - "${RunCMake_BINARY_DIR}/generate_feature_list-build/features.txt" - FEATURES + "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_features.txt" + CXX_FEATURES ) -if (NOT FEATURES) +if (NOT CXX_FEATURES) run_cmake(NoSupportedCxxFeatures) run_cmake(NoSupportedCxxFeaturesGenex) endif() diff --git a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake index 06c4f739b..beb15fc89 100644 --- a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake +++ b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake @@ -1,5 +1,5 @@ -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/features.txt" +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_features.txt" "${CMAKE_CXX_COMPILE_FEATURES}" ) From bc9a8bba4660e9216f87323006d936bf6d43f799 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 10 May 2014 13:11:50 +0200 Subject: [PATCH 6/6] Makefile: Undef FEATURE_STRING iteration define after use. --- Source/cmMakefile.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 29d2fb085..90a7b0bd4 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4978,6 +4978,7 @@ static const char * const CXX_FEATURES[] = { 0 FOR_EACH_CXX_FEATURE(FEATURE_STRING) }; +#undef FEATURE_STRING static const char * const CXX_STANDARDS[] = { "98"