2 # types: DISABLED < RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED
4 macro(find_feature _feature _type _purpose _description)
6 string(TOUPPER ${_feature} _feature_upper)
7 string(TOLOWER ${_type} _type_lower)
9 if(${_type} STREQUAL "DISABLED")
10 set(_feature_default "OFF")
11 message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
13 if(${_type} STREQUAL "REQUIRED")
14 set(_feature_default "ON")
15 message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
16 find_package(${_feature} REQUIRED)
17 elseif(${_type} STREQUAL "RECOMMENDED")
18 if(NOT ${WITH_${_feature_upper}})
19 set(_feature_default "OFF")
20 message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
22 set(_feature_default "ON")
23 message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
24 message(STATUS " Disable feature ${_feature} using \"-DWITH_${_feature_upper}=OFF\"")
25 find_package(${_feature})
27 elseif(${_type} STREQUAL "OPTIONAL")
28 if(${WITH_${_feature_upper}})
29 set(_feature_default "ON")
30 message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
31 find_package(${_feature} REQUIRED)
33 set(_feature_default "OFF")
34 message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
35 message(STATUS " Enable feature ${_feature} using \"-DWITH_${_feature_upper}=ON\"")
38 set(_feature_default "ON")
39 message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
40 find_package(${_feature})
44 if(NOT ${${_feature_upper}_FOUND})
45 if(${_feature_default})
46 message(WARNING " feature ${_feature} was requested but could not be found! ${_feature_default} / ${${_feature_upper}_FOUND}")
48 set(_feature_default "OFF")
51 option(WITH_${_feature_upper} "Enable feature ${_feature} for ${_purpose}" ${_feature_default})
53 set_package_properties(${_feature} PROPERTIES
56 DESCRIPTION "${_description}")
58 endmacro(find_feature)