{"slug":"cmake","title":"cmake","summary":"Use when writing CMakeLists.txt, out-of-source builds, target_link_libraries, target properties, find_package/FetchContent, toolchain files, CPack, CMake presets, or cmake configure errors.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-30T19:50:03.334892Z","repo":{"url":"https://github.com/OutlineDriven/outline-driven-development","stars":54,"forks":10,"license":"Apache-2.0","updatedAt":"2026-09-28T03:16:21Z"},"bodyHtml":"<hr>\n<h2>name: cmake\ndescription: 'Use when writing CMakeLists.txt, out-of-source builds, target_link_libraries, target properties, find_package/FetchContent, toolchain files, CPack, CMake presets, or cmake configure errors.'\ndisable-model-invocation: true</h2>\n<h1>CMake</h1>\n<p>Modern target-first CMake for C/C++ projects. Grounded against CMake 4.4.3; the examples floor at CMake 3.25 so the preset schema version 6 works.</p>\n<h2>Contract</h2>\n<table>\n<thead>\n<tr>\n<th>Field</th>\n<th>Bound contract</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Trigger</td>\n<td>The task writes or refactors <code>CMakeLists.txt</code>, configures out-of-source builds, selects generators, manages targets with <code>target_link_libraries</code>, integrates packages via <code>find_package</code> or <code>FetchContent</code>, enables sanitizers, writes toolchain files, sets up presets, or resolves a cmake configure error.</td>\n</tr>\n<tr>\n<td>Authority</td>\n<td>Reversible local: writes only <code>CMakeLists.txt</code>, <code>CMakePresets.json</code>, toolchain files, and the build directory; rollback is version control plus deleting the build directory. No remote mutation.</td>\n</tr>\n<tr>\n<td>Side effect</td>\n<td><code>cmake --build</code> and <code>cmake --install</code> write local build outputs and install trees; <code>FetchContent</code> downloads declared dependencies.</td>\n</tr>\n<tr>\n<td>Done</td>\n<td>The project configures and builds with the requested options, or the failing command and its error are reported.</td>\n</tr>\n</tbody>\n</table>\n<h2>Inputs</h2>\n<ul>\n<li>Project layout (required): sources, headers, and where the root <code>CMakeLists.txt</code> lives.</li>\n<li>CMake version (required if not inferrable): run <code>cmake --version</code>. Preset schema version 6 needs CMake 3.25 or newer.</li>\n<li>Dependencies (optional): system packages, FetchContent sources, or vendored trees.</li>\n<li>Target platform (optional): a cross-compilation target needs a toolchain file.</li>\n</ul>\n<h2>Procedure</h2>\n<ol>\n<li><p>Apply modern CMake rules. Define targets, not variables. Use <code>target_*</code> commands with <code>PUBLIC</code>/<code>PRIVATE</code>/<code>INTERFACE</code> to control propagation. Never use <code>include_directories()</code> or <code>link_libraries()</code>; they are legacy global state. Done when: every property attaches to a target.</p>\n</li>\n<li><p>Write the minimal project. Done when: <code>cmake -S . -B build</code> configures cleanly.</p>\n</li>\n</ol>\n<pre><code>cmake_minimum_required(VERSION 3.25)\nproject(MyApp VERSION 1.0 LANGUAGES C CXX)\n\nset(CMAKE_C_STANDARD 23)\nset(CMAKE_C_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_STANDARD 23)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_EXPORT_COMPILE_COMMANDS ON)   # clang-tidy and IDEs read this\n\nadd_executable(myapp src/main.c src/utils.c)\ntarget_include_directories(myapp PRIVATE include)\ntarget_compile_options(myapp PRIVATE -Wall -Wextra)\n</code></pre>\n<ol start=\"3\">\n<li>Add libraries and link them. Done when: each library target carries its own include paths and the executable links against it.</li>\n</ol>\n<pre><code>add_library(mylib STATIC lib/foo.c lib/bar.c)\ntarget_include_directories(mylib\n    PUBLIC  include    # consumers inherit this\n    PRIVATE src        # only mylib sees this\n)\n\nadd_library(myshared SHARED lib/foo.c)\nset_target_properties(myshared PROPERTIES VERSION 1.0.0 SOVERSION 1)\n\ntarget_link_libraries(myapp PRIVATE mylib)\n</code></pre>\n<ol start=\"4\">\n<li>Configure and build out of source. Done when: the build completes in a separate directory.</li>\n</ol>\n<pre><code>cmake -S . -B build -G Ninja\ncmake --build build -- -j\"$(nproc)\"\n\ncmake -S . -B build-debug   -DCMAKE_BUILD_TYPE=Debug\ncmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release\ncmake --install build-release --prefix /usr/local\n</code></pre>\n<p>Build types: <code>Debug</code>, <code>Release</code>, <code>RelWithDebInfo</code>, <code>MinSizeRel</code>.</p>\n<ol start=\"5\">\n<li>Integrate external dependencies. Prefer <code>find_package</code> for system libraries, <code>FetchContent</code> for source builds, <code>pkg_check_modules</code> as a fallback. Done when: the dependency resolves and links.</li>\n</ol>\n<pre><code>find_package(OpenSSL REQUIRED)\nfind_package(Threads REQUIRED)\nfind_package(ZLIB REQUIRED)\ntarget_link_libraries(myapp PRIVATE OpenSSL::SSL OpenSSL::Crypto Threads::Threads ZLIB::ZLIB)\n\ninclude(FetchContent)\nFetchContent_Declare(\n    googletest\n    GIT_REPOSITORY https://github.com/google/googletest.git\n    GIT_TAG        v1.17.0\n    GIT_SHALLOW    TRUE\n)\nFetchContent_MakeAvailable(googletest)\n\nfind_package(PkgConfig REQUIRED)\npkg_check_modules(LIBFOO REQUIRED libfoo&gt;=1.2)\ntarget_link_libraries(myapp PRIVATE ${LIBFOO_LIBRARIES})\ntarget_include_directories(myapp PRIVATE ${LIBFOO_INCLUDE_DIRS})\n</code></pre>\n<ol start=\"6\">\n<li>Set per-configuration flags with generator expressions. Done when: each flag applies only to its intended configuration or compiler.</li>\n</ol>\n<pre><code>target_compile_options(myapp PRIVATE\n    $&lt;$&lt;CONFIG:Debug&gt;:-g -Og -fsanitize=address&gt;\n    $&lt;$&lt;CONFIG:Release&gt;:-O2 -DNDEBUG&gt;\n    $&lt;$&lt;CXX_COMPILER_ID:GNU&gt;:-fanalyzer&gt;\n)\ntarget_link_options(myapp PRIVATE\n    $&lt;$&lt;CONFIG:Debug&gt;:-fsanitize=address&gt;\n)\n</code></pre>\n<ol start=\"7\">\n<li>Gate sanitizers behind an option. Done when: <code>cmake -DENABLE_ASAN=ON</code> produces an instrumented build.</li>\n</ol>\n<pre><code>option(ENABLE_ASAN \"Enable AddressSanitizer\" OFF)\nif(ENABLE_ASAN)\n    target_compile_options(myapp PRIVATE -fsanitize=address -fno-omit-frame-pointer -g -O1)\n    target_link_options(myapp PRIVATE -fsanitize=address)\nendif()\n</code></pre>\n<ol start=\"8\">\n<li>Write a toolchain file for cross-compilation. Done when: <code>cmake -DCMAKE_TOOLCHAIN_FILE=...</code> configures for the target.</li>\n</ol>\n<pre><code># toolchain-aarch64.cmake\nset(CMAKE_SYSTEM_NAME Linux)\nset(CMAKE_SYSTEM_PROCESSOR aarch64)\nset(CMAKE_C_COMPILER   aarch64-linux-gnu-gcc)\nset(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)\nset(CMAKE_SYSROOT /opt/aarch64-sysroot)\nset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\nset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\nset(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n</code></pre>\n<ol start=\"9\">\n<li>Capture common configurations in <code>CMakePresets.json</code>. Schema version 6 requires CMake 3.25 or newer. Done when: <code>cmake --preset &lt;name&gt;</code> configures and <code>cmake --build --preset &lt;name&gt;</code> builds.</li>\n</ol>\n<pre><code>{\n  \"version\": 6,\n  \"configurePresets\": [\n    {\n      \"name\": \"release\",\n      \"generator\": \"Ninja\",\n      \"binaryDir\": \"${sourceDir}/build/release\",\n      \"cacheVariables\": {\n        \"CMAKE_BUILD_TYPE\": \"Release\",\n        \"CMAKE_EXPORT_COMPILE_COMMANDS\": \"ON\"\n      }\n    },\n    {\n      \"name\": \"debug\",\n      \"generator\": \"Ninja\",\n      \"binaryDir\": \"${sourceDir}/build/debug\",\n      \"cacheVariables\": { \"CMAKE_BUILD_TYPE\": \"Debug\", \"ENABLE_ASAN\": \"ON\" }\n    }\n  ],\n  \"buildPresets\": [\n    { \"name\": \"release\", \"configurePreset\": \"release\" },\n    { \"name\": \"debug\",   \"configurePreset\": \"debug\" }\n  ]\n}\n</code></pre>\n<ol start=\"10\">\n<li>Diagnose configure errors against this table. Done when: the error maps to a cause and a fix.</li>\n</ol>\n<table>\n<thead>\n<tr>\n<th>Error</th>\n<th>Cause</th>\n<th>Fix</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>Could not find package Foo</code></td>\n<td>Package missing or wrong prefix</td>\n<td>Install the dev package; set <code>CMAKE_PREFIX_PATH</code></td>\n</tr>\n<tr>\n<td><code>No CMAKE_CXX_COMPILER</code></td>\n<td>No C++ compiler found</td>\n<td>Install g++ or clang++; check <code>PATH</code></td>\n</tr>\n<tr>\n<td><code>target_link_libraries called with wrong number of arguments</code></td>\n<td>Missing <code>PUBLIC</code>/<code>PRIVATE</code>/<code>INTERFACE</code></td>\n<td>Add the keyword</td>\n</tr>\n<tr>\n<td><code>Cannot find source file</code></td>\n<td>Typo or wrong relative path</td>\n<td>Check the path relative to <code>CMakeLists.txt</code></td>\n</tr>\n<tr>\n<td>Compatibility error on old <code>cmake_minimum_required</code></td>\n<td>CMake 4 dropped compatibility with versions below 3.5</td>\n<td>Raise the floor to 3.25</td>\n</tr>\n</tbody>\n</table>\n<p>For complete project templates see <code>references/templates.md</code>.</p>\n<h2>Failure and recovery</h2>\n<ul>\n<li><code>find_package</code> fails: install the <code>-dev</code> package or set <code>CMAKE_PREFIX_PATH</code>; fall back to <code>FetchContent</code> when no system package exists.</li>\n<li>FetchContent fails offline: pre-seed <code>FETCHCONTENT_SOURCE_DIR_&lt;NAME&gt;</code> with a local copy.</li>\n<li>Generator expression error: check the expression name against <code>cmake --help-manual cmake-generator-expressions</code>.</li>\n<li>Preset rejected: confirm <code>cmake --version</code> meets the schema version's floor.</li>\n<li>Stale cache after option changes: delete the build directory or pass <code>-U</code> to clear a cache entry; do not edit <code>CMakeCache.txt</code> by hand.</li>\n</ul>\n<h2>Output</h2>\n<p>A working <code>CMakeLists.txt</code> or build configuration, verified by a successful <code>cmake -S . -B build</code> and <code>cmake --build build</code>. For debugging tasks, the diagnosed error with its cause and applied fix.</p>\n","files":[{"path":"agents/openai.yaml","sizeBytes":291,"isText":true},{"path":"references/templates.md","sizeBytes":3310,"isText":true},{"path":"SKILL.md","sizeBytes":7768,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-30T19:51:46.221977Z","sha256":"76AD7B00D613B4F1AD026125DD10F34FD88245F2F0CF123A43871B71534C83E1","sizeBytes":5038},"review":null,"source":{"repositoryUrl":"https://github.com/OutlineDriven/outline-driven-development","path":".devin/skills/cmake","license":"Apache-2.0","commit":"b0e8ce89a19fac880251dc3ea1babfeb4503a4fe","subtreeSha":"CFDDAF6C61D7EBB828E25E2BFE22DC6F75E5AF3DAAD9AEFAC2B2F0B762866134","lastSyncedAt":"2026-09-30T19:49:48.917811Z"},"reviewedAt":"2026-09-30T19:55:17.810882Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/OutlineDriven/outline-driven-development/tree/main/.devin/skills/cmake"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install outlinedriven-outline-driven-development@llmmart"},{"target":"git","command":"git clone https://github.com/OutlineDriven/outline-driven-development.git"}]}