# packtpublishing/modern-cmake-for-cpp-2e architecture

> Architecture diagram of the GitHub repository packtpublishing/modern-cmake-for-cpp-2e, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/packtpublishing/modern-cmake-for-cpp-2e
- Repository: https://github.com/packtpublishing/modern-cmake-for-cpp-2e

## Overview

Based on our analysis of the file tree and README, this repository is not a typical full‑stack application or a library that’s deployed in production, but rather a “living” set of examples demonstrating modern CMake usage in C++ projects. Its purpose is to illustrate best practices for building, testing, and packaging C++ projects using CMake. The repository’s structure is organized by chapter (ch01, ch02, …, ch16, etc.) with each chapter offering one or more sample projects, complete with CMakeLists.txt files, example source code, and in many cases associated tests, installation scripts, or configuration files.

##### Main Components
- Build Environment & Configuration: Include the high-level build scripts such as build.sh, build_base.sh, devel.sh, and change-clang-version.sh, plus the various CMake modules and configuration snippets across the repository (for instance, under the examples’ chapters and the cmake/ subdirectories). Also note the Dockerfile, docker-compose.yaml, and compose-dev.yaml, which serve as infrastructure for reproducing build environments.
- Examples by Chapter: Organize the “examples” folder as an umbrella module that is further subdivided into chapters (ch01 to ch16). Each chapter acts as a module demonstrating specific features such as handling of arguments, modules, dependencies, install targets, tests, and even configuration for tooling (e.g., ClangTidy, Valgrind, Doxygen).
- Testing & Quality Assurance Subsystems: Within several chapter examples (especially chapters related to unit testing frameworks like Catch2, GTest, and GMock), highlight the testing components. Show how tests are integrated into the build process.
- Packaging and Distribution: Some chapters (e.g., those about install targets, export, and configuration files) emphasize packaging. Represent these components with their corresponding CMake and supporting scripts.
- Auxiliary Infrastructure: Tools such as Docker (with its Dockerfile and compose files) and development container configuration (like the .devcontainer.json) should be depicted as part of the “infrastructure” that supports reproducible builds and cross-platform development.

##### Relationships and Interactions
- At the top-level, the repository splits into infrastructure/build scripts and the examples folder – each example is itself a mini-project with its own CMake configuration.
- Directional relationships from the build scripts and Docker configuration to the examples: the build system (CMake) orchestrates the compilation, linking, and testing of each chapter’s project.
- That the test suites are invoked by the build scripts and can report results (integration between test components and CI pipelines if any were to be added).
- How the examples depend on common tooling and configuration files provided at the repository root (e.g., .gitignore, LICENSE, and top-level build scripts).

##### Architectural Patterns / Design Principles
- Modularity: The repository is organized in a modular fashion by chapter, each one reflecting a self-contained CMake demonstration. Emphasize how this structure reinforces separation of concerns.
- Declarative Build Configuration: The pervasive use of CMakeLists.txt files across the repository illustrates a declarative approach to building software. This is central to the repository’s design.
- Environment Isolation: The inclusion of Docker and development container configurations underscores a principle of ensuring consistency across development environments.

##### Relevant Technologies, Frameworks, or Libraries
- CMake – as the primary build configuration and scripting tool.
- Docker – for environment configuration and containerized builds.
- Unit testing frameworks – such as Catch2, GTest, and GMock, featured in several examples.
- Static/dynamic analysis tools – implied via chapters on Clang-Tidy, Valgrind, and Code Coverage.
- Additional C++ tooling – such as Doxygen for documentation and formatting tools (clang-format).

##### Specific Elements
- Annotations or sub-labels to indicate how specific technologies are used (e.g., “CMakeLists.txt defines build rules” in each example, “Dockerfile defines container environment”, etc.)
- Optionally, include a small inset that shows the progression of complexity across chapters to capture the educational intent of the repository.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Infrastructure & Build Environment"
        subgraph "Build Scripts"
            script1["build.sh"]:::script
            script2["build_base.sh"]:::script
            script3["devel.sh"]:::script
            script4["change-clang-version.sh"]:::script
        end
        subgraph "Docker & Container Config"
            docker1["Dockerfile"]:::docker
            docker2["docker-compose.yaml"]:::docker
            docker3["compose-dev.yaml"]:::docker
            docker4[".devcontainer.json"]:::docker
            docker5[".dockerignore"]:::docker
        end
        subgraph "Auxiliary Infrastructure"
            lic["LICENSE"]:::auxiliary
            readme["README.md"]:::auxiliary
            git[".gitignore"]:::auxiliary
        end
        cmake["CMake Build System"]:::cmake
    end

    subgraph "Examples by Chapter"
        examples["examples"]:::examples
        subgraph "Basic Examples"
            be1["ch01-ch10 & ch16"]:::basic
        end
        subgraph "Testing & Quality Assurance"
            tst1["ch11: 01-no-framework/test"]:::testing
            tst2["ch11: 02-structured/test"]:::testing
            tst3["ch11: 03-catch2/test"]:::testing
            tst4["ch11: 04-gtest/test"]:::testing
            tst5["ch11: 05-gmock/test"]:::testing
            tst6["ch12: Static Analysis Tests"]:::testing
            tst7["ch15: 01-full-project/test"]:::testing
        end
        subgraph "Packaging & Distribution"
            pkg["ch14 Packaging & Distribution"]:::packaging
        end
    end

    %% Connections from Infrastructure to CMake Build System
    script1 --> cmake
    script2 --> cmake
    script3 --> cmake
    script4 --> cmake
    docker1 --> cmake
    docker2 --> cmake
    docker3 --> cmake
    docker4 --> cmake
    docker5 --> cmake
    lic --> cmake
    readme --> cmake
    git --> cmake

    %% Connection from CMake Build System to Examples
    cmake --> examples

    %% Connections within Examples submodules
    examples --> be1
    examples --> tst1
    examples --> pkg

    %% Click Events
    click script1 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/build.sh"
    click script2 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/build_base.sh"
    click script3 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/devel.sh"
    click script4 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/change-clang-version.sh"
    click docker1 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/Dockerfile"
    click docker2 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/docker-compose.yaml"
    click docker3 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/compose-dev.yaml"
    click docker4 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/.devcontainer.json"
    click docker5 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/.dockerignore"
    click lic "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/LICENSE"
    click readme "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/README.md"
    click git "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/blob/main/.gitignore"
    click examples "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples"
    click tst1 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch11/01-no-framework/test"
    click tst2 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch11/02-structured/test"
    click tst3 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch11/03-catch2/test"
    click tst4 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch11/04-gtest/test"
    click tst5 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch11/05-gmock/test"
    click tst6 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch12"
    click tst7 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch15/01-full-project/test"
    click pkg "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples/ch14"
    click be1 "https://github.com/packtpublishing/modern-cmake-for-cpp-2e/tree/main/examples"

    %% Class Definitions for Colors & Styles
    classDef script fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef docker fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef auxiliary fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef cmake fill:#F0E68C,stroke:#000,stroke-width:1px;
    classDef examples fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef testing fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef packaging fill:#9370DB,stroke:#000,stroke-width:1px;
    classDef basic fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
