nixpkgs/pkgs/by-name/cm/cmake/000-nixpkgs-cmake-prefix-path.diff
Reno Dakota 8c9c8ade2f
cmake: fix strictDeps
patch cmake to implement a NIXPKGS_CMAKE_PREFIX_PATH env variable which
is similar to CMAKE_PREFIX_PATH except it is not searched for programs.

This is required because cmake will search CMAKE_PREFIX_PATH for
programs before PATH which is problematic as that means buildInputs gets
searched before nativeBuildInputs which can break things when the
binaries in PATH are covered or the order re-arranged.
2024-07-27 18:36:23 +00:00

29 lines
1.2 KiB
Diff

diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 8840cdcb..c34b7ee9 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -280,6 +280,11 @@ void cmFindBase::FillCMakeEnvironmentPath()
// Add CMAKE_*_PATH environment variables
std::string var = cmStrCat("CMAKE_", this->CMakePathName, "_PATH");
paths.AddEnvPrefixPath("CMAKE_PREFIX_PATH");
+ if (this->CMakePathName != "PROGRAM") {
+ // Like CMAKE_PREFIX_PATH except when searching for programs. Programs need
+ // to be located via PATH
+ paths.AddEnvPrefixPath("NIXPKGS_CMAKE_PREFIX_PATH");
+ }
paths.AddEnvPath(var);
if (this->CMakePathName == "PROGRAM") {
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 9b51b1ad..6acc676c 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -2039,6 +2039,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
// And now the general CMake environment variables
paths.AddEnvPath("CMAKE_PREFIX_PATH");
+ paths.AddEnvPath("NIXPKGS_CMAKE_PREFIX_PATH");
if (this->DebugMode) {
debugBuffer = cmStrCat(debugBuffer,
"CMAKE_PREFIX_PATH env variable "