Skip to content

Commit 855369c

Browse files
committed
Rework coverage, update documentation.
1 parent f1d7688 commit 855369c

4 files changed

Lines changed: 506 additions & 675 deletions

File tree

README.md

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,153 @@ The `include/project_name` folder will also include a `include.cmake` file that
8888

8989
Tests are contained in the component's `tests` folder. See `idi_component_test` and `idi_component_test_public` function documentation below for more information on how tests can be added. Tests are built around CTest and use Catch2 by default.
9090

91-
## Documentation
91+
## Code Coverage
9292

93-
WIP
93+
The framework includes built-in support for code coverage instrumentation and reporting via GCC/Clang's `--coverage` flag.
94+
95+
### Requirements
96+
97+
- **Compiler:** GCC or Clang (MSVC is not supported for coverage)
98+
- **Report tools (at least one recommended):**
99+
- `lcov` + `genhtml` — generates HTML reports (preferred)
100+
- `gcovr` — generates HTML and/or Cobertura XML reports (useful for CI)
101+
102+
Install on Debian/Ubuntu:
103+
104+
```sh
105+
$ sudo apt install lcov # lcov + genhtml
106+
$ pip install gcovr # gcovr (alternative / CI XML reports)
107+
```
108+
109+
### Usage
110+
111+
Enable coverage by passing `-DCODE_COVERAGE=ON` at configure time:
112+
113+
```sh
114+
$ cd build
115+
$ cmake .. -DCODE_COVERAGE=ON
116+
$ cmake --build .
117+
```
118+
119+
Then run one of the coverage build targets:
120+
121+
| Target | Description |
122+
|---|---|
123+
| `ccov-all` | Run all tests and generate an aggregate HTML coverage report |
124+
| `ccov-all-xml` | Generate a Cobertura XML report (requires `gcovr`, available when `lcov` is also present) |
125+
| `ccov-clean` | Remove all generated coverage data and reports |
126+
127+
```sh
128+
$ cmake --build . --target ccov-all
129+
```
130+
131+
Reports are written to `build/reports/coverage/`:
132+
133+
- **HTML report:** `build/reports/coverage/html/index.html`
134+
- **LCOV info file:** `build/reports/coverage/coverage.info`
135+
- **Cobertura XML:** `build/reports/coverage/coverage.xml` (when using `gcovr`)
136+
137+
### How It Works
138+
139+
Coverage is integrated into the framework's component system automatically. The existing `idi_component`, `idi_component_test`, and `idi_component_test_public` functions call `target_code_coverage()` on their targets. When `CODE_COVERAGE=ON`:
140+
141+
1. All component object libraries and test executables are compiled with `--coverage`.
142+
2. Test executables registered with the `ALL` flag are collected for the aggregate report.
143+
3. At the end of configuration, the `ccov-all` target is created which runs all registered tests and produces a filtered coverage report excluding test files, third-party libraries, and system headers.
144+
145+
When `CODE_COVERAGE=OFF` (the default), all coverage functions are no-ops and no build overhead is added.
146+
147+
### Tool Priority
148+
149+
The report generation strategy depends on which tools are available:
150+
151+
1. **lcov + genhtml** — HTML report via `ccov-all`; if `gcovr` is also available, `ccov-all-xml` is added for Cobertura XML.
152+
2. **gcovr only**`ccov-all` produces both HTML and XML reports.
153+
3. **Neither**`ccov-all` runs the tests and generates raw `.gcda`/`.gcno` data files only.
154+
155+
## Updating the Framework
156+
157+
The CMake framework includes a self-update mechanism that can pull in new versions of the framework files without overwriting your project-specific code (components, configuration, etc.).
158+
159+
### Update Sources
160+
161+
The updater supports three source modes:
162+
163+
| Mode | Description | Required Variable |
164+
|---|---|---|
165+
| `url` (default) | Downloads a zip archive from a URL | `FRAMEWORK_UPDATE_URL` (defaults to the IDI template master branch on GitHub) |
166+
| `file` | Extracts from a local zip archive | `FRAMEWORK_UPDATE_FILE_LOC` — path to the archive relative to the project root |
167+
| `folder` | Copies from a local folder | `FRAMEWORK_UPDATE_FOLDER_LOC` — absolute path to a template project folder |
168+
169+
### Running an Update
170+
171+
Trigger an update by passing `-DDO_FRAMEWORK_UPDATE=ON` during CMake configuration:
172+
173+
```sh
174+
$ cd build
175+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON
176+
```
177+
178+
This will:
179+
180+
1. Download/extract/copy the update source into a temporary `.idi-framework-update` directory.
181+
2. Compare the incoming framework version against the current one.
182+
3. If an update is available, replace the framework files (`cmake/idi/`, `src/base/`, root `CMakeLists.txt`, `src/CMakeLists.txt`, and `lib/.gitignore`).
183+
4. Rename the base component's include directory to match your `IDICMAKE_PROJECT_NAME`.
184+
5. Clean up the temporary directory and set `IDICMAKE_DID_UPDATE` so the rest of configuration is skipped — you must re-run `cmake ..` after an update to configure normally.
185+
186+
**If the framework is already up-to-date**, the updater will error out. To force a re-application of the same version:
187+
188+
```sh
189+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON -DFRAMEWORK_UPDATE_FORCE=ON
190+
```
191+
192+
### Specifying a Source
193+
194+
**From a URL (default — GitHub master):**
195+
196+
```sh
197+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON
198+
```
199+
200+
**From a custom URL:**
201+
202+
```sh
203+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON -DFRAMEWORK_UPDATE_MODE=url \
204+
-DFRAMEWORK_UPDATE_URL=https://example.com/framework-v6.zip
205+
```
206+
207+
**From a local zip file:**
208+
209+
```sh
210+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON -DFRAMEWORK_UPDATE_MODE=file \
211+
-DFRAMEWORK_UPDATE_FILE_LOC=path/to/framework-update.zip
212+
```
213+
214+
**From a local folder (useful during framework development):**
215+
216+
```sh
217+
$ cmake .. -DDO_FRAMEWORK_UPDATE=ON -DFRAMEWORK_UPDATE_MODE=folder \
218+
-DFRAMEWORK_UPDATE_FOLDER_LOC=/absolute/path/to/template-project
219+
```
220+
221+
### What Gets Updated
222+
223+
The updater replaces only the framework-managed files:
224+
225+
| Path | Content |
226+
|---|---|
227+
| `cmake/idi/` | Entire framework directory (functions, updater, templates, scripts) |
228+
| `src/base/` | Base component boilerplate (include directory is renamed to match your project) |
229+
| `CMakeLists.txt` | Root CMake file |
230+
| `src/CMakeLists.txt` | Source directory CMake file |
231+
| `lib/.gitignore` | Library gitignore |
232+
233+
Your project-specific files are **not touched**: `platform-config.cmake`, `platform-compile-options.cmake`, `version.cmake`, `components.cmake`, custom components, `cmake-hooks/`, `lib/libraries.cmake`, and `demo/`.
234+
235+
### Version Checks
236+
237+
After updating, the framework validates that your root and `src/` CMakeLists.txt files meet the minimum required version numbers (`IDICMAKE_ROOT_REQ_CML_V`, `IDICMAKE_SRC_REQ_CML_V`, `IDICMAKE_BASE_REQ_CML_V`). If the update replaced these files, they will already be at the correct version. If a major framework update changes the required versions, the updater will replace these files automatically.
94238

95239
## License
96240

0 commit comments

Comments
 (0)