|
| 1 | +# PHP/Set |
| 2 | + |
| 3 | +See: [Set.cmake](https://github.com/petk/php-build-system/tree/master/cmake/cmake/modules/PHP/Set.cmake) |
| 4 | + |
| 5 | +Set a CACHE variable that depends on a set of conditions. |
| 6 | + |
| 7 | +In CMake there are 3 main ways to create non-internal cache variables that can |
| 8 | +be also customized using the `-D` command-line option, through CMake presets, or |
| 9 | +similar: |
| 10 | +* `option()` |
| 11 | +* `set(<variable> <value> CACHE <type> <docstring>)` |
| 12 | +* `cmake_dependent_option()` |
| 13 | + |
| 14 | +Ideally, these are the recommended ways to set configuration variables. However, |
| 15 | +there are many cases where a `CACHE` variable of a type other than `BOOL` |
| 16 | +depends on certain conditions. Additionally, an edge-case issue with |
| 17 | +`cmake_dependent_option()` is that it sets a local variable if the conditions |
| 18 | +are not met. Local variables in such edge cases can be difficult to work with |
| 19 | +when using `add_subdirectory()`. In the parent scope, instead of the local |
| 20 | +variable with a forced value, the cached variable is still defined as |
| 21 | +`INTERNAL`, which can lead to bugs in the build process. |
| 22 | + |
| 23 | +This module exposes the following function: |
| 24 | + |
| 25 | +```cmake |
| 26 | +php_set( |
| 27 | + <variable> |
| 28 | + <default> |
| 29 | + CACHE <type> |
| 30 | + [STRINGS <string>...] |
| 31 | + [DOC <docstring>...] |
| 32 | + IF <condition> |
| 33 | + FORCED <forced> |
| 34 | +) |
| 35 | +``` |
| 36 | + |
| 37 | +It sets the given CACHE `<variable>` of `<type>` to a `<value>` if `<condition>` |
| 38 | +is met. Otherwise it sets the `<variable>` to `<default>` value and hides it in |
| 39 | +the GUI. |
| 40 | + |
| 41 | +* The `CACHE` `<type>` can be `BOOL`, `FILEPATH`, `PATH`, or `STRING`. |
| 42 | + |
| 43 | +* `STRINGS` is an optional list of items when `CACHE` `STRING` is used to create |
| 44 | + a list of supported options to pick in the GUI. |
| 45 | + |
| 46 | +* `DOC` is a short variable help text visible in the GUIs. Multiple strings are |
| 47 | + joined together. |
| 48 | + |
| 49 | +* `IF` behaves the same as the `<depends>` argument in |
| 50 | + `cmake_dependent_option()`. If conditions `<condition>` are met, the variable |
| 51 | + is set to `<default>` value. Otherwise, it is set to `<forced>` value and |
| 52 | + hidden in the GUIs. This supports both full condition sytanx and |
| 53 | + semicolon-separated list of conditions. |
| 54 | + |
| 55 | +* `FORCED` is a value that is set when `IF <conditions>` are not met. |
0 commit comments