summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auxiliary/vim/syntax/cmake.vim1
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/release/dev/make-test-depend-on-all.rst6
-rw-r--r--Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst2
-rw-r--r--Help/variable/CMAKE_SKIP_TEST_ALL_DEPENDENCY.rst19
-rw-r--r--Source/cmGlobalGenerator.cxx8
-rw-r--r--Tests/RunCMake/BuiltinTargets/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/BuiltinTargets/TestDependsAll-No.cmake2
-rw-r--r--Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes-build-check.cmake3
-rw-r--r--Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes.cmake2
10 files changed, 46 insertions, 0 deletions
diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim
index 4bbdc65..a13dfc9 100644
--- a/Auxiliary/vim/syntax/cmake.vim
+++ b/Auxiliary/vim/syntax/cmake.vim
@@ -1656,6 +1656,7 @@ syn keyword cmakeVariable contained
\ CMAKE_SKIP_INSTALL_RPATH
\ CMAKE_SKIP_INSTALL_RULES
\ CMAKE_SKIP_RPATH
+ \ CMAKE_SKIP_TEST_ALL_DEPENDENCY
\ CMAKE_SOURCE_DIR
\ CMAKE_STAGING_PREFIX
\ CMAKE_STATIC_LIBRARY_PREFIX
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index bf6fc0a..4ce3b2f 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -255,6 +255,7 @@ Variables that Change Behavior
/variable/CMAKE_PROJECT_TOP_LEVEL_INCLUDES
/variable/CMAKE_REQUIRE_FIND_PACKAGE_PackageName
/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
+ /variable/CMAKE_SKIP_TEST_ALL_DEPENDENCY
/variable/CMAKE_STAGING_PREFIX
/variable/CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
/variable/CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE
diff --git a/Help/release/dev/make-test-depend-on-all.rst b/Help/release/dev/make-test-depend-on-all.rst
new file mode 100644
index 0000000..ef43faf
--- /dev/null
+++ b/Help/release/dev/make-test-depend-on-all.rst
@@ -0,0 +1,6 @@
+make-test-depend-on-all
+-----------------------
+
+* The :variable:`CMAKE_SKIP_TEST_ALL_DEPENDENCY` variable was added
+ to control whether the ``test`` (or ``RUN_TESTS``) buildsystem
+ target depends on the ``all`` (or ``ALL_BUILD``) target.
diff --git a/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst b/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst
index e88db36..69c762b 100644
--- a/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst
+++ b/Help/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.rst
@@ -9,3 +9,5 @@ built, first the ``all`` target is built, then the installation starts.
If ``CMAKE_SKIP_INSTALL_ALL_DEPENDENCY`` is set to ``TRUE``, this
dependency is not created, so the installation process will start immediately,
independent from whether the project has been completely built or not.
+
+See also :variable:`CMAKE_SKIP_TEST_ALL_DEPENDENCY`.
diff --git a/Help/variable/CMAKE_SKIP_TEST_ALL_DEPENDENCY.rst b/Help/variable/CMAKE_SKIP_TEST_ALL_DEPENDENCY.rst
new file mode 100644
index 0000000..bae8e99
--- /dev/null
+++ b/Help/variable/CMAKE_SKIP_TEST_ALL_DEPENDENCY.rst
@@ -0,0 +1,19 @@
+CMAKE_SKIP_TEST_ALL_DEPENDENCY
+------------------------------
+
+.. versionadded:: 3.29
+
+Control whether the ``test`` target depends on the ``all`` target.
+
+If this variable is not defined, or is set to ``TRUE``, then the
+``test`` (or ``RUN_TESTS``) target does not depend on the
+``all`` (or ``ALL_BUILD``) target. When the ``test`` target is built,
+e.g., via ``make test``, the test process will start immediately,
+regardless of whether the project has been completely built or not.
+
+If ``CMAKE_SKIP_TEST_ALL_DEPENDENCY`` is explicitly set to ``FALSE``,
+then the ``test`` target will depend on the ``all`` target. When the
+``test`` target is built, e.g., via ``make test``, the ``all`` target
+will be built first, and then the tests will run.
+
+See also :variable:`CMAKE_SKIP_INSTALL_ALL_DEPENDENCY`.
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index ef0f40f..3f9bcd5 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -2865,6 +2865,14 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
gti.Name = this->GetTestTargetName();
gti.Message = "Running tests...";
gti.UsesTerminal = true;
+ // Unlike the 'install' target, the 'test' target does not depend on 'all'
+ // by default. Enable it only if CMAKE_SKIP_TEST_ALL_DEPENDENCY is
+ // explicitly set to OFF.
+ if (cmValue noall = mf->GetDefinition("CMAKE_SKIP_TEST_ALL_DEPENDENCY")) {
+ if (cmIsOff(noall)) {
+ gti.Depends.emplace_back(this->GetAllTargetName());
+ }
+ }
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.push_back("--force-new-ctest-process");
diff --git a/Tests/RunCMake/BuiltinTargets/RunCMakeTest.cmake b/Tests/RunCMake/BuiltinTargets/RunCMakeTest.cmake
index 9c58bae..6a74f57 100644
--- a/Tests/RunCMake/BuiltinTargets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/BuiltinTargets/RunCMakeTest.cmake
@@ -15,3 +15,5 @@ function(run_BuiltinTarget case target)
endfunction()
run_BuiltinTarget(TestDependsAll-Default test)
+run_BuiltinTarget(TestDependsAll-No test)
+run_BuiltinTarget(TestDependsAll-Yes test)
diff --git a/Tests/RunCMake/BuiltinTargets/TestDependsAll-No.cmake b/Tests/RunCMake/BuiltinTargets/TestDependsAll-No.cmake
new file mode 100644
index 0000000..50ec3b9
--- /dev/null
+++ b/Tests/RunCMake/BuiltinTargets/TestDependsAll-No.cmake
@@ -0,0 +1,2 @@
+include(TestDependsAll-common.cmake)
+set(CMAKE_SKIP_TEST_ALL_DEPENDENCY ON)
diff --git a/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes-build-check.cmake b/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes-build-check.cmake
new file mode 100644
index 0000000..ed175d4
--- /dev/null
+++ b/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes-build-check.cmake
@@ -0,0 +1,3 @@
+if(NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/custom-output.txt)
+ set(RunCMake_TEST_FAILED "Building 'test' target did not build 'all' target:\n ${RunCMake_TEST_BINARY_DIR}/custom-output.txt")
+endif()
diff --git a/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes.cmake b/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes.cmake
new file mode 100644
index 0000000..c35c98d
--- /dev/null
+++ b/Tests/RunCMake/BuiltinTargets/TestDependsAll-Yes.cmake
@@ -0,0 +1,2 @@
+include(TestDependsAll-common.cmake)
+set(CMAKE_SKIP_TEST_ALL_DEPENDENCY OFF)