ModernSharedLibTemplate  
1.0.0
Template for cmake shared library
ModernSharedLibTemplate

This is a template for static and shared library which give a good starter point for new C++ project. It has been designed to use Modern CMake practices in mind, and should be a good starting point for both people willing to learn it and those who want to update their own project.

Ubuntu MacOS Windows

codecov Quality Gate Status Coverage Maintainability Rating

Features

  • [x] Reproducible dependency management via CPM.cmake.
  • [x] Clean separation of code, tests and documentation.
  • [x] Integrated test suite with Catch2.
  • [x] Automatic documentation and deployment with Doxygen and GitHub Pages.
  • [x] Code formatting enforced by clang-format and cmake-format from script.
  • [x] Code coverage via codecov.
  • [x] Code coverage and analysis via sonarcloud.
  • [x] CI workflows for Windows, Linux and MacOS using GitHub Actions.

Todo

Usage

All source code can be found in the following directories :

  • include\mlt :
    • Replace the mlt directory according to the PROJECT_ID defined in CMakeLists.txt
    • Add your own source code.
  • src :
    • Add your own source code.

then add you files to CMakeLists_files.cmake.

Build as static lib

Use the following commands to build as a static library.

cmake -S . -B build/static -DBUILD_SHARED_LIBS=NO -DMLT_PACKAGE=YES -DCMAKE_INSTALL_PREFIX=install
cmake --build build/static --target install

Build as shared lib

Use the following commands to build as a shared library.

cmake -S . -B build/shared -DBUILD_SHARED_LIBS=YES -DMLT_PACKAGE=YES -DCMAKE_INSTALL_PREFIX=install
cmake --build build/shared --target install

Build and run test suite

Use the following commands to run the test suite.

cmake -S test -B build/test
cmake --build build/test
cmake --build build/test --target test
# for more details, run:
./build/test/ModernSharedLibTemplateTest

Build the documentation

Use the following commands to manually build the documentation.

cmake -S doc -B build/doc
cmake --build build/doc --target GenerateDocs

Related projects

CppMfLibTemplate got inspired from the following :