Skip to content
Back to skills

Using Cmake

ASecurity

Use when writing or editing CMake builds for C or C++ projects on CMake 3.20+. Triggers on `CMakeLists.txt` and `*.cmake` files, adding targets, target_link_libraries, PUBLIC/PRIVATE/INTERFACE visibility, FetchContent, find_package, CTest, install rules, even when the user doesn't say 'CMake'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgoc++expresstestingdebugging

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill using-cmake --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Using Cmake?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Using Cmake
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-using-cmake/badge)](https://www.skillsdirectory.com/skills/xonovex-using-cmake)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: using-cmake
description: "Use when writing or editing CMake builds for C or C++ projects on CMake 3.20+. Triggers on `CMakeLists.txt` and `*.cmake` files, adding targets, target_link_libraries, PUBLIC/PRIVATE/INTERFACE visibility, FetchContent, find_package, CTest, install rules, even when the user doesn't say 'CMake'."
---

# CMake Coding Guidelines

Define builds through CMake targets with explicit dependencies, visibility, and installation rules.

## Requirements

- CMake ≥ 3.20; modern target-based usage.

## Essentials

- **Target-based builds** - Use targets, no global include/link dirs, see [references/target-types.md](references/target-types.md), [references/compile-options.md](references/compile-options.md)
- **Visibility specifiers** - Use PUBLIC/PRIVATE/INTERFACE correctly, see [references/visibility-specifiers.md](references/visibility-specifiers.md)
- **Dependencies** - Declare explicitly with find_package, see [references/find-package.md](references/find-package.md)
- **Testing** - Enable testing with CTest, see [references/testing.md](references/testing.md)
- **Project structure** - Organize multi-directory projects, see [references/project-structure.md](references/project-structure.md)

## Gotchas

- `target_link_libraries` scope matters: PRIVATE = consumers don't see it, INTERFACE = no compile, PUBLIC = both. Wrong scope leaks transitive deps
- `find_package` may use PATHS or HINTS but ignores both if a config file is on a system path; use `<Pkg>_ROOT` env var to force-locate
- Generator expressions (`$<CONFIG:Debug>`) only evaluate at build time: debugging by `message()` won't show their final values
- `CMAKE_INSTALL_PREFIX` is captured at configure time; changing it after first config requires a clean reconfigure

## Progressive disclosure

- Read [references/target-types.md](references/target-types.md) - Load when choosing between library types or executables
- Read [references/visibility-specifiers.md](references/visibility-specifiers.md) - Load when deciding PUBLIC vs PRIVATE vs INTERFACE
- Read [references/compile-options.md](references/compile-options.md) - Load when adding compiler flags to targets
- Read [references/find-package.md](references/find-package.md) - Load when integrating external dependencies
- Read [references/testing.md](references/testing.md) - Load when setting up CTest or test targets
- Read [references/project-structure.md](references/project-structure.md) - Load when organizing multi-directory CMake projects
- Read [references/generator-expressions.md](references/generator-expressions.md) - Load when using conditional build configuration
- Read [references/installation.md](references/installation.md) - Load when creating install targets or package exports

Files in this skill

  • SKILL.md2.7 KB
  • eval-output.json3.1 KB
  • eval-trigger.json5.4 KB
  • moon.yml86 B
  • references/compile-options.md250 B
  • references/find-package.md586 B
  • references/generator-expressions.md588 B
  • references/installation.md667 B
  • references/project-structure.md779 B
  • references/target-types.md733 B
  • references/testing.md243 B
  • references/visibility-specifiers.md602 B
  • sources.json1.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.