CMake Modules Guidelines

From Wiki for iCub and Friends
Jump to navigation Jump to search

NOTE: THIS PAGE IS A DRAFT 17:02, 8 November 2012 (CET)

CMake Modules Guidelines for YARP and iCub

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)
 I still vote for UPPERCASE variables, see 15:32, 14 November 2012 (CET)
 Fine. But there was already a change of capitalization in the past. Such changes cause problems that are difficult to catch.
 In addition there is no way we can change OpenCV_* variables capitalizations to OPENCV_* (Lorenzo 14/11)
  • 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