Skip to content

Preparing projects for CPM.cmake

Lars Melchior edited this page Jan 20, 2021 · 5 revisions

CPM.cmake differs from conventional package managers as it supports adding any type of project from any source without any modifications to the original code base. However, this means that all information required to download and configure the project must be provided by project users, as illustrated in the examples. To make this as convenient as possible, please see the following guidelines:

  1. Use CMake to build your project.
  2. Structure your project. See Here.
  3. Use modern CMake features like targets and properties. See here and here.
  4. Understand semantic versioning here and here.
  5. Tag your releases with the version prefixed by a v.
  6. Use the same version for the installed target for compatibility between local and global installations.
  7. Don't include tests or other projects from the main CMakeLists.
  8. Add your libraries dependencies using CPMAddPackage (for deterministic builds) or CPMFindPackage (will use global installs, if available).
  9. Scope any options your root CMakeLists.txt depends on (e.g. BUILD_TESTING -> MY_LIBRARY_BUILD_TESTING)

For a minimal example, see the ModernCppStarter.