diff options
author | Brad King <brad.king@kitware.com> | 2014-05-22 14:37:48 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-05-22 14:37:48 (GMT) |
commit | 5ce40619db2d89f7cfbc2cd47968346fb22fa795 (patch) | |
tree | a964e2227eb25fa745c719e536a4c8360dc2345e /Tests | |
parent | 04fc5dd493b6ccb24972a69641d5e41f1a76bf8e (diff) | |
parent | 0dfe395e3cb1a720c4853087db554a6827feaadb (diff) | |
download | CMake-5ce40619db2d89f7cfbc2cd47968346fb22fa795.zip CMake-5ce40619db2d89f7cfbc2cd47968346fb22fa795.tar.gz CMake-5ce40619db2d89f7cfbc2cd47968346fb22fa795.tar.bz2 |
Merge topic 'COMPILE_FEATURES-genex'
0dfe395e Features: Add COMPILE_FEATURES generator expression.
aa8a6fce cmMakefile: Add methods for checking availability of a feature.
b6dedf03 cmMakefile: Extract CheckNeeded{C,Cxx}Language methods.
8dd129df cmMakefile: Extract CompileFeaturesAvailable method.
6b9b2fff cmMakefile: Extract CompileFeatureKnown method.
Diffstat (limited to 'Tests')
15 files changed, 129 insertions, 0 deletions
diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 0e1e6c9..7a8a975 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -83,3 +83,17 @@ set_property(TARGET iface ) add_executable(IfaceCompileFeatures main.cpp) target_link_libraries(IfaceCompileFeatures iface) + +add_executable(CompileFeaturesGenex genex_test.cpp) +set_property(TARGET CompileFeaturesGenex PROPERTY CXX_STANDARD 11) +target_compile_definitions(CompileFeaturesGenex PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>) + +add_executable(CompileFeaturesGenex2 genex_test.cpp) +target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_constexpr) +target_compile_definitions(CompileFeaturesGenex2 PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>) + +add_library(noexcept_iface INTERFACE) +target_compile_features(noexcept_iface INTERFACE cxx_noexcept) +add_executable(CompileFeaturesGenex3 genex_test.cpp) +target_link_libraries(CompileFeaturesGenex3 PRIVATE noexcept_iface) +target_compile_definitions(CompileFeaturesGenex3 PRIVATE HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>) diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp new file mode 100644 index 0000000..ca38883 --- /dev/null +++ b/Tests/CompileFeatures/genex_test.cpp @@ -0,0 +1,21 @@ + +#if !HAVE_OVERRIDE_CONTROL +#error "Expect override control feature" +#else + +struct A +{ + virtual int getA() { return 7; } +}; + +struct B final : A +{ + int getA() override { return 42; } +}; + +#endif + +int main() +{ + +} diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt new file mode 100644 index 0000000..a584d7d --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle-stderr.txt @@ -0,0 +1,7 @@ +CMake Error in CMakeLists.txt: + The COMPILE_FEATURES property of target "empty1" was evaluated when + computing the link implementation, and the "CXX_STANDARD" was "98" for that + computation. Computing the COMPILE_FEATURES based on the link + implementation resulted in a higher "CXX_STANDARD" "11". This is not + permitted. The COMPILE_FEATURES may not both depend on and be depended on + by the link implementation. diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake new file mode 100644 index 0000000..9d56bc0 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycle.cmake @@ -0,0 +1,15 @@ + +add_library(empty1 empty.cpp) + +add_library(empty2 INTERFACE) +add_library(empty3 INTERFACE) +target_compile_features(empty3 INTERFACE cxx_constexpr) + +target_link_libraries(empty1 + # When starting, $<COMPILE_FEATURES:cxx_final> is '0', so 'freeze' the + # CXX_STANDARD at 98 during computation. + $<$<COMPILE_FEATURES:cxx_final>:empty2> + # This would add cxx_constexpr, but that would require CXX_STANDARD = 11, + # which is not allowed after freeze. Report an error. + empty3 +) diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt new file mode 100644 index 0000000..10f3293 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved-stderr.txt @@ -0,0 +1 @@ +^$ diff --git a/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake new file mode 100644 index 0000000..0df548b --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/LinkImplementationFeatureCycleSolved.cmake @@ -0,0 +1,14 @@ + +add_library(empty1 empty.cpp) + +add_library(empty2 INTERFACE) +add_library(empty3 INTERFACE) +target_compile_features(empty3 INTERFACE cxx_constexpr) + +target_link_libraries(empty1 + $<$<COMPILE_FEATURES:cxx_final>:empty2> + empty3 +) +# This, or populating the COMPILE_FEATURES property with a feature in the +# same standard as cxx_final, solves the cycle above. +set_property(TARGET empty1 PROPERTY CXX_STANDARD 11) diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt new file mode 100644 index 0000000..7f3b43b --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget1.cmake:[0-9]+ \(add_custom_command\): + Error evaluating generator expression: + + \$<COMPILE_FEATURES:cxx_final> + + \$<COMPILE_FEATURE> may only be used with binary targets. It may not be + used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake b/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake new file mode 100644 index 0000000..c6707c1 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget1.cmake @@ -0,0 +1,17 @@ + +set(genexvar $<COMPILE_FEATURES:cxx_final>) + +if (HAVE_FINAL) + set(expected_result 1) +else() + set(expected_result 0) +endif() + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file${HAVE_FINAL}.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp") +if (HAVE_FINAL) + target_compile_features(empty PRIVATE cxx_final) +endif() diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt b/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt new file mode 100644 index 0000000..635150c --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget2.cmake:4 \(add_custom_target\): + Error evaluating generator expression: + + \$<COMPILE_FEATURES:cxx_final> + + \$<COMPILE_FEATURE> may only be used with binary targets. It may not be + used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake b/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake new file mode 100644 index 0000000..eb84692 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NonValidTarget2.cmake @@ -0,0 +1,8 @@ + +set(genexvar $<COMPILE_FEATURES:cxx_final>) + +add_custom_target(copy_target + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.txt" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file${genexvar}.cpp") diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index a23d44f..1892a5c 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -26,6 +26,16 @@ endif() if (NOT CXX_FEATURES) run_cmake(NoSupportedCxxFeatures) run_cmake(NoSupportedCxxFeaturesGenex) +else() + run_cmake(LinkImplementationFeatureCycle) + run_cmake(LinkImplementationFeatureCycleSolved) + + if (";${CXX_FEATURES};" MATCHES ";cxx_final;") + set(RunCMake_TEST_OPTIONS "-DHAVE_FINAL=1") + endif() + run_cmake(NonValidTarget1) + run_cmake(NonValidTarget2) + unset(RunCMake_TEST_OPTIONS) endif() foreach(standard 98 11) |