Skip to content

Commit

Permalink
feat cmake: add download_userver()
Browse files Browse the repository at this point in the history
  • Loading branch information
segoon committed Nov 8, 2024
1 parent b9ce71f commit 31e37f0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
19 changes: 8 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
cmake_minimum_required(VERSION 3.12)
project(service_template CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include(DownloadUserver)

# 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 ${CMAKE_CURRENT_SOURCE_DIR}/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()
download_userver(
# Compatibility mode: some systems don't support these features
FEATURES_OFF
CRYPTOPP_BLAKE2
GRPC_CHANNELZ
)
endif()

userver_setup_environment()
Expand Down
28 changes: 28 additions & 0 deletions DownloadUserver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(FetchContent)

function(download_userver)
set(OPTIONS)
set(ONE_VALUE_ARGS VERSION)
set(MULTI_VALUE_ARGS FEATURES FEATURES_OFF)
cmake_parse_arguments(
ARG "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN}
)
if(NOT ARG_VERSION)
set(ARG_VERSION develop)
endif()

set(FETCHCONTENT_QUIET OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
userver
GIT_REPOSITORY https://github.com/userver-framework/userver.git
GIT_TAG ${ARG_VERSION}
)
FetchContent_MakeAvailable(userver)

foreach(FEATURE ${ARG_FEATURES})
set(USERVER_FEATURE_${FEATURE} ON CACHE BOOL "" FORCE)
endforeach()
foreach(FEATURE ${ARG_FEATURES_OFF})
set(USERVER_FEATURE_${FEATURE} OFF CACHE BOOL "" FORCE)
endforeach()
endfunction()
11 changes: 0 additions & 11 deletions third_party/Readme.md

This file was deleted.

0 comments on commit 31e37f0

Please sign in to comment.