1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# Download, unpack and setup Tink dependencies. 16# 17# Despite the looks, http_archive rules are not purely declarative, and order 18# matters. All variables defined before a rule are visible when configuring the 19# dependency it declares, and the targets provided by a dependency are visible 20# (only) after it has been declared. Following dependencies may rely on targets 21# defined by a previous one, for instance on gtest or absl. 22# 23# Some rules imported from dependencies require small fixes, which are specified 24# after the relative http_archive rule. Please always document the intended 25# purpose of such statements, and why they are necessary. 26# 27# In general, when adding a new dependency you should follow this structure: 28# 29# <set any configuration variable, if any> 30# <http_archive for your dependency> 31# <define or fix newly imported targets, if any> 32# 33# Many projects provide switches to disable tests or examples, which you should 34# specify, in order to speed up the compilation process. 35 36include(HttpArchive) 37include(TinkUtil) 38 39# Creates an interface target from an imported one. 40# 41# Parameters: 42# INTERFACE_TARGET Name of the interface target. 43# IMPORTED_TARGET Name of the imported target (e.g., with find_package). 44# 45macro(_create_interface_target INTERFACE_TARGET IMPORTED_TARGET) 46 add_library(${INTERFACE_TARGET} INTERFACE) 47 target_link_libraries(${INTERFACE_TARGET} INTERFACE ${IMPORTED_TARGET}) 48 target_include_directories(${INTERFACE_TARGET} INTERFACE ${IMPORTED_TARGET}) 49endmacro() 50 51set(gtest_force_shared_crt ON CACHE BOOL "Tink dependency override" FORCE) 52 53if (TINK_BUILD_TESTS) 54 if (TINK_USE_INSTALLED_GOOGLETEST) 55 # This uses the CMake's FindGTest module; if successful, this call to 56 # find_package generates the targets GTest::gmock, GTest::gtest and 57 # GTest::gtest_main. 58 find_package(GTest CONFIG REQUIRED) 59 _create_interface_target(gmock GTest::gmock) 60 _create_interface_target(gtest_main GTest::gtest_main) 61 else() 62 http_archive( 63 NAME googletest 64 URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz 65 SHA256 b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5 66 ) 67 endif() 68 69 http_archive( 70 NAME wycheproof 71 URL https://github.com/google/wycheproof/archive/d8ed1ba95ac4c551db67f410c06131c3bc00a97c.zip 72 SHA256 eb1d558071acf1aa6d677d7f1cabec2328d1cf8381496c17185bd92b52ce7545 73 DATA_ONLY 74 ) 75 # Symlink the Wycheproof test data. 76 # Tests expect Wycheproof test vectors to be in a local testvectors/ folder. 77 add_directory_alias("${wycheproof_SOURCE_DIR}/testvectors" 78 "${CMAKE_BINARY_DIR}/testvectors") 79endif() 80 81if (NOT TINK_USE_INSTALLED_ABSEIL) 82 # Release from 2023-05-04. 83 http_archive( 84 NAME abseil 85 URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.zip 86 SHA256 51d676b6846440210da48899e4df618a357e6e44ecde7106f1e44ea16ae8adc7 87 ) 88else() 89 # This is everything that needs to be done here. Abseil already defines its 90 # targets, which gets linked in tink_cc_(library|test). 91 find_package(absl REQUIRED) 92endif() 93 94# Don't fetch BoringSSL or look for OpenSSL if target `crypto` is already 95# defined. 96if (NOT TARGET crypto) 97 if (NOT TINK_USE_SYSTEM_OPENSSL) 98 # Commit from Feb 15, 2023. 99 # NOTE: This is one commit ahead of Bazel; the commit fixes a CMake issue, 100 # which made build fail on CMake 3.10. 101 # See https://github.com/google/boringssl/compare/5c22014...e27ff0e. 102 http_archive( 103 NAME boringssl 104 URL https://github.com/google/boringssl/archive/e27ff0e4312c91357778b36bbd8a7ec7bfc67be3.zip 105 SHA256 11d3c87906bed215a915b0db11cefd0fc7b939ddbec4952a29e343a83ce3bc50 106 CMAKE_SUBDIR src 107 ) 108 # BoringSSL targets do not carry include directory info, this fixes it. 109 target_include_directories(crypto PUBLIC 110 "$<BUILD_INTERFACE:${boringssl_SOURCE_DIR}/src/include>") 111 else() 112 # Support for ED25519 was added from 1.1.1. 113 find_package(OpenSSL 1.1.1 REQUIRED) 114 _create_interface_target(crypto OpenSSL::Crypto) 115 endif() 116else() 117 message(STATUS "Using an already declared `crypto` target") 118 get_target_property(crypto_INCLUDE_DIR crypto INTERFACE_INCLUDE_DIRECTORIES) 119 message(STATUS "crypto Include Dir: ${crypto_INCLUDE_DIR}") 120endif() 121 122set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "Tink dependency override" FORCE) 123set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "Tink dependency override" FORCE) 124set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "Tink dependency override" FORCE) 125 126http_archive( 127 NAME rapidjson 128 URL https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz 129 SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e 130) 131# Rapidjson is a header-only library with no explicit target. Here we create one. 132add_library(rapidjson INTERFACE) 133target_include_directories(rapidjson INTERFACE "${rapidjson_SOURCE_DIR}") 134 135set(protobuf_BUILD_TESTS OFF CACHE BOOL "Tink dependency override" FORCE) 136set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "Tink dependency override" FORCE) 137## Use protobuf X.21.9. 138http_archive( 139 NAME com_google_protobuf 140 URL https://github.com/protocolbuffers/protobuf/archive/v21.9.zip 141 SHA256 5babb8571f1cceafe0c18e13ddb3be556e87e12ceea3463d6b0d0064e6cc1ac3 142 CMAKE_SUBDIR cmake 143) 144