Need help with CMake?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

139 Stars 69 Forks Other 2.0K Commits 8 Opened issues


Common CMake modules

Services available


Need anything else?

Contributors list

CMake Modules

This repository contains common CMake modules and a collection of find scripts to locate non-CMake dependencies. The recommended way to use it is:

As a git submodule

In your project source dir, do:

git submodule add CMake/common

And include it in the top-level CMakeLists.txt as follows:



The following CMake modules can be included in your project:

  • Common does a common CMake setup, and also includes:
    • CommonLibrary common_library function to build a (shared) library using a standard recipe and generates header files for the library (api.h, version.h).
    • CommonApplication common_application function to build an application using a standard recipe.
    • CommonFindPackage commonfindpackage for more convenience over findpackage and *commonfindpackagepost* (must be last after all commonfindpackage calls) to generate defines.h and options.cmake for feature checking.
    • CommonCompiler: Default compiler flags (including C++14) and useful default warnings can be set on given target to commoncompileoptions(); automatically applied for targets created with commonapplication() and commonlibrary()
    • CommonHelp common_help function to create a documentation page from an application's --help output.
    • GitInfo sets variables with information about the git source tree.
    • GitTargets branch, cut, tag, erase, retag, tarball targets.
  • CommonCTest should be included from a tests subfolder. Does a common CTest setup, automatically adding all .cpp files in the current folder as unit tests to a tests target. It also includes:
    • CommonCoverage coverage target to generate a code coverage report as html, if COMMONENABLECOVERAGE option is set. Additional compiler flags are set in that case, so it should be enabled only for debug builds.
    • CommonCheckTargets adds test targets for various static code checkers if the COMMONENABLESTATIC_TESTS option is set.
    • CommonCPPCheck: cppcheck target for static code analysis. Also adds all cppcheck targets to tests target.
    • CommonClangCheck: clangcheck target for clang-check code analysis. Adds all clangcheck targets to tests if COMMONENABLECLANGCHECK_TESTS is set.
  • CommonPackageConfig generates cmake package information files for the project. These files let other CMake-based projects locate it through findpackage (in config mode, without the need for a finder script). Must be included at the end of the CMakeLists.txt, after all targets have been added via commonlibrary() and common_application().
  • CommonCPack Configures the CPack package generator to redistribute the project as an installable package. Also includes CommonPackageConfig.
  • DoxygenRule: doxygen target to build documentation into PROJECTBINARYDIR/doc. Optional doxycopy target to copy the results to ../GITHUB_ORGANIZATION/Project-M.m/. Must be included after all other targets.
  • SubProject: This module is automatically included in Common.cmake to build several CMake subprojects (which may depend on each other), which are declared in a .gitsubprojects file. To be compatible with the SubProject feature, (sub)projects might need to adapt their CMake scripts. Generally, CMAKEBINARYDIR should be changed to PROJECTBINARYDIR and CMAKESOURCEDIR should be changed to PROJECTSOURCEDIR. See SubProject documentation for more details. A simple example project can be found at, and a more complex one at

Additional features: * InstallDependencies lets users install known system packages during the initial configuration by doing "cmake -DINSTALL_PACKAGES=1". This is only implemented for Linux distributions using apt-get and yum package managers and MacPorts in OS X. The actual support depends on the project declaring its dependencies for each particular case. * CommonGraph adds graphs target to generate .png tree view of dependencies, gathered by CommonFindPackage and SubProject.

Detailed Change Log

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.