(new "End Commands" section) |
(→Upper/lower casing) |
||
| Line 16: | Line 16: | ||
==Upper/lower casing== | ==Upper/lower casing== | ||
| − | + | Most important: use consistent upper- or lowercasing within one file ! | |
| + | |||
| + | In general, in KDE the '''all-lowercase''' style is preferred. | ||
| + | |||
| + | So, this is recommended: | ||
<syntaxhighlight lang="cmake"> | <syntaxhighlight lang="cmake"> | ||
add_executable(foo foo.c) | add_executable(foo foo.c) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | This is also acceptable: | ||
| + | |||
| + | <syntaxhighlight lang="cmake"> | ||
ADD_EXECUTABLE(bar bar.c) | ADD_EXECUTABLE(bar bar.c) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | Mixed casing as shown below works too, but should '''not''' be done within KDE: | ||
| + | <syntaxhighlight lang="cmake"> | ||
Add_Executable(hello hello.c) | Add_Executable(hello hello.c) | ||
aDd_ExEcUtAbLe(blub blub.c) | aDd_ExEcUtAbLe(blub blub.c) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | |||
| − | |||
| − | |||
| − | |||
== End commands == | == End commands == | ||
This document describes the recommended coding style for CMake files in KDE, i.e. CMakeLists.txt files and *.cmake files.
Contents |
Indent all code correctly, i.e. the body of
Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount of spaces for indenting as is used in the rest of the file. Do not use tabs.
Most important: use consistent upper- or lowercasing within one file !
In general, in KDE the all-lowercase style is preferred.
So, this is recommended:
add_executable(foo foo.c)
This is also acceptable:
ADD_EXECUTABLE(bar bar.c)
Mixed casing as shown below works too, but should not be done within KDE:
Add_Executable(hello hello.c) aDd_ExEcUtAbLe(blub blub.c)
To make the code easier to read, use empty commands for endforeach(), endif(), endfunction(), endmacro() and endwhile(). Also, use empty else() commands.
For example, do this:
if(FOOVAR) some_command(...) else() another_command(...) endif()
and not this:
if(FOOVAR) some_command(...) else(FOOVAR) another_command(...) endif(FOOVAR)
You are free to use pkg-config in FindXXX.cmake modules, as long as the following conditions are met:
if(FOO_LIBRARY AND FOO_INCLUDE_DIR) set(FOO_FOUND TRUE) else() ... execute the whole find-logic endif()
should be removed, the find-logic should be executed always. These shortcuts can cause problems e.g. when the same file is used from multiple directories but e.g. with different required versions or components etc.