Backported #6865: Disable websockets command line option
[platform/upstream/freerdp.git] / cmake / FindFeature.cmake
1
2 # types: DISABLED < RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED
3
4 macro(find_feature _feature _type _purpose _description)
5
6         string(TOUPPER ${_feature} _feature_upper)
7         string(TOLOWER ${_type} _type_lower)
8
9         if(${_type} STREQUAL "DISABLED")
10                 set(_feature_default "OFF")
11                 message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
12         else()
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})")
21                         else()
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})
26                         endif()
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)
32                         else()
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\"")
36                         endif()
37                 else()
38                         set(_feature_default "ON")
39                         message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
40                         find_package(${_feature})
41                 endif()
42                 
43
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}")
47                         endif()
48                         set(_feature_default "OFF")
49                 endif()
50
51                 option(WITH_${_feature_upper} "Enable feature ${_feature} for ${_purpose}" ${_feature_default})
52
53                 set_package_properties(${_feature} PROPERTIES
54                         TYPE ${_type}
55                         PURPOSE "${_purpose}"
56                         DESCRIPTION "${_description}")
57         endif()
58 endmacro(find_feature)
59