diff options
author | Brad King <brad.king@kitware.com> | 2022-02-18 14:01:14 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-02-18 14:01:22 (GMT) |
commit | ee8cd65c76c046d3854eb057dc1e69be77a42d49 (patch) | |
tree | 65381a7f560692730dc5136627683841f39eb6db /Source/cmake.cxx | |
parent | 3702f3524d4eee90d8ee37e9aefe2e810e517783 (diff) | |
parent | 7083b1949801dcab8b76cd3978261aca7be30c0e (diff) | |
download | CMake-ee8cd65c76c046d3854eb057dc1e69be77a42d49.zip CMake-ee8cd65c76c046d3854eb057dc1e69be77a42d49.tar.gz CMake-ee8cd65c76c046d3854eb057dc1e69be77a42d49.tar.bz2 |
Merge topic 'correct_multiple_source_warnings'
7083b19498 cmake: When given multiple source paths use last instead of first
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7001
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 07732e5..14d74a8 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); |