-
Notifications
You must be signed in to change notification settings - Fork 213
/
OptionRequires.cmake
52 lines (44 loc) · 1.33 KB
/
OptionRequires.cmake
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
# - Add an option that depends on one or more variables being true.
#
# option_requires(<option_name> <description> <variable_name> [<variable_name>...])
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
function(option_requires name desc)
set(args ${ARGN})
set(OFF_BY_DEFAULT true)
list(FIND args "OFF_BY_DEFAULT" _off_found)
if(NOT _off_found EQUAL -1)
list(REMOVE_AT args ${_off_found})
set(OFF_BY_DEFAULT true)
endif()
set(found)
set(missing)
foreach(var ${args})
if(${var})
list(APPEND found ${var})
else()
list(APPEND missing ${var})
endif()
endforeach()
if(NOT missing)
set(OK TRUE)
else()
set(OK FALSE)
endif()
set(default ${OK})
if(OFF_BY_DEFAULT)
set(default OFF)
endif()
option(${name} "${desc}" ${default})
if(${name} AND (NOT OK))
message(FATAL_ERROR "${name} enabled but these dependencies were not valid: ${missing}")
endif()
endfunction()