Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | # |
| 5 | |
| 6 | #[=======================================================================[.rst: |
| 7 | ArmConfigOptionOverride |
| 8 | ----------------------- |
| 9 | |
| 10 | .. default-domain:: cmake |
| 11 | |
| 12 | .. command:: arm_config_option_override |
| 13 | |
| 14 | Override 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 | |
| 22 | Override Default Value |
| 23 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 24 | |
| 25 | .. code:: cmake |
| 26 | |
| 27 | arm_config_option_override(NAME <name> DEFAULT <default>) |
| 28 | |
| 29 | Overrides the default value of the configuration option ``<name>`` with the |
| 30 | value ``<default>``. |
| 31 | |
| 32 | For 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 | |
| 44 | In this situation, the configuration option ``USE_FOO`` is created with a |
| 45 | default value of ``FALSE``, but will use the overridden default value of |
| 46 | ``TRUE``. This is most often useful in larger projects where certain default |
| 47 | values make more sense under certain conditions. |
| 48 | |
| 49 | Forcibly Override Value |
| 50 | ======================= |
| 51 | |
| 52 | .. code:: cmake |
| 53 | |
| 54 | arm_config_option_override(NAME <name> FORCE <force>) |
| 55 | |
| 56 | Forcibly overrides the value of the configuration option ``<name>`` with |
| 57 | ``<force>``. |
| 58 | |
| 59 | For 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 | |
| 71 | In this situation, ``USE_FOO`` will be forcibly set to ``TRUE``, and it will be |
| 72 | hidden from the GUI. Users may also no longer configure this value themselves. |
| 73 | Attempting to change the value of the configuration option will cause a |
| 74 | configuration failure, and the previous value will be restored. |
| 75 | #]=======================================================================] |
| 76 | |
| 77 | include_guard() |
| 78 | |
| 79 | function(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() |
| 94 | endfunction() |