Debian Codegraph @

cmake/modules/PrintableOptions.cmake

raw
1 # PrintableOptions.cmake
2 #
3 # Provides functions to manage printable options,
4 # which can be printed at the end of the configuration
5 #
6 # add_printable_variable_bare(_name)
7 # adds variable named _name to the list of prinable options
8 #
9 # add_printable_option(_name _description _default_value)
10 # the same as option() command, only also notes this option for later printing
11 #
12 # add_printable_variable(_name _description _default_value)
13 # sets a new cached STRING variable and adds it to the list of printable options
14 #
15 # add_printable_variable_path(_name _description _default_value)
16 # sets a new cached PATH variable and adds it to the list of printable options
17 #
18 # print_build_options()
19 # prints all the build options previously added with the above functions
20
21 macro(add_printable_variable_bare _name)
22 if("${_name}" STREQUAL "")
23 message(FATAL_ERROR "variable name cannot be empty")
24 endif("${_name}" STREQUAL "")
25 list(APPEND _printable_options ${_name})
26 endmacro()
27
28 macro(add_printable_option _name _description _default_value)
29 if("${_name}" STREQUAL "")
30 message(FATAL_ERROR "option name cannot be empty")
31 endif("${_name}" STREQUAL "")
32 option(${_name} ${_description} ${_default_value})
33 add_printable_variable_bare(${_name})
34 endmacro()
35
36 macro(add_printable_variable _name _description _default_value)
37 if("${_name}" STREQUAL "")
38 message(FATAL_ERROR "variable name cannot be empty")
39 endif("${_name}" STREQUAL "")
40 set(${_name} ${_default_value} CACHE STRING ${_description})
41 add_printable_variable_bare(${_name})
42 endmacro()
43
44 macro(add_printable_variable_path _name _description _default_value)
45 if("${_name}" STREQUAL "")
46 message(FATAL_ERROR "path variable name cannot be empty")
47 endif("${_name}" STREQUAL "")
48 set(${_name} ${_default_value} CACHE PATH ${_description})
49 add_printable_variable_bare(${_name})
50 endmacro()
51
52 macro(add_printable_variable_filepath _name _description _default_value)
53 if("${_name}" STREQUAL "")
54 message(FATAL_ERROR "filepath variable name cannot be empty")
55 endif("${_name}" STREQUAL "")
56 set(${_name} ${_default_value} CACHE FILEPATH ${_description})
57 add_printable_variable_bare(${_name})
58 endmacro()
59
60 function(print_build_options)
61 message(STATUS "Configure options:")
62
63 set(max_len 0)
64 foreach(opt IN LISTS _printable_options)
65 string(LENGTH "${opt}" len)
66 if(max_len LESS len)
67 set(max_len ${len})
68 endif(max_len LESS len)
69 endforeach()
70 math(EXPR max_len "${max_len} + 2")
71
72 foreach(opt IN LISTS _printable_options)
73 string(LENGTH "${opt}" len)
74 set(str " ${opt} ")
75 foreach (IGNORE RANGE ${len} ${max_len})
76 set(str "${str}.")
77 endforeach ()
78 set(str "${str} ${${opt}}")
79
80 message(STATUS ${str})
81 endforeach()
82 endfunction()