Skip to content

dvd0bvb/BrilliantCMake

Repository files navigation

BrilliantCMake

Multiplatform Tests Asan Msan Tsan clang-format Check clang-tidy Check cmake-format Check cppcheck coverage Doxygen License: MIT Buy Me A Coffee

A CMake project template

This is a CMake project template aimed at new C++ projects. It is rather opinionated - it is expected that there is only one artifact being produced by the project, ie, only one (possibly header only) library or executable. It is also expected that tests will be written using the Google Test framework.

For these small concessions you get:

  • Test detection and running using CTest
  • Test coverage checks using lcov
  • Documentation generation using doxygen
  • All the analyzers
    • Address sanitizer
    • UB sanitizer
    • Leak sanitizer
    • Memory sanitizer
    • Thread sanitizer
    • clang-tidy
    • cppcheck
  • C++ code formatting using clang-format
  • CMake formatting using cmake-format
  • All of this running in Github workflows with fancy badges for your documentation

Creating a new project from this repo

  1. Get the template

    Create a new project from the template using the "Use this template" button in the top of the repo page. You can find more detailed instructions here.

    You can also use the github CLI with the following command gh repo create my-new-project --template dvd0bvb/BrilliantCMake --private --clone.

  2. Set the project name

    Once you have the template, edit the top level CMakeLists.txt file to set the THIS_PROJECT_NAME variable. This controls the name of the build targets that are generated, more information is given below.

  3. Rename the include directory

    Rename the include/project directory to include/$THIS_PROJECT_NAME.

  4. Edit the .project-config.yml file

    Change the values of the options in .project-config.yml to match your desired configuration. The project-name field should match THIS_PROJECT_NAME. This config file affects CMake commands called from github actions.

  5. Update badge urls

    This readme provides examples of badges generated by GitHub workflows supported by this template. Badge urls should be updated accordingly. Normally this just means replacing https://github.com/dvd0bvb/BrilliantCMake/ in the urls with the url of your repo.

    NOTE: Your github token requires read and write permissions to push changes for coverage badges and documentation.

And that's it, you're done with setup. You may then move on to development. The CMakeLists.txt files in the src and test directories contain variables which you may use to list your sources and dependencies. You may edit cmake/Options.cmake so that your preferred artifact option is ON by default, eg: set(BRILLIANT_CMAKE_BUILD_SHARED ... ON) so you do not have to define it when you configure CMake.

The THIS_PROJECT_NAME variable

The CMake variable THIS_PROJECT_NAME determines the names of targets generated by BrilliantCMake. The generated targets are as follows:

Target Name Description Example
${THIS_PROJECT_NAME} The main target MyProject
${THIS_PROJECT_NAME}_TEST A target to build a test executable MyProject_TEST
${THIS_PROJECT_NAME}_DOCS A target to generate documentation using doxygen MyProject_DOCS

The ${THIS_PROJECT_NAME}_DOCS target is not included in CMake's all target and so must be called explicitly.

Supporting the project

If you have suggestions please feel free to open an issue or create a PR.

You can support me directly via Buy Me a Coffee here.

About

A CMake template for new C++ projects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published