find_package in config mode doesn't seem to be appropriately ignoring CMAKE_IGNORE_PREFIX_PATH

Bit confused about the behavior of CMAKE_IGNORE_PREFIX_PATH. I’m on macOS and trying to exclude homebrew for a particular package (or in general). I’ve added an ignore prefix like so:

list(APPEND CMAKE_IGNORE_PREFIX_PATH "/opt/homebrew" "/usr/local/lib")

Running --debug-find for this package with and without this exclusion reveals some oddities.

Without the ignore:

  find_package considered the following locations for MbedTLS's Config
  module:

    /Users/me/code/cmaketest/obs-studio/build_macos/CMakeFiles/pkgRedirects/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/build_macos/CMakeFiles/pkgRedirects/mbedtls-config.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-2024-09-05-universal/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-2024-09-05-universal/mbedtls-config.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-qt6-2024-09-05-universal/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-qt6-2024-09-05-universal/mbedtls-config.cmake
    /opt/homebrew/MbedTLSConfig.cmake
    /opt/homebrew/mbedtls-config.cmake
    /opt/homebrew/lib/cmake/MbedTLS/MbedTLSConfig.cmake
    /opt/homebrew/lib/cmake/MbedTLS/mbedtls-config.cmake
    /MbedTLSConfig.cmake
    /mbedtls-config.cmake
    /usr/local/opt/game-porting-toolkit/MbedTLSConfig.cmake
    /usr/local/opt/game-porting-toolkit/mbedtls-config.cmake
    /usr/local/MbedTLSConfig.cmake
    /usr/local/mbedtls-config.cmake
    /usr/local/lib/cmake/MbedTLS/MbedTLSConfig.cmake
    /usr/local/lib/cmake/MbedTLS/mbedtls-config.cmake
    /System/Cryptexes/App/usr/MbedTLSConfig.cmake
    /System/Cryptexes/App/usr/mbedtls-config.cmake
    /usr/MbedTLSConfig.cmake
    /usr/mbedtls-config.cmake
    /opt/X11/MbedTLSConfig.cmake
    /opt/X11/mbedtls-config.cmake
    /Library/Apple/usr/MbedTLSConfig.cmake
    /Library/Apple/usr/mbedtls-config.cmake
    /usr/local/share/dotnet/MbedTLSConfig.cmake
    /usr/local/share/dotnet/mbedtls-config.cmake
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/MbedTLSConfig.cmake
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/mbedtls-config.cmake
    /Users/me/.cargo/MbedTLSConfig.cmake
    /Users/me/.cargo/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/mbedtls-config.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/MbedTLSConfig.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/mbedtls-config.cmake
    /opt/MbedTLSConfig.cmake
    /opt/mbedtls-config.cmake
    /opt/local/MbedTLSConfig.cmake
    /opt/local/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/mbedtls-config.cmake
    /Library/Frameworks/MbedTLSConfig.cmake
    /Library/Frameworks/mbedtls-config.cmake
    /System/Library/Frameworks/MbedTLSConfig.cmake
    /System/Library/Frameworks/mbedtls-config.cmake
    /Users/me/Applications/MbedTLSConfig.cmake
    /Users/me/Applications/mbedtls-config.cmake
    /Applications/MbedTLSConfig.cmake
    /Applications/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Applications/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Applications/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Applications/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Applications/mbedtls-config.cmake

  The file was not found.

  find_package considered the following paths for FindMbedTLS.cmake:

    /Users/me/code/cmaketest/obs-studio/cmake/common/FindMbedTLS.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/share/cmake/Modules/FindMbedTLS.cmake

  The file was found at

    /Users/me/code/cmaketest/obs-studio/cmake/finders/FindMbedTLS.cmake

With the ignore:

  find_package considered the following locations for MbedTLS's Config
  module:

    /Users/me/code/cmaketest/obs-studio/build_macos/CMakeFiles/pkgRedirects/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/build_macos/CMakeFiles/pkgRedirects/mbedtls-config.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-2024-09-05-universal/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-2024-09-05-universal/mbedtls-config.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-qt6-2024-09-05-universal/MbedTLSConfig.cmake
    /Users/me/code/cmaketest/obs-studio/.deps/obs-deps-qt6-2024-09-05-universal/mbedtls-config.cmake
    /MbedTLSConfig.cmake
    /mbedtls-config.cmake
    /usr/local/opt/game-porting-toolkit/MbedTLSConfig.cmake
    /usr/local/opt/game-porting-toolkit/mbedtls-config.cmake
    /usr/local/MbedTLSConfig.cmake
    /usr/local/mbedtls-config.cmake
    /usr/local/lib/cmake/MbedTLS/MbedTLSConfig.cmake
    /usr/local/lib/cmake/MbedTLS/mbedtls-config.cmake
    /System/Cryptexes/App/usr/MbedTLSConfig.cmake
    /System/Cryptexes/App/usr/mbedtls-config.cmake
    /usr/MbedTLSConfig.cmake
    /usr/mbedtls-config.cmake
    /opt/X11/MbedTLSConfig.cmake
    /opt/X11/mbedtls-config.cmake
    /Library/Apple/usr/MbedTLSConfig.cmake
    /Library/Apple/usr/mbedtls-config.cmake
    /usr/local/share/dotnet/MbedTLSConfig.cmake
    /usr/local/share/dotnet/mbedtls-config.cmake
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/MbedTLSConfig.cmake
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/mbedtls-config.cmake
    /Users/me/.cargo/MbedTLSConfig.cmake
    /Users/me/.cargo/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/mbedtls-config.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/MbedTLSConfig.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/mbedtls-config.cmake
    /opt/MbedTLSConfig.cmake
    /opt/mbedtls-config.cmake
    /opt/local/MbedTLSConfig.cmake
    /opt/local/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Library/Frameworks/mbedtls-config.cmake
    /Library/Frameworks/MbedTLSConfig.cmake
    /Library/Frameworks/mbedtls-config.cmake
    /System/Library/Frameworks/MbedTLSConfig.cmake
    /System/Library/Frameworks/mbedtls-config.cmake
    /Users/me/Applications/MbedTLSConfig.cmake
    /Users/me/Applications/mbedtls-config.cmake
    /Applications/MbedTLSConfig.cmake
    /Applications/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Applications/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Applications/mbedtls-config.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Applications/MbedTLSConfig.cmake
    /Applications/Xcode-beta.app/Contents/Developer/Applications/mbedtls-config.cmake

  The file was not found.

  find_package considered the following paths for FindMbedTLS.cmake:

    /Users/me/code/cmaketest/obs-studio/cmake/common/FindMbedTLS.cmake
    /opt/homebrew/Cellar/cmake/3.30.2/share/cmake/Modules/FindMbedTLS.cmake

  The file was found at

    /Users/me/code/cmaketest/obs-studio/cmake/finders/FindMbedTLS.cmake

CMAKE_IGNORE_PREFIX_PATH seems to be having some sort of effect, but many homebrew paths are still included, just shuffled around a bit.

Digging into the code a bit, I’m seeing some oddities. For example, FindConfig is called here for find_package in config mode, but the subsequent call to ComputePrefixes here passes IgnorePaths::No, which seems to indicate that it’s not actually paying any attention at all to ignored prefixes.

Furthermore the actual call to FindConfigFile here is checking against IgnoredPaths explicitly, but not IgnoredPrefixPaths.

So overall in this call tree within find_package, I’m a bit confused about where and how the ignored prefixes are actually supposed to be applied. I mean, clearly they are not fully being applied, which seems like a bug itself, but overall I’m just trying to understand why and how this is happening and what the intended behavior here is.