|
| 1 | +# CLI11 Agent Guide |
| 2 | + |
| 3 | +Header-only C++11 command line parser library. CMake is the primary build |
| 4 | +system; Meson and Bazel are also supported. |
| 5 | + |
| 6 | +## Quick Build & Test |
| 7 | + |
| 8 | +```bash |
| 9 | +# Default workflow (configure + build + test) |
| 10 | +cmake --workflow default |
| 11 | + |
| 12 | +# Or manually |
| 13 | +cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug |
| 14 | +cmake --build build -j4 |
| 15 | +cmake --build build --target test # or: cd build && ctest --output-on-failure |
| 16 | +``` |
| 17 | + |
| 18 | +## Running a Single Test |
| 19 | + |
| 20 | +Tests are individual Catch2 executables in `build/tests/`. |
| 21 | + |
| 22 | +```bash |
| 23 | +# Run one test executable directly |
| 24 | +./build/tests/AppTest |
| 25 | + |
| 26 | +# Or via CTest with a regex |
| 27 | +ctest -R AppTest --output-on-failure |
| 28 | +``` |
| 29 | + |
| 30 | +## Key CMake Options |
| 31 | + |
| 32 | +| Option | Default | Purpose | |
| 33 | +| -------------------------- | ----------------------- | --------------------------------------- | |
| 34 | +| `CLI11_BUILD_TESTS` | `ON` (if top-level) | Build Catch2 test suite | |
| 35 | +| `CLI11_BUILD_EXAMPLES` | `ON` (if top-level) | Build `examples/` | |
| 36 | +| `CLI11_BUILD_DOCS` | `ON` (if Doxygen found) | Build Doxygen docs | |
| 37 | +| `CLI11_SINGLE_FILE` | `OFF` | Generate single `CLI11.hpp` header | |
| 38 | +| `CLI11_PRECOMPILED` | `OFF` | Build static lib instead of header-only | |
| 39 | +| `CLI11_WARNINGS_AS_ERRORS` | `OFF` | Turn warnings into errors | |
| 40 | +| `CLI11_SANITIZERS` | `OFF` | Enable ASan/TSan/UBSan | |
| 41 | +| `CLI11_BOOST` | `OFF` | Enable Boost.Optional tests | |
| 42 | +| `CLI11_CUDA_TESTS` | `OFF` | Compile tests with NVCC | |
| 43 | + |
| 44 | +`CLI11_SINGLE_FILE` and `CLI11_PRECOMPILED` are mutually exclusive. |
| 45 | + |
| 46 | +## Presets |
| 47 | + |
| 48 | +- `default` — Debug, Ninja, `CLI11_WARNINGS_AS_ERRORS=ON`, export compile |
| 49 | + commands. |
| 50 | +- `tidy` — Inherits `default`, adds `clang-tidy` with warnings-as-errors. |
| 51 | + |
| 52 | +```bash |
| 53 | +cmake --preset tidy |
| 54 | +cmake --build --preset tidy |
| 55 | +``` |
| 56 | + |
| 57 | +## Single Header Generation |
| 58 | + |
| 59 | +Requires Python. Enable with `CLI11_SINGLE_FILE=ON`: |
| 60 | + |
| 61 | +```bash |
| 62 | +cmake -S . -B build -DCLI11_SINGLE_FILE=ON |
| 63 | +cmake --build build --target CLI11-generate-single-file |
| 64 | +# Output: build/single-include/CLI11.hpp |
| 65 | +``` |
| 66 | + |
| 67 | +Script: `scripts/MakeSingleHeader.py`. |
| 68 | + |
| 69 | +## Library Structure |
| 70 | + |
| 71 | +- `include/CLI/` — Public headers. The umbrella header is `CLI.hpp`. |
| 72 | +- `include/CLI/impl/` — `_inl.hpp` implementation headers included by the main |
| 73 | + headers. |
| 74 | +- `src/` — `.cpp` files used **only** when `CLI11_PRECOMPILED=ON`. |
| 75 | +- `single-include/` — CMake rules for the single-header build. |
| 76 | +- `tests/` — Catch2 tests. `main.cpp` + `catch.hpp` provide the test runner. |
| 77 | +- `tests/data/` — Test data files copied to the build dir automatically. |
| 78 | +- `examples/` — Standalone example programs. |
| 79 | +- `book/` — Extra documentation/examples built only when top-level. |
| 80 | + |
| 81 | +## Testing Notes |
| 82 | + |
| 83 | +- Catch2 is auto-downloaded (v2.13.10 header) if not found on the system. Both |
| 84 | + Catch2 v2 and v3 are supported. |
| 85 | +- Some tests launch helper applications (`ensure_utf8`, `ensure_utf8_twice`) |
| 86 | + built from `tests/applications/`. |
| 87 | +- `FuzzFailTest` requires C++17. |
| 88 | +- `WindowsTest` is only built on Windows. |
| 89 | +- `DeprecatedTest` compiles with `-Wno-deprecated-declarations`. |
| 90 | +- `TimerTest` is in `CLI11_MULTIONLY_TESTS` (exercises multi-threading). |
| 91 | + |
| 92 | +## Code Style & Linting |
| 93 | + |
| 94 | +Pre-commit hooks are configured in `.pre-commit-config.yaml`: |
| 95 | + |
| 96 | +- `clang-format` for C++/C/CUDA |
| 97 | +- `cmake-format` for CMake |
| 98 | +- `black` for Python |
| 99 | +- `prettier` for YAML/Markdown/JSON/etc. |
| 100 | +- `codespell` for typos |
| 101 | +- `markdownlint-cli2` |
| 102 | +- Custom checks: disallow a few common mistakes Run locally: |
| 103 | + |
| 104 | +```bash |
| 105 | +prek -a |
| 106 | +``` |
| 107 | + |
| 108 | +## Version Source of Truth |
| 109 | + |
| 110 | +The version string is read from `include/CLI/Version.hpp` at configure time. Do |
| 111 | +not edit project version in `CMakeLists.txt`. |
0 commit comments