aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorTink Team <tink-dev@google.com>2019-03-27 04:55:50 -0700
committerCharles Lee <ckl@google.com>2019-05-02 00:33:16 -0700
commitbfb01f7dd0b406a09905a54de4703b39866f9d06 (patch)
treeebe0539a01f11a8b636780490c2d34e91031834a /CMakeLists.txt
parent1f96f1004dcc99cd44344fdb8cd762d7e2e89eb4 (diff)
downloadtink-bfb01f7dd0b406a09905a54de4703b39866f9d06.tar.gz
Experimental build of libtink.so on Linux and Darwin, guarded by an option.
Add targets to build a tarball with headers included like in Bazel, using "make package" or equivalent. This is the very first take and brings CMake up to speed with Bazel. We'll improve on this in the next releases. PiperOrigin-RevId: 240534917 GitOrigin-RevId: c5bcb02a1e1be8d3c95e9426a17f950e4511c352
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt50
1 files changed, 50 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b69692224..5978aa364 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,26 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(TINK_BUILD_TESTS "Build Tink tests" OFF)
+# Build libtink.so and the bundle tarball (libtink + dependent headers).
+# This is useful to create a self-contained export of Tink, to be used in
+# projects that do not wish to include the full set of Tink targets in their
+# build system, or do not use CMake.
+#
+# Together with libtink, TinkConfig.cmake is created too, which allows to pull
+# Tink into your project as an external dependency using find_package().
+#
+# Off by default, since we don't currently support Windows and the shared lib
+# requires position independent code, which adds a small performance penalty.
+option(TINK_BUILD_SHARED_LIB "Build libtink bundle it with the headers" OFF)
+
+if (TINK_BUILD_SHARED_LIB)
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "libtink override" FORCE)
+endif()
+
+set(CPACK_GENERATOR TGZ)
+set(CPACK_PACKAGE_VERSION ${TINK_VERSION_LABEL})
+
+include(CPack)
include(TinkWorkspace)
include(TinkBuildRules)
include(TinkUtil)
@@ -29,3 +49,33 @@ list(APPEND TINK_INCLUDE_DIRS "${TINK_INCLUDE_ALIAS_DIR}")
add_subdirectory(cc)
add_subdirectory(proto)
+
+install(FILES README.md LICENSE DESTINATION "share/doc/tink")
+
+# The trailing slash in a directory name is used to strip it from the paths
+# being installed. Do not add or remove it just for style reasons.
+install(
+ DIRECTORY
+ "${CMAKE_CURRENT_SOURCE_DIR}/cc/"
+ "${TINK_GENFILE_DIR}/tink/"
+ "${TINK_GENFILE_DIR}/proto"
+ DESTINATION "include/tink"
+ FILES_MATCHING PATTERN "*.h"
+)
+
+# Bundle Abseil and BoringSSL headers with Tink.
+install(
+ DIRECTORY
+ "${com_google_absl_SOURCE_DIR}/absl"
+ "${com_google_protobuf_SOURCE_DIR}/src/google"
+ DESTINATION "include"
+ FILES_MATCHING
+ REGEX "\\.(h|inc)$"
+ PATTERN "testdata" EXCLUDE
+)
+
+# At the moment we only mark libtink for export, so we need to wrap this in a
+# if(). Otherwise we get error when TINK_BUILD_SHARED_LIB is OFF.
+if (TINK_BUILD_SHARED_LIB)
+ export(EXPORT Tink FILE TinkConfig.cmake)
+endif()