Difference between revisions of "CMake Modules Guidelines"

From Wiki for iCub and Friends
Jump to: navigation, search
Line 59: Line 59:
* http://www.cmake.org/cmake/help/cmake2.6docs.html#module:FeatureSummary
* http://www.cmake.org/cmake/help/cmake2.6docs.html#module:FeatureSummary
* http://stackoverflow.com/questions/9942843/how-to-organize-cmake-file-hierarchy-which-multiple-optional-dependencies
* http://stackoverflow.com/questions/9942843/how-to-organize-cmake-file-hierarchy-which-multiple-optional-dependencies
* http://www.cmake.org/pipermail/cmake/2009-January/026317.html
=== Files in CMake package ===
=== Files in CMake package ===

Revision as of 13:51, 13 November 2012

CMake Modules Guidelines for YARP and iCub

NOTE: THIS PAGE IS A DRAFT --Daniele.Domenichelli@iit.it 17:02, 8 November 2012 (CET)

These are the guidelines for writing a Module to use in YARP and in iCub

Find Module Guidelines

For each library XxxYxx that can be used in YARP/iCub

  • The only file will be FindXxxYyy.cmake (remove FindXxxYyy{Win32,Unix}.cmake)
  • The case for the name name of the created variables is always according to the name of the FindXxxYyy.cmake file (i.e. XxxYyy_ZZZZZ)
  • Variables created by pkg-config (for the modules using them) always start with the prefix "PC_" and the name of the module is uppercase (therefore "pkg_check_modules(PC_XXXYYY ...)").
  • Internal variables, are prefixed with "X_", so that it is easy to recognize them, and it's less confusing.
  • The defined variables are the following (and nothing else unless there is a specific reason for it):
    TRUE if the system has XxxYyy.
    Directories to include to use XxxYyy.
    Libraries to link against to use XxxYyy. Always full path.
    (Only for modules that require them) Flags to pass to the C/C++ compiler for XxxYyy.
    A human-readable string containing the version of the XxxYyy package found.
    The major version of the package XxxYyy found.
    The minor version of the package XxxYyy found.
    The patch version of the package XxxYyy found.
  • XxxYyy_INCLUDE_DIRS, XxxYyy_LIBRARIES and XxxYyy_DEFINITIONS are cached and marked as advanced, so that they are editable by the user

Style Guidelines

  • Indentation = 4 spaces
  • No tabs
  • Use adeguate spacing and comments where needed (i.e. to show a clear separation between UNIX and WINDOWS parts, etc)
  • Commands and macros are used lowercase and do not have spaces before the bracket (i.e. "if(" and not "IF(", "IF (", or "if (")
  • In if and similar cmake constructs always use the full expression unless it is very long
   foreach(loop_var arg1 arg2 ...)
  • Comment containing module description should contain a list of the variables with their descriptions, and should be before the copyright and separated from that by an empty line (so that it can be printed by cmake --help-module)
  • <emacs/vi modelines?>



Files in CMake package

  • Modules/readme.txt
  • Modules/FindPkgConfig.cmake
  • Modules/FeatureSummary.cmake