blob: c9c0b6d134e85ecf3432d2ecb5cf451f80fd5a89 (
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
|
#[=======================================================================[.rst:
DefaultOption
-------------
Macros to provide an option with defaults dependent on other options.
Usage:
.. code-block:: cmake
default_option(<option> "<help_text>" <depends>)
Where ``<option>`` uses the given ``<help_text>`` and is ``ON`` by default if
``<depends>`` is true. If the ``<depends>`` condition is not true,
``<option>`` will be ``OFF`` by default. Each element in the ``<depends>``
parameter is evaluated as an if-condition, so :ref:`Condition Syntax` can be
used.
Example invocation:
.. code-block:: cmake
default_option(USE_FOO "Use Foo" "USE_BAR;NOT USE_ZOT")
If ``USE_BAR`` is true and ``USE_ZOT`` is false, the option called ``USE_FOO``
will default to ``ON``, otherwise it will default to ``OFF``.
In contrast to ``cmake_dependent_option`` which disables the option completely
if the ``<depends>`` condition evaluates to false, ``default_option`` will only
set a default and the value may be overridden by the user.
#]=======================================================================]
macro(DEFAULT_OPTION option doc depends)
set(${option}_DEFAULT_ON 1)
foreach(d ${depends})
string(REGEX REPLACE " +" ";" DEFAULT_OPTION_DEP "${d}")
if(${DEFAULT_OPTION_DEP})
else()
set(${option}_DEFAULT_ON 0)
endif()
endforeach()
if(${option}_DEFAULT_ON)
option(${option} "${doc}" "ON")
else()
option(${option} "${doc}" "OFF")
endif()
endmacro()
|