diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2022-02-17 13:46:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-02-17 21:54:30 (GMT) |
commit | 7083b1949801dcab8b76cd3978261aca7be30c0e (patch) | |
tree | bc30fcc51660f49bca38b1cef47a1fa4d3c938f2 /Source/cmake.cxx | |
parent | 9c81f2cb8bcb5f4ad96f2ad527035649bd70d5fc (diff) | |
download | CMake-7083b1949801dcab8b76cd3978261aca7be30c0e.zip CMake-7083b1949801dcab8b76cd3978261aca7be30c0e.tar.gz CMake-7083b1949801dcab8b76cd3978261aca7be30c0e.tar.bz2 |
cmake: When given multiple source paths use last instead of first
When given two source paths via `-S` or just directory paths prefer
the last one. When the paths are mixed always prefer the last `-S`
entry.
Fixes: #23238
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index d80c4bc..fe4d252 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -818,7 +818,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) } std::string path = cmSystemTools::CollapseFullPath(value); cmSystemTools::ConvertToUnixSlashes(path); - state->SetHomeDirectory(path); + + state->SetHomeDirectoryViaCommandLine(path, HomeDirArgStyle::Dash_S); return true; }; @@ -1486,6 +1487,7 @@ bool cmake::SetDirectoriesFromFile(const std::string& arg) // CMakeLists.txt file. std::string listPath; std::string cachePath; + bool is_source_dir = false; bool is_empty_directory = false; if (cmSystemTools::FileIsDirectory(arg)) { std::string path = cmSystemTools::CollapseFullPath(arg); @@ -1501,6 +1503,7 @@ bool cmake::SetDirectoriesFromFile(const std::string& arg) if (cmSystemTools::FileExists(listFile)) { listPath = path; is_empty_directory = false; + is_source_dir = true; } } else if (cmSystemTools::FileExists(arg)) { std::string fullPath = cmSystemTools::CollapseFullPath(arg); @@ -1545,19 +1548,23 @@ bool cmake::SetDirectoriesFromFile(const std::string& arg) const bool passed_same_path = (listPath == this->GetHomeDirectory()) || (listPath == this->GetHomeOutputDirectory()); bool used_provided_path = - (passed_same_path || no_source_tree || no_build_tree); + (passed_same_path || is_source_dir || no_build_tree); // If there is a CMakeLists.txt file, use it as the source tree. if (!listPath.empty()) { // 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) { + if (is_source_dir) { + this->SetHomeDirectoryViaCommandLine(listPath, HomeDirArgStyle::Plain); + if (!no_build_tree) { + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + this->SetHomeOutputDirectory(cwd); + } + } else 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); } @@ -1773,6 +1780,30 @@ void cmake::PrintPresetList(const cmCMakePresetsGraph& graph) const } #endif +void cmake::SetHomeDirectoryViaCommandLine(std::string const& path, + HomeDirArgStyle argStyle) +{ + bool fromDashS = argStyle == HomeDirArgStyle::Dash_S; + static bool homeDirectorySetExplicitly = false; + if (path.empty()) { + return; + } + + auto prev_path = this->GetHomeDirectory(); + if (prev_path != path && !prev_path.empty()) { + const bool ignore_prev_path = + (fromDashS || (!fromDashS && !homeDirectorySetExplicitly)); + const std::string& ignored_path = (ignore_prev_path) ? prev_path : path; + this->IssueMessage(MessageType::WARNING, + cmStrCat("Ignoring extra path from command line:\n \"", + ignored_path, "\"")); + } + if (fromDashS || !homeDirectorySetExplicitly) { + this->SetHomeDirectory(path); + } + homeDirectorySetExplicitly = fromDashS; +} + void cmake::SetHomeDirectory(const std::string& dir) { this->State->SetSourceDirectory(dir); |