Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-template

CMake + GoogleTest starting point for small C++ projects.

CMakeLists.txt          library + executable + dependency wiring
cmake/FindOrFetch.cmake system package first, GitHub clone as fallback
include/cpp_template/   public headers
src/                    everything except main.cpp becomes cpp_template_lib
tests/                  every .cpp here is a gtest source

Build

cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failure

-DBUILD_TESTS=OFF skips the tests and the GoogleTest dependency.

Adding sources

GLOB_RECURSE ... CONFIGURE_DEPENDS re-globs on every build, so a new file under src/ or tests/ only needs cmake --build build.

Adding a dependency

find_or_fetch(fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG        11.0.2)
target_link_libraries(${PROJECT_NAME}_lib PUBLIC fmt::fmt)

Target names can differ between the installed package and the source build (libuv exports libuv::uv_a when installed but only defines uv_a in-tree), so check both and add an ALIAS if needed.

Renaming the project

Change project() in the top-level CMakeLists.txt; the library, executable and include namespace follow from ${PROJECT_NAME}. Rename include/cpp_template/ and the cpp_template namespace to match.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages