summaryrefslogtreecommitdiffstats
path: root/cmake/FindFeature.cmake
blob: 63c4b6feddd30ed6142bcf17029bf77b3f9c2bdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
include(FeatureSummary)

# types: DISABLED < RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED

macro(find_feature _feature _type _purpose _description)

	string(TOUPPER ${_feature} _feature_upper)
	string(TOLOWER ${_type} _type_lower)

	if(${_type} STREQUAL "DISABLED")
		set(_feature_default "OFF")
		message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
	else()
		if(${_type} STREQUAL "REQUIRED")
			set(_feature_default "ON")
			message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
			find_package(${_feature} REQUIRED)
		elseif(${_type} STREQUAL "RECOMMENDED")
			if(NOT ${WITH_${_feature_upper}})
				set(_feature_default "OFF")
				message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
			else()
				set(_feature_default "ON")
				message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
				message(STATUS "    Disable feature ${_feature} using \"-DWITH_${_feature_upper}=OFF\"")
				find_package(${_feature})
				if (NOT ${_feature}_FOUND)
					set(_feature_default "OFF")
					message(STATUS "Not detected ${_type_lower} feature ${_feature} for ${_purpose} (${_description}), feature disabled")
				endif()
			endif()
		elseif(${_type} STREQUAL "OPTIONAL")
			if(${WITH_${_feature_upper}})
				set(_feature_default "ON")
				message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
				find_package(${_feature} REQUIRED)
			else()
				set(_feature_default "OFF")
				message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
				message(STATUS "    Enable feature ${_feature} using \"-DWITH_${_feature_upper}=ON\"")
			endif()
		else()
			set(_feature_default "ON")
			message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
			find_package(${_feature})
		endif()
		

		if(NOT ${${_feature}_FOUND})
			if(${_feature_default})
				message(WARNING "    feature ${_feature} was requested but could not be found! ${_feature_default} / ${${_feature}_FOUND}")
			endif()
			set(_feature_default "OFF")
		endif()

		option(WITH_${_feature_upper} "Enable feature ${_feature} for ${_purpose}" ${_feature_default})

		set_package_properties(${_feature} PROPERTIES
			TYPE ${_type}
			PURPOSE "${_purpose}"
			DESCRIPTION "${_description}")
	endif()
endmacro(find_feature)