2025-06-15 20:12:24 +01:00
# libloot C++ wrapper
2025-03-06 22:24:39 +00:00
2025-06-08 17:14:38 +01:00
This is a wrapper around libloot that provides a C++ interface that's ABI-compatible with libloot v0.27.0.
2025-03-06 22:24:39 +00:00
2025-03-14 17:05:34 +00:00
The wrapper has two layers:
2025-03-12 20:29:41 +00:00
- a static library built using Cargo, which provides a C++ interface
2025-06-15 20:12:24 +01:00
- a shared library built using CMake, which wraps that C++ interface to provide another that is more idiomatic.
2025-03-12 20:29:41 +00:00
2025-06-15 20:12:24 +01:00
## Build
2025-03-26 17:56:36 +00:00
2025-06-15 20:12:24 +01:00
The prerequisites for building libloot and its C++ wrapper are [CMake ](https://cmake.org/ ), the [Rust ](https://www.rust-lang.org/ ) toolchain and a C++ toolchain. The CI builds currently use a recent version of CMake, the latest version of Rust, MSVC 2022 on Windows and GCC 13 on Linux, so alternatives such as other versions, Mingw-w64 or Clang may not work without modifications.
2025-05-08 16:57:00 +01:00
2025-06-15 20:12:24 +01:00
To build a release build with debug info on Windows:
2025-03-06 22:24:39 +00:00
```
cmake -B build .
2025-03-26 17:56:36 +00:00
cmake --build build --parallel --config RelWithDebInfo
2025-03-12 20:29:41 +00:00
```
2025-06-15 20:12:24 +01:00
To do the same on Linux:
2025-03-12 20:29:41 +00:00
```
2025-03-26 17:56:36 +00:00
cmake -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build --parallel
2026-01-31 16:55:06 +00:00
```
To cross-compile on Linux for Windows:
```
cmake -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw64.cmake
cmake --build build --parallel
2025-03-26 17:56:36 +00:00
```
2025-06-15 20:12:24 +01:00
To build a debug build, pass `Debug` instead of `RelWithDebInfo` .
The following CMake variables can be used to configure the build:
2026-01-31 16:04:23 +00:00
| Parameter | Values | Default | Description |
|------------------------|-------------|---------|----------------------------------------------------------------------------------------------------------|
| `LIBLOOT_BUILD_SHARED` | `ON` , `OFF` | `ON` | Whether or not to build a shared libloot binary. |
| `LIBLOOT_BUILD_TESTS` | `ON` , `OFF` | `ON` | Whether or not to build libloot's tests. |
| `LIBLOOT_INSTALL_DOCS` | `ON` , `OFF` | `ON` | Whether or not to install libloot's docs (which need to be built separately). |
| `RUN_CLANG_TIDY` | `ON` , `OFF` | `OFF` | Whether or not to run clang-tidy during build. Has no effect when using CMake's Visual Studio generator. |
2025-06-15 20:12:24 +01:00
2025-08-01 18:21:44 +01:00
An example of using libloot with CMake's FetchContent:
```cmake
set ( LIBLOOT_BUILD_TESTS OFF )
set ( LIBLOOT_INSTALL_DOCS OFF )
FetchContent_Declare ( libloot
GIT_REPOSITORY "https://github.com/loot/libloot.git"
GIT_TAG "master" # Better to use a specific commit hash.
SOURCE_SUBDIR "cpp" )
FetchContent_MakeAvailable ( libloot )
add_executable ( myapp ${ MYAPP_SOURCES } )
target_link_libraries ( myapp PRIVATE libloot::loot )
```
2025-06-15 20:12:24 +01:00
### Documentation
Install [Doxygen ](https://www.doxygen.nl/ ), [Python ](https://www.python.org/ ) and [uv ](https://docs.astral.sh/uv/getting-started/installation/ ) and make sure they're accessible from your `PATH` , then run:
2025-03-26 17:56:36 +00:00
```
2025-06-15 20:12:24 +01:00
uv run --directory ../docs -- sphinx-build -b html . build/html
2025-03-26 17:56:36 +00:00
```
2025-06-15 20:12:24 +01:00
## Tests
2025-03-26 17:56:36 +00:00
2025-06-15 20:12:24 +01:00
If the tests are built they can be run using:
2025-03-26 17:56:36 +00:00
```
ctest --test-dir build --output-on-failure --parallel -V
2025-03-06 22:24:39 +00:00
```
2025-06-15 20:12:24 +01:00
## Packaging
2025-05-08 16:32:33 +01:00
2025-03-06 22:24:39 +00:00
To package the build:
```
2025-03-26 17:56:36 +00:00
cpack --config build/CPackConfig.cmake -C RelWithDebInfo
2025-03-06 22:24:39 +00:00
```
2026-04-03 16:19:47 +01:00
## Minimum supported Rust version
The minimum supported Rust version is `1.89` . This may change at any time, but there is a CI job to check that it does not change unexpectedly.