@@ -15,7 +15,7 @@ ecosystem.
1515    *  [ 3.1.2. Directory variables] ( #312-directory-variables ) 
1616    *  [ 3.1.3. Cache variables] ( #313-cache-variables ) 
1717  *  [ 3.2. Naming variables] ( #32-naming-variables ) 
18-     *  [ 3.2.1. Configuration  variables] ( #321-configuration -variables ) 
18+     *  [ 3.2.1. Cache  variables] ( #321-cache -variables ) 
1919    *  [ 3.2.2. Find module variables] ( #322-find-module-variables ) 
2020    *  [ 3.2.3. Temporary variables] ( #323-temporary-variables ) 
2121  *  [ 3.3. Setting and unsetting variables] ( #33-setting-and-unsetting-variables ) 
@@ -47,8 +47,8 @@ system, especially when multiple developers are involved. Following some coding
4747conventions can maintain a clear and organized CMake project structure while
4848avoiding conflicts with external libraries and CMake scope.
4949
50- For instance, it's important to note that CMake functions, macros, and commands 
51- are  not case- sensitive. In other words, the following two expressions are
50+ For instance, it's important to note that CMake commands ( functions, macros) are 
51+ not case  sensitive. In other words, the following two expressions are
5252equivalent:
5353
5454``` cmake 
@@ -59,18 +59,26 @@ add_library(foo src.c)
5959ADD_LIBRARY(foo src.c) 
6060``` 
6161
62- On the contrary, variable names are case-sensitive.
62+ On the contrary, variable names are case sensitive:
63+ 
64+ ``` cmake 
65+ set(variable_name "value") 
66+ ``` 
67+ 
68+ ``` cmake 
69+ set(VARIABLE_NAME "value") 
70+ ``` 
6371
6472## 2. General guidelines  
6573
6674*  In most cases, the preferred style is to use ** all lowercase letters** .
6775
6876  ``` cmake 
69-   add_library(foo  src.c) 
77+   add_library(php_foo  src.c) 
7078
71-   function(bar argument ) 
72-     if(argument ) 
73-       set(var  "value") 
79+   function(php_function_name argument_name another_argument ) 
80+     if(argument_name ) 
81+       set(variable_name  "value") 
7482    endif() 
7583
7684    # ... 
@@ -102,8 +110,8 @@ On the contrary, variable names are case-sensitive.
102110  This practice facilitates concatenation of such variables:
103111
104112  ``` cmake 
105-   set(parentDir  "foo/bar") 
106-   set(childDir  "${parentDir}/baz") 
113+   set(parent_dir  "foo/bar") 
114+   set(child_dir  "${parentDir}/baz") 
107115``` 
108116
109117>  [ !TIP] 
@@ -166,15 +174,15 @@ and `PROJECT_BINARY_DIR`, or `<ProjectName>_SOURCE_DIR` and
166174For example, instead of:
167175
168176``` cmake 
169- set(somePath  ${CMAKE_SOURCE_DIR}/main/php_config.h) 
177+ set(some_path  ${CMAKE_SOURCE_DIR}/main/php_config.h) 
170178``` 
171179
172180use:
173181
174182``` cmake 
175- set(somePath  ${PROJECT_SOURCE_DIR}/file.h) 
183+ set(some_path  ${PROJECT_SOURCE_DIR}/file.h) 
176184# and 
177- set(somePath  ${PHP_SOURCE_DIR}/main/php_config.h) 
185+ set(some_path  ${PHP_SOURCE_DIR}/main/php_config.h) 
178186``` 
179187
180188These variables succinctly define the root directories of the project, ensuring
@@ -202,11 +210,11 @@ and manage them effectively within the project.
202210#### 3.1.1. Local variables  
203211
204212Variables with a scope inside functions and blocks. These should preferably be
205- in * camelCase * .
213+ in * snake_case * .
206214
207215``` cmake 
208216function(foo) 
209-   set(variableName  <value>) 
217+   set(variable_name  <value>) 
210218  # ... 
211219endfunction() 
212220``` 
@@ -230,7 +238,7 @@ child directories. To distinguish them, these variables should be in
230238* UPPER_CASE* .
231239
232240``` cmake 
233- set(VAR  <value>) 
241+ set(VARIABLE_NAME  <value>) 
234242``` 
235243
236244This naming convention helps identify the variables that pertain to the current
@@ -243,13 +251,13 @@ should be *UPPER_CASE*.
243251
244252``` cmake 
245253# Cache variable 
246- set(CACHE{VAR } TYPE <type> HELP <help> VALUE <value>) 
254+ set(CACHE{PHP_VAR } TYPE <type> HELP <help> VALUE <value>) 
247255
248256# Cache variable as a boolean option 
249- option(FOO  "<help_text >" [value]) 
257+ option(PHP_FOO  "<help >" [value]) 
250258
251259# Cache variables created by CMake command invocations. For example 
252- find_program(PHP_SED_EXECUTABLE sed) 
260+ find_program(PHP_SED_EXECUTABLE NAMES  sed) 
253261``` 
254262
255263### 3.2. Naming variables  
@@ -260,26 +268,28 @@ alphanumeric characters and underscores, enhancing readability.
260268Variables prefixed with ` CMAKE_ ` , ` _CMAKE_ ` , and ` _<any-cmake-command-name> `  are
261269reserved for CMake's internal use.
262270
263- #### 3.2.1. Configuration  variables  
271+ #### 3.2.1. Cache  variables  
264272
265- Configuration  variables are cache variables  designed to be adjusted by the user 
266- during the configuration phase, either  through the presets, command line, or by 
267- using GUI, such as cmake-gui or ccmake. It is  recommended to prefix them with 
268- ` PHP_ ` , and similar  to facilitate their grouping within the GUI or IDE.
273+ Cache  variables, either internal ones, or those  designed to be adjusted by the
274+ user  during the configuration phase, for example,  through the presets, command
275+ line, or by  using GUI, such as ` cmake-gui `  or ` ccmake ` , are  recommended to be 
276+ prefixed with  ` PHP_ `  to facilitate their grouping within the GUI or IDE.
269277
270278``` cmake 
271- option(PHP_ENABLE_FOO "<help_text>" [value]) 
272- cmake_dependent_option(PHP_ENABLE_BAR "<help_text>" <value> <depends> <force>) 
273- set(CACHE{PHP_FOO_BAR} TYPE <BOOL|FILEPATH|PATH|STRING> HELP <help> VALUE <value>) 
279+ option(PHP_ENABLE_FOO "<help>" [value]) 
280+ 
281+ cmake_dependent_option(PHP_ENABLE_BAR "<help>" <value> <depends> <force>) 
282+ 
283+ set(CACHE{PHP_FOO_BAR} TYPE <type> HELP <help> VALUE <value>) 
274284
275285# Zend Engine configuration variables 
276- option(PHP_ZEND_ENABLE_FOO "<help_text >" [value]) 
286+ option(PHP_ZEND_ENABLE_FOO "<help >" [value]) 
277287
278288# Configuration variables related to PHP extensions 
279- option(PHP_EXT_FOO "<help_text >" [value]) 
289+ option(PHP_EXT_FOO "<help >" [value]) 
280290
281291# Configuration variables related to PHP SAPI modules 
282- option(PHP_SAPI_FOO "<help_text >" [value]) 
292+ option(PHP_SAPI_FOO "<help >" [value]) 
283293``` 
284294
285295#### 3.2.2. Find module variables  
@@ -297,13 +307,14 @@ that these variables are meant exclusively for internal use within the current
297307CMake file and should not be accessed outside of that context.
298308
299309``` cmake 
300- set(_temporaryVariable  <value>) 
310+ set(_temporary_variable  <value>) 
301311``` 
302312
303313>  [ !TIP] 
304314>  Variables named ` _ `  can be used for values that are not important for code.
305315>  For example, here only the matched value of variable ` CMAKE_MATCH_1 `  is
306- >  important:
316+ >  important, while variable ` _ `  is used as a container for ` string() `  command
317+ >  argument and not used in the code later on:
307318> 
308319>  ``` cmake 
309320> string(REGEX MATCH "foo\\(([0-9]+)\\)" _ "${content}") 
@@ -317,23 +328,25 @@ scope to avoid unintended use of previous values. When ensuring a variable is
317328empty before use, explicitly set it to an empty string: 
318329
319330```cmake 
320- set(someVariable  "") 
331+ set(some_variable  "") 
321332``` 
322333
323334Avoid this approach:
324335
325336``` cmake 
326- set(someVariable) 
337+ set(some_variable) 
338+ # or 
339+ unset(some_variable) 
327340``` 
328341
329- The latter is equivalent to ` unset(someVariable ) ` , which can unintentionally
342+ The latter is equivalent to ` unset(some_variable ) ` , which can unintentionally
330343expose a cache variable with the same name if it exists. For example:
331344
332345``` cmake 
333- set(someVariable "Foo"  CACHE  INTERNAL "Some cache variable") 
346+ set(CACHE{some_variable} TYPE  INTERNAL HELP  "Some cache variable" VALUE "Foo ") 
334347# ... 
335- set(someVariable ) 
336- message(STATUS "${someVariable }") 
348+ set(some_variable ) 
349+ message(STATUS "${some_variable }") 
337350# Outputs: Foo 
338351``` 
339352
@@ -365,8 +378,8 @@ find_package(PackageName)
365378target_link_libraries(php PRIVATE PackageName::PackageName) 
366379``` 
367380
368- ` PackageName `  can be in any case (a-zA-Z0-9 ), with * PascalCase*  or package
369- original  name case preferred.
381+ ` PackageName `  can be in any case (a-zA-Z0-9 _ ), with * PascalCase*  or package
382+ upstream  name case preferred.
370383
371384### 4.2. Utility modules  
372385
@@ -391,7 +404,7 @@ upstream CMake modules.
391404CMake interprets ` 1 ` , ` ON ` , ` YES ` , ` TRUE ` , and ` Y `  as representing boolean true
392405values, while ` 0 ` , ` OFF ` , ` NO ` , ` FALSE ` , ` N ` , ` IGNORE ` , ` NOTFOUND ` , an empty
393406string, or any value ending with the suffix ` -NOTFOUND `  are considered boolean
394- false values. Named boolean constants are case- insensitive (e.g., ` on ` , ` Off ` ,
407+ false values. Named boolean constants are case  insensitive (e.g., ` on ` , ` Off ` ,
395408` True ` ).
396409
397410A general convention is to use ` ON `  and ` OFF `  for boolean values that can be
@@ -400,11 +413,11 @@ should not be modified externally. For example:
400413
401414``` cmake 
402415# Boolean variables that can be modified by the user use ON/OFF values 
403- option(FOO  "<help_text >" ON) 
416+ option(PHP_FOO  "<help >" ON) 
404417
405418# The IMPORTED property is set to TRUE and cannot be modified after being set 
406- add_library(foo  UNKNOWN IMPORTED) 
407- get_target_property(value foo  IMPORTED) 
419+ add_library(php_foo  UNKNOWN IMPORTED) 
420+ get_target_property(value php_foo  IMPORTED) 
408421message(STATUS "value=${value}") 
409422# Outputs: value=TRUE 
410423
@@ -424,11 +437,11 @@ prefix them contextually, for example `php_`. It is preferred to adhere to the
424437* snake_case*  style.
425438
426439``` cmake 
427- function(php_function_name argumentName ) 
440+ function(php_function_name argument_name ) 
428441  # Function body 
429442endfunction() 
430443
431- macro(php_macro_name argumentName ) 
444+ macro(php_macro_name argument_name ) 
432445  # Macro body 
433446endmacro() 
434447``` 
0 commit comments