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.
This commit is contained in:
Sam Edwards 2018-09-21 19:22:59 -06:00
parent 968ca123d4
commit bd187643f3
2 changed files with 29 additions and 1 deletions

View File

@ -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)

View File

@ -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.")