
Cmake
Configure modern target-first CMake for C/C++ apps, dependencies, sanitizers, cross-compile toolchains, and presets.
Overview
CMake is an agent skill for the Build phase that guides modern target-first CMakeLists setup for C/C++ projects.
Install
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill cmakeWhat is this skill?
- Modern target-first CMake (3.20+): target_* APIs, PUBLIC/PRIVATE/INTERFACE
- find_package and FetchContent patterns for external dependencies
- Generator selection (Ninja, Make, Visual Studio) and out-of-source builds
- Sanitizer and cross-compilation toolchain file guidance
- CMake Presets and package export (CPack/install) orientation
- Recommends cmake_minimum_required VERSION 3.20
Adoption & trust: 792 installs on skills.sh; 102 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your C/C++ build breaks on configure, cannot find packages, or still uses legacy CMake globals.
Who is it for?
Solo developers shipping native CLIs, libraries, or game/engine code who standardize on CMake 3.20+.
Skip if: Pure JavaScript/Python projects with no native compile step or teams that only use Bazel/Meson with no CMake migration intent.
When should I use this skill?
Writing or refactoring CMakeLists.txt, fixing configure errors, managing dependencies, sanitizers, cross-compilation, or CMake Presets for C/C++.
What do I get? / Deliverables
You get corrected CMakeLists patterns—targets, dependencies, generators, and toolchains—that configure and link reliably.
- Updated CMakeLists.txt patterns
- Toolchain/preset configuration guidance
- Install/export rules as applicable
Recommended Skills
Journey fit
CMake work lands in Build when you are compiling native libraries, binaries, or embedded components—not when validating market fit. backend covers native services, CLIs, and performance-critical C/C++ codebases where CMake is the build orchestrator.
How it compares
Procedural CMake authoring skill—not a one-click scaffold generator or hosted build farm.
Common Questions / FAQ
Who is cmake for?
Indie and solo builders working in C/C++ who need agent help writing or fixing CMakeLists.txt and build configuration.
When should I use cmake?
During Build when configuring targets, adding libraries, fixing find_package errors, enabling sanitizers, or setting up cross-compile and presets.
Is cmake safe to install?
It is documentation-style guidance; review the Security Audits panel on this Prism page and validate any generated CMake against your repo policies.
SKILL.md
READMESKILL.md - Cmake
# CMake ## Purpose Guide agents through modern (target-first) CMake for C/C++ projects: out-of-source builds, dependency management, generator selection, and integration with CI and IDEs. ## Triggers - "How do I write a CMakeLists.txt for my project?" - "How do I add an external library with CMake?" - "CMake can't find my package / library" - "How do I enable sanitizers in CMake?" - "How do I cross-compile with CMake?" - "How do I use CMake Presets?" ## Workflow ### 1. Modern CMake principles - Define targets, not variables. Use `target_*` commands. - Use `PUBLIC`/`PRIVATE`/`INTERFACE` to control property propagation. - Never use `include_directories()` or `link_libraries()` (legacy). - Minimum CMake version: `cmake_minimum_required(VERSION 3.20)` for most features. ### 2. Minimal project ```cmake cmake_minimum_required(VERSION 3.20) project(MyApp VERSION 1.0 LANGUAGES C CXX) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(myapp src/main.c src/utils.c ) target_include_directories(myapp PRIVATE include) target_compile_options(myapp PRIVATE -Wall -Wextra) ``` ### 3. Static / shared libraries ```cmake # Static library add_library(mylib STATIC lib/foo.c lib/bar.c) target_include_directories(mylib PUBLIC include # consumers get this include path PRIVATE src # only mylib itself sees this ) # Shared library add_library(myshared SHARED lib/foo.c) set_target_properties(myshared PROPERTIES VERSION 1.0.0 SOVERSION 1 ) # Link executable against library add_executable(myapp src/main.c) target_link_libraries(myapp PRIVATE mylib) ``` ### 4. Configure and build ```bash # Out-of-source build (always do this) cmake -S . -B build cmake --build build # With generator cmake -S . -B build -G Ninja cmake --build build -- -j$(nproc) # Debug build cmake -S . -B build-debug -DCMAKE_BUILD_TYPE=Debug cmake --build build-debug # Release cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release cmake --build build-release # Install cmake --install build --prefix /usr/local ``` Build types: `Debug`, `Release`, `RelWithDebInfo`, `MinSizeRel`. ### 5. External dependencies #### find_package (system-installed libraries) ```cmake find_package(OpenSSL REQUIRED) target_link_libraries(myapp PRIVATE OpenSSL::SSL OpenSSL::Crypto) find_package(Threads REQUIRED) target_link_libraries(myapp PRIVATE Threads::Threads) find_package(ZLIB REQUIRED) target_link_libraries(myapp PRIVATE ZLIB::ZLIB) ``` #### FetchContent (download and build dependency) ```cmake include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0 ) FetchContent_MakeAvailable(googletest) add_executable(mytest test/test_foo.cpp) target_link_libraries(mytest PRIVATE GTest::gtest_main mylib) ``` #### pkg-config fallback ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(LIBFOO REQUIRED libfoo>=1.2) target_link_libraries(myapp PRIVATE ${LIBFOO_LIBRARIES}) target_include_directories(myapp PRIVATE ${LIBFOO_INCLUDE_DIRS}) ``` ### 6. Compiler options by configuration ```cmake target_compile_options(myapp PRIVATE $<$<CONFIG:Debug>:-g -Og -fsanitize=address> $<$<CONFIG:Release>:-O2 -DNDEBUG> $<$<CXX_COMPILER_ID:GNU>:-fanalyzer> $<$<CXX_COMPILER_ID:Clang>:-Weverything> ) target_link_options(myapp PRIVATE