- 
                Notifications
    
You must be signed in to change notification settings  - Fork 22
 
(Draft) Use CPM for package fetching #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.42.0) | ||
| set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") | ||
| 
     | 
||
| 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}) | 
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||
| include_guard() | ||||||
| 
     | 
||||||
| if(NOT DEFINED CPM_USE_NAMED_CACHE_DIRECTORIES) | ||||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А что этот флаг делает? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот тут увидел, вроде он не вредит и есть польза ссылка  | 
||||||
| set(CPM_USE_NAMED_CACHE_DIRECTORIES ON) | ||||||
| endif() | ||||||
| 
     | 
||||||
| # Workaround for https://github.com/cpm-cmake/CPM.cmake/issues/505 | ||||||
| if(${CMAKE_VERSION} VERSION_LESS "3.17.0") | ||||||
| include(FetchContent) | ||||||
| endif() | ||||||
| 
     | 
||||||
| include(cmake/CPM.cmake) | ||||||
| 
     | 
||||||
| if(NOT COMMAND CPMAddPackage) | ||||||
| message(FATAL_ERROR "Failed to find CPM to download a package. You can turn off " | ||||||
| "YDB_SDK_DOWNLOAD_PACKAGES to avoid automatic downloads." | ||||||
| ) | ||||||
| endif() | ||||||
| 
     | 
||||||
| # If A uses find_package(B), and we install A and B using CPM, then: 1. make sure to call write_package_stub in SetupB | ||||||
| # 2. make sure to call SetupB at the beginning of SetupA | ||||||
| function(write_package_stub PACKAGE_NAME) | ||||||
| file(WRITE "${CMAKE_BINARY_DIR}/package_stubs/${PACKAGE_NAME}Config.cmake" ) | ||||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
    
  | 
||||||
| endfunction() | ||||||
| 
     | 
||||||
| function(_list_subdirectories directory result_list) | ||||||
| set(result "${directory}") | ||||||
| get_property( | ||||||
| subdirectories | ||||||
| DIRECTORY "${directory}" | ||||||
| PROPERTY SUBDIRECTORIES | ||||||
| ) | ||||||
| foreach(subdirectory IN LISTS subdirectories) | ||||||
| _list_subdirectories("${subdirectory}" partial_result) | ||||||
| list(APPEND result ${partial_result}) | ||||||
| endforeach() | ||||||
| set("${result_list}" | ||||||
| ${result} | ||||||
| PARENT_SCOPE | ||||||
| ) | ||||||
| endfunction() | ||||||
| 
     | 
||||||
| function(mark_targets_as_system directory) | ||||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А эта функция для чего нужна? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Там была проблема, что установка и сборка зависимостей была уже во время нашей сборки, а из них вылетали предупреждения. Увидел что в усервере отключали так, помогло  | 
||||||
| if(NOT directory OR NOT EXISTS "${directory}") | ||||||
| message(FATAL_ERROR "Trying to mark a non-existent subdirectory '${directory}' as SYSTEM") | ||||||
| endif() | ||||||
| _list_subdirectories("${directory}" subdirectories) | ||||||
| foreach(subdirectory IN LISTS subdirectories) | ||||||
| get_property( | ||||||
| targets | ||||||
| DIRECTORY "${subdirectory}" | ||||||
| PROPERTY BUILDSYSTEM_TARGETS | ||||||
| ) | ||||||
| # Disable warnings in public headers | ||||||
| if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") | ||||||
| set_target_properties(${targets} PROPERTIES SYSTEM TRUE) | ||||||
| endif() | ||||||
| # Disable warnings in sources | ||||||
| foreach(target IN LISTS targets) | ||||||
| get_target_property(target_sources "${target}" SOURCES) | ||||||
| get_target_property(target_type "${target}" TYPE) | ||||||
| if(target_sources AND NOT target_type STREQUAL "INTERFACE_LIBRARY") | ||||||
| target_compile_options("${target}" PRIVATE -w) | ||||||
| endif() | ||||||
| endforeach() | ||||||
| endforeach() | ||||||
| endfunction() | ||||||
| 
     | 
||||||
| function(_ydb_sdk_print_cpm_packages) | ||||||
| message(STATUS "Dependencies from CPM:") | ||||||
| foreach(PACKAGE ${CPM_PACKAGES}) | ||||||
| message(STATUS "- ${PACKAGE}") | ||||||
| endforeach() | ||||||
| endfunction() | ||||||
| 
     | 
||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| include(DownloadUsingCPM) | ||
| 
     | 
||
| if(NOT "${CMAKE_BINARY_DIR}/${STUB_DIR}" IN_LIST CMAKE_PREFIX_PATH) | ||
| set(CMAKE_PREFIX_PATH | ||
| "${CMAKE_BINARY_DIR}/${STUB_DIR}" ${CMAKE_PREFIX_PATH} | ||
| ) | ||
| endif() | ||
| 
     | 
||
| # todo сделать нормально без этих страшных путей | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupBrotli.cmake) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupBase64.cmake) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupAbseil.cmake) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupJwtCpp.cmake) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupProtobuf.cmake) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/dependencies/SetupGrpc.cmake) | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| option(YDB_SDK_DOWNLOAD_PACKAGE_ABSEIL "Download and setup Abseil if no Abseil matching version was found" | ||
| ${YDB_SDK_DOWNLOAD_PACKAGES} | ||
| ) | ||
| option(YDB_SDK_FORCE_DOWNLOAD_ABSEIL "Download Abseil even if it exists in a system" ${YDB_SDK_DOWNLOAD_PACKAGES}) | ||
| 
     | 
||
| if(NOT YDB_SDK_FORCE_DOWNLOAD_ABSEIL) | ||
| set(ABSL_PROPAGATE_CXX_STD ON) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А зачем этот флаг тут нужен? Он же нужен для сборки и установки abseil, тут-то зачем?  | 
||
| 
     | 
||
| if(YDB_SDK_DOWNLOAD_PACKAGE_ABSEIL) | ||
| find_package(absl QUIET) | ||
| else() | ||
| find_package(absl REQUIRED) | ||
| endif() | ||
| 
     | 
||
| if(absl_FOUND) | ||
| return() | ||
| endif() | ||
| endif() | ||
| 
     | 
||
| include(DownloadUsingCPM) | ||
| 
     | 
||
| cpmaddpackage( | ||
| NAME | ||
| abseil-cpp | ||
| VERSION | ||
| 20230802.0 | ||
| GIT_TAG | ||
| 20230802.0 | ||
| GITHUB_REPOSITORY | ||
| abseil/abseil-cpp | ||
| OPTIONS | ||
| "ABSL_PROPAGATE_CXX_STD ON" | ||
| "ABSL_ENABLE_INSTALL ON" | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А тут точно нужен этот флаг?  | 
||
| ) | ||
| 
     | 
||
| mark_targets_as_system("${abseil-cpp_SOURCE_DIR}") | ||
| write_package_stub(absl) | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| option(YDB_SDK_DOWNLOAD_PACKAGE_BASE64 "Download and setup Base64 if no Base64 of matching version was found" | ||
| ${YDB_SDK_DOWNLOAD_PACKAGES} | ||
| ) | ||
| 
     | 
||
| set(YDB_SDK_BASE64_VERSION 0.5.2) | ||
| 
     | 
||
| if(NOT YDB_SDK_FORCE_DOWNLOAD_PACKAGES) | ||
| if(YDB_SDK_DOWNLOAD_PACKAGE_BASE64) | ||
| find_package(base64 QUIET) | ||
| else() | ||
| find_package(base64 REQUIRED) | ||
| endif() | ||
| 
     | 
||
| if(base64_FOUND) | ||
| return() | ||
| endif() | ||
| endif() | ||
| 
     | 
||
| include(DownloadUsingCPM) | ||
| cpmaddpackage( | ||
| NAME base64 | ||
| VERSION ${YDB_SDK_BASE64_VERSION} | ||
| GITHUB_REPOSITORY | ||
| aklomp/base64 | ||
| OPTIONS | ||
| "CMAKE_SKIP_INSTALL_RULES ON" | ||
| ) | ||
| write_package_stub(base64) | ||
| add_library(aklomp::base64 ALIAS base64) | ||
| set(base64_FOUND TRUE) | ||
| 
     | 
||
| 
     | 
||
| 
     | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| option(YDB_SDK_DOWNLOAD_PACKAGE_BROTLI "Download and setup Brotli if no Brotli of matching version was found" | ||
| ${YDB_SDK_DOWNLOAD_PACKAGES} | ||
| ) | ||
| 
     | 
||
| set(YDB_SDK_BROTLI_VERSION 1.1.0) | ||
| 
     | 
||
| if(NOT YDB_SDK_FORCE_DOWNLOAD_PACKAGES) | ||
| if(YDB_SDK_DOWNLOAD_PACKAGE_BROTLI) | ||
| find_package(Brotli ${YDB_SDK_BROTLI_VERSION} QUIET) | ||
| else() | ||
| find_package(Brotli ${YDB_SDK_BROTLI_VERSION} REQUIRED) | ||
| endif() | ||
| 
     | 
||
| if(Brotli_FOUND) | ||
| return() | ||
| endif() | ||
| endif() | ||
| 
     | 
||
| include(DownloadUsingCPM) | ||
| cpmaddpackage( | ||
| NAME | ||
| Brotli | ||
| VERSION | ||
| ${YDB_SDK_BROTLI_VERSION} | ||
| GITHUB_REPOSITORY | ||
| google/brotli | ||
| OPTIONS | ||
| "BROTLI_DISABLE_TESTS TRUE" | ||
| "BUILD_SHARED_LIBS OFF" | ||
| ) | ||
| 
     | 
||
| set(Brotli_FOUND TRUE) | ||
| set(Brotli_VERSION ${YDB_SDK_BROTLI_VERSION}) | ||
| add_custom_target(Brotli) | ||
| write_package_stub(Brotli) | ||
| 
     | 
||
| if(NOT TARGET Brotli::dec) | ||
| add_library(Brotli::dec ALIAS brotlidec) | ||
| endif() | ||
| if(NOT TARGET Brotli::enc) | ||
| add_library(Brotli::enc ALIAS brotlienc) | ||
| endif() | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # возможно нужен для grpc | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| cmake_policy(SET CMP0079 NEW) | ||
| 
     | 
||
| option(YDB_SDK_DOWNLOAD_PACKAGE_GRPC "Download and setup gRPC" ${YDB_SDK_DOWNLOAD_PACKAGES}) | ||
| option(YDB_SDK_FORCE_DOWNLOAD_GRPC "Download gRPC even if there is an installed system package" | ||
| ${YDB_SDK_FORCE_DOWNLOAD_PACKAGES} | ||
| ) | ||
| 
     | 
||
| set(YDB_SDK_GRPC_VERSION 1.54.3) | ||
| 
     | 
||
| macro(try_find_cmake_grpc) | ||
| find_package(gRPC QUIET CONFIG) | ||
| if(NOT gRPC_FOUND) | ||
| find_package(gRPC QUIET) | ||
| endif() | ||
| 
     | 
||
| if(gRPC_FOUND) | ||
| # Use the found CMake-enabled gRPC package | ||
| get_target_property(PROTO_GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION) | ||
| endif() | ||
| endmacro() | ||
| 
     | 
||
| macro(try_find_system_grpc) | ||
| # Find the system gRPC package | ||
| set(GRPC_USE_SYSTEM_PACKAGE | ||
| ON | ||
| CACHE INTERNAL "" | ||
| ) | ||
| 
     | 
||
| if(YDB_SDK_DOWNLOAD_PACKAGE_GRPC) | ||
| find_package(YdbSdkGrpc QUIET) | ||
| else() | ||
| find_package(YdbSdkGrpc REQUIRED) | ||
| endif() | ||
| 
     | 
||
| if(YdbSdkGrpc_FOUND) | ||
| set(gRPC_VERSION | ||
| "${YdbSdkGrpc_VERSION}" | ||
| CACHE INTERNAL "" | ||
| ) | ||
| 
     | 
||
| if(NOT TARGET gRPC::grpc++) | ||
| add_library(gRPC::grpc++ ALIAS YdbSdkGrpc) | ||
| endif() | ||
| 
     | 
||
| find_program(PROTO_GRPC_CPP_PLUGIN grpc_cpp_plugin) | ||
| find_program(PROTO_GRPC_PYTHON_PLUGIN grpc_python_plugin) | ||
| endif() | ||
| endmacro() | ||
| 
     | 
||
| if(NOT YDB_SDK_FORCE_DOWNLOAD_GRPC) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему тут поиск gRPC так усложнился?  | 
||
| try_find_cmake_grpc() | ||
| if(gRPC_FOUND) | ||
| return() | ||
| endif() | ||
| 
     | 
||
| try_find_system_grpc() | ||
| if(YdbSdkGrpc_FOUND) | ||
| return() | ||
| endif() | ||
| endif() | ||
| 
     | 
||
| 
     | 
||
| # include(${CMAKE_CURRENT_LIST_DIR}/SetupAbseil.cmake) | ||
| # include(${CMAKE_CURRENT_LIST_DIR}/SetupCAres.cmake) | ||
| # include(${CMAKE_CURRENT_LIST_DIR}/SetupProtobuf.cmake) | ||
| include(DownloadUsingCPM) | ||
| 
     | 
||
| set(YDB_SDK_GPRC_BUILD_FROM_SOURCE ON) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А зачем этот флаг?  | 
||
| 
     | 
||
| cpmaddpackage( | ||
| NAME gRPC | ||
| VERSION ${YDB_SDK_GRPC_VERSION} | ||
| GITHUB_REPOSITORY | ||
| grpc/grpc | ||
| OPTIONS | ||
| "BUILD_SHARED_LIBS OFF" | ||
| "CARES_BUILD_TOOLS OFF" | ||
| "RE2_BUILD_TESTING OFF" | ||
| "OPENSSL_NO_ASM ON" | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А зачем OPENSSL_NO_ASM ставить?  | 
||
| "gRPC_BUILD_TESTS OFF" | ||
| "gRPC_BUILD_GRPC_NODE_PLUGIN OFF" | ||
| "gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF" | ||
| "gRPC_BUILD_GRPC_PHP_PLUGIN OFF" | ||
| "gRPC_BUILD_GRPC_RUBY_PLUGIN OFF" | ||
| "gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF" | ||
| "gRPC_ZLIB_PROVIDER package" | ||
| "gRPC_CARES_PROVIDER package" | ||
| "gRPC_RE2_PROVIDER package" | ||
| "gRPC_SSL_PROVIDER package" | ||
| "gRPC_PROTOBUF_PROVIDER package" | ||
| "gRPC_BENCHMARK_PROVIDER none" | ||
| "gRPC_ABSL_PROVIDER package" | ||
| "gRPC_CARES_LIBRARIES c-ares::cares" | ||
| "gRPC_INSTALL OFF" | ||
| "gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF" | ||
| ) | ||
| 
     | 
||
| set(gRPC_VERSION "${YDB_SDK_GRPC_VERSION}") | ||
| set(PROTO_GRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>) | ||
| 
     | 
||
| write_package_stub(gRPC) | ||
| if(NOT TARGET "gRPC::grpc++") | ||
| add_library(gRPC::grpc++ ALIAS grpc++) | ||
| endif() | ||
| if(NOT TARGET "gRPC::grpc_cpp_plugin") | ||
| add_executable(gRPC::grpc_cpp_plugin ALIAS grpc_cpp_plugin) | ||
| endif() | ||
| if(NOT TARGET "gRPC::grpcpp_channelz") | ||
| add_library(gRPC::grpcpp_channelz ALIAS grpcpp_channelz) | ||
| endif() | ||
| mark_targets_as_system("${gRPC_SOURCE_DIR}") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сложное поведение как по мне. Проще дать пользователю выбор download, system или none для каждого пакета. А по умолчанию сделать download
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Подглядел в доке усервера, там есть небольшое объяснение
Как мне кажется, получается более гибко, так можно будет одной переменной отключить скачивание всех пакетов разом. Полезно будет потом на PPA, где не будет интернета, или в случае, когда хотим устанавливать все
А так ниже для каждого пакета появляются свои переменные для установки, которые по-умолчанию равны этой и их можно переопределить вручную