{"enrichment":{"faq":[{"a":"cmake uses a target-first approach. Start with cmake_minimum_required() and project(), then define targets using add_executable() or add_library(). Use target_include_directories(), target_link_libraries(), and target_compile_options() to configure each target's properties. Apply PUBLIC, PRIVATE, or INTERFACE keywords to control visibility. cmake supports out-of-source builds\u2014create a separate build directory, run cmake from there, and keep source clean. This modern pattern scales better than older file-level commands.","q":"How do I write CMakeLists.txt for a C/C++ project?"},{"a":"cmake find_package locates pre-installed packages on your system via Find modules or config files, ideal for system libraries. FetchContent downloads and builds dependencies at configure time, giving you version control and reproducibility. Use find_package for optional or system-provided libraries; use FetchContent for vendored or tightly-versioned dependencies. cmake Presets can pin both strategies for team consistency.","q":"What's the difference between find_package and fetchcontent in cmake?"},{"a":"cmake Configure external dependencies via find_package(PackageName) or FetchContent_Declare(). For find_package, ensure the package's config or Find module is in CMAKE_PREFIX_PATH. Handle missing packages gracefully with REQUIRED or QUIET flags. Use target_link_libraries() to attach dependencies to your targets. For complex setups, cmake Presets define toolchain paths and cache variables, and cpack handles installation rules and distribution.","q":"How do I configure cmake to handle external dependencies and packages?"},{"a":"cmake cross-compilation requires a toolchain file specifying the target architecture. Create a file (e.g., aarch64-toolchain.cmake) setting CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_PROCESSOR, CMAKE_C_COMPILER, and CMAKE_CXX_COMPILER. Pass it via cmake -DCMAKE_TOOLCHAIN_FILE=aarch64-toolchain.cmake. Define CMAKE_FIND_ROOT_PATH to guide dependency search. cmake Presets can embed toolchain references for reproducible arm or other cross-builds.","q":"How do I set up cross-compilation with cmake toolchain files?"},{"a":"cmake Enable AddressSanitizer by adding compiler flags: target_compile_options(mytarget PRIVATE -fsanitize=address -g). For debug/release, set CMAKE_BUILD_TYPE (single-config) or use multi-config generators like Visual Studio. Use generator expressions like $<CONFIG:Debug> to apply flags conditionally. cmake Presets simplify this: define separate preset entries for debug (with sanitizer) and release builds, ensuring consistent configuration across your team.","q":"How do I enable address sanitizer and configure debug/release builds?"},{"a":"cmake Configure error \"can't find package\" usually means the package's config or Find module isn't in CMAKE_PREFIX_PATH. Check the package's installation location and add its directory to CMAKE_PREFIX_PATH via -DCMAKE_PREFIX_PATH=/path/to/package. Verify the Find module name matches find_package() exactly. Use cmake --debug-output to trace search paths. Alternatively, use FetchContent to download the dependency directly, bypassing system search entirely.","q":"What should I do if cmake can't find a package I need?"}],"shadow_tags":["build-automation","dependency-resolution","cross-platform-compilation","compiler-configuration","project-scaffolding","sanitizer-integration","ci-cd-pipeline","target-based-design"],"summary_rewrite":"Master modern CMake for C/C++ with target-first principles, out-of-source builds, and dependency management via find_package or FetchContent. Configure generators like Ninja and Make, set up sanitizers, cross-compile with toolchain files, and leverage CMake Presets for reproducible builds."},"files":[{"bytes":6732,"path":"skills/build-systems/cmake/SKILL.md","sha256":"3dc7ad6d429baf208ae6615036b53957e4ed4490f310ee09060e6b197361aa5d","url":"https://skillfed.io/files/mohitmishra786/low-level-dev-skills/cmake/edc54977/SKILL.md"}],"id":"mohitmishra786/low-level-dev-skills/cmake","links":{"html":"https://skillfed.io/mohitmishra786/low-level-dev-skills/cmake","md":"https://skillfed.io/mohitmishra786/low-level-dev-skills/cmake.md","repo":"https://github.com/mohitmishra786/low-level-dev-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":19,"language":"JavaScript","last_updated":"2026-06-27","license":"MIT","name":"cmake","publisher":"mohitmishra786","stars":148},"relations":{"similar":[{"id":"xu-xiang/everything-claude-code-zh/cpp-testing"},{"id":"affaan-m/ECC/cpp-testing"},{"id":"mohitmishra786/low-level-dev-skills/meson"},{"id":"mohitmishra786/low-level-dev-skills/conan-vcpkg"},{"id":"TheQtCompanyRnD/agent-skills/qt-cmake-project"},{"id":"softspark/ai-toolkit/cpp-rules"},{"id":"mohitmishra786/low-level-dev-skills/build-acceleration"},{"id":"mohitmishra786/low-level-dev-skills/llvm-passes"},{"id":"personamanagmentlayer/pcl/cpp-expert"},{"id":"mohitmishra786/low-level-dev-skills/ninja"}]},"slug":{"owner":"mohitmishra786","repo":"low-level-dev-skills","skill":"cmake"},"version":"edc54977"}
