From b785db3131c4b2aeed68d2bd7d3cb42a79ae5c7e Mon Sep 17 00:00:00 2001 From: Anton Zhilin Date: Wed, 24 Apr 2024 21:15:50 +0300 Subject: [PATCH] feat cmake: download userver via CPM --- CMakeLists.txt | 28 ++++++++++++++++------------ cmake/get_cpm.cmake | 24 ++++++++++++++++++++++++ third_party/Readme.md | 11 ----------- 3 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 cmake/get_cpm.cmake delete mode 100644 third_party/Readme.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 591b2d8..3f1e47e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,18 +4,22 @@ project(service_template CXX) # Adding userver dependency find_package(userver COMPONENTS core postgresql QUIET) -if(NOT userver_FOUND) # Fallback to subdirectory usage - # Compatibility mode: some systems don't support these features - set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE) - set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE) - set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE) - - if (EXISTS third_party/userver) - message(STATUS "Using userver framework from third_party/userver") - add_subdirectory(third_party/userver) - else() - message(FATAL_ERROR "Either install the userver or provide a path to it") - endif() +if(NOT userver_FOUND) # Fallback to CPM + include(cmake/get_cpm.cmake) + + CPMAddPackage( + NAME userver + # Optionally: update the minimum userver version here + VERSION 2.0 + # Optionally: pin userver version for reproducible builds + GIT_TAG develop + GITHUB_REPOSITORY userver-framework/userver + OPTIONS + # Compatibility mode: some systems don't support these features + "USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF" + "USERVER_FEATURE_GRPC_CHANNELZ OFF" + "USERVER_FEATURE_REDIS_HI_MALLOC ON" + ) endif() userver_setup_environment() diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake new file mode 100644 index 0000000..cf0d051 --- /dev/null +++ b/cmake/get_cpm.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.39.0) +set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/third_party/Readme.md b/third_party/Readme.md deleted file mode 100644 index 2e623aa..0000000 --- a/third_party/Readme.md +++ /dev/null @@ -1,11 +0,0 @@ -### Directory for third party libraries - -`userver` placed into this directory would be used if there's no installed -userver framework. For example: - -``` -cd /data/code -git clone --depth 1 https://github.com/userver-framework/userver.git -git clone --depth 1 https://github.com/userver-framework/service_template.git -ln -s /data/code/userver /data/code/service_template/third_party/userver -```