diff options
author | ambrosin <ambrosin@google.com> | 2023-04-26 02:14:35 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-04-26 02:15:42 -0700 |
commit | fefa7ce0144d1ea4a82a20f0ff0e039bd6243472 (patch) | |
tree | 62048ab611e523b9775d24d03758bc825c39ba01 /cmake | |
parent | 48ccfcaa456c6c70e20ebe1ae05efdf386f82b11 (diff) | |
download | tink-fefa7ce0144d1ea4a82a20f0ff0e039bd6243472.tar.gz |
Use FetchContent to download, unpack and configure in-tree dependencies
FetchContent is available since CMake 3.11, and does all the heavy lifting that `http_archive` did.
NOTE: `FetchContent_MakeAvailable` is only available >= 3.14, so for now we must use `add_subdirectory`.
PiperOrigin-RevId: 527204754
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/HttpArchive.cmake | 71 | ||||
-rw-r--r-- | cmake/HttpArchiveDownloader.cmake.in | 37 | ||||
-rw-r--r-- | cmake/TinkWorkspace.cmake | 7 |
3 files changed, 31 insertions, 84 deletions
diff --git a/cmake/HttpArchive.cmake b/cmake/HttpArchive.cmake index d13a10398..75fd0d3a6 100644 --- a/cmake/HttpArchive.cmake +++ b/cmake/HttpArchive.cmake @@ -12,21 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -include(ExternalProject) +include(FetchContent) include(CMakeParseArguments) -if (NOT DEFINED TINK_THIRD_PARTY_DIR) - set(TINK_THIRD_PARTY_DIR "${CMAKE_CURRENT_BINARY_DIR}/__third_party") -endif() - # Download, unpack and configure a dependency. # # The project is added as a subdirectory of Tink, unless DATA_ONLY is # specified. This makes all target defined by it available as dependencies. # -# This rule also defines a <NAME>_SOURCE_DIR variable, which points to the -# root directory of the downloaded package and can be used to reference data in -# tests, or append extra include/link paths in the Workspace file. +# This rule also defines two variables: +# - <NAME>_SOURCE_DIR points to the root directory of the downloaded package; +# it can be used to reference data in tests, or append extra include/link +# paths in the Workspace file. +# - <NAME>_BINARY_DIR points to the build directory. # # Parameters: # NAME name of the dependency. @@ -49,40 +47,29 @@ function(http_archive) "NAME;URL;SHA256;CMAKE_SUBDIR" "CMAKE_ARGS" ) - + FetchContent_Declare( + ${http_archive_NAME} + URL ${http_archive_URL} + URL_HASH SHA256=${http_archive_SHA256} + ) message(STATUS "Fetching ${http_archive_NAME}") - - set(http_archive_PREFIX "${TINK_THIRD_PARTY_DIR}/${http_archive_NAME}") - set(http_archive_SOURCE_DIR "${http_archive_PREFIX}/src") - set(http_archive_BINARY_DIR "${http_archive_PREFIX}/build") - - configure_file( - cmake/HttpArchiveDownloader.cmake.in - "${http_archive_PREFIX}/CMakeLists.txt") - - execute_process( - COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE errors - WORKING_DIRECTORY "${http_archive_PREFIX}") - - if (errors) - message(FATAL_ERROR "While configuring ${http_archive_NAME}: ${errors}") - endif() - - set(${http_archive_NAME}_SOURCE_DIR "${http_archive_SOURCE_DIR}" PARENT_SCOPE) - - execute_process( - COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE errors - WORKING_DIRECTORY "${http_archive_PREFIX}") - - if (errors) - message(FATAL_ERROR "While fetching ${http_archive_NAME}: ${errors}") - endif() - - if (NOT http_archive_DATA_ONLY) - add_subdirectory( - "${http_archive_SOURCE_DIR}/${http_archive_CMAKE_SUBDIR}" - "${http_archive_BINARY_DIR}" EXCLUDE_FROM_ALL) + FetchContent_GetProperties(${http_archive_NAME}) + if(NOT ${http_archive_NAME}_POPULATED) + FetchContent_Populate(${http_archive_NAME}) + if (NOT http_archive_DATA_ONLY) + add_subdirectory( + ${${http_archive_NAME}_SOURCE_DIR}/${http_archive_CMAKE_SUBDIR} + ${${http_archive_NAME}_BINARY_DIR} + EXCLUDE_FROM_ALL) + endif() + # Expose these variables to the caller. + set( + "${http_archive_NAME}_SOURCE_DIR" + "${${http_archive_NAME}_SOURCE_DIR}" + PARENT_SCOPE) + set( + "${http_archive_NAME}_BINARY_DIR" + "${${http_archive_NAME}_BINARY_DIR}" + PARENT_SCOPE) endif() endfunction(http_archive) diff --git a/cmake/HttpArchiveDownloader.cmake.in b/cmake/HttpArchiveDownloader.cmake.in deleted file mode 100644 index 03a314b7b..000000000 --- a/cmake/HttpArchiveDownloader.cmake.in +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2019 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This template is used by http_archive() to download, unpack and configure Tink -# dependencies. You shouldn't need to use it directly. - -cmake_minimum_required(VERSION 3.13) -project(http-archive-${http_archive_NAME}) - -include(ExternalProject) - -ExternalProject_Add(${http_archive_NAME} - URL "${http_archive_URL}" - URL_HASH SHA256=${http_archive_SHA256} - TLS_VERIFY true - SOURCE_DIR "${http_archive_SOURCE_DIR}" - BINARY_DIR "${http_archive_BINARY_DIR}" - SOURCE_SUBDIR "${http_archive_CMAKE_SUBDIR}" - CMAKE_ARGS ${http_archive_CMAKE_ARGS} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - TEST_COMMAND "" - INSTALL_COMMAND "" - ${http_archive_EXTRA_OPTIONS} - EXCLUDE_FROM_ALL -) diff --git a/cmake/TinkWorkspace.cmake b/cmake/TinkWorkspace.cmake index 0245a233b..077293727 100644 --- a/cmake/TinkWorkspace.cmake +++ b/cmake/TinkWorkspace.cmake @@ -60,7 +60,7 @@ if (TINK_BUILD_TESTS) _create_interface_target(gtest_main GTest::gtest_main) else() http_archive( - NAME com_google_googletest + NAME googletest URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz SHA256 b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5 ) @@ -72,7 +72,6 @@ if (TINK_BUILD_TESTS) SHA256 eb1d558071acf1aa6d677d7f1cabec2328d1cf8381496c17185bd92b52ce7545 DATA_ONLY ) - # Symlink the Wycheproof test data. # Tests expect Wycheproof test vectors to be in a local testvectors/ folder. add_directory_alias("${wycheproof_SOURCE_DIR}/testvectors" @@ -82,7 +81,7 @@ endif() if (NOT TINK_USE_INSTALLED_ABSEIL) # Commit from 2023-01-25 http_archive( - NAME com_google_absl + NAME abseil URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.0.zip SHA256 70a2e30f715a7adcf5b7fcd2fcef7b624204b8e32ede8a23fd35ff5bd7d513b0 ) @@ -129,14 +128,12 @@ http_archive( URL https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e ) - # Rapidjson is a header-only library with no explicit target. Here we create one. add_library(rapidjson INTERFACE) target_include_directories(rapidjson INTERFACE "${rapidjson_SOURCE_DIR}") set(protobuf_BUILD_TESTS OFF CACHE BOOL "Tink dependency override" FORCE) set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "Tink dependency override" FORCE) - ## Use protobuf X.21.9. http_archive( NAME com_google_protobuf |