|
c2pa-cpp
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.
Note: This project uses pre-built dynamic libraries from the c2pa-rs repository. It should select the correct library for your platform. If your platform is not supported, you can build your own library using the c2pa_rs repo.
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 pre-build libraries published with c2pa releases, build and link the C++ code.
The Makefile has a number of other targets; for example:
test to run unit testsexamples to build and run the C++ examples.emscripten-example to build the Emscripten/WebAssembly example (see below).all to build and run everything.Results are saved in the build directory.
This project can also be built entirely from source (without pre-built library download), with the pre-requisite 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:
API documentation generated by Doxygen is automatically built on each PR.
To generate API docs locally, these are the main files:
c2pa-cpp/Doxyfilec2pa-cpp/scripts/generate_api_docs.shdocs/_build/htmlInstall Doxygen if needed:
To generate docs, enter the command:
Or run make -C docs.
Open _build/html/index.html to see the results.
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.