Files
CMake/Tests/RunCMake/find_package/ConfigureLog.cmake
Moritz Haase 61d8fae116 find_package: Use deterministic search order by default
Historically, find_package() does not guarantee the order in which directories
matching a search path containing a glob expression are processed in - the
"first valid package" will be selected if there are multiple candidates. In such
cases, which package is chosen is completely random and can change, potentially
leading to build failures and reproducibility issues. This is rather unexpected
and confusing for developers.

Now that CMake has bumped its major version, it's a good time to change default
sort order and direction could be changed to natural sorting with a descending
order. That will result in the newest version of a library being picked in case
there are multiple ones available.
2025-06-18 06:34:59 +02:00

29 lines
755 B
CMake

list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_LIST_DIR}/ConfigureLog/cmake")
list(INSERT CMAKE_PREFIX_PATH 0
"${CMAKE_CURRENT_LIST_DIR}/ConfigureLog")
set(CMAKE_FIND_DEBUG_MODE 1)
# Stable sorting for predictable behaviors.
set(CMAKE_FIND_PACKAGE_SORT_ORDER NAME)
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASCENDING)
# Unset search variables for more predictable output.
unset(CMAKE_FRAMEWORK_PATH)
unset(CMAKE_APPBUNDLE_PATH)
unset(ENV{CMAKE_PREFIX_PATH})
unset(ENV{CMAKE_FRAMEWORK_PATH})
unset(ENV{CMAKE_APPBUNDLE_PATH})
# Find a config package
find_package(ViaConfig)
# Find a module
find_package(ViaModule)
# Find a module that chains to a config package
find_package(WithInner)
# Version insufficiency testing
find_package(VersionCheck 2.0)