diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-10-13 12:25:08 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2014-04-07 16:11:18 (GMT) |
commit | 8ed59fc207fd028d5b2b1f8cb8a323291ef04ffc (patch) | |
tree | 6d5257aac8000c17b6338fef90ff1b59e34d6ea9 /Tests/RunCMake | |
parent | 4e6ca504459640ff39eac48eb62fcae95c8fc8d2 (diff) | |
download | CMake-8ed59fc207fd028d5b2b1f8cb8a323291ef04ffc.zip CMake-8ed59fc207fd028d5b2b1f8cb8a323291ef04ffc.tar.gz CMake-8ed59fc207fd028d5b2b1f8cb8a323291ef04ffc.tar.bz2 |
Add target_compile_features command.
This can be used to set the compiler features required by particular
targets. An error is issued at CMake time if the compiler does not
support the required feature. If a language dialect flag is required
by the features used, that will be added automatically.
Base the target_compile_features command on cmTargetPropCommandBase. This
gives us 'free' handling of IMPORTED, ALIAS, INTERFACE, non-compilable
and missing targets.
Diffstat (limited to 'Tests/RunCMake')
35 files changed, 142 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index dd769ac..00e6702 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -125,6 +125,10 @@ endif() add_RunCMake_test(File_Generate) add_RunCMake_test(ExportWithoutLanguage) add_RunCMake_test(target_link_libraries) + +if (CMAKE_CXX_COMPILER_ID STREQUAL GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + add_RunCMake_test(target_compile_features) +endif() add_RunCMake_test(CheckModules) add_RunCMake_test(CommandLine) diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt new file mode 100644 index 0000000..d819d15 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at NotAFeature_OriginDebug_target_compile_features.cmake:4 \(target_compile_features\): + target_compile_features specified unknown feature "not_a_feature" for + target "somelib". +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake new file mode 100644 index 0000000..467d9a1 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeature_OriginDebug_target_compile_features.cmake @@ -0,0 +1,4 @@ + +set(CMAKE_DEBUG_TARGET_PROPERTIES COMPILE_FEATURES) +add_library(somelib STATIC empty.cpp) +target_compile_features(somelib PRIVATE not_a_feature) diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index a059900..a6aeeee 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -6,3 +6,4 @@ run_cmake(NotAFeatureTransitive) run_cmake(NotAFeature_OriginDebug) run_cmake(NotAFeature_OriginDebugGenex) run_cmake(NotAFeature_OriginDebugTransitive) +run_cmake(NotAFeature_OriginDebug_target_compile_features) diff --git a/Tests/RunCMake/target_compile_features/CMakeLists.txt b/Tests/RunCMake/target_compile_features/CMakeLists.txt new file mode 100644 index 0000000..3482e6b --- /dev/null +++ b/Tests/RunCMake/target_compile_features/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} CXX) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake new file mode 100644 index 0000000..f2abef7 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake @@ -0,0 +1,11 @@ +include(RunCMake) + +run_cmake(not_enough_args) +run_cmake(alias_target) +run_cmake(utility_target) +run_cmake(invalid_args) +run_cmake(invalid_args_on_interface) +run_cmake(imported_target) +run_cmake(no_target) +run_cmake(not_a_cxx_feature) +run_cmake(no_matching_cxx_feature) diff --git a/Tests/RunCMake/target_compile_features/alias_target-result.txt b/Tests/RunCMake/target_compile_features/alias_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/alias_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt new file mode 100644 index 0000000..417bf62 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at alias_target.cmake:4 \(target_compile_features\): + target_compile_features can not be used on an ALIAS target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/alias_target.cmake b/Tests/RunCMake/target_compile_features/alias_target.cmake new file mode 100644 index 0000000..d35ddba --- /dev/null +++ b/Tests/RunCMake/target_compile_features/alias_target.cmake @@ -0,0 +1,4 @@ + +add_executable(main empty.cpp) +add_executable(Alias::Main ALIAS main) +target_compile_features(Alias::Main PRIVATE cxx_delegating_constructors) diff --git a/Tests/RunCMake/target_compile_features/empty.cpp b/Tests/RunCMake/target_compile_features/empty.cpp new file mode 100644 index 0000000..bfbbdde --- /dev/null +++ b/Tests/RunCMake/target_compile_features/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} diff --git a/Tests/RunCMake/target_compile_features/imported_target-result.txt b/Tests/RunCMake/target_compile_features/imported_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/imported_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/imported_target-stderr.txt b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt new file mode 100644 index 0000000..c6ff5ec --- /dev/null +++ b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at imported_target.cmake:3 \(target_compile_features\): + Cannot specify compile features for imported target "main". +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/imported_target.cmake b/Tests/RunCMake/target_compile_features/imported_target.cmake new file mode 100644 index 0000000..e248c2f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/imported_target.cmake @@ -0,0 +1,3 @@ + +add_library(main INTERFACE IMPORTED) +target_compile_features(main INTERFACE cxx_delegating_constructors) diff --git a/Tests/RunCMake/target_compile_features/invalid_args-result.txt b/Tests/RunCMake/target_compile_features/invalid_args-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt new file mode 100644 index 0000000..bd5b7b9 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at invalid_args.cmake:3 \(target_compile_features\): + target_compile_features called with invalid arguments +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/invalid_args.cmake b/Tests/RunCMake/target_compile_features/invalid_args.cmake new file mode 100644 index 0000000..1a7fb37 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args.cmake @@ -0,0 +1,3 @@ + +add_executable(main empty.cpp) +target_compile_features(main INVALID cxx_delegating_constructors) diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt new file mode 100644 index 0000000..c30209a --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at invalid_args_on_interface.cmake:3 \(target_compile_features\): + target_compile_features may only be set INTERFACE properties on INTERFACE + targets +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake new file mode 100644 index 0000000..324d0f3 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface.cmake @@ -0,0 +1,3 @@ + +add_library(main INTERFACE) +target_compile_features(main PRIVATE cxx_delegating_constructors) diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt new file mode 100644 index 0000000..4c76c7a --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at no_matching_cxx_feature.cmake:[0-9][0-9]? \((target_compile_features|message)\): + The compiler feature "[^"]+" is not known to compiler + + "[^"]*" + + version *[.0-9]+\. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake new file mode 100644 index 0000000..0452dbf --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature.cmake @@ -0,0 +1,26 @@ + +if (NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnu_cxx_typeof;" + AND NOT ";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvc_cxx_sealed;" ) + # Simulate passing the test. + message(SEND_ERROR + "The compiler feature \"gnu_cxx_dummy\" is not known to compiler\n\"GNU\"\nversion 4.8.1." + ) + return() +endif() + +if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";gnu_cxx_typeof;") + set(feature msvc_cxx_sealed) + if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";msvc_cxx_sealed;") + # If a compiler supports both extensions, remove one of them. + list(REMOVE_ITEM CMAKE_CXX_COMPILE_FEATURES msvc_cxx_sealed) + endif() +else() + set(feature gnu_cxx_typeof) +endif() + +add_executable(main empty.cpp) + +target_compile_features(main + PRIVATE + ${feature} +) diff --git a/Tests/RunCMake/target_compile_features/no_target-result.txt b/Tests/RunCMake/target_compile_features/no_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/no_target-stderr.txt b/Tests/RunCMake/target_compile_features/no_target-stderr.txt new file mode 100644 index 0000000..323ba7a --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_target-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at no_target.cmake:2 \(target_compile_features\): + Cannot specify compile features for target "main" which is not built by + this project. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/no_target.cmake b/Tests/RunCMake/target_compile_features/no_target.cmake new file mode 100644 index 0000000..3f0afe2 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/no_target.cmake @@ -0,0 +1,2 @@ + +target_compile_features(main INTERFACE cxx_delegating_constructors) diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt new file mode 100644 index 0000000..efa2bad --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at not_a_cxx_feature.cmake:3 \(target_compile_features\): + target_compile_features specified unknown feature "cxx_not_a_feature" for + target "main". +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake new file mode 100644 index 0000000..0207b72 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature.cmake @@ -0,0 +1,6 @@ + +add_executable(main empty.cpp) +target_compile_features(main + PRIVATE + cxx_not_a_feature +) diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-result.txt b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_enough_args-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt new file mode 100644 index 0000000..2f8d812 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at not_enough_args.cmake:3 \(target_compile_features\): + target_compile_features called with incorrect number of arguments +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/not_enough_args.cmake b/Tests/RunCMake/target_compile_features/not_enough_args.cmake new file mode 100644 index 0000000..9561230 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/not_enough_args.cmake @@ -0,0 +1,3 @@ + +add_executable(main empty.cpp) +target_compile_features(main) diff --git a/Tests/RunCMake/target_compile_features/utility_target-result.txt b/Tests/RunCMake/target_compile_features/utility_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_compile_features/utility_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_compile_features/utility_target-stderr.txt b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt new file mode 100644 index 0000000..d239059 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at utility_target.cmake:4 \(target_compile_features\): + target_compile_features called with non-compilable target type +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_compile_features/utility_target.cmake b/Tests/RunCMake/target_compile_features/utility_target.cmake new file mode 100644 index 0000000..8919056 --- /dev/null +++ b/Tests/RunCMake/target_compile_features/utility_target.cmake @@ -0,0 +1,4 @@ + +add_custom_target(utility) + +target_compile_features(utility PRIVATE cxx_delegating_constructors) |