CMake for Tink HOW-TO

Incorporating Tink into your project

If you are developing a project that uses Tink, you might incorporate the library following one of the following approaches. At the moment, only the in-tree dependency is supported, although all of them should work.

In-tree dependency

Tink can be embedded directly in your CMake project and statically linked in your executable. This is the approach we currently recommend. Assuming the Tink source tree has been copied in the third_party/tink directory of your project, your top-level CMake script should look like this:

cmake_minimum_required(VERSION 3.5)
project(YourProject CXX)


target_link_libraries(your_app tink::static)

NOTE: You need at least CMake 3.5 to build Tink and its dependencies.

Include Tink headers in as follows:

#include "tink/config.h"
#include "tink/json_keyset_reader.h"

// ...

NOTE: tink::static provides the tink/... include path. It is just a shortcut for your convenience, and you might still refer to Tink headers using a filesystem path, such as third_party/tink/cc/..., if you prefer or need to.

You can see a full example in examples/helloworld/cc/

Generate the build directory as you normally would and invoke your build system of choice:

$ ls
CMakeLists.txt third_party/
$ mkdir build && cd build
$ cmake ..
$ make
$ ./your_app

If you have the option, we recommend using Ninja to build your project:

$ cmake -DCMAKE_GENERATOR=Ninja ..
$ ninja


Alternatively, you may build on Linux and Darwin systems. This feature is disabled by default, and is currently not supported on Windows. You can enable it at configure time:

$ ls
$ mkdir tink-build && cd tink-build
$ cmake ../tink -DTINK_BUILD_SHARED_LIB=ON
$ make package

We recommend using Ninja in this case too:

$ ninja package

This produces a .tar.gz archive containing, all Tink headers and some extra support headers. This is a stand-alone build that you can integrate in your own process.

WARNING: Setting TINK_BUILD_SHARED_LIB to ON is not recommended in combination with the in-tree dependency approach, as this option causes several install targets to be created, which will pollute your own install. CMake config

Building also writes a CMake config to the build directory, TinkConfig.cmake. You can use it with find_package in CONFIG mode to import the tink target in your project without embedding all of Tink internal targets in your CMake build. In this case you have to provide your own system for building and keeping up to date.

NOTE: We currently only export as tink. We are working on a way to provide tink::static too.

Developing Tink with CMake

If you are developing Tink, Bazel is the primary build system, but you should test all your changes with CMake too. Build Tink as a regular CMake project, but enable tests and build the shared library as well:

$ ls
$ mkdir tink-build && cd tink-build
$ ninja
$ ninja package

This combination of options ensures that the entire CMake configuration is evaluated.

WARNING: When editing a BUILD.bazel file, remember to keep it in sync with the corresponding CMakeLists.txt file.