From bd187643f361b519d6369fcff699ebfd9e7ff63b Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Fri, 21 Sep 2018 19:22:59 -0600 Subject: [PATCH] CMake: Look for packages by CONFIG first This requires a macro to override find_package, as the default behavior in CMake is to fall back from MODULE onto CONFIG. Note that Bullet is given a specific override not to look for a CONFIG, since Bullet tends to use weird paths in its CONFIG script. --- cmake/macros/PackageConfig.cmake | 28 ++++++++++++++++++++++++++++ dtool/Package.cmake | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake index 847cb95281..b35b5e5bb9 100644 --- a/cmake/macros/PackageConfig.cmake +++ b/cmake/macros/PackageConfig.cmake @@ -256,3 +256,31 @@ function(show_packages) endif() endforeach() endfunction() + +# +# 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. +# +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() + string(TOUPPER "${name}" __pkgname_upper) + + # Try CONFIG + _find_package("${name}" CONFIG ${ARGN}) + if(NOT ${name}_FOUND) + # CONFIG didn't work, fall back to MODULE + _find_package("${name}" MODULE ${ARGN}) + else() + # Case-sensitivity + set(${__pkgname_upper}_FOUND 1) + endif() + endif() +endmacro(find_package) diff --git a/dtool/Package.cmake b/dtool/Package.cmake index 2d01f72d39..558871f43a 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -296,7 +296,7 @@ package_option(GTK2) # # Bullet -find_package(Bullet QUIET) +find_package(Bullet MODULE QUIET) package_option(BULLET "Enable this option to support game dynamics with the Bullet physics library.")