Target reference#
All LIBRA build targets. Targets are only defined for the top-level
CMake project() — dependent projects that also use LIBRA are
unaffected.
For a conceptual overview of how targets are organised and the availability model, see Targets. For common workflows using these targets, see Build lifecycle.
Note
All examples assume the Ninja or Unix Makefiles generator.
Adjust make → cmake --build . as needed.
Discovery#
Target |
Description |
|---|---|
|
Emit a table of all LIBRA targets, whether or not they are
enabled/available, and — more importantly — why. E.g., a
necessary program was not found, or a |
Test targets#
Requires LIBRA_TESTS to be enabled. No tests are
included in the default build — see Testing for the
rationale.
Target |
Description |
|---|---|
|
Build all unit tests. To build a single test: make hfsm-utest
for a file named |
|
Build all integration tests. To build a single test: make hfsm-itest
|
|
Build all regression tests. To build a single test: make hfsm-rtest
|
|
Build all unit, integration, and regression tests. Equivalent to
|
|
Build |
|
Run already-built tests via |
Analysis and formatting targets#
Requires LIBRA_ANALYSIS to be enabled. Only targets
for tools that are found on PATH are created — see
Targets for the availability model.
Target |
Description |
|---|---|
|
Run all enabled static checkers. Runs the following sub-targets individually:
Changed in version 0.8.5: Renamed from For tool-specific configuration, see Static analysis. |
|
Run all enabled formatters (changes files in place):
Added in version 0.8.15. |
|
Run all enabled auto-fixers:
Important Always reconfigure and rebuild the analysis preset
before running any |
Analysis internals: header stubs and the fix targets#
This section documents the mechanics of how LIBRA gives analysis tools correct compiler flags for every source file, including public headers. For the conceptual summary, see Static analysis.
Compilation database#
All supported analysis tools use a compilation database
(compile_commands.json) by default. This is the most reliable source
of truth for compiler flags, include paths, and defines, since it
reflects exactly what was passed to the compiler for each translation
unit. When not using a compilation database, LIBRA walks only the
INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS
of the main target — it does not recurse into PRIVATE dependencies,
as doing so would violate CMake’s visibility contract. For projects with
multiple layers of PRIVATE deps, this path is unreliable;
LIBRA_USE_COMPDB =YES (the default) is strongly
preferred.
Note
The GNU extension versions of -std are passed when not
using a compilation database, to match LIBRA behaviour in
standard autodetection.
Header stub generation#
Headers included by at least one .c/.cpp translation unit are covered
automatically by a compdb: tools analyze them in the context of the
including TU, which has a full compilation database entry and therefore
correct flags. Headers that are part of the public API but are not
included by any .c/.cpp — for example, in header-only libraries or
partially header-only components — would otherwise be invisible to the
compilation database. LIBRA handles these by generating a lightweight
stub translation unit for each such header at configure time in the build
directory:
// Auto-generated by libra -- DO NOT EDIT
#include <myproject/config/profiling_config.hpp>
Note
.c stubs are generated for .h files and .cpp stubs
are generated for .hpp files. Under LIBRA conventions (see
Project layout) .h files are always C
code and .hpp files are always C++ code.
Each stub is compiled as part of an object library that links privately against the analysis target, giving it a real compilation database entry with the correct include paths and defines. The stub is then registered as an analysis target in the same way as any other source file. If a header fails analysis when checked via its stub, that is a real bug in the header — not a tooling artifact. The fix is to make the header self-contained, not to suppress the error.
Why fix-* requires a fresh configure#
Stubs are only generated for headers with no real .c/.cpp coverage.
This is a correctness requirement for the fix analysis variant (e.g.
fix-clang-tidy): if a header gains .c/.cpp coverage after stubs
were generated, both the stub TU and the real TU will analyze it and
generate identical patches. The second patch application fails because
the first has already modified the file, invalidating the expected
context. Generating stubs only for uncovered headers also enables
fix analysis to run in parallel.
To avoid this, always reconfigure and rebuild before running any
fix-* target. The separate analysis preset makes this natural:
cmake --preset analyze
cmake --build --preset analyze
cmake --build --preset analyze --target fix-clang-tidy
The sequence that produces a conflict:
foo.hhas no.ccoverage → stub generated → stub compiled → compdb entry exists.User adds
#include <foo.h>to some.c.User runs
fix-clang-tidywithout reconfiguring.Both the stub TU and the real TU analyze
foo.hand generate identical patches.Second patch application fails with a conflict error.
foo.hpphas no.cppcoverage → stub generated → stub compiled → compdb entry exists.User adds
#include <foo.hpp>to some.cpp.User runs
fix-clang-tidywithout reconfiguring.Both the stub TU and the real TU analyze
foo.hppand generate identical patches.Second patch application fails with a conflict error.
Coverage targets#
Requires LIBRA_COVERAGE to be enabled.
Target |
Description |
|---|---|
|
Capture baseline coverage data (0%) for all files before running
tests. First step in generating an absolute report that shows
untested files. Requires GNU format
( |
|
Generate an absolute HTML coverage report using
lcov/genhtml. All source files are included; files with 0%
coverage are shown. Requires |
|
Generate a relative HTML coverage report using gcovr. Only files with >0% coverage are included. Requires GNU format. |
|
Check coverage against configured thresholds and fail if any threshold is not met. Thresholds are set via: Requires GNU format. |
|
Merge raw Warning Run test binaries from the build directory root to
ensure |
|
Print LLVM coverage summary to the terminal. Requires LLVM format. |
|
Print detailed per-file LLVM coverage to the terminal. Requires LLVM format. |
|
Generate an HTML LLVM coverage report. Requires LLVM format. |
|
Export LLVM coverage data to lcov format for further processing. Requires LLVM format. |
|
Run |
Documentation targets#
Requires LIBRA_DOCS to be enabled. For tool-specific
configuration, see Documentation.
Target |
Description |
|---|---|
|
Generate API documentation with Doxygen. |
|
Check API documentation. Sub-targets:
For tool-specific notes, see Documentation. |
|
Generate project documentation with Sphinx. Depends on
|
Packaging targets#
Target |
Description |
|---|---|
|
Build deployable packages using CPack. Requires
|