summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-01-19 14:05:13 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-01-19 14:05:21 (GMT)
commit2042e0781acde4920051d5b94f57d96a20d13ad4 (patch)
tree3e441d4d028863549ef5635c69bea91a219bebb1
parentc4e4456b9ce3ca9f5e2cea47ea2c4a095d81fc0e (diff)
parentb2bc3364f0c220f560e4cf09b56b8486d8bfddfe (diff)
downloadCMake-2042e0781acde4920051d5b94f57d96a20d13ad4.zip
CMake-2042e0781acde4920051d5b94f57d96a20d13ad4.tar.gz
CMake-2042e0781acde4920051d5b94f57d96a20d13ad4.tar.bz2
Merge topic 'handle_multiple_source_dirs'
b2bc3364f0 CMake: `-S` paths preferred over other provided paths 2e1b7e5b9a Add tests that showcase cmake -S limitations Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6874
-rw-r--r--Source/cmake.cxx54
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake13
2 files changed, 39 insertions, 28 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index c708eb2..5632c38 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1456,7 +1456,6 @@ void cmake::SetDirectoriesFromFile(const std::string& arg)
// CMakeLists.txt file.
std::string listPath;
std::string cachePath;
- bool argIsFile = false;
if (cmSystemTools::FileIsDirectory(arg)) {
std::string path = cmSystemTools::CollapseFullPath(arg);
cmSystemTools::ConvertToUnixSlashes(path);
@@ -1469,7 +1468,6 @@ void cmake::SetDirectoriesFromFile(const std::string& arg)
listPath = path;
}
} else if (cmSystemTools::FileExists(arg)) {
- argIsFile = true;
std::string fullPath = cmSystemTools::CollapseFullPath(arg);
std::string name = cmSystemTools::GetFilenameName(fullPath);
name = cmSystemTools::LowerCase(name);
@@ -1485,7 +1483,6 @@ void cmake::SetDirectoriesFromFile(const std::string& arg)
std::string name = cmSystemTools::GetFilenameName(fullPath);
name = cmSystemTools::LowerCase(name);
if (name == "cmakecache.txt"_s || name == "cmakelists.txt"_s) {
- argIsFile = true;
listPath = cmSystemTools::GetFilenamePath(fullPath);
} else {
listPath = fullPath;
@@ -1505,36 +1502,37 @@ void cmake::SetDirectoriesFromFile(const std::string& arg)
}
}
+ bool no_source_tree = this->GetHomeDirectory().empty();
+ bool no_build_tree = this->GetHomeOutputDirectory().empty();
+
// If there is a CMakeLists.txt file, use it as the source tree.
if (!listPath.empty()) {
- this->SetHomeDirectory(listPath);
- if (argIsFile) {
- // Source CMakeLists.txt file given. It was probably dropped
- // onto the executable in a GUI. Default to an in-source build.
+ // When invoked with a path that points to an existing CMakeCache
+ // This function is called multiple times with the same path
+ if (no_source_tree && no_build_tree) {
+ this->SetHomeDirectory(listPath);
+
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeOutputDirectory(cwd);
+ } else if (no_source_tree) {
+ this->SetHomeDirectory(listPath);
+ } else if (no_build_tree) {
this->SetHomeOutputDirectory(listPath);
- } else {
- // Source directory given on command line. Use current working
- // directory as build tree if -B hasn't been given already
- if (this->GetHomeOutputDirectory().empty()) {
- std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- this->SetHomeOutputDirectory(cwd);
- }
}
- return;
- }
-
- if (this->GetHomeDirectory().empty()) {
- // We didn't find a CMakeLists.txt and it wasn't specified
- // with -S. Assume it is the path to the source tree
- std::string full = cmSystemTools::CollapseFullPath(arg);
- this->SetHomeDirectory(full);
- }
- if (this->GetHomeOutputDirectory().empty()) {
- // We didn't find a CMakeCache.txt and it wasn't specified
- // with -B. Assume the current working directory as the build tree.
- std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- this->SetHomeOutputDirectory(cwd);
+ } else {
+ if (no_source_tree) {
+ // We didn't find a CMakeLists.txt and it wasn't specified
+ // with -S. Assume it is the path to the source tree
+ std::string full = cmSystemTools::CollapseFullPath(arg);
+ this->SetHomeDirectory(full);
+ }
+ if (no_build_tree) {
+ // We didn't find a CMakeCache.txt and it wasn't specified
+ // with -B. Assume the current working directory as the build tree.
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeOutputDirectory(cwd);
+ }
}
}
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 74cd90a..3622e64 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -130,6 +130,19 @@ project(ExplicitDirsMissing LANGUAGES NONE)
set(RunCMake_TEST_BINARY_DIR "${source_dir}")
run_cmake_with_options(no-S-B -DFOO=BAR)
+ file(WRITE ${source_dir}/CMakeLists.txt [=[
+cmake_minimum_required(VERSION 3.13)
+project(ExplicitDirsMissing LANGUAGES NONE)
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+ message(FATAL_ERROR "CWD used as binary dir")
+endif()
+]=])
+
+ file(REMOVE_RECURSE "${source_dir}/build")
+ # Test with a setup where binary_dir won't be created by `run_cmake_with_options`
+ run_cmake_with_options(S-arg-build-dir-not-created -S ${source_dir} build/)
+ run_cmake_with_options(S-arg-reverse-build-dir-not-created build/ -S${source_dir} )
+
set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)