CMake Scaffolding
metis init --enable-cmake generates a production-grade CMakeLists.txt and a minimal src/main.cpp:
$ metis 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 |
--add-dep | name:url:tag | - | Add a FetchContent dependency (repeatable) |
Adding Dependencies (FetchContent)
$ metis init --enable-cmake \ --add-dep fmt:https://github.com/fmtlib/fmt.git:11.0.2 \ --add-dep tomlplusplus:https://github.com/marzer/tomlplusplus.git:v3.4.0
Each validated dependency generates a FetchContent_Declare block. With --enable-conan, find_package(<name> REQUIRED) is emitted instead, alongside a generated conanfile.py. Validate resolved dependencies at any time with metis deps. See the deps page for details.
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 $ metis init --enable-cmake # C++17 static library with testing $ metis init --enable-cmake --cmake-cpp-standard 17 --cmake-target-type static --cmake-enable-testing # Full-featured project with clang-tidy + sanitizers $ metis 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) $ metis init --enable-cmake --cmake-target-type header-only # Project with Conan package manager support $ metis init --enable-cmake --enable-conan # Full-featured project with Conan + clang-tidy + testing $ metis 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
$ metis init --generate-src
Creates only src/main.cpp, no CMakeLists.txt.
Conan Package Manager Integration
When --enable-conan is passed with --enable-cmake, metis 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
.metis.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 $ metis 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