diff options
author | Chuck Atkins <chuck.atkins@kitware.com> | 2017-05-15 18:06:29 (GMT) |
---|---|---|
committer | Chuck Atkins <chuck.atkins@kitware.com> | 2017-05-29 17:51:45 (GMT) |
commit | e556f1b909a910f7124bd26f82e4b42dd2142c17 (patch) | |
tree | 6077a5aa10d408d2b00e20b2993e5bb87cfc20c6 /Tests | |
parent | 20ffa14708e5e1b324ac954fd06a1415b9398b7c (diff) | |
download | CMake-e556f1b909a910f7124bd26f82e4b42dd2142c17.zip CMake-e556f1b909a910f7124bd26f82e4b42dd2142c17.tar.gz CMake-e556f1b909a910f7124bd26f82e4b42dd2142c17.tar.bz2 |
CompileFeatures: Makes tests work with meta-feature only
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeCommands/target_compile_features/CMakeLists.txt | 70 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_compile_features/dummy.cpp | 5 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/CompileFeatures/CMakeLists.txt | 23 | ||||
-rw-r--r-- | Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 5 |
7 files changed, 81 insertions, 42 deletions
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt index 555a08f..5096a58 100644 --- a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt @@ -1,45 +1,65 @@ cmake_minimum_required(VERSION 3.0) +cmake_policy(SET CMP0057 NEW) project(target_compile_features) -if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES) - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_dummy.cpp" - "int main(int,char**) { return 0; }\n" - ) - add_executable(target_compile_features "${CMAKE_CURRENT_BINARY_DIR}/test_dummy.cpp") - return() -endif() - set(CMAKE_VERBOSE_MAKEFILE ON) -if (CMAKE_C_COMPILE_FEATURES) - add_executable(target_compile_features main.c) - target_compile_features(target_compile_features +if (c_restrict IN_LIST CMAKE_C_COMPILE_FEATURES) + add_executable(c_target_compile_features_specific main.c) + target_compile_features(c_target_compile_features_specific PRIVATE c_restrict ) - add_library(lib_restrict lib_restrict.c) - target_compile_features(lib_restrict + add_library(c_lib_restrict_specific lib_restrict.c) + target_compile_features(c_lib_restrict_specific PUBLIC c_restrict ) - add_executable(restrict_user restrict_user.c) - target_link_libraries(restrict_user lib_restrict) + add_executable(c_restrict_user_specific restrict_user.c) + target_link_libraries(c_restrict_user_specific c_lib_restrict_specific) endif() -if (CMAKE_CXX_COMPILE_FEATURES AND ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;") - if (CMAKE_C_COMPILE_FEATURES) - set(target_suffix _cxx) - endif() - add_executable(target_compile_features${target_suffix} main.cpp) - target_compile_features(target_compile_features${target_suffix} +if (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES) + add_executable(c_target_compile_features_meta main.c) + target_compile_features(c_target_compile_features_meta + PRIVATE c_std_99 + ) + + add_library(c_lib_restrict_meta lib_restrict.c) + target_compile_features(c_lib_restrict_meta + PUBLIC c_std_99 + ) + + add_executable(c_restrict_user_meta restrict_user.c) + target_link_libraries(c_restrict_user_meta c_lib_restrict_meta) +endif() + +if (cxx_auto_type IN_LIST CMAKE_CXX_COMPILE_FEATURES) + add_executable(cxx_target_compile_features_specific main.cpp) + target_compile_features(cxx_target_compile_features_specific PRIVATE cxx_auto_type ) - add_library(lib_auto_type lib_auto_type.cpp) - target_compile_features(lib_auto_type + add_library(cxx_lib_auto_type_specific lib_auto_type.cpp) + target_compile_features(cxx_lib_auto_type_specific PUBLIC cxx_auto_type ) - add_executable(lib_user lib_user.cpp) - target_link_libraries(lib_user lib_auto_type) + add_executable(cxx_lib_user_specific lib_user.cpp) + target_link_libraries(cxx_lib_user_specific cxx_lib_auto_type_specific) +endif() + +if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES) + add_executable(cxx_target_compile_features_meta main.cpp) + target_compile_features(cxx_target_compile_features_meta + PRIVATE cxx_std_11 + ) + + add_library(cxx_lib_auto_type_meta lib_auto_type.cpp) + target_compile_features(cxx_lib_auto_type_meta + PUBLIC cxx_std_11 + ) + + add_executable(cxx_lib_user_meta lib_user.cpp) + target_link_libraries(cxx_lib_user_meta cxx_lib_auto_type_meta) endif() diff --git a/Tests/CMakeCommands/target_compile_features/dummy.cpp b/Tests/CMakeCommands/target_compile_features/dummy.cpp deleted file mode 100644 index e9ad257..0000000 --- a/Tests/CMakeCommands/target_compile_features/dummy.cpp +++ /dev/null @@ -1,5 +0,0 @@ - -int main(int, char**) -{ - return 0; -} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index cbd7906..02156e8 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -275,7 +275,7 @@ if(BUILD_TESTING) ADD_TEST_MACRO(SystemInformation SystemInformation) ADD_TEST_MACRO(MathTest MathTest) ADD_TEST_MACRO(CompileFeatures CompileFeatures) - ADD_TEST_MACRO(CMakeCommands.target_compile_features target_compile_features) + ADD_TEST_MACRO(CMakeCommands.target_compile_features) if(CMake_TEST_RESOURCES) ADD_TEST_MACRO(VSResource VSResource) diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index bb18543..4a5558d 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -1,10 +1,11 @@ cmake_minimum_required(VERSION 3.1) +cmake_policy(SET CMP0057 NEW) project(CompileFeatures) macro(run_test feature lang) - if (";${CMAKE_${lang}_COMPILE_FEATURES};" MATCHES ${feature}) + if (${feature} IN_LIST CMAKE_${lang}_COMPILE_FEATURES) add_library(test_${feature} OBJECT ${feature}) set_property(TARGET test_${feature} PROPERTY COMPILE_FEATURES "${feature}" @@ -15,12 +16,13 @@ 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) +list(FILTER c_features EXCLUDE REGEX "^c_std_[0-9][0-9]") 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 cxx_std_17) +list(FILTER cxx_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]") foreach(feature ${cxx_features}) run_test(${feature} CXX) endforeach() @@ -171,12 +173,20 @@ if (CMAKE_C_COMPILER_ID STREQUAL "Intel") endif() endif() +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]") +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]") +endif () set(C_ext c) set(C_standard_flag 11) set(CXX_ext cpp) set(CXX_standard_flag 14) foreach(lang CXX C) - if (CMAKE_${lang}_COMPILE_FEATURES) + if (${lang}_expected_features) foreach(feature ${${lang}_non_features}) message("Testing feature : ${feature}") try_compile(${feature}_works @@ -198,7 +208,7 @@ foreach(lang CXX C) endif() endforeach() -if (CMAKE_C_COMPILE_FEATURES) +if (C_expected_features) if (CMAKE_C_STANDARD_DEFAULT) string(FIND "${CMAKE_C_FLAGS}" "-std=" std_flag_idx) if (std_flag_idx EQUAL -1) @@ -280,7 +290,8 @@ if (CMAKE_CXX_COMPILE_FEATURES) endif () # always add a target "CompileFeatures" -if (NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;") +if ((NOT CXX_expected_features) OR + (NOT cxx_auto_type IN_LIST CXX_expected_features)) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" "int main(int,char**) { return 0; }\n" ) diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index 2657aeb..52d4613 100644 --- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -48,7 +48,14 @@ macro(set_defines target true_defs false_defs) ) endmacro() +# Only run the compiler detection header test for compilers with +# 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]") +endif() +if (C_expected_features) string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" COMPILER_VERSION_MAJOR "${CMAKE_C_COMPILER_VERSION}") string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" COMPILER_VERSION_MINOR "${CMAKE_C_COMPILER_VERSION}") string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_C_COMPILER_VERSION}") @@ -85,7 +92,11 @@ if (CMAKE_C_COMPILE_FEATURES) endif() endif() -if (NOT CMAKE_CXX_COMPILE_FEATURES) +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]") +endif() +if (NOT CXX_expected_features) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" "int main(int,char**) { return 0; }\n" ) diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake index 2d14a9e..b24a680 100644 --- a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake @@ -6,9 +6,10 @@ add_library(empty3 INTERFACE) target_compile_features(empty3 INTERFACE cxx_std_11) target_link_libraries(empty1 - # When starting, $<COMPILE_FEATURES:cxx_auto_type> is '0', so 'freeze' the + # When starting, $<COMPILE_FEATURES:cxx_std_11> is '0', so 'freeze' the # CXX_STANDARD at 98 during computation. - $<$<COMPILE_FEATURES:cxx_auto_type>:empty2> + $<$<COMPILE_FEATURES:cxx_std_11>:empty2> + # This would add cxx_std_11, but that would require CXX_STANDARD = 11, # which is not allowed after freeze. Report an error. empty3 diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index 8dc627d..5a70da2 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -1,3 +1,4 @@ +cmake_policy(SET CMP0057 NEW) include(RunCMake) run_cmake(NotAFeature) @@ -28,13 +29,13 @@ endif() if (NOT CXX_FEATURES) run_cmake(NoSupportedCxxFeatures) run_cmake(NoSupportedCxxFeaturesGenex) -else() +elseif (cxx_std_98 IN_LIST CXX_FEATURES AND cxx_std_11 IN_LIST CXX_FEATURES) if(CXX_STANDARD_DEFAULT EQUAL 98) run_cmake(LinkImplementationFeatureCycle) endif() run_cmake(LinkImplementationFeatureCycleSolved) - if (";${CXX_FEATURES};" MATCHES ";cxx_final;") + if (cxx_final IN_LIST CXX_FEATURES) set(RunCMake_TEST_OPTIONS "-DHAVE_FINAL=1") endif() run_cmake(NonValidTarget1) |