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
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.
GLOB_RECURSE ... CONFIGURE_DEPENDS re-globs on every build, so a new file under
src/ or tests/ only needs cmake --build build.
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.
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.