From f5bf9d431166250257d4ff2716f74668b1fce16b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 21 Oct 2013 16:59:40 +0200 Subject: [PATCH] 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; +}