From 31e37f0ef9fe8cdb1166db27c82a156569eac173 Mon Sep 17 00:00:00 2001 From: Vasily Kulikov Date: Fri, 8 Nov 2024 06:14:57 +0300 Subject: [PATCH] feat cmake: add download_userver() --- CMakeLists.txt | 19 ++++++++----------- DownloadUserver.cmake | 28 ++++++++++++++++++++++++++++ third_party/Readme.md | 11 ----------- 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 DownloadUserver.cmake delete mode 100644 third_party/Readme.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 61dfe19..10f582c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/DownloadUserver.cmake b/DownloadUserver.cmake new file mode 100644 index 0000000..3952522 --- /dev/null +++ b/DownloadUserver.cmake @@ -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() 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 -```