summaryrefslogtreecommitdiffstats
path: root/Source/cmFindBase.cxx
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2022-08-30 19:26:30 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2022-08-30 19:26:30 (GMT)
commit43d31c519882f63456eafcaa2bd5c1bfc4e2ef1f (patch)
treee8a1f34d963960a87a90d5de78dac475f480457f /Source/cmFindBase.cxx
parentc3793b41573ee584e572ea546527b9350f46a05d (diff)
downloadCMake-43d31c519882f63456eafcaa2bd5c1bfc4e2ef1f.zip
CMake-43d31c519882f63456eafcaa2bd5c1bfc4e2ef1f.tar.gz
CMake-43d31c519882f63456eafcaa2bd5c1bfc4e2ef1f.tar.bz2
cmFindBase: Refactor CMAKE_FIND_USE_INSTALL_PREFIX handling
Diffstat (limited to 'Source/cmFindBase.cxx')
-rw-r--r--Source/cmFindBase.cxx67
1 files changed, 45 insertions, 22 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 4dfbef9..896c5d2 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -278,6 +278,45 @@ void cmFindBase::FillSystemEnvironmentPath()
paths.AddSuffixes(this->SearchPathSuffixes);
}
+#include <iostream>
+namespace {
+struct entry_to_remove
+{
+ entry_to_remove(std::string name, cmMakefile* makefile)
+ : count(-1)
+ , value()
+ {
+ if (cmValue to_skip = makefile->GetDefinition(
+ cmStrCat("_CMAKE_SYSTEM_PREFIX_PATH_", name, "_PREFIX_COUNT"))) {
+ cmStrToLong(to_skip, &count);
+ }
+ if (cmValue prefix_value = makefile->GetDefinition(
+ cmStrCat("_CMAKE_SYSTEM_PREFIX_PATH_", name, "_PREFIX_VALUE"))) {
+ value = *prefix_value;
+ }
+ }
+ bool valid() const { return count > 0 && !value.empty(); }
+
+ void remove_self(std::vector<std::string>& entries) const
+ {
+ if (this->valid()) {
+ long to_skip = this->count;
+ long index_to_remove = 0;
+ for (const auto& path : entries) {
+ if (path == this->value && --to_skip == 0) {
+ break;
+ }
+ ++index_to_remove;
+ }
+ entries.erase(entries.begin() + index_to_remove);
+ }
+ }
+
+ long count;
+ std::string value;
+};
+}
+
void cmFindBase::FillCMakeSystemVariablePath()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem];
@@ -298,37 +337,21 @@ void cmFindBase::FillCMakeSystemVariablePath()
// computed by `CMakeSystemSpecificInformation.cmake` while constructing
// `CMAKE_SYSTEM_PREFIX_PATH`. This ensures that if projects / toolchains
// have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove
- // some other entry by mistake
- long install_prefix_count = -1;
- std::string install_path_to_remove;
- if (cmValue to_skip = this->Makefile->GetDefinition(
- "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT")) {
- cmStrToLong(to_skip, &install_prefix_count);
- }
- if (cmValue install_value = this->Makefile->GetDefinition(
- "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE")) {
- install_path_to_remove = *install_value;
- }
+ // some other entry by mistake ( likewise for `CMAKE_STAGING_PREFIX` )
+ entry_to_remove install_entry("INSTALL", this->Makefile);
if (remove_install_prefix && install_prefix_in_list &&
- install_prefix_count > 0 && !install_path_to_remove.empty()) {
+ install_entry.valid()) {
cmValue prefix_paths =
this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH");
- // remove entry from CMAKE_SYSTEM_PREFIX_PATH
+ // remove entries from CMAKE_SYSTEM_PREFIX_PATH
std::vector<std::string> expanded = cmExpandedList(*prefix_paths);
- long index_to_remove = 0;
- for (const auto& path : expanded) {
- if (path == install_path_to_remove && --install_prefix_count == 0) {
- break;
- }
- ++index_to_remove;
- }
- expanded.erase(expanded.begin() + index_to_remove);
+ install_entry.remove_self(expanded);
+
paths.AddPrefixPaths(expanded,
this->Makefile->GetCurrentSourceDirectory().c_str());
} else if (add_install_prefix && !install_prefix_in_list) {
-
paths.AddCMakePrefixPath("CMAKE_INSTALL_PREFIX");
paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
} else {