Explorar el Código

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.
Sam Edwards hace 7 años
padre
commit
bd187643f3
Se han modificado 2 ficheros con 29 adiciones y 1 borrados
  1. 28 0
      cmake/macros/PackageConfig.cmake
  2. 1 1
      dtool/Package.cmake

+ 28 - 0
cmake/macros/PackageConfig.cmake

@@ -256,3 +256,31 @@ function(show_packages)
     endif()
     endif()
   endforeach()
   endforeach()
 endfunction()
 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)

+ 1 - 1
dtool/Package.cmake

@@ -296,7 +296,7 @@ package_option(GTK2)
 #
 #
 
 
 # Bullet
 # Bullet
-find_package(Bullet QUIET)
+find_package(Bullet MODULE QUIET)
 
 
 package_option(BULLET
 package_option(BULLET
   "Enable this option to support game dynamics with the Bullet physics library.")
   "Enable this option to support game dynamics with the Bullet physics library.")