|
c2pa-cpp v0.27.0
C++ API for the C2PA SDK
|
The c2pa-cpp repository implements C++ APIs that:
Although this library works for plain C applications, the documentation assumes you're using C++, since that's most common for modern applications.
The recommended way to use this library in your own CMake project is with FetchContent:
This will automatically fetch, build, and link the c2pa_cpp library and its dependencies.
See the examples/ directory for sample applications that demonstrate how to use the library in practice.
This project has been tested on macOS and should also work on common Linux distributions.
You must install the Ninja build system to run the unit tests.
Building the library holding the C++ SDK requires GNU make, which is installed on most macOS systems.
Enter this command to build the SDK:
This will download the prebuilt libraries published with c2pa releases, build and link the C++ code.
The Makefile has a number of other targets; for example:
Results are saved in the build directory.
By default the prebuilt c2pa_c libraries are downloaded from the c2pa-rs GitHub releases. To use a mirror instead, set C2PA_PREBUILT_BASE_URL to the mirror's equivalent of https://github.com/contentauth/c2pa-rs/releases/download:
This project can also be built entirely from source (without pre-built library download), with the prerequisite that you will also need c2pa-rs on the local machine, as well as the Rust toolchain.
To build in this case, the build scripts need to be able to locate the c2pa-rs sources as well as the library this builds for linking. This is done by setting environment variables in the terminal where the builds will run.
The examples/emscripten_example.cpp file demonstrates using the c2pa C++ library compiled to WebAssembly via Emscripten. It includes reading manifests from files, streams, and using a custom HTTP resolver with emscripten_fetch.
Prerequisites: Install the Emscripten SDK (4.x or later recommended) and activate it in your shell:
Build and run:
This downloads prebuilt wasm libraries from the c2pa-rs release, compiles the C++ sources with emcc, and produces a Node.js-runnable output. The HTTP resolver example requires a Web Worker in the browser but works without restriction under Node.js.
Build the unit tests by entering this make command:
The Rust c2pa_c library does not need to be sanitizer-instrumented for this to work.
make test-san builds the tests with AddressSanitizer/UBSan. On some recent macOS versions the AddressSanitizer runtime shipped with Xcode's AppleClang can abort at process start with a message like:
This is an incompatibility between an older AppleClang sanitizer runtime and the host malloc. The fix is to build the sanitizer target with a newer LLVM/Clang (for example, Homebrew's llvm).
To do so, install (or update) an llvm version. For instance, using homebrew:
Then, build and run the tests with the sanitizers activated. First, configure the build:
Note that the llvm compiler from brew --prefix llvm must properly resolve for this command to work.
Then run the build scripts:
And finally run the test executable:
The API documentation is built with Doxygen from selected published releases. Use the version selector to switch releases. The first tag in api-docs/versions.json is the default at the existing root URL; each release is also available at https://contentauth.github.io/c2pa-cpp/versions/<tag>/.
To generate API docs locally, these are the main files:
Install Doxygen if needed:
To generate docs, enter the command:
Open api-docs/_build/html/index.html to see the working-tree documentation. This local build does not include a version selector.
To build the versioned site, install Python 3.10 or newer and the GitHub CLI, authenticate with gh auth login (or set GH_TOKEN), and ensure the selected release tags are available locally with git fetch --tags. Then run:
Open api-docs/_build/versioned/index.html to see the default release. Version-specific pages are under api-docs/_build/versioned/versions/<tag>/. The build verifies that each configured tag has a published GitHub release and reads that tag's headers, C sources, and README without running release code. It uses the current branch's Doxygen configuration and styling.
Publishing a stable GitHub release automatically prepends its exact vX.Y.Z tag to api-docs/versions.json on main, preserving older entries and promoting an existing tag without duplicates. The bot commits this update after publication; it does not modify the release tag. The same workflow then builds and deploys the updated site, without relying on the bot's push triggering another workflow. Prerelease publications rebuild the configured versions without changing the version list. Rerunning a release workflow does not create an empty commit.
The version-update job requires contents: write, and branch protection or repository rules must allow github-actions[bot] to push to main. If that push fails, deployment is blocked rather than publishing a stale version list. The deployment job retains read-only repository access.
To adjust the selected releases manually, edit api-docs/versions.json, putting the desired default first. Pushes to main and manual workflow runs also rebuild and deploy the site without changing the version list.
Run the documentation tooling tests with:
The selector tests require Node.js 18 or newer. CI runs these tests and builds the versioned documentation on pull requests.
This package is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Note that some components and dependent crates are licensed under different terms; please check the license terms for each crate and component for details.
We welcome contributions to this project. For information on contributing, providing feedback, and about ongoing work, see Contributing.