# CMake Coding Style
###### tags: `Software Management` `DAQ` `DUNE`
### General
* Functions are always to be preferred over macros;
* Named arguments over all but the most basic mandatory unnamed arguments;
* No space between function name and open paren, except for `if`, `else` or `while`;
* Closing paren of a multi-line call on a separate line.
### Indention
Indent all code correctly, i.e. the body of
* if/else/endif
* foreach/endforeach
* while/endwhile
* macro/endmacro
* function/endfunction
Use spaces for indenting, 4 spaces.
### Functions
lower_case name.
Example: `do_something(...)`
### Local variables
lower_case name.
Local variables are used exclusively inside the file that contained them, and their values were simply passed as parameters to CMake functions.
Example: `set(some_variable "...")`
### Global variables
UPPER_CASE name.
Global variables(can also be called “export variables”) are intended for exporting up/down-stream via the environment variable mechanism.
Example: `set(SOME_VARIABLE "...")`
### Control statements
lower_case name without repeating the condition in the closing brackets.
Example:
```cmake
if(condition)
...
else() # not repeat condition
...
endif() # not repeat condition
```
### Operators
UPPER_CASE name.
Example: `if(condition STREQUAL "")`
### Directives and/or extra options
UPPER_CASE name.
Example: `do_something(... USE_THIS)`
## Examples
An real-world example:
```cmake
function(set_platform system_name)
if(${system_name} MATCHES "Darwin")
set(PLATFORM "darwin")
elseif(${system_name} MATCHES "Linux")
set(PLATFORM "linux")
else()
set(PLATFORM "")
endif()
endfunction()
cmake_minimum_required(VERSION 3.0)
set_platform(${CMAKE_SYSTEM_NAME})
```