Policies/CMake Coding Style: Difference between revisions

From KDE TechBase
(New page: This document describes the recommended coding style for CMake files in KDE, i.e. CMakeLists.txt files and *.cmake files. ==Indentation== Indent all code correctly, i.e. the body of * I...)
 
Line 5: Line 5:
Indent all code correctly, i.e. the body of  
Indent all code correctly, i.e. the body of  
* IF/ELSE/ENDIF
* IF/ELSE/ENDIF
* MACRO
* FOREACH/ENDFOREACH
* FUNCTION
* WHILE/ENDWHILE
* FOREACH
* MACRO/ENDMACRO
* WHILE
* FUNCTION/ENDFUNCTION (CMake 2.6)


Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount
Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount

Revision as of 19:17, 16 August 2008

This document describes the recommended coding style for CMake files in KDE, i.e. CMakeLists.txt files and *.cmake files.

Indentation

Indent all code correctly, i.e. the body of

  • IF/ELSE/ENDIF
  • FOREACH/ENDFOREACH
  • WHILE/ENDWHILE
  • MACRO/ENDMACRO
  • FUNCTION/ENDFUNCTION (CMake 2.6)

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.

Upper/lower casing

CMake commands are case-insensitiv (only the commands, not the arguments or variable names). So all the following versions work: add_executable(foo foo.c) ADD_EXECUTABLE(bar bar.c) Add_Executable(hello hello.c) aDd_ExEcUtAbLe(hello hello.c)

But this would be ugly. In KDE the all-lowercase style is preferred. The all-uppercase style is also ok. Mixing upper- and lowercase should not be done in KDE CMake files. Although all-lowercase is preferred, if a file is apparently in all-uppercase style, then stay consistent and also use all-uppercase in this file.

Writing CMake Find-modules

Follow the style guide from CMake when writing some FindFoo.cmake module: readme.txt