Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions cmake/SetupYdbCppSDK.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,112 @@
# @ingroup download
option(USERVER_DOWNLOAD_PACKAGE_YDBCPPSDK "Download and setup ydb-cpp-sdk" ${USERVER_DOWNLOAD_PACKAGES})

set(_USERVER_YDB_COMPONENTS
Iam
Coordination
Driver
Operation
Query
Result
Scheme
SolomonStats
Table
Topic
FederatedTopic
Types
)

function(_userver_ydb_make_component_alias component)
if(TARGET YDB-CPP-SDK::${component})
return()
endif()

string(TOLOWER "${component}" component_lower)
set(candidate_targets
ydb-cpp-sdk::${component_lower}
ydb-cpp-sdk::${component}
ydb-cpp-sdk::ydb-cpp-sdk-${component_lower}
ydb-cpp-sdk::ydb-cpp-sdk_${component_lower}
ydb-cpp-sdk::ydb-cpp-sdk-${component}
ydb-cpp-sdk::ydb-cpp-sdk_${component}
)

foreach(candidate_target IN LISTS candidate_targets)
if(TARGET ${candidate_target})
add_library(YDB-CPP-SDK::${component} INTERFACE IMPORTED)
target_link_libraries(YDB-CPP-SDK::${component} INTERFACE ${candidate_target})
get_target_property(include_dirs ${candidate_target} INTERFACE_INCLUDE_DIRECTORIES)
if(include_dirs AND NOT include_dirs MATCHES "-NOTFOUND$")
set_target_properties(
YDB-CPP-SDK::${component}
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}"
)
endif()
return()
endif()
endforeach()

message(
FATAL_ERROR
"Could not map ydb-cpp-sdk component '${component}' to required target "
"'YDB-CPP-SDK::${component}'. The external ydb-cpp-sdk package was found, "
"but it does not provide a recognized target for this component."
)
endfunction()

function(_userver_ydb_populate_include_dirs)
if(ydb-cpp-sdk_INCLUDE_DIRS)
return()
endif()

foreach(component IN LISTS _USERVER_YDB_COMPONENTS)
get_target_property(include_dirs YDB-CPP-SDK::${component} INTERFACE_INCLUDE_DIRECTORIES)
if(include_dirs AND NOT include_dirs MATCHES "-NOTFOUND$")
set(ydb-cpp-sdk_INCLUDE_DIRS
${include_dirs}
PARENT_SCOPE
)
return()
endif()
endforeach()
endfunction()

if(NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
if(NOT TARGET googleapis::google_api_annotations_cc_proto)
find_package(googleapis QUIET CONFIG)
endif()

if(NOT TARGET googleapis::google_api_annotations_cc_proto)
if(TARGET userver-api-common-protos)
add_library(googleapis::google_api_annotations_cc_proto INTERFACE IMPORTED)
target_link_libraries(googleapis::google_api_annotations_cc_proto INTERFACE userver-api-common-protos)
elseif(USERVER_DOWNLOAD_PACKAGES)
include(SetupGoogleProtoApis)
if(TARGET userver-api-common-protos)
add_library(googleapis::google_api_annotations_cc_proto INTERFACE IMPORTED)
target_link_libraries(googleapis::google_api_annotations_cc_proto INTERFACE userver-api-common-protos)
endif()
else()
find_package(googleapis REQUIRED CONFIG)
endif()
endif()

if(USERVER_DOWNLOAD_PACKAGE_YDBCPPSDK)
find_package(ydb-cpp-sdk QUIET CONFIG)
else()
find_package(ydb-cpp-sdk REQUIRED CONFIG)
endif()

if(ydb-cpp-sdk_FOUND)
foreach(component IN LISTS _USERVER_YDB_COMPONENTS)
_userver_ydb_make_component_alias(${component})
endforeach()

_userver_ydb_populate_include_dirs()
return()
endif()
endif()

include(DownloadUsingCPM)
include(SetupBrotli)

Expand Down
16 changes: 13 additions & 3 deletions cmake/install/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ if(NOT userver_FIND_COMPONENTS)
return()
endif()

include(CMakeFindDependencyMacro)

set(USERVER_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})

if("ydb" IN_LIST userver_FIND_COMPONENTS)
set(USERVER_YDB_CONFIG_PHASE deps)
include("${USERVER_CMAKE_DIR}/userver-ydb-config.cmake")
unset(USERVER_YDB_CONFIG_PHASE)
if(NOT _USERVER_YDB_DEPS_LOADED)
return()
endif()
endif()

if(CMAKE_BUILD_TYPE MATCHES "^.*Rel.*$") # same as in UserverSetupEnvironment
include("${CMAKE_CURRENT_LIST_DIR}/release/userver-targets.cmake")
else()
Expand All @@ -32,10 +45,7 @@ endif()

message(STATUS "Userver components: ${userver_FIND_COMPONENTS}")

include(CMakeFindDependencyMacro)

set(USERVER_DOWNLOAD_PACKAGES OFF)
set(USERVER_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
set(USERVER_TESTSUITE_DIR "${USERVER_CMAKE_DIR}/testsuite")
set(USERVER_CONAN @USERVER_CONAN@)
set(USERVER_IMPL_ORIGINAL_CXX_STANDARD @CMAKE_CXX_STANDARD@)
Expand Down
15 changes: 11 additions & 4 deletions cmake/install/userver-ydb-config.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# TODO: not working yet
include_guard(GLOBAL)
if(USERVER_YDB_CONFIG_PHASE STREQUAL "deps")
if(_USERVER_YDB_DEPS_LOADED)
return()
endif()

find_dependency(googleapis CONFIG)
find_dependency(ydb-cpp-sdk CONFIG)

set(_USERVER_YDB_DEPS_LOADED TRUE)
return()
endif()

if(userver_ydb_FOUND)
return()
endif()

find_package(userver REQUIRED COMPONENTS core)

# include("${USERVER_CMAKE_DIR}/ydb-cpp-sdk.cmake")

include("${USERVER_CMAKE_DIR}/UserverSql.cmake")

set(userver_ydb_FOUND TRUE)
2 changes: 1 addition & 1 deletion ydb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ userver_module(

_userver_directory_install(
COMPONENT ydb
FILES "${USERVER_ROOT_DIR}/cmake/SetupYdbCPPSDK.cmake"
FILES "${USERVER_ROOT_DIR}/cmake/SetupYdbCppSDK.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
)

Expand Down
Loading