KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?
Please ask development related questions in the KDE Community Forum.

Policies/CMake Coding Style

< Policies
Revision as of 18:05, 29 April 2009 by Neundorf (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

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

Contents

  • 1 Indentation
  • 2 Upper/lower casing
  • 3 (Not) Using pkg-config
  • 4 Writing CMake Find-modules

[edit] 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.

[edit] Upper/lower casing

CMake commands are case-insensitive (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(blub blub.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.


[edit] (Not) Using pkg-config

You are free to use pkg-config in FindXXX.cmake modules, as long as the following conditions are met:

  • the FindXXX.cmake must also work without pkg-config, as long as the package is either installed to one of the default locations (as /usr or /usr/local) or if CMAKE_PREFIX_PATH is set accordingly
  • use only FIND_PACKAGE(PkgConfig), don't use INCLUDE(UsePkgConfig), this one is deprecated
  • make sure the variables created by PKG_CHECK_MODULES() are all prefixed with "PC_", so they don't mix up with other variables, e.g. set via FIND_PATH() etc.


[edit] Writing CMake Find-modules

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

Retrieved from "http://techbase.kde.org/Policies/CMake_Coding_Style"

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • 38.107.191.95
  • Talk for this IP
  • Log in / create account
  • Login with OpenID
Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal