[build-script] Prioritize SDK paths in CMake find_ functions #32436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a build failure that happens on macOS when both the CommandLineTools and homebrew
pkg-config
are installed.Homebrew's
pkg-config
is setup to hardcode CommandLineTools paths, which causes many issues. As a result, whenfind_package()
consultspkg-config
, targets can have paths containing CommandLineTools, which can result in non-obvious build failures. Two example packages are libedit and libxml2.This fix assumes that, as a default,
xcrun --sdk macosx --show-sdk-path
should be preferred topkg-config
.The CMake documentation shows the search order that the
find_
functions use (see find_path). This change makes use ofCMAKE_PREFIX_PATH
as an environment variable to prioritize the SDK sysroot overpkg-config
. This is the 3rd search pass, just above theHINTS
search pass (which is what's used by packages such asFindLibEdit.cmake
).If needed, to explicitly build with a custom package, the documentation shows that higher priority search passes are available, such as setting
-DCMAKE_PREFIX_PATH=...
.Setting the environment variable is also composable with a user supplied
CMAKE_PREFIX_PATH
env variable.Resolves SR-12726.