Compile libc2pa

Compile the Dependencies

Truepic's libc2pa library depends on multiple third-party libraries. Listed here are all of the required libraries, along with an example of how to compile each library for Alpine Linux. These steps might need to be adjusted to compile for other platforms.

Compile openssl 1.1.1t

Required
wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1t/openssl-1.1.1t.tar.gz
tar -xzf openssl-1.1.1t.tar.gz
cd openssl-1.1.1t
mkdir -p $PREBUILT_PATH/alpine_linux/x86_64/openssl
./config --prefix=$PREBUILT_PATH/alpine_linux/x86_64/openssl \
    --openssldir=$PREBUILT_PATH/alpine_linux/x86_64/openssl \
    no-ssl no-ssl2 no-ssl3 \
    no-comp no-idea no-dtls no-dtls1 no-shared \
    no-engine no-threads no-psk no-weak-ssl-ciphers \
    no-srp no-deprecated no-hw no-dso no-tests
make install

Compile libjpeg-turbo 2.1.5.1

Optional

This library is optional. It can be omitted if libc2pa is compiled with the -DLIBJPEG_ENABLED:BOOL=OFF flag. Without it, libc2pa will be unable to auto-generate JPEG thumbnail images.

wget https://downloads.sourceforge.net/libjpeg-turbo/libjpeg-turbo-2.1.5.1.tar.gz
tar -xzf libjpeg-turbo-2.1.5.1.tar.gz
cd libjpeg-turbo-2.1.5.1
cmake -G"Unix Makefiles"
make
mkdir -p $PREBUILT_PATH/alpine_linux/x86_64/libjpeg-turbo/include/libjpeg-turbo
cp jerror.h jconfig.h jmorecfg.h jpeglib.h turbojpeg.h \
    $PREBUILT_PATH/alpine_linux/x86_64/libjpeg-turbo/include/libjpeg-turbo
mkdir -p $PREBUILT_PATH/alpine_linux/x86_64/libjpeg-turbo/lib
cp libjpeg.a libturbojpeg.a $PREBUILT_PATH/alpine_linux/x86_64/libjpeg-turbo/lib

Compile libpng 1.6.39

Optional

This library is optional. It can be omitted if libc2pa is compiled with the -DLIBPNG_ENABLED:BOOL=OFF flag. Without it, libc2pa will be unable to auto-generate PNG thumbnail images.

wget https://download.sourceforge.net/libpng/libpng-1.6.39.tar.gz
tar -xzf libpng-1.6.39.tar.gz
cd libpng-1.6.39
mkdir -p $PREBUILT_PATH/alpine_linux/x86_64/libpng
./configure --prefix=$PREBUILT_PATH/alpine_linux/x86_64/libpng
make install

Compile libwebp 1.3.2

Optional

This library is optional. It can be omitted if libc2pa is compiled with the -DLIBWEBP_ENABLED:BOOL=OFF flag. Without it, libc2pa will be unable to auto-generate WebP thumbnail images.

wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.3.2.tar.gz
tar -xzvf libwebp-1.3.2.tar.gz
cd libwebp-1.3.2
./configure --disable-gl --disable-sdl \
    --disable-png --disable-jpeg --disable-tiff --disable-gif \
    --disable-wic --disable-threading --enable-shared=no \
     --prefix=$PREBUILT_PATH/alpine_linux/x86_64/libwebp
make install

Compile curl 8.4.0

Optional

This library is optional. It can be omitted if libc2pa is compiled with the -DLIBCURL_ENABLED:BOOL=OFF flag. Without it, libc2pa will be unable to POST requests to the TSA.

wget https://curl.se/download/curl-8.4.0.tar.bz2
tar -xjf curl-8.4.0.tar.bz2
cd curl-8.4.0
mkdir -p $PREBUILT_PATH/alpine_linux/x86_64/curl
./configure --without-hyper --without-zlib \
    --without-brotli --without-zstd --without-libpsl \
    --without-libgsasl --without-librtmp --without-winidn \
    --without-libidn2 --without-quiche \
    --without-zsh-functions-dir \
    --without-fish-functions-dir --disable-rt \
    --disable-ares --disable-ech --disable-ftp \
    --disable-ldap --disable-ldaps --disable-rtsp \
    --disable-telnet --disable-tftp  --disable-pop3  \
    --disable-imap  --disable-smb  --disable-smtp  \
    --disable-gopher  --disable-mqtt  --disable-manual  \
    --disable-ipv6  --disable-ntlm  --disable-ntlm-wb \
    --disable-pthreads --disable-threaded-resolver \
    --enable-shared=no --disable-alt-svc --without-nghttp2
    --with-openssl=$PREBUILT_PATH/alpine_linux/x86_64/openssl \
    --prefix=$PREBUILT_PATH/alpine_linux/x86_64/curl
make install

Ensure the Build Scripts Are Setup for Your Platform

Near the top of the root-level CMakeLists.txt file, there is a section that configures many options, including an ARCH (architecture) variable and a PLATFORM_DIR variable. You may need to edit this section to support your build architecture and platform.

Prepare the Build Directory

To prepare the build directory, you will need to execute the following command from the root of the libc2pa source tree:

cmake -B builddir -DCMAKE_BUILD_TYPE=<build-type> [build-options]

The build-type can be one of:

  • Debug
  • Release

The following build options are supported:

FlagDescription
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ONWill create a "verbose" Makefile that prints out debug information while building.
-DLIBJPEG_ENABLED:BOOL=OFFBuilds without a dependency on the 3rd-party libturbojpeg. The resulting library won't be able to auto-generate JPEG thumbnails and won't be able to compress YUV input to JPEG output.
-DLIBPNG_ENABLED:BOOL=OFFBuilds without a dependency on the 3rd-party libpng. The resulting library won't be able to auto-generate PNG thumbnails.
-DLIBWEBP_ENABLED:BOOL=OFFBuilds without a dependency on the 3rd-party libwebp. The resulting library won't be able to auto-generate WebP thumbnails.
-DLIBCURL_ENABLED:BOOL=OFFBuilds without a dependency on the 3rd-party libcurl. The resulting library won't be able to POST requests to a TSA.
-DSHOULD_INCLUDE_CLAIM_GENERATION: BOOL=OFFIf this flag is set, then the library will only be able to validate C2PA media. It will not be able to sign media.
-DUSE_SCHEMA_ORG:BOOL=OFFDisables the schema.org schema checker (which is a large chunk of code).
-DUSE_ERROR_BACKTRACE:BOOL=OFFDisables the inclusion of backtrace information in exceptions. This is useful for building on platforms that do not support the functionality.
-DMAKE_SHARED:BOOL=ONCreates a shared library. By default only a static library is built.
-DMAKE_STATIC:BOOL=OFFDisables output of the static library.
-DMAKE_TESTS:BOOL=OFFDisables building the unit tests. By default they are always built.
-DMAKE_TOOL:BOOL=OFFDisables building the c2pa_tool command-line program. By default it is always built.
-DMAKE_EXAMPLES:BOOL=ONEnables building the example binaries. By default they are not built.
-DPREBUILT_LOCATION= "$PREBUILT_PATH"Tells the build system where to find the previously built 3rd-party dependencies. If this option isn't set then it will try to pull them down from one of Truepic's private repositories.
-DPREBUILT_TAG="$PREBUILT_TAG"Overrides the tag to use when pulling from the prebuilt repository.
-DUSE_CLAING_TIDY:BOOL=ONRuns each source file through the clang-tidy linting tool.
-DSANITIZATION_ENABLED:BOOL=OFFPrevents linking in the AddressSanitizer library, which is a tool for detecting certain memory errors.
-DBUILD_SOURCE_ZIP:BOOL=ONWill create a source archive containing all the files necessary to build libc2pa.
-DFROM_SOURCE_ZIP:BOOL=ONInforms the build system that it is building from a source archive. This prevents it from attempting to grab code from Truepic repositories. Instead, it looks within the source directory for all external dependencies. This includes pulling down 3rd party libraries from public locations and building them.
-DUSE_OPENSSL111:BOOL=ONUse version 1.1.1 of the OpenSSL libraries. By default the code will compile against the latest version 3.0.
-DMAKE_TEST_LIB:BOOL=ONEnables building of a test library (libc2pa_tests_lib) that contains all of the unit and integration tests.
-DFUZZER_ENABLED:BOOL=ONBuild the fuzzer (libfuzzer) binaries.

Build the code

Execute the following command from the root of the source tree:

cmake --build builddir --config <build-type>

The build-type should match what was passed in to the previous cmake command.

The output library will be located at builddir/libc2pa.a.

Run unit tests

ctest -C Debug --test-dir builddir --output-on-failure