find*: Add options to ignore entire prefixes
I'm trying to prevent find_library
and find_package
from considering /usr/local
as a system prefix path on macOS, because that location usually contains libraries installed by Homebrew. I want to limit it to the SDK locations only.
I can achieve that for find_library
by setting either CMAKE_IGNORE_PATH
or CMAKE_SYSTEM_IGNORE_PATH
. But that doesn't work for find_package
(and the docs for the variables don't mention find_package
).
Is there a reason for that?
Setting NO_CMAKE_SYSTEM_PATH
for find_package
is a no-go as well, because that disables a lot more paths.
It's also a bit inconsistent that the docs for CMAKE_SYSTEM_PREFIX_PATH
mention CMAKE_SYSTEM_IGNORE_PATH
,
but the latter doesn't affect find_package
even though the former does.
Here's a sample project to demonstrate, i have harfbuzz installed in /usr/local:
cmake_minimum_required(VERSION 3.15.0)
set(CMAKE_SYSTEM_IGNORE_PATH "/usr/local/lib;/usr/local/lib/cmake;/usr/X11R6/lib;/opt;/usr/pkg")
project(app LANGUAGES CXX)
set(CMAKE_IGNORE_PATH "/usr/local/lib;/usr/local/lib/cmake;/usr/X11R6/lib;/opt;/usr/pkg")
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(harfbuzz
NO_SYSTEM_ENVIRONMENT_PATH)
unset(CMAKE_FIND_DEBUG_MODE)
$ cmake ..
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Debug Log at CMakeLists.txt:8 (find_package):
<PackageName>_ROOT CMake variable [CMAKE_FIND_USE_PACKAGE_ROOT_PATH].
none
CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].
none
CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables
[CMAKE_FIND_USE_CMAKE_PATH].
none
Env variable harfbuzz_DIR [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].
none
CMAKE_PREFIX_PATH env variable [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].
none
CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env variables
[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].
none
Paths specified by the find_package HINTS option.
none
CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].
none
CMake variables defined in the Platform file
[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].
/usr/local
/usr
/
/Users/alex
/usr/X11R6
/usr/pkg
/opt
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr
/sw
/opt/local
/Users/alex/Library/Frameworks
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/Library/Frameworks
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/Network/Library/Frameworks
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks
/Applications/Xcode.app/Contents/Developer/Library/Frameworks
/Library/Frameworks
/Network/Library/Frameworks
/System/Library/Frameworks
/Users/alex/Applications
/Applications
/Applications/Xcode.app/Contents/Applications
/Applications/Xcode.app/Contents/Developer/Applications
CMake System Package Registry
[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].
none
Paths specified by the find_package PATHS option.
none
find_package considered the following locations for the Config module:
/usr/local/harfbuzzConfig.cmake
/usr/local/harfbuzz-config.cmake
/usr/local/lib/cmake/harfbuzz/harfbuzzConfig.cmake
/usr/local/lib/cmake/harfbuzz/harfbuzz-config.cmake
The file was found at
/usr/local/lib/cmake/harfbuzz/harfbuzz-config.cmake
-- Configuring done
-- Generating done