cmake

Write and configure modern target-based CMakeLists.txt for C/C++ projects.

Updated Mar 4, 2026
One-click install
npx skills add https://github.com/chisuhua/home --skill cmake-chisuhua
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cmake
Source: https://github.com/chisuhua/home/tree/main/.agents/skills.disabled/cmake
Command: npx skills add https://github.com/chisuhua/home --skill cmake-chisuhua

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing correct CMake build configuration is error-prone: legacy variable-based patterns, missing PUBLIC/PRIVATE keywords, and confusing configure errors slow down C/C++ developers. This Skill provides modern target-first CMake guidance with working examples for builds, dependencies, and cross-compilation. ## Core Features & Use Cases - Modern CMake Patterns: Target-based configuration with target_link_libraries, target_include_directories, and generator expressions instead of legacy commands. - Dependency Management: Integrate external packages via find_package, FetchContent, pkg-config, or vendored add_subdirectory with fallback patterns. - Build Configuration: Out-of-source builds, Ninja/Make generators, Debug/Release build types, CMake Presets, sanitizer options, and cross-compilation toolchain files. - Use Case: You need to add GoogleTest to a C++ project. The Skill provides a complete FetchContent setup with gtest_discover_tests, plus a matching CMakePresets.json for debug and release builds. ## Quick Start Ask the assistant to write a CMakeLists.txt for a C++ project with a static library, an executable, and GoogleTest unit tests using FetchContent.

Frequently Asked Questions about cmake

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a CMakeLists.txt for a C++ project?▼

Start with cmake_minimum_required(VERSION 3.20), declare the project with LANGUAGES CXX, then define targets with add_library or add_executable. Use target_include_directories and target_link_libraries with PUBLIC/PRIVATE keywords instead of legacy include_directories.

How do I add an external library with CMake FetchContent?▼

Use FetchContent_Declare with the dependency's GIT_REPOSITORY and GIT_TAG, then call FetchContent_MakeAvailable. Link against the imported target, for example target_link_libraries(mytest PRIVATE GTest::gtest_main) for GoogleTest.

find_package vs FetchContent in CMake, which should I use?▼

find_package locates system-installed libraries and is faster when the dependency is already installed. FetchContent downloads and builds the dependency from source, which is better for pinning versions. A common pattern tries find_package first and falls back to FetchContent.

Why does CMake say it could not find my package?▼

The package is either not installed or not on the search path. Install the development package for your platform, or set CMAKE_PREFIX_PATH to the installation prefix so find_package can locate the config files.

How do I enable AddressSanitizer in a CMake build?▼

Add -fsanitize=address to both target_compile_options and target_link_options, typically guarded by an option like ENABLE_ASAN. Configure with cmake -DENABLE_ASAN=ON -S . -B build-asan and rebuild.

How do I cross-compile with CMake for ARM targets?▼

Create a toolchain file setting CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_PROCESSOR, the cross compilers, and CMAKE_SYSROOT. Pass it at configure time with -DCMAKE_TOOLCHAIN_FILE=toolchain-aarch64.cmake.