This is your reference guide when you need to write or fix CMakeLists.txt files for C/C++ projects. It pushes modern, target-first CMake practices (target_link_libraries, target_compile_options) and explicitly tells you to avoid the old global commands. You get concrete patterns for out-of-source builds, FetchContent for pulling in dependencies, find_package for system libraries, and toolchain files for cross-compilation. The sanitizer integration and CMake Presets sections are especially handy if you're setting up CI or trying to standardize builds across a team. The error table at the end covers the usual "can't find package" headaches. It assumes CMake 3.20 or newer, so if you're stuck on an older version, some syntax won't work.
- skills.sh installs
- 1.8K
- GitHub stars
- 279
- last updated
- Aug 21, 2026
Install
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill cmake --agent claude-codeInstalls into .claude/skills of the current project.
Files
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/INTERFACEto control property propagation. - Never use
include_directories()orlink_libraries()(legacy). - Minimum CMake version:
cmake_minimum_required(VERSION 3.20)for most features.
2. Minimal project
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)
Sponsors
Details
- Repository
- github.com/mohitmishra786/low-level-dev-skills
- Categories
- DevOps & CI/CD, Documentation, Code Review & Quality
- First seen
- May 16, 2026
More from mohitmishra786/low-level-dev-skills
All 54- Static Analysis1.2K
- Gdb1K
- Llvm948
- Sanitizers895
- Core Dumps828
- Linux Perf814
- Clang789
- Cross Gcc742
- Gcc741
- Valgrind740
- Flamegraphs728
- Assembly X86724
- Strace Ltrace711
- Cpu Cache Opt709
- Assembly Arm707
- Lldb703
- Elf Inspection702
- Simd Intrinsics701
- Make697
- Memory Model693
- Freertos691
- Linux Kernel Modules689
- Ninja681
- Heaptrack676
