Mastering Cmake Pdf May 2026
"version": 3, "configurePresets": [ "name": "debug", "displayName": "Debug", "generator": "Ninja", "binaryDir": "$sourceDir/build/debug", "cacheVariables": "CMAKE_BUILD_TYPE": "Debug", "BUILD_TESTS": "ON" , "name": "release", "inherits": "debug", "displayName": "Release", "binaryDir": "$sourceDir/build/release", "cacheVariables": "CMAKE_BUILD_TYPE": "Release" ], "buildPresets": [ "name": "debug", "configurePreset": "debug" , "name": "release", "configurePreset": "release" ]
#include <catch2/catch.hpp> #include "math/add.h" TEST_CASE("Addition works", "[math]") REQUIRE(add(2, 2) == 4); mastering cmake pdf
add_custom_command( OUTPUT $CMAKE_CURRENT_BINARY_DIR/version.h COMMAND $CMAKE_COMMAND -DVERSION=$PROJECT_VERSION -P write_version.cmake DEPENDS write_version.cmake COMMENT "Generating version.h" ) add_custom_target(generate_version DEPENDS $CMAKE_CURRENT_BINARY_DIR/version.h) add_dependencies(my_app generate_version) toolchain_arm.cmake : "configurePresets": [ "name": "debug"
add_executable(test_core test_core.cpp) target_link_libraries(test_core PRIVATE core) add_test(NAME CoreSanity COMMAND test_core) add_test(NAME CoreEdgeCase COMMAND test_core --edge) Presets: The Future of CMake Workflows (3.19+) CMakePresets.json standardizes configuring, building, and testing across teams: "cacheVariables": "CMAKE_BUILD_TYPE": "Debug"
# Different compile definitions per config target_compile_definitions(my_app PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD> $<$<CONFIG:Release>:NDEBUG> ) target_link_libraries(my_app PRIVATE $<$<PLATFORM_ID:Windows>:ws2_32> $<$<PLATFORM_ID:Linux>:dl> ) 2. Custom Commands and Targets Generate code or run tools: