summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/OPTIONS_BUILD.txt3
-rw-r--r--Help/release/dev/cmake-initial-cache-dirs.rst6
-rw-r--r--Source/cmake.cxx17
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir-stderr.txt8
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir-stdout.txt2
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir.cmake0
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt6
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir/src/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir/src/PreLoad.cmake6
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake7
10 files changed, 51 insertions, 10 deletions
diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
index 810aaa9..0947e41 100644
--- a/Help/manual/OPTIONS_BUILD.txt
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -18,6 +18,9 @@
containing :command:`set` commands that use the ``CACHE`` option, not a
cache-format file.
+ References to :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`
+ within the script evaluate to the top-level source and build tree.
+
``-D <var>:<type>=<value>, -D <var>=<value>``
Create or update a CMake ``CACHE`` entry.
diff --git a/Help/release/dev/cmake-initial-cache-dirs.rst b/Help/release/dev/cmake-initial-cache-dirs.rst
new file mode 100644
index 0000000..be91902
--- /dev/null
+++ b/Help/release/dev/cmake-initial-cache-dirs.rst
@@ -0,0 +1,6 @@
+cmake-initial-cache-dirs
+------------------------
+
+* The :manual:`cmake(1)` ``-C <initial-cache>`` option now evaluates the
+ initial cache script with :variable:`CMAKE_SOURCE_DIR` and
+ :variable:`CMAKE_BINARY_DIR` set to the top-level source and build trees.
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 4ed17a3..b9902a3 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -430,6 +430,11 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
}
// Register fake project commands that hint misuse in script mode.
GetProjectCommandsInScriptMode(this->GetState());
+ // Documented behaviour of CMAKE{,_CURRENT}_{SOURCE,BINARY}_DIR is to be
+ // set to $PWD for -P mode.
+ this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
+ this->SetHomeOutputDirectory(
+ cmSystemTools::GetCurrentWorkingDirectory());
this->ReadListFile(args, path);
} else if (arg.find("--find-package", 0) == 0) {
findPackageMode = true;
@@ -459,15 +464,9 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
// read in the list file to fill the cache
if (!path.empty()) {
this->CurrentSnapshot = this->State->Reset();
- std::string homeDir = this->GetHomeDirectory();
- std::string homeOutputDir = this->GetHomeOutputDirectory();
- this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
- this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
cmStateSnapshot snapshot = this->GetCurrentSnapshot();
- snapshot.GetDirectory().SetCurrentBinary(
- cmSystemTools::GetCurrentWorkingDirectory());
- snapshot.GetDirectory().SetCurrentSource(
- cmSystemTools::GetCurrentWorkingDirectory());
+ snapshot.GetDirectory().SetCurrentBinary(this->GetHomeOutputDirectory());
+ snapshot.GetDirectory().SetCurrentSource(this->GetHomeDirectory());
snapshot.SetDefaultDefinitions();
cmMakefile mf(gg, snapshot);
if (this->GetWorkingMode() != NORMAL_MODE) {
@@ -480,8 +479,6 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
if (!mf.ReadListFile(path)) {
cmSystemTools::Error("Error processing file: " + path);
}
- this->SetHomeDirectory(homeDir);
- this->SetHomeOutputDirectory(homeOutputDir);
}
// free generic one if generated
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir-stderr.txt b/Tests/RunCMake/CommandLine/C_buildsrcdir-stderr.txt
new file mode 100644
index 0000000..0d8f72e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir-stderr.txt
@@ -0,0 +1,8 @@
+initial-cache.txt: CMAKE_SOURCE_DIR: .*/C_buildsrcdir/src
+initial-cache.txt: CMAKE_BINARY_DIR: .*/C_buildsrcdir-build/DummyBuildDir
+PreLoad.cmake: CMAKE_SOURCE_DIR: .*/C_buildsrcdir/src
+PreLoad.cmake: CMAKE_BINARY_DIR: .*/C_buildsrcdir-build/DummyBuildDir
+CMakeLists.txt: INITIAL_SOURCE_DIR: .*/C_buildsrcdir/src
+CMakeLists.txt: INITIAL_BINARY_DIR: .*/C_buildsrcdir-build/DummyBuildDir
+CMakeLists.txt: PRELOAD_SOURCE_DIR: .*/C_buildsrcdir/src
+CMakeLists.txt: PRELOAD_BINARY_DIR: .*/C_buildsrcdir-build/DummyBuildDir
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir-stdout.txt b/Tests/RunCMake/CommandLine/C_buildsrcdir-stdout.txt
new file mode 100644
index 0000000..c69b11e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir-stdout.txt
@@ -0,0 +1,2 @@
+loading initial cache file .*/C_buildsrcdir/initial-cache.txt
+.*
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir.cmake b/Tests/RunCMake/CommandLine/C_buildsrcdir.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir.cmake
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt b/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt
new file mode 100644
index 0000000..adc125b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt
@@ -0,0 +1,6 @@
+# Used to verify that the values match what is passed via -S and -B, and are retained in cache.
+set(INITIAL_SOURCE_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "defined in initial.cmake")
+set(INITIAL_BINARY_DIR "${CMAKE_BINARY_DIR}" CACHE PATH "defined in initial.cmake")
+
+message("initial-cache.txt: CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
+message("initial-cache.txt: CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir/src/CMakeLists.txt b/Tests/RunCMake/CommandLine/C_buildsrcdir/src/CMakeLists.txt
new file mode 100644
index 0000000..4893fe7
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir/src/CMakeLists.txt
@@ -0,0 +1,6 @@
+project(C_buildsrcdir)
+
+message("CMakeLists.txt: INITIAL_SOURCE_DIR: ${INITIAL_SOURCE_DIR}")
+message("CMakeLists.txt: INITIAL_BINARY_DIR: ${INITIAL_BINARY_DIR}")
+message("CMakeLists.txt: PRELOAD_SOURCE_DIR: ${PRELOAD_SOURCE_DIR}")
+message("CMakeLists.txt: PRELOAD_BINARY_DIR: ${PRELOAD_BINARY_DIR}")
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir/src/PreLoad.cmake b/Tests/RunCMake/CommandLine/C_buildsrcdir/src/PreLoad.cmake
new file mode 100644
index 0000000..5199219
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir/src/PreLoad.cmake
@@ -0,0 +1,6 @@
+# Used to verify that the values match what is passed via -S and -B, and are retained in cache.
+message("PreLoad.cmake: CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
+message("PreLoad.cmake: CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
+
+set(PRELOAD_BINARY_DIR "${CMAKE_BINARY_DIR}" CACHE PATH "value of cmake_binary_dir during preload")
+set(PRELOAD_SOURCE_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "value of cmake_source_dir during preload")
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index dd49423..71a3843 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -391,6 +391,13 @@ run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1)
run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR})
run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake)
+# Documented to return the same result as above even if -S and -B are set to something else.
+# Tests the values of CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_SOURCE_DIR.
+run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake -S something_else -B something_else_1)
+
+# CMAKE_BINARY_DIR should be determined by -B if specified, and CMAKE_SOURCE_DIR determined by -S if specified.
+run_cmake_with_options(C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_SOURCE_DIR}/C_buildsrcdir/initial-cache.txt)
+
set(RunCMake_TEST_OPTIONS
"-DFOO=-DBAR:BOOL=BAZ")