Template repository to be used as a base for creating C++ libraries built with CMake.
-
Commonly accepted directory layout:
cmake
for CMake utilities and package configinclude/<libname>
for public headerssrc
for library sources and private headersexamples
tests
for library examples and tests correspondingly
-
CMakeLists.txt
files thoroughly implemented with the following ideas in mind:- user should be able to build library both as subproject (probably fetched with CMake's FetchContent_MakeAvailable) and as a stand-alone project
- user should be able to build examples/tests as part of the library build or as a stand-alone projects
- multi-configuration CMake generators should be supported
- package systems (conan, vcpkg and others) should be respected, which means that library
CMakeLists.txt
file should contain only build requirements, i.e. should not hardcode any compiler/linker flags unless they are absolutely required to build the library
-
CMake Workflow preset file
CMakePresets.json
which is a modern way (since CMake 3.25) for specifying build options (instead of hardcoding them in theCMakeLists.txt
or setting on the command line) -
My personal
.clang-format
for code-style worth trying -
And too
.cmake-format.yml
to format the CMake files
Note, that I prefer googletest as a testing framework so it's the one used in this repository. Still it's not a big deal to replace it with any other of your choice.
- Anton Pantyukhin - Modern CMake tutorial for C++ library developers
- Dominik Berner - Organizing CMake presets
- Craig Scott -C++20 Modules, CMake, And Shared Libraries
- cmake-init - CMake project generator that creates good
CMakeLists.tx
files