Files
libloot/cpp/README.md
Oliver Hamlet 81388873da Add bits for cross-compiling to Windows using MinGW
Some tests have been updated because UTF-8 is used as the native
path encoding with MinGW/Wine, unlike MSVC/Windows.

Some of the tests fail:

- 4 Rust tests fail because long paths are not enabled and so the
  paths used when creating symlinks and junction paths are too
  long. I've tested them with x86_64-pc-windows-gnu and
  x86_64-pc-windows-gnullvm, and both see the same behaviour. The
  tests pass when the MinGW-built executable is run on Windows, so
  this is a Wine limitation.
- 12 C++ tests fail because directory symlink creation is not
  implemented. They fail whether the MinGW-built executable is run
  in Wine or on Windows, so this is a MinGW limitation.
- 1 C++ filesystem test fails because long paths are not enabled.

The failing tests are skipped at runtime when built with MinGW,
aside from the one test for long paths being enabled, which expects
them to be disabled when built with MinGW.

If long paths are enabled, e.g. by running

wine reg add HKLM\\System\\CurrentControlSet\\Control\\Filesystem /v LongPathsEnabled /t REG_DWORD /d 1 /f

then many more tests fail because the C++ tests create long paths
when that Registry value is set, but it doesn't seem to actually
enable long path support in Wine, so various filesystem operations
fail.
2026-02-03 08:52:23 +00:00

86 lines
3.1 KiB
Markdown

# libloot C++ wrapper
This is a wrapper around libloot that provides a C++ interface that's ABI-compatible with libloot v0.27.0.
The wrapper has two layers:
- a static library built using Cargo, which provides a C++ interface
- a shared library built using CMake, which wraps that C++ interface to provide another that is more idiomatic.
## Build
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.
To build a release build with debug info on Windows:
```
cmake -B build .
cmake --build build --parallel --config RelWithDebInfo
```
To do the same on Linux:
```
cmake -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build --parallel
```
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
```
To build a debug build, pass `Debug` instead of `RelWithDebInfo`.
The following CMake variables can be used to configure the build:
| 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. |
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)
```
### 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:
```
uv run --directory ../docs -- sphinx-build -b html . build/html
```
## Tests
If the tests are built they can be run using:
```
ctest --test-dir build --output-on-failure --parallel -V
```
## Packaging
To package the build:
```
cpack --config build/CPackConfig.cmake -C RelWithDebInfo
```