Use config mode if possible when finding packages
This commit is contained in:
parent
7104ac7dae
commit
e75d69ef1d
@ -55,9 +55,30 @@ endforeach (name)
|
||||
macro (find_and_append_package_to prefix name)
|
||||
# if we have specified a directory, don't revert to searching the
|
||||
# system default paths afterwards
|
||||
string (TOUPPER "${name}" NAME)
|
||||
string (REPLACE "-" "_" NAME "${NAME}")
|
||||
# the documentation says that if *-config.cmake files are not found,
|
||||
# find_package will revert to doing a full search, but that is not
|
||||
# true, so unconditionally setting ${name}_DIR is not safe. however,
|
||||
# if the directory given to us contains a config file, then copy the
|
||||
# value over to this variable to switch to config mode (CMake will
|
||||
# always use config mode if *_DIR is defined)
|
||||
if (NOT DEFINED ${name}_DIR AND (DEFINED ${name}_ROOT OR DEFINED ${NAME}_ROOT))
|
||||
if (EXISTS ${${name}_ROOT}/${name}-config.cmake OR EXISTS ${${name}_ROOT}/${name}Config.cmake)
|
||||
set (${name}_DIR "${${name}_ROOT}")
|
||||
endif (EXISTS ${${name}_ROOT}/${name}-config.cmake OR EXISTS ${${name}_ROOT}/${name}Config.cmake)
|
||||
if (EXISTS ${${NAME}_ROOT}/${name}-config.cmake OR EXISTS ${${NAME}_ROOT}/${name}Config.cmake)
|
||||
set (${name}_DIR "${${NAME}_ROOT}")
|
||||
endif (EXISTS ${${NAME}_ROOT}/${name}-config.cmake OR EXISTS ${${NAME}_ROOT}/${name}Config.cmake)
|
||||
endif (NOT DEFINED ${name}_DIR AND (DEFINED ${name}_ROOT OR DEFINED ${NAME}_ROOT))
|
||||
# using config mode is better than using module (aka. find) mode
|
||||
# because then the package has already done all its probes and
|
||||
# stored them in the config file for us
|
||||
if (${name}_DIR)
|
||||
find_package (${name} ${ARGN} PATHS ${${name}_DIR} NO_DEFAULT_PATH)
|
||||
message (STATUS "Finding package ${name} using config mode")
|
||||
find_package (${name} ${ARGN} CONFIG PATHS ${${name}_DIR} NO_DEFAULT_PATH)
|
||||
else (${name}_DIR)
|
||||
message (STATUS "Finding package ${name} using module mode")
|
||||
find_package (${name} ${ARGN})
|
||||
endif (${name}_DIR)
|
||||
if (${name}_FOUND)
|
||||
@ -73,7 +94,6 @@ macro (find_and_append_package_to prefix name)
|
||||
endif (DEFINED ${name}_${var})
|
||||
endforeach (var)
|
||||
# some libraries only define xxx_FOUND and not a corresponding HAVE_xxx
|
||||
string (TOUPPER "${name}" NAME)
|
||||
if (NOT DEFINED HAVE_${NAME})
|
||||
set (HAVE_${NAME} 1)
|
||||
endif (NOT DEFINED HAVE_${NAME})
|
||||
|
Loading…
Reference in New Issue
Block a user