From bd805a51ae4b5be5be6bbadf4afab108fcf4ddb3 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 1 Feb 2022 14:42:54 -0500 Subject: Refactor: Keep track of prefixes in cmSearchPath --- Source/cmFindCommon.h | 2 +- Source/cmFindPackageCommand.cxx | 2 +- Source/cmSearchPath.cxx | 59 ++++++++++++++++++++++++++--------------- Source/cmSearchPath.h | 18 ++++++++++--- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index 49d64e4..6649c35 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -135,7 +135,7 @@ protected: std::map LabeledPaths; std::vector SearchPaths; - std::set SearchPathsEmitted; + std::set SearchPathsEmitted; bool SearchFrameworkFirst; bool SearchFrameworkOnly; diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c468a3c..85badf6 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1309,7 +1309,7 @@ inline std::size_t collectPathsForDebug(std::string& buffer, return 0; } for (std::size_t i = startIndex; i < paths.size(); i++) { - buffer += " " + paths[i] + "\n"; + buffer += " " + paths[i].Path + "\n"; } return paths.size(); } diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx index 1bb459c..ff54a8a 100644 --- a/Source/cmSearchPath.cxx +++ b/Source/cmSearchPath.cxx @@ -26,16 +26,16 @@ void cmSearchPath::ExtractWithout(const std::set& ignore, if (clear) { outPaths.clear(); } - for (std::string const& path : this->Paths) { - if (ignore.count(path) == 0) { - outPaths.push_back(path); + for (auto const& path : this->Paths) { + if (ignore.count(path.Path) == 0) { + outPaths.push_back(path.Path); } } } void cmSearchPath::AddPath(const std::string& path) { - this->AddPathInternal(path); + this->AddPathInternal(path, ""); } void cmSearchPath::AddUserPath(const std::string& path) @@ -69,7 +69,7 @@ void cmSearchPath::AddUserPath(const std::string& path) // Process them all from the current directory for (std::string const& p : outPaths) { this->AddPathInternal( - p, this->FC->Makefile->GetCurrentSourceDirectory().c_str()); + p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str()); } } @@ -83,7 +83,7 @@ void cmSearchPath::AddCMakePath(const std::string& variable) for (std::string const& p : expanded) { this->AddPathInternal( - p, this->FC->Makefile->GetCurrentSourceDirectory().c_str()); + p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str()); } } } @@ -93,7 +93,7 @@ void cmSearchPath::AddEnvPath(const std::string& variable) std::vector expanded; cmSystemTools::GetPath(expanded, variable.c_str()); for (std::string const& p : expanded) { - this->AddPathInternal(p); + this->AddPathInternal(p, ""); } } @@ -132,24 +132,25 @@ void cmSearchPath::AddEnvPrefixPath(const std::string& variable, bool stripBin) void cmSearchPath::AddSuffixes(const std::vector& suffixes) { - std::vector inPaths; + std::vector inPaths; inPaths.swap(this->Paths); this->Paths.reserve(inPaths.size() * (suffixes.size() + 1)); - for (std::string& inPath : inPaths) { - cmSystemTools::ConvertToUnixSlashes(inPath); + for (PathWithPrefix& inPath : inPaths) { + cmSystemTools::ConvertToUnixSlashes(inPath.Path); + cmSystemTools::ConvertToUnixSlashes(inPath.Prefix); // if *i is only / then do not add a // // this will get incorrectly considered a network // path on windows and cause huge delays. - std::string p = inPath; + std::string p = inPath.Path; if (!p.empty() && p.back() != '/') { p += "/"; } // Combine with all the suffixes for (std::string const& suffix : suffixes) { - this->Paths.push_back(p + suffix); + this->Paths.push_back(PathWithPrefix{ p + suffix, inPath.Prefix }); } // And now the original w/o any suffix @@ -178,6 +179,10 @@ void cmSearchPath::AddPrefixPaths(const std::vector& paths, if (!subdir.empty() && !dir.empty() && dir.back() != '/') { dir += "/"; } + std::string prefix = dir; + if (!prefix.empty() && prefix != "/") { + prefix.erase(prefix.size() - 1); + } if (subdir == "include" || subdir == "lib") { cmValue arch = this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"); @@ -185,37 +190,47 @@ void cmSearchPath::AddPrefixPaths(const std::vector& paths, if (this->FC->Makefile->IsDefinitionSet("CMAKE_SYSROOT") && this->FC->Makefile->IsDefinitionSet( "CMAKE_PREFIX_LIBRARY_ARCHITECTURE")) { - this->AddPathInternal(cmStrCat('/', *arch, dir, subdir), base); + this->AddPathInternal(cmStrCat('/', *arch, dir, subdir), + cmStrCat('/', *arch, prefix), base); } else { - this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), base); + this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), prefix, + base); } } } std::string add = dir + subdir; if (add != "/") { - this->AddPathInternal(add, base); + this->AddPathInternal(add, prefix, base); } if (subdir == "bin") { - this->AddPathInternal(dir + "sbin", base); + this->AddPathInternal(dir + "sbin", prefix, base); } if (!subdir.empty() && path != "/") { - this->AddPathInternal(path, base); + this->AddPathInternal(path, prefix, base); } } } -void cmSearchPath::AddPathInternal(const std::string& path, const char* base) +void cmSearchPath::AddPathInternal(const std::string& path, + const std::string& prefix, const char* base) { assert(this->FC != nullptr); - std::string collapsed = cmSystemTools::CollapseFullPath(path, base); + std::string collapsedPath = cmSystemTools::CollapseFullPath(path, base); - if (collapsed.empty()) { + if (collapsedPath.empty()) { return; } + std::string collapsedPrefix; + if (!prefix.empty()) { + collapsedPrefix = cmSystemTools::CollapseFullPath(prefix, base); + } + // Insert the path if has not already been emitted. - if (this->FC->SearchPathsEmitted.insert(collapsed).second) { - this->Paths.push_back(std::move(collapsed)); + PathWithPrefix pathWithPrefix{ std::move(collapsedPath), + std::move(collapsedPrefix) }; + if (this->FC->SearchPathsEmitted.insert(pathWithPrefix).second) { + this->Paths.emplace_back(std::move(pathWithPrefix)); } } diff --git a/Source/cmSearchPath.h b/Source/cmSearchPath.h index 09f9722..08f9cfa 100644 --- a/Source/cmSearchPath.h +++ b/Source/cmSearchPath.h @@ -29,7 +29,18 @@ public: cmSearchPath(const cmSearchPath&) = default; cmSearchPath& operator=(const cmSearchPath&) = default; - const std::vector& GetPaths() const { return this->Paths; } + struct PathWithPrefix + { + std::string Path; + std::string Prefix; + + bool operator<(const PathWithPrefix& other) const + { + return this->Path < other.Path || + (this->Path == other.Path && this->Prefix < other.Prefix); + } + }; + const std::vector& GetPaths() const { return this->Paths; } std::size_t size() const { return this->Paths.size(); } void ExtractWithout(const std::set& ignore, @@ -47,8 +58,9 @@ public: const char* base = nullptr); protected: - void AddPathInternal(const std::string& path, const char* base = nullptr); + void AddPathInternal(const std::string& path, const std::string& prefix, + const char* base = nullptr); cmFindCommon* FC; - std::vector Paths; + std::vector Paths; }; -- cgit v0.12 From 201d8c429843e9e57f833fcca8794f532e6d3028 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 26 Jan 2022 16:35:54 -0500 Subject: find_*(): Add CMAKE_IGNORE_PREFIX_PATH variable Fixes: #20878 --- Help/manual/cmake-variables.7.rst | 2 + Help/release/dev/cmake-ignore-prefix-path.rst | 7 ++++ Help/variable/CMAKE_IGNORE_PREFIX_PATH.rst | 17 ++++++++ Help/variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH.rst | 18 +++++++++ Source/cmFindCommon.cxx | 46 ++++++++++++++++++---- Source/cmFindCommon.h | 4 ++ Source/cmFindPackageCommand.cxx | 13 +++++- Source/cmFindPackageCommand.h | 1 + Source/cmSearchPath.cxx | 6 ++- Source/cmSearchPath.h | 3 +- Tests/RunCMake/find_package/IgnorePrefixPath.cmake | 26 ++++++++++++ Tests/RunCMake/find_package/RunCMakeTest.cmake | 1 + Tests/RunCMake/find_program/IgnorePrefixPath.cmake | 30 ++++++++++++++ Tests/RunCMake/find_program/Prefix/bin/prog | 1 + Tests/RunCMake/find_program/RunCMakeTest.cmake | 1 + Tests/RunCMake/find_program/SystemPrefix/bin/prog | 1 + 16 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 Help/release/dev/cmake-ignore-prefix-path.rst create mode 100644 Help/variable/CMAKE_IGNORE_PREFIX_PATH.rst create mode 100644 Help/variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH.rst create mode 100644 Tests/RunCMake/find_package/IgnorePrefixPath.cmake create mode 100644 Tests/RunCMake/find_program/IgnorePrefixPath.cmake create mode 100755 Tests/RunCMake/find_program/Prefix/bin/prog create mode 100755 Tests/RunCMake/find_program/SystemPrefix/bin/prog diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 04c5a53..59566b5 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -212,6 +212,7 @@ Variables that Change Behavior /variable/CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY /variable/CMAKE_FRAMEWORK_PATH /variable/CMAKE_IGNORE_PATH + /variable/CMAKE_IGNORE_PREFIX_PATH /variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE /variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE /variable/CMAKE_INCLUDE_PATH @@ -250,6 +251,7 @@ Variables that Change Behavior /variable/CMAKE_SYSTEM_APPBUNDLE_PATH /variable/CMAKE_SYSTEM_FRAMEWORK_PATH /variable/CMAKE_SYSTEM_IGNORE_PATH + /variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH /variable/CMAKE_SYSTEM_INCLUDE_PATH /variable/CMAKE_SYSTEM_LIBRARY_PATH /variable/CMAKE_SYSTEM_PREFIX_PATH diff --git a/Help/release/dev/cmake-ignore-prefix-path.rst b/Help/release/dev/cmake-ignore-prefix-path.rst new file mode 100644 index 0000000..780e04f --- /dev/null +++ b/Help/release/dev/cmake-ignore-prefix-path.rst @@ -0,0 +1,7 @@ +cmake-ignore-prefix-path +------------------------ + +* :command:`find_package`, :command:`find_program`, :command:`find_library`, + :command:`find_path`, and :command:`find_file` now recognize the + :variable:`CMAKE_IGNORE_PREFIX_PATH` and + :variable:`CMAKE_SYSTEM_IGNORE_PREFIX_PATH` variables. diff --git a/Help/variable/CMAKE_IGNORE_PREFIX_PATH.rst b/Help/variable/CMAKE_IGNORE_PREFIX_PATH.rst new file mode 100644 index 0000000..45e51dd --- /dev/null +++ b/Help/variable/CMAKE_IGNORE_PREFIX_PATH.rst @@ -0,0 +1,17 @@ +CMAKE_IGNORE_PREFIX_PATH +------------------------ + +:ref:`Semicolon-separated list ` of prefix to be *ignored* by +the :command:`find_program`, :command:`find_library`, :command:`find_file`, +:command:`find_path`, and :command:`find_package` commands. This is useful in cross-compiling +environments where some system directories contain incompatible but +possibly linkable libraries. For example, on cross-compiled cluster +environments, this allows a user to ignore directories containing +libraries meant for the front-end machine. + +By default this is empty; it is intended to be set by the project. +Note that ``CMAKE_IGNORE_PREFIX_PATH`` takes a list of prefixes, *not* +a list of directory names. + +See also the :variable:`CMAKE_PREFIX_PATH`, :variable:`CMAKE_LIBRARY_PATH`, +:variable:`CMAKE_INCLUDE_PATH`, and :variable:`CMAKE_PROGRAM_PATH` variables. diff --git a/Help/variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH.rst b/Help/variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH.rst new file mode 100644 index 0000000..b177834 --- /dev/null +++ b/Help/variable/CMAKE_SYSTEM_IGNORE_PREFIX_PATH.rst @@ -0,0 +1,18 @@ +CMAKE_SYSTEM_IGNORE_PREFIX_PATH +------------------------------- + +:ref:`Semicolon-separated list ` of prefixes to be *ignored* by +the :command:`find_program`, :command:`find_library`, :command:`find_file`, +:command:`find_path`, and :command:`find_package` commands. This is useful in cross-compiling +environments where some system directories contain incompatible but +possibly linkable libraries. For example, on cross-compiled cluster +environments, this allows a user to ignore directories containing +libraries meant for the front-end machine. + +By default this contains a list of directories containing incompatible +binaries for the host system. See the :variable:`CMAKE_IGNORE_PREFIX_PATH` variable +that is intended to be set by the project. + +See also the :variable:`CMAKE_SYSTEM_PREFIX_PATH`, +:variable:`CMAKE_SYSTEM_LIBRARY_PATH`, :variable:`CMAKE_SYSTEM_INCLUDE_PATH`, +and :variable:`CMAKE_SYSTEM_PROGRAM_PATH` variables. diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index c58db1e..1bb98ea 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -262,11 +262,13 @@ void cmFindCommon::RerootPaths(std::vector& paths) (stagePrefix && isSameDirectoryOrSubDirectory(up, *stagePrefix))) { rootedDir = up; } else if (!up.empty() && up[0] != '~') { - // Start with the new root. - rootedDir = cmStrCat(r, '/'); - - // Append the original path with its old root removed. - rootedDir += cmSystemTools::SplitPathRootComponent(up); + auto const* split = cmSystemTools::SplitPathRootComponent(up); + if (split && *split) { + // Start with the new root. + rootedDir = cmStrCat(r, '/', split); + } else { + rootedDir = r; + } } // Store the new path. @@ -306,6 +308,31 @@ void cmFindCommon::GetIgnoredPaths(std::set& ignore) ignore.insert(ignoreVec.begin(), ignoreVec.end()); } +void cmFindCommon::GetIgnoredPrefixPaths(std::vector& ignore) +{ + static constexpr const char* paths[] = { + "CMAKE_SYSTEM_IGNORE_PREFIX_PATH", + "CMAKE_IGNORE_PREFIX_PATH", + }; + + // Construct the list of path roots with no trailing slashes. + for (const char* pathName : paths) { + // Get the list of paths to ignore from the variable. + this->Makefile->GetDefExpandList(pathName, ignore); + } + + for (std::string& i : ignore) { + cmSystemTools::ConvertToUnixSlashes(i); + } +} + +void cmFindCommon::GetIgnoredPrefixPaths(std::set& ignore) +{ + std::vector ignoreVec; + this->GetIgnoredPrefixPaths(ignoreVec); + ignore.insert(ignoreVec.begin(), ignoreVec.end()); +} + bool cmFindCommon::CheckCommonArgument(std::string const& arg) { if (arg == "NO_DEFAULT_PATH") { @@ -369,16 +396,19 @@ static void AddTrailingSlash(std::string& s) void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths) { // Filter out ignored paths from the prefix list - std::set ignored; + std::set ignoredPaths; + std::set ignoredPrefixes; if (ignorePaths == IgnorePaths::Yes) { - this->GetIgnoredPaths(ignored); + this->GetIgnoredPaths(ignoredPaths); + this->GetIgnoredPrefixPaths(ignoredPrefixes); } // Combine the separate path types, filtering out ignores this->SearchPaths.clear(); std::vector& allLabels = this->PathGroupLabelMap[PathGroup::All]; for (PathLabel const& l : allLabels) { - this->LabeledPaths[l].ExtractWithout(ignored, this->SearchPaths); + this->LabeledPaths[l].ExtractWithout(ignoredPaths, ignoredPrefixes, + this->SearchPaths); } // Expand list of paths inside all search roots. diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index 6649c35..5d9b3e1 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -86,6 +86,10 @@ protected: void GetIgnoredPaths(std::vector& ignore); void GetIgnoredPaths(std::set& ignore); + /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PREFIX_PATH variables. */ + void GetIgnoredPrefixPaths(std::vector& ignore); + void GetIgnoredPrefixPaths(std::set& ignore); + /** Compute final search path list (reroot + trailing slash). */ enum class IgnorePaths { diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 85badf6..fac0e08 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -665,6 +665,16 @@ bool cmFindPackageCommand::FindPackageUsingConfigMode() this->IgnoredPaths.clear(); this->IgnoredPaths.insert(ignored.begin(), ignored.end()); + // get igonored prefix paths from vars and reroot them. + std::vector ignoredPrefixes; + this->GetIgnoredPrefixPaths(ignoredPrefixes); + this->RerootPaths(ignoredPrefixes); + + // Construct a set of ignored prefix paths + this->IgnoredPrefixPaths.clear(); + this->IgnoredPrefixPaths.insert(ignoredPrefixes.begin(), + ignoredPrefixes.end()); + // Find and load the package. return this->HandlePackageMode(HandlePackageModeType::Config); } @@ -2291,7 +2301,8 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) if (prefixWithoutSlash != "/" && prefixWithoutSlash.back() == '/') { prefixWithoutSlash.erase(prefixWithoutSlash.length() - 1); } - if (this->IgnoredPaths.count(prefixWithoutSlash)) { + if (this->IgnoredPaths.count(prefixWithoutSlash) || + this->IgnoredPrefixPaths.count(prefixWithoutSlash)) { return false; } diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 9d6eddf..439d934 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -205,6 +205,7 @@ private: std::vector Names; std::vector Configs; std::set IgnoredPaths; + std::set IgnoredPrefixPaths; std::string DebugBuffer; /*! the selected sortOrder (None by default)*/ diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx index ff54a8a..bfee64c 100644 --- a/Source/cmSearchPath.cxx +++ b/Source/cmSearchPath.cxx @@ -19,7 +19,8 @@ cmSearchPath::cmSearchPath(cmFindCommon* findCmd) cmSearchPath::~cmSearchPath() = default; -void cmSearchPath::ExtractWithout(const std::set& ignore, +void cmSearchPath::ExtractWithout(const std::set& ignorePaths, + const std::set& ignorePrefixes, std::vector& outPaths, bool clear) const { @@ -27,7 +28,8 @@ void cmSearchPath::ExtractWithout(const std::set& ignore, outPaths.clear(); } for (auto const& path : this->Paths) { - if (ignore.count(path.Path) == 0) { + if (ignorePaths.count(path.Path) == 0 && + ignorePrefixes.count(path.Prefix) == 0) { outPaths.push_back(path.Path); } } diff --git a/Source/cmSearchPath.h b/Source/cmSearchPath.h index 08f9cfa..4c0cabb 100644 --- a/Source/cmSearchPath.h +++ b/Source/cmSearchPath.h @@ -43,7 +43,8 @@ public: const std::vector& GetPaths() const { return this->Paths; } std::size_t size() const { return this->Paths.size(); } - void ExtractWithout(const std::set& ignore, + void ExtractWithout(const std::set& ignorePaths, + const std::set& ignorePrefixes, std::vector& outPaths, bool clear = false) const; diff --git a/Tests/RunCMake/find_package/IgnorePrefixPath.cmake b/Tests/RunCMake/find_package/IgnorePrefixPath.cmake new file mode 100644 index 0000000..65709a2 --- /dev/null +++ b/Tests/RunCMake/find_package/IgnorePrefixPath.cmake @@ -0,0 +1,26 @@ +set(CMAKE_PREFIX_PATH + ${CMAKE_SOURCE_DIR}/PackageRoot/foo/cmake_root + ${CMAKE_SOURCE_DIR}/PackageRoot/foo/env_root + ) +set(CMAKE_IGNORE_PREFIX_PATH + ${CMAKE_SOURCE_DIR}/PackageRoot//foo/cmake_root// # Test double slashes + ) +set(CMAKE_SYSTEM_IGNORE_PREFIX_PATH + ${CMAKE_SOURCE_DIR}/PackageRoot/foo/env_root + ) +find_package(Bar QUIET CONFIG) +if(Bar_FOUND) + message(SEND_ERROR "Bar should not be found, was found in ${Bar_DIR}") +endif() + +set(CMAKE_PREFIX_PATH) +set(CMAKE_FIND_ROOT_PATH + ${CMAKE_SOURCE_DIR}/PackageRoot/foo/cmake_root + ${CMAKE_SOURCE_DIR}/PackageRoot/foo/env_root + ) +set(CMAKE_IGNORE_PREFIX_PATH /) +set(CMAKE_SYSTEM_IGNORE_PREFIX_PATH) +find_package(Bar2 NAMES Bar QUIET CONFIG) +if(Bar2_FOUND) + message(SEND_ERROR "Bar2 should not be found, was found in ${Bar2_DIR}") +endif() diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index 12701dc..037502f 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -45,6 +45,7 @@ run_cmake(VersionRangeConfig02) run_cmake(VersionRangeConfigStd) run_cmake(VersionRangeConfigStd2) run_cmake(IgnorePath) +run_cmake(IgnorePrefixPath) if(UNIX AND NOT MSYS # FIXME: This works on CYGWIN but not on MSYS ) diff --git a/Tests/RunCMake/find_program/IgnorePrefixPath.cmake b/Tests/RunCMake/find_program/IgnorePrefixPath.cmake new file mode 100644 index 0000000..5f0dba9 --- /dev/null +++ b/Tests/RunCMake/find_program/IgnorePrefixPath.cmake @@ -0,0 +1,30 @@ +function(assert_eq var value) + if(NOT "${${var}}" STREQUAL "${value}") + message(SEND_ERROR "Expected value of ${var}:\n ${value}\nActual value:\n ${${var}}") + endif() +endfunction() + +set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE) + +set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/Prefix) +set(_old_CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_SYSTEM_PREFIX_PATH}) +set(CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_SOURCE_DIR}/SystemPrefix) +set(prog_ROOT + ${CMAKE_SOURCE_DIR}/Prefix + ${CMAKE_SOURCE_DIR}/SystemPrefix + ) + +set(CMAKE_IGNORE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/Prefix) +set(CMAKE_SYSTEM_IGNORE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/SystemPrefix) +find_program(prog prog) +assert_eq(prog "prog-NOTFOUND") + +set(CMAKE_PREFIX_PATH) +set(CMAKE_SYSTEM_PREFIX_PATH ${_old_CMAKE_SYSTEM_PREFIX_PATH}) +set(CMAKE_IGNORE_PREFIX_PATH /) +set(CMAKE_FIND_ROOT_PATH + ${CMAKE_SOURCE_DIR}/Prefix + ${CMAKE_SOURCE_DIR}/SystemPrefix + ) +find_program(prog2 prog) +assert_eq(prog2 "prog2-NOTFOUND") diff --git a/Tests/RunCMake/find_program/Prefix/bin/prog b/Tests/RunCMake/find_program/Prefix/bin/prog new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/Tests/RunCMake/find_program/Prefix/bin/prog @@ -0,0 +1 @@ +#!/bin/sh diff --git a/Tests/RunCMake/find_program/RunCMakeTest.cmake b/Tests/RunCMake/find_program/RunCMakeTest.cmake index 2a1dae4..c2c07af 100644 --- a/Tests/RunCMake/find_program/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_program/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(NamesPerDir) run_cmake(RelAndAbsPath) run_cmake(Required) run_cmake(NO_CACHE) +run_cmake(IgnorePrefixPath) if(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS)$") run_cmake(WindowsCom) diff --git a/Tests/RunCMake/find_program/SystemPrefix/bin/prog b/Tests/RunCMake/find_program/SystemPrefix/bin/prog new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/Tests/RunCMake/find_program/SystemPrefix/bin/prog @@ -0,0 +1 @@ +#!/bin/sh -- cgit v0.12