A template for c++ projects with cmake.
This is a template that I personally used for single artifact projects.
This template automates source file and dependency management.
You can build a project with the following commands:
cmake -S . -B build
cmake --build build -j
You can also run unit tests for your library.
ctest --test-dir build
This template builds one library and multiple executables.
AutoBuild(
LIB_DIR "lib" SHARED # Where to search for library source and headers
BIN_DIR "bin" # Where to search for executable source
)
You can declare a dependency https://github.com/nlohmann/json
with package name nlohmann_json
.
The PRIVATE
flag will make the dependency private. You can also use PUBLIC
flag.
The FLAGS
feeds into the process that runs CMAKE INSTALL
.
Git(
SITE "https://github.com"
USER "nlohmann"
REPO "json"
PACK "nlohmann_json"
BRANCH "v3.11.3"
PIPELINE "CMAKE INSTALL" FLAGS "-DJSON_BuildTests=OFF" PRIVATE
)
By default, any file with suffix .test.cpp
will be excluded from the library source.
Instead, they will be included as unit tests for the library.