diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake index 574ef3f8b3..8039039e1b 100644 --- a/cmake/macros/PackageConfig.cmake +++ b/cmake/macros/PackageConfig.cmake @@ -483,24 +483,28 @@ endfunction(export_targets) # # find_package # -# This override is necessary because CMake's default behavior is to run -# find_package in MODULE mode, *then* in CONFIG mode. This is silly! CONFIG -# mode makes more sense to be done first, since any system config file will -# know vastly more about the package's configuration than a module can hope to -# guess. +# This override implements CMAKE_FIND_PACKAGE_PREFER_CONFIG on versions of +# CMake too old to include it. # -macro(find_package name) - if(";${ARGN};" MATCHES ";(CONFIG|MODULE|NO_MODULE);") - # Caller explicitly asking for a certain mode; so be it. - _find_package(${ARGV}) +if(CMAKE_VERSION VERSION_LESS "3.15") + macro(find_package name) + if(";${ARGN};" MATCHES ";(CONFIG|MODULE|NO_MODULE);") + # Caller explicitly asking for a certain mode; so be it. + _find_package(${ARGV}) - else() - # Try CONFIG - _find_package("${name}" CONFIG ${ARGN}) + elseif(CMAKE_FIND_PACKAGE_PREFER_CONFIG) + # Try CONFIG + _find_package("${name}" CONFIG ${ARGN}) + + if(NOT ${name}_FOUND) + # CONFIG didn't work, fall back to MODULE + _find_package("${name}" MODULE ${ARGN}) + endif() + + else() + # Default behavior + _find_package(${ARGV}) - if(NOT ${name}_FOUND) - # CONFIG didn't work, fall back to MODULE - _find_package("${name}" MODULE ${ARGN}) endif() - endif() -endmacro(find_package) + endmacro(find_package) +endif() diff --git a/dtool/CompilerFlags.cmake b/dtool/CompilerFlags.cmake index 18f611352c..a947d50927 100644 --- a/dtool/CompilerFlags.cmake +++ b/dtool/CompilerFlags.cmake @@ -67,6 +67,7 @@ endif() # Set certain CMake flags we expect set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) # Set up the output directory structure, mimicking that of makepanda set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/cmake")