Yes. The second edition covers CMake 3.15+. Most recipes remain valid. For newer features like cmake-presets , supplement with online docs.
add_executable(game_engine main.cpp) # Define the assets directory set(ASSET_DIR "$CMAKE_CURRENT_SOURCE_DIR/assets") # Copy assets after every successful compilation add_custom_command( TARGET game_engine POST_BUILD COMMAND $CMAKE_COMMAND -E copy_directory "$ASSET_DIR" "$ /assets" COMMENT "Syncing game runtime assets to build directory..." ) Use code with caution. Chapter 4: Cross-Platform & Compiler Adjustments
Example GitHub Actions Workflow ( .github/workflows/cmake.yml )
# toolchain.cmake set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_C_COMPILER /path/to/arm-gcc) set(CMAKE_CXX_COMPILER /path/to/arm-g++) cmake cookbook pdf github work
name: CMake Build on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Configure CMake run: cmake -B $github.workspace/build -DCMAKE_BUILD_TYPE=Release - name: Build run: cmake --build $github.workspace/build --config Release - name: Test working-directory: $github.workspace/build run: ctest -C Release Use code with caution. Key Principles for GitHub Workflows
Unlike a standard manual, this book is structured around specific that address real-world development hurdles:
The book's complete source code is hosted on GitHub within the "dev-cafe" organization. This is the central, official repository for the book's examples, and it's where you'll find the most up-to-date and corrected content. For newer features like cmake-presets , supplement with
If you are using these repositories to supplement your reading material, focus on these critical building blocks that appear throughout the chapters: Target-Based Configuration
: Internal modules to check if specific C/C++ headers or compiler flags are supported by the target machine. Cross-Language Compilation
: For modern dependency injection without relying on pre-installed system packages, utilize CMake's native FetchContent module to pull libraries directly from GitHub at configure time. What external libraries or dependencies your project uses Your target operating systems and compilers Key Principles for GitHub Workflows Unlike a standard
The repository is meticulously organized to mirror the book's chapters and recipes. Each recipe is contained in its own folder, making it easy to find the specific example you are studying. To ensure maximum overlap with the printed book, the authors have tagged a specific version ( v1.0 ), which you can clone directly.
include(FetchContent) # Fetching a JSON utility library FetchContent_Declare( json_library GIT_REPOSITORY https://github.com GIT_TAG v3.11.2 ) # Fetching a logging framework FetchContent_Declare( spdlog_logger GIT_REPOSITORY https://github.com GIT_TAG v1.11.0 ) # Make the targets available FetchContent_MakeAvailable(json_library spdlog_logger) # Link cleanly to your target target_link_libraries(engine_core PRIVATE nlohmann_json::nlohmann_json spdlog::spdlog ) Use code with caution.
Doxyfile.in: set GENERATE_XML = YES and XML_OUTPUT = xml
4. Multi-Platform Compiler Flags and Optimization Configurations
The CMake Cookbook (published by Packt, written by Radovan Bast and Roberto Di Remigio) solves this. Instead of long explanations, it provides showing exactly how to: