|
| 1 | +# Design doc: add Catch2 to mcpp-index |
| 2 | + |
| 3 | +Date: 2026-07-26 |
| 4 | + |
| 5 | +## Source |
| 6 | + |
| 7 | +- Repo: [catchorg/Catch2](https://github.com/catchorg/Catch2) |
| 8 | +- License: BSL-1.0 (Boost Software License 1.0) |
| 9 | +- Upstream release model: amalgamated files published as GitHub release assets |
| 10 | + |
| 11 | +Catch2 has two major versions with incompatible APIs and source layouts: |
| 12 | + |
| 13 | +| Version | Source layout | Shape | |
| 14 | +|---------|--------------|-------| |
| 15 | +| v2.13.10 | `single_include/catch2/catch.hpp` (single amalgamated header) | **header-only** | |
| 16 | +| v3.15.2 | `src/catch2/**/*.{hpp,cpp}` (individual source files) | **C-source compat (static lib)** | |
| 17 | + |
| 18 | +The v2→v3 jump changed the repo layout completely (`single_include/` → `src/catch2/`), |
| 19 | +so the two versions cannot share a single `mcpp` block. Two separate packages are used: |
| 20 | + |
| 21 | +- `compat.catch2` — v3, C-source compat (static library from individual source files) |
| 22 | +- `compat.catch2-v2` — v2, header-only |
| 23 | + |
| 24 | +## Package shape decision |
| 25 | + |
| 26 | +### compat.catch2 (v3) |
| 27 | + |
| 28 | +- **Shape**: C-source compat static library (same as compat.cjson / compat.gtest) |
| 29 | +- **Sources**: `*/src/catch2/**/*.cpp` — all Catch2 implementation files (107 TUs) |
| 30 | +- **include_dirs**: `{ "*/src", "mcpp_generated" }` — exposes `<catch2/catch_all.hpp>` |
| 31 | + etc. from the source tree, and `catch2/catch_user_config.hpp` from generated files |
| 32 | +- **catch_user_config.hpp**: materialised via `generated_files` (normally |
| 33 | + CMake-generated; provides `CATCH_CONFIG_DEFAULT_REPORTER` and |
| 34 | + `CATCH_CONFIG_CONSOLE_WIDTH`). Both value-defines use `#ifndef` guards so |
| 35 | + users can override them via `cxxflags = ["-DCATCH_CONFIG_DEFAULT_REPORTER=xml"]` |
| 36 | + in their own `mcpp.toml`. Other boolean toggles (e.g. `CATCH_CONFIG_WCHAR`) |
| 37 | + are auto-detected by `catch_compiler_capabilities.hpp` and can likewise be |
| 38 | + forced on/off via `-D` flags. |
| 39 | +- **catch_main.cpp**: provides a default `main()`. Excluded from the default |
| 40 | + source set via `!` negation (`"!*/src/catch2/internal/catch_main.cpp"`); |
| 41 | + only compiled when `features = ["main"]` is requested (same pattern as |
| 42 | + `compat.gtest`'s `main` feature gating `gtest_main.cc`) |
| 43 | + |
| 44 | +### compat.catch2-v2 (v2) |
| 45 | + |
| 46 | +- **Shape**: header-only (same as compat.eigen / compat.opengl) |
| 47 | +- **include_dirs**: `{ "*/single_include" }` — consumers `#include <catch2/catch.hpp>` |
| 48 | +- **Anchor**: trivial `.c` TU (`mcpp_generated/catch2_v2_anchor.c`) to give mcpp |
| 49 | + a buildable lib target |
| 50 | +- **`main` feature**: gates a generated `main.cpp` that defines |
| 51 | + `CATCH_CONFIG_MAIN` and includes `<catch2/catch.hpp>`, providing a ready-made |
| 52 | + `main()`. Excluded by default |
| 53 | + |
| 54 | +## Download URLs |
| 55 | + |
| 56 | +Both packages use GitHub tag archive tarballs (not individual release assets) |
| 57 | +because xpm supports one URL per version. |
| 58 | + |
| 59 | +| Package | Version | GitHub archive URL | SHA256 | |
| 60 | +|---------|---------|--------------------|--------| |
| 61 | +| compat.catch2 | 3.15.2 | `https://github.com/catchorg/Catch2/archive/refs/tags/v3.15.2.tar.gz` | `acfae120892c2b67a74142d36d060c0caa96f1c3aaa8aabd96e19961163d0420` | |
| 62 | +| compat.catch2-v2 | 2.13.10 | `https://github.com/catchorg/Catch2/archive/refs/tags/v2.13.10.tar.gz` | `d54a712b7b1d7708bc7a819a8e6e47b2fde9536f487b89ccbca295072a7d9943` | |
| 63 | + |
| 64 | +### Individual release asset SHAs (for reference) |
| 65 | + |
| 66 | +| File | Release URL | SHA256 | |
| 67 | +|------|------------|--------| |
| 68 | +| catch.hpp (v2.13.10) | `https://github.com/catchorg/Catch2/releases/download/v2.13.10/catch.hpp` | `3725c0f0a75f376a5005dde31ead0feb8f7da7507644c201b814443de8355170` | |
| 69 | +| catch_amalgamated.cpp (v3.15.2) | `https://github.com/catchorg/Catch2/releases/download/v3.15.2/catch_amalgamated.cpp` | `1ec0b0c0d6133f76fea521295be3e69e3aa5464ab92972897414ca59b7f674d5` | |
| 70 | +| catch_amalgamated.hpp (v3.15.2) | `https://github.com/catchorg/Catch2/releases/download/v3.15.2/catch_amalgamated.hpp` | `f0573f46ac989896a20c524085307b633f01c8e1cdbbe6d9b39f63827c2d6c5e` | |
| 71 | + |
| 72 | +## CN mirror |
| 73 | + |
| 74 | +Not configured yet — no `mcpp-res` write access. Using plain-string upstream URLs |
| 75 | +(no `{ GLOBAL=…, CN=… }` table). CN users will fall back to the upstream source. |
| 76 | +Mirrors can be added later by a maintainer. |
| 77 | + |
| 78 | +## Test examples |
| 79 | + |
| 80 | +- **tests/examples/catch2/**: v3 static library build. Includes |
| 81 | + `<catch2/catch_all.hpp>`, provides own `main()` using |
| 82 | + `Catch::Session().run()`, runs two `TEST_CASE`s. |
| 83 | +- **tests/examples/catch2-v2/**: v2 header-only. Defines `CATCH_CONFIG_MAIN` to |
| 84 | + get a built-in main, includes `<catch2/catch.hpp>`, runs two `TEST_CASE`s |
| 85 | + within a single TU. |
| 86 | + |
| 87 | +## Verification |
| 88 | + |
| 89 | +- SHA256 computed twice (confirmed stable) via `sha256sum` on the codeload tarballs |
| 90 | +- File paths confirmed by `tar -tzf` against tag archives |
| 91 | +- Both packages pass `mcpp xpkg parse` lint |
| 92 | +- `mcpp test -p catch2` → **test result ok** (2 assertions in 2 test cases) |
| 93 | +- `mcpp test -p catch2-v2` → **test result ok** (2 assertions in 2 test cases) |
| 94 | +- Tested with mcpp 0.0.108 (matching CI `MCPP_VERSION`) on x86_64-windows-msvc |
| 95 | + |
| 96 | +## Notes |
| 97 | + |
| 98 | +- Catch2 v3 static library requires `catch_user_config.hpp` (normally |
| 99 | + CMake-generated). A minimal version is materialised via `generated_files` at |
| 100 | + `mcpp_generated/catch2/catch_user_config.hpp` with `#ifndef` guards on the |
| 101 | + two value-defines (`CATCH_CONFIG_DEFAULT_REPORTER` and |
| 102 | + `CATCH_CONFIG_CONSOLE_WIDTH`), allowing users to override them via `-D` flags. |
| 103 | +- `catch_main.cpp` is gated via `!` negation in `sources` + feature listing, |
| 104 | + following the exact `compat.gtest` pattern. No `-DCATCH_AMALGAMATED_CUSTOM_MAIN` |
| 105 | + needed. |
| 106 | +- Catch2 v3 requires C++14 or later; v2 requires C++11; both compatible with |
| 107 | + mcpp's `language = "c++23"`. |
| 108 | +- No `c_standard` needed for v3 (pure C++); anchor for v2 uses |
| 109 | + `c_standard = "c11"`. |
0 commit comments