CMake Scaffolding
sniffercommit init --enable-cmake generates a production-grade CMakeLists.txt and a minimal src/main.cpp:
$ sniffercommit init --enable-cmake
Creates:
CMakeLists.txt— full CMake project configurationsrc/main.cpp— entry point withmain()stub
CMake Options
| Flag | Values | Default | Description |
|---|---|---|---|
--cmake-cpp-standard | 17, 20, 23 | 20 | C++ standard version |
--cmake-target-type | executable, static, shared, header-only | executable | Build target type |
--cmake-enable-testing | (flag) | off | Add enable_testing() + add_subdirectory(tests) |
--cmake-enable-sanitizers | (flag) | off | AddressSanitizer + UBSan (Debug only) |
--enable-conan | (flag) | off | Generate conanfile.py alongside CMakeLists.txt for Conan package manager |
What the Generated CMakeLists.txt Includes
cmake_minimum_required(VERSION 3.20)with project declaration- C++ standard enforcement (
CMAKE_CXX_STANDARD_REQUIRED ON, extensions OFF) - Build type configuration (Debug + Release)
CMAKE_EXPORT_COMPILE_COMMANDSfor IDE support- Source file and include directory setup
- Compiler warnings:
-Wall -Wextra -Wpedantic -Wconversion -Wshadow(GCC/Clang) or/W4(MSVC) - Sanitizers: address + undefined behaviour in Debug builds
- clang-tidy integration (if
--enable-clang-tidywas also passed) - clang-format custom target (
make format) - Testing:
enable_testing() + add_subdirectory(tests)(if--cmake-enable-testing) - Installation rules with GNUInstallDirs
Examples
# Minimal C++20 executable project $ sniffercommit init --enable-cmake # C++17 static library with testing $ sniffercommit init --enable-cmake --cmake-cpp-standard 17 --cmake-target-type static --cmake-enable-testing # Full-featured project with clang-tidy + sanitizers $ sniffercommit init \ --enable-cmake \ --cmake-cpp-standard 20 \ --cmake-enable-testing \ --cmake-enable-sanitizers \ --enable-clang-tidy \ --tidy-preset strict \ --style google # Header-only library (no src/main.cpp generated) $ sniffercommit init --enable-cmake --cmake-target-type header-only # Project with Conan package manager support $ sniffercommit init --enable-cmake --enable-conan # Full-featured project with Conan + clang-tidy + testing $ sniffercommit init \ --enable-cmake \ --enable-conan \ --cmake-cpp-standard 20 \ --cmake-enable-testing \ --enable-clang-tidy \ --tidy-preset strict \ --style google
Generate src/main.cpp Without CMake
$ sniffercommit init --generate-src
Creates only src/main.cpp, no CMakeLists.txt.
Conan Package Manager Integration
When --enable-conan is passed with --enable-cmake, sniffercommit generates:
conanfile.py— Conan package definition with CMakeToolchain/CMakeDepsCMakeLists.txt— Updated to usefind_package()instead of FetchContent
The generated conanfile.py includes:
- Python class-based Conan recipe
- CMakeToolchain and CMakeDeps generators
- Proper dependency resolution from
.sniffercommit.toml
What the generated CMakeLists.txt includes (with Conan):
- Uses
find_package(fmt REQUIRED)instead of FetchContent - Uses
find_package(tomlplusplus REQUIRED)instead of FetchContent - Links against imported targets (
fmt::fmt,tomlplusplus::tomlplusplus)
Usage:
# Generate with Conan support $ sniffercommit init --enable-cmake --enable-conan # Build with Conan $ conan install . --output-folder=build --build=missing $ cmake -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release $ cmake --build build