summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/ExcludeFromAll
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2020-07-16 08:15:04 (GMT)
committerJoerg Bornemann <joerg.bornemann@qt.io>2020-07-21 15:16:26 (GMT)
commit2cdaf43d966f8407f0fb75ceb131fdca16617915 (patch)
tree15e3284091c62ca73b22fa15ea1a93770c97305d /Tests/RunCMake/ExcludeFromAll
parentc7b7547d8da6b9a4225d111440d0cf6c2f55914d (diff)
downloadCMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.zip
CMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.tar.gz
CMake-2cdaf43d966f8407f0fb75ceb131fdca16617915.tar.bz2
Allow generator expressions in the EXCLUDE_FROM_ALL target property
This allows for setting EXCLUDE_FROM_ALL, conditional on the build configuration. However, only the Ninja Multi-Config generator supports different property values per config. All other multi-config generators will yield an error in that situation. Fixes: #20923
Diffstat (limited to 'Tests/RunCMake/ExcludeFromAll')
-rw-r--r--Tests/RunCMake/ExcludeFromAll/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ExcludeFromAll/RunCMakeTest.cmake26
-rw-r--r--Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-result.txt1
-rw-r--r--Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-stderr.txt3
-rw-r--r--Tests/RunCMake/ExcludeFromAll/error-on-mixed-config.cmake6
-rw-r--r--Tests/RunCMake/ExcludeFromAll/main.c3
-rw-r--r--Tests/RunCMake/ExcludeFromAll/single-config-build-check.cmake17
-rw-r--r--Tests/RunCMake/ExcludeFromAll/single-config.cmake11
8 files changed, 70 insertions, 0 deletions
diff --git a/Tests/RunCMake/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/ExcludeFromAll/CMakeLists.txt
new file mode 100644
index 0000000..74b3ff8
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.3)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ExcludeFromAll/RunCMakeTest.cmake b/Tests/RunCMake/ExcludeFromAll/RunCMakeTest.cmake
new file mode 100644
index 0000000..25201e4
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/RunCMakeTest.cmake
@@ -0,0 +1,26 @@
+include(RunCMake)
+
+function(run_single_config_test label config exclude_from_all_value expectation)
+ set(case single-config)
+ message("-- Starting ${case} test: ${label}")
+ set(full_case_name "${case}-build-${config}")
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${full_case_name}/")
+ run_cmake_with_options(${case}
+ -DCMAKE_BUILD_TYPE=${config}
+ -DTOOL_EXCLUDE_FROM_ALL=${exclude_from_all_value})
+ set(RunCMake_TEST_NO_CLEAN 1)
+ include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake)
+ run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config ${config})
+endfunction()
+
+run_single_config_test("explictly not excluded" Debug 0 "should_exist")
+run_single_config_test("excluded" Debug 1 "should_not_exist")
+
+if(RunCMake_GENERATOR MATCHES "^(Xcode|Visual Studio)")
+ run_cmake(error-on-mixed-config)
+else()
+ run_single_config_test("explicitly not excluded with genex"
+ Release $<CONFIG:Debug> "should_exist")
+ run_single_config_test("excluded with genex"
+ Debug $<CONFIG:Debug> "should_not_exist")
+endif()
diff --git a/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-result.txt b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-stderr.txt b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-stderr.txt
new file mode 100644
index 0000000..eee5278
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ The EXCLUDED_FROM_ALL property of target "release_only_tool" varies by
+ configuration. This is not supported by the "[^"]+"
diff --git a/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config.cmake b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config.cmake
new file mode 100644
index 0000000..6c0ed1d
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/error-on-mixed-config.cmake
@@ -0,0 +1,6 @@
+enable_language(C)
+
+set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "")
+
+add_executable(release_only_tool main.c)
+set_property(TARGET release_only_tool PROPERTY EXCLUDE_FROM_ALL "$<NOT:$<CONFIG:Release>>")
diff --git a/Tests/RunCMake/ExcludeFromAll/main.c b/Tests/RunCMake/ExcludeFromAll/main.c
new file mode 100644
index 0000000..5047a34
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/main.c
@@ -0,0 +1,3 @@
+int main()
+{
+}
diff --git a/Tests/RunCMake/ExcludeFromAll/single-config-build-check.cmake b/Tests/RunCMake/ExcludeFromAll/single-config-build-check.cmake
new file mode 100644
index 0000000..1c455f2
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/single-config-build-check.cmake
@@ -0,0 +1,17 @@
+if(expectation STREQUAL "should_not_exist")
+ set(should_exist FALSE)
+elseif(expectation STREQUAL "should_exist")
+ set(should_exist TRUE)
+else()
+ message(FATAL_ERROR "Encountered unknown expectation: ${expectation}")
+endif()
+
+if(EXISTS "${TARGET_FILE_tool_${config}}")
+ if(NOT should_exist)
+ message(FATAL_ERROR "${TARGET_FILE_tool_${config}} should not exist.")
+ endif()
+else()
+ if(should_exist)
+ message(FATAL_ERROR "${TARGET_FILE_tool_${config}} should exist.")
+ endif()
+endif()
diff --git a/Tests/RunCMake/ExcludeFromAll/single-config.cmake b/Tests/RunCMake/ExcludeFromAll/single-config.cmake
new file mode 100644
index 0000000..71a9f06
--- /dev/null
+++ b/Tests/RunCMake/ExcludeFromAll/single-config.cmake
@@ -0,0 +1,11 @@
+enable_language(C)
+add_executable(tool main.c)
+set_property(TARGET tool PROPERTY EXCLUDE_FROM_ALL "${TOOL_EXCLUDE_FROM_ALL}")
+
+include(../NinjaMultiConfig/Common.cmake)
+set(orig_CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES})
+if("${CMAKE_CONFIGURATION_TYPES}" STREQUAL "")
+ set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
+endif()
+generate_output_files(tool)
+set(CMAKE_CONFIGURATION_TYPES ${orig_CMAKE_CONFIGURATION_TYPES})