CMake Modules Guidelines

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

NOTE: THIS PAGE IS A DRAFT --Daniele.Domenichelli@iit.it 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 http://www.cmake.org/pipermail/cmake/2009-January/026317.html --Daniele.Domenichelli@iit.it 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):
    XxxYyy_FOUND
    TRUE if the system has XxxYyy.
    XxxYyy_INCLUDE_DIRS
    Directories to include to use XxxYyy.
    XxxYyy_LIBRARIES
    Libraries to link against to use XxxYyy. Always full path.
    XxxYyy_DEFINITIONS
    (Only for modules that require them) Flags to pass to the C/C++ compiler for XxxYyy.
    XxxYyy_VERSION_STRING
    A human-readable string containing the version of the XxxYyy package found.
    XxxYyy_MAJOR_VERSION
    The major version of the package XxxYyy found.
    XxxYyy_MINOR_VERSION
    The minor version of the package XxxYyy found.
    XxxYyy_PATCH_VERSION
    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
   if(expression)
       ...
   elseif(expression2)
       ...
   else(expression)
       ...
   endif(expression)
   foreach(loop_var arg1 arg2 ...)
       ...
   endforeach(loop_var)
  • 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?>

References

Web

Files in CMake package

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