blob: 8e5b270aa7b9a8a69917a73d8d78087a3f165168 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001#
2# SPDX-License-Identifier: BSD-3-Clause
3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4#
5
6#[=======================================================================[.rst:
7ArmConfigOptionOverride
8-----------------------
9
10.. default-domain:: cmake
11
12.. command:: arm_config_option_override
13
14Override the default or final value of a configuration option defined by
15:command:`arm_config_option`.
16
17.. note::
18
19 Configuration options can only be overridden if their dependencies are met.
20 This ensures the configuration space is always in a valid state.
21
22Override Default Value
23^^^^^^^^^^^^^^^^^^^^^^
24
25.. code:: cmake
26
27 arm_config_option_override(NAME <name> DEFAULT <default>)
28
29Overrides the default value of the configuration option ``<name>`` with the
30value ``<default>``.
31
32For example:
33
34.. code:: cmake
35
36 arm_config_option_override(
37 NAME MYPROJECT_USE_FOO
38 DEFAULT TRUE)
39
40 arm_config_option(
41 NAME MYPROJECT_USE_FOO
42 HELP "Use foo.")
43
44In this situation, the configuration option ``USE_FOO`` is created with a
45default value of ``FALSE``, but will use the overridden default value of
46``TRUE``. This is most often useful in larger projects where certain default
47values make more sense under certain conditions.
48
49Forcibly Override Value
50=======================
51
52.. code:: cmake
53
54 arm_config_option_override(NAME <name> FORCE <force>)
55
56Forcibly overrides the value of the configuration option ``<name>`` with
57``<force>``.
58
59For example:
60
61.. code:: cmake
62
63 arm_config_option_override(
64 NAME MYPROJECT_USE_FOO
65 FORCE TRUE)
66
67 arm_config_option(
68 NAME MYPROJECT_USE_FOO
69 HELP "Use foo.")
70
71In this situation, ``USE_FOO`` will be forcibly set to ``TRUE``, and it will be
72hidden from the GUI. Users may also no longer configure this value themselves.
73Attempting to change the value of the configuration option will cause a
74configuration failure, and the previous value will be restored.
75#]=======================================================================]
76
77include_guard()
78
79function(arm_config_option_override)
80 set(_options "")
81 set(_single_args "NAME;DEFAULT;FORCE")
82 set(_multi_args "")
83
84 cmake_parse_arguments(arg "${_options}" "${_single_args}" "${_multi_args}"
85 ${ARGN})
86
87 if(DEFINED arg_FORCE)
88 set("${arg_NAME}_FORCE" "${arg_FORCE}" CACHE INTERNAL
89 "Forced value for `${arg_NAME}`." FORCE)
90 elseif(DEFINED arg_DEFAULT)
91 set("${arg_NAME}_INIT" "${arg_DEFAULT}" CACHE INTERNAL
92 "Default value for `${arg_NAME}`." FORCE)
93 endif()
94endfunction()