Skip to content

Commit

Permalink
feat cmake: download userver via CPM
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton3 committed Apr 24, 2024
1 parent a84cf8a commit b785db3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
28 changes: 16 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions cmake/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 0 additions & 11 deletions third_party/Readme.md

This file was deleted.

0 comments on commit b785db3

Please sign in to comment.