File: PrintableOptions.cmake

package info (click to toggle)
evolution 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 135,044 kB
  • sloc: ansic: 519,950; javascript: 8,494; xml: 5,207; python: 702; makefile: 563; sh: 294; perl: 169
file content (82 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download | duplicates (10)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# PrintableOptions.cmake
#
# Provides functions to manage printable options,
# which can be printed at the end of the configuration
#
# add_printable_variable_bare(_name)
#    adds variable named _name to the list of prinable options
#
# add_printable_option(_name _description _default_value)
#    the same as option() command, only also notes this option for later printing
#
# add_printable_variable(_name _description _default_value)
#    sets a new cached STRING variable and adds it to the list of printable options
#
# add_printable_variable_path(_name _description _default_value)
#    sets a new cached PATH variable and adds it to the list of printable options
#
# print_build_options()
#    prints all the build options previously added with the above functions

macro(add_printable_variable_bare _name)
	if("${_name}" STREQUAL "")
		message(FATAL_ERROR "variable name cannot be empty")
	endif("${_name}" STREQUAL "")
	list(APPEND _printable_options ${_name})
endmacro()

macro(add_printable_option _name _description _default_value)
	if("${_name}" STREQUAL "")
		message(FATAL_ERROR "option name cannot be empty")
	endif("${_name}" STREQUAL "")
	option(${_name} ${_description} ${_default_value})
	add_printable_variable_bare(${_name})
endmacro()

macro(add_printable_variable _name _description _default_value)
	if("${_name}" STREQUAL "")
		message(FATAL_ERROR "variable name cannot be empty")
	endif("${_name}" STREQUAL "")
	set(${_name} ${_default_value} CACHE STRING ${_description})
	add_printable_variable_bare(${_name})
endmacro()

macro(add_printable_variable_path _name _description _default_value)
	if("${_name}" STREQUAL "")
		message(FATAL_ERROR "path variable name cannot be empty")
	endif("${_name}" STREQUAL "")
	set(${_name} ${_default_value} CACHE PATH ${_description})
	add_printable_variable_bare(${_name})
endmacro()

macro(add_printable_variable_filepath _name _description _default_value)
	if("${_name}" STREQUAL "")
		message(FATAL_ERROR "filepath variable name cannot be empty")
	endif("${_name}" STREQUAL "")
	set(${_name} ${_default_value} CACHE FILEPATH ${_description})
	add_printable_variable_bare(${_name})
endmacro()

function(print_build_options)
	message(STATUS "Configure options:")

	set(max_len 0)
	foreach(opt IN LISTS _printable_options)
		string(LENGTH "${opt}" len)
		if(max_len LESS len)
			set(max_len ${len})
		endif(max_len LESS len)
	endforeach()
	math(EXPR max_len "${max_len} + 2")

	foreach(opt IN LISTS _printable_options)
		string(LENGTH "${opt}" len)
		set(str "   ${opt} ")
		foreach (IGNORE RANGE ${len} ${max_len})
			set(str "${str}.")
		endforeach ()
		set(str "${str} ${${opt}}")

		message(STATUS ${str})
	endforeach()
endfunction()