File: OptionRequires.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (53 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (7)
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
# - 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 <rpavlik@iastate.edu> <abiryan@ryand.net>
# 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 false)
	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()