Skip to content

Commit 850ce67

Browse files
committed
Update code style
1 parent 55cea5b commit 850ce67

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

docs/cmake/cmake-code-style.md

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ block of code:
221221
```cmake
222222
block()
223223
set(bar <value>)
224-
225-
# <commands>...
224+
# ...
226225
endblock()
227226
```
228227

@@ -254,7 +253,7 @@ set(VAR <value> CACHE <type> "<help_text>")
254253
option(FOO "<help_text>" [value])
255254
256255
# Cache variables created by CMake command invocations. For example
257-
find_program(RE2C_EXECUTABLE re2c)
256+
find_program(SED_EXECUTABLE sed)
258257
```
259258

260259
### 3.2. Naming variables
@@ -270,11 +269,10 @@ reserved for CMake's internal use.
270269
Configuration variables are cache variables designed to be adjusted by the user
271270
during the configuration phase, either through the presets, command line, or by
272271
using GUI, such as cmake-gui or ccmake. It is recommended to prefix them with
273-
`PHP_`, `ZEND_`, `EXT_`, and similar to facilitate their grouping within the
274-
GUI or IDE.
272+
`PHP_`, `ZEND_`, `EXT_`, `SAPI_`, and similar to facilitate their grouping
273+
within the GUI or IDE.
275274

276275
```cmake
277-
# PHP configuration variables
278276
set(PHP_FOO_BAR <value>... CACHE <BOOL|FILEPATH|PATH|STRING> "<help_text>")
279277
option(PHP_ENABLE_FOO "<help_text>" [value])
280278
cmake_dependent_option(PHP_ENABLE_BAR "<help_text>" <value> <depends> <force>)
@@ -284,6 +282,9 @@ option(ZEND_ENABLE_FOO "<help_text>" [value])
284282
285283
# Configuration variables related to PHP extensions
286284
option(EXT_FOO "<help_text>" [value])
285+
286+
# Configuration variables related to PHP SAPI modules
287+
option(SAPI_FOO "<help_text>" [value])
287288
```
288289

289290
While it's a good practice to consider grouping variables inside an extension by
@@ -295,12 +296,16 @@ the primary prefix `EXT_` can be optional and context-dependent, when the
295296
extension involves multiple options:
296297

297298
```cmake
299+
# These will be grouped in the 'EXT_' group
298300
option(EXT_GD "<help_text>" [value])
299301
cmake_dependent_option(EXT_GD_AVIF "<help_text>" OFF "EXT_GD" OFF)
300302
cmake_dependent_option(EXT_GD_WEBP "<help_text>" OFF "EXT_GD" OFF)
301303
304+
# Here, the 'EXT_MYSQL_SOCKET' is used by both extensions - mysqli and pdo_mysql
302305
option(EXT_MYSQLI "<help_text>" [value])
306+
# ...
303307
option(EXT_PDO_MYSQL "<help_text>" [value])
308+
# ...
304309
cmake_dependent_option(
305310
EXT_MYSQL_SOCKET
306311
"<help_text>"
@@ -388,22 +393,26 @@ upstream CMake modules.
388393

389394
CMake interprets `1`, `ON`, `YES`, `TRUE`, and `Y` as representing boolean true
390395
values, while `0`, `OFF`, `NO`, `FALSE`, `N`, `IGNORE`, `NOTFOUND`, an empty
391-
string, or a value ending with the suffix `-NOTFOUND` are considered as boolean
392-
false values. Named boolean constants are case-insensitive.
396+
string, or any value ending with the suffix `-NOTFOUND` are considered boolean
397+
false values. Named boolean constants are case-insensitive (e.g., `on`, `Off`,
398+
`True`).
393399

394-
To ensure compatibility with existing C code and the configuration header
395-
`php_config.h`, some potential simplifications may be considered for this
396-
repository:
400+
A general convention is to use `ON` and `OFF` for boolean values that can be
401+
modified by the user, and `TRUE` and `FALSE` for intrinsic values that cannot or
402+
should not be modified externally. For example:
397403

398404
```cmake
399-
# Options have ON/OFF values.
405+
# Boolean variables that can be modified by the user use ON/OFF values
400406
option(FOO "<help_text>" ON)
401407
402-
# Conditional variables have 1/0 values.
403-
set(HAVE_FOO_H 1 CACHE INTERNAL "<help_text>")
408+
# The IMPORTED property is set to TRUE and cannot be modified after being set
409+
add_library(foo UNKNOWN IMPORTED)
410+
get_target_property(value foo IMPORTED)
411+
message(STATUS "value=${value}")
412+
# Outputs: value=TRUE
404413
405-
# Elsewhere in commands, functions, etc. use TRUE/FALSE
406-
set(CMAKE_C_STANDARD_REQUIRED TRUE)
414+
# Similarly, intrinsic values in the code use TRUE/FALSE
415+
set(HAVE_FOO TRUE)
407416
```
408417

409418
## 6. Functions and macros
@@ -601,13 +610,12 @@ Values for `CMAKE_HOST_SYSTEM_PROCESSOR` and `CMAKE_SYSTEM_PROCESSOR`:
601610

602611
### 10.1. Tools
603612

604-
There are some tools available for formatting and linting CMake files, each with
605-
varying levels of maintenance and utility. While these tools can offer valuable
606-
assistance, it's worth emphasizing that the current recommendation is generally
607-
not to rely on any specific linting tool. This is primarily due to their varying
608-
levels of maturity and a lack of updates to keep pace with new CMake versions.
609-
It's worth mentioning that this recommendation may evolve in the future as these
610-
tools continue to develop and adapt.
613+
There are some tools available for formatting and linting CMake files. While
614+
these tools can offer valuable assistance, it's worth emphasizing that the
615+
current recommendation is generally not to rely on any specific linting tool.
616+
This is primarily due to their varying levels of utility and a lack of updates
617+
to keep pace with new CMake versions. It's worth mentioning that this
618+
recommendation may evolve in the future as these tools continue to develop.
611619

612620
#### 10.1.1. Gersemi
613621

@@ -702,3 +710,4 @@ values from the upstream defaults.
702710
### 10.2. Further resources
703711

704712
* [CMake developers docs](https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html)
713+
* [CMake documentation guide](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/documentation.rst)

0 commit comments

Comments
 (0)