| 1 |
# - MACRO_OPTIONAL_FIND_PACKAGE() combines FIND_PACKAGE() with an OPTION() |
| 2 |
# MACRO_OPTIONAL_FIND_PACKAGE( <name> [QUIT] ) |
| 3 |
# This macro is a combination of OPTION() and FIND_PACKAGE(), it |
| 4 |
# works like FIND_PACKAGE(), but additionally it automatically creates |
| 5 |
# an option name WITH_<name>, which can be disabled via the cmake GUI. |
| 6 |
# or via -DWITH_<name>=OFF |
| 7 |
# The standard <name>_FOUND variables can be used in the same way |
| 8 |
# as when using the normal FIND_PACKAGE() |
| 9 |
|
| 10 |
# SPDX-FileCopyrightText: 2006-2010 Alexander Neundorf <[email protected]> |
| 11 |
# |
| 12 |
# Redistribution and use is allowed according to the terms of the BSD license. |
| 13 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 14 |
|
| 15 |
# This is just a helper macro to set a bunch of variables empty. |
| 16 |
# We don't know whether the package uses UPPERCASENAME or CamelCaseName, so we try both: |
| 17 |
macro(_MOFP_SET_EMPTY_IF_DEFINED _name _var) |
| 18 |
if(DEFINED ${_name}_${_var}) |
| 19 |
set(${_name}_${_var} "") |
| 20 |
endif(DEFINED ${_name}_${_var}) |
| 21 |
|
| 22 |
string(TOUPPER ${_name} _nameUpper) |
| 23 |
if(DEFINED ${_nameUpper}_${_var}) |
| 24 |
set(${_nameUpper}_${_var} "") |
| 25 |
endif(DEFINED ${_nameUpper}_${_var}) |
| 26 |
endmacro(_MOFP_SET_EMPTY_IF_DEFINED _package _var) |
| 27 |
|
| 28 |
|
| 29 |
macro (MACRO_OPTIONAL_FIND_PACKAGE _name ) |
| 30 |
option(WITH_${_name} "Search for ${_name} package" ON) |
| 31 |
if (WITH_${_name}) |
| 32 |
find_package(${_name} ${ARGN}) |
| 33 |
else (WITH_${_name}) |
| 34 |
string(TOUPPER ${_name} _nameUpper) |
| 35 |
set(${_name}_FOUND FALSE) |
| 36 |
set(${_nameUpper}_FOUND FALSE) |
| 37 |
|
| 38 |
_mofp_set_empty_if_defined(${_name} INCLUDE_DIRS) |
| 39 |
_mofp_set_empty_if_defined(${_name} INCLUDE_DIR) |
| 40 |
_mofp_set_empty_if_defined(${_name} INCLUDES) |
| 41 |
_mofp_set_empty_if_defined(${_name} LIBRARY) |
| 42 |
_mofp_set_empty_if_defined(${_name} LIBRARIES) |
| 43 |
_mofp_set_empty_if_defined(${_name} LIBS) |
| 44 |
_mofp_set_empty_if_defined(${_name} FLAGS) |
| 45 |
_mofp_set_empty_if_defined(${_name} DEFINITIONS) |
| 46 |
endif (WITH_${_name}) |
| 47 |
endmacro (MACRO_OPTIONAL_FIND_PACKAGE) |
| 48 |
|