Skip to content

Commit

Permalink
Consistent Kafka build
Browse files Browse the repository at this point in the history
  • Loading branch information
fdr400 committed Jan 7, 2025
1 parent 7104b98 commit 1956aea
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 28 deletions.
3 changes: 1 addition & 2 deletions cmake/SetupMongoDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ include_guard(GLOBAL)
option(USERVER_MONGODB_USE_CMAKE_CONFIG "Use mongoc cmake configuration" ON)

if (USERVER_MONGODB_USE_CMAKE_CONFIG)
find_package(bson-1.0 QUIET CONFIG)
find_package(mongoc-1.0 QUIET CONFIG)
if(bson-1.0_FOUND AND mongoc-1.0_FOUND)
if(mongoc-1.0_FOUND)
message(STATUS "Mongoc: using config version")
add_library(bson ALIAS mongo::bson_static)
add_library(mongoc ALIAS mongo::mongoc_static)
Expand Down
1 change: 1 addition & 0 deletions cmake/SetupRdKafka.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ find_package(CURL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(libzstd REQUIRED)
find_package(lz4 REQUIRED)
find_package(SASL2 REQUIRED)

if(NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
if(USERVER_DOWNLOAD_PACKAGE_KAFKA)
Expand Down
1 change: 1 addition & 0 deletions cmake/install/userver-kafka-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if(USERVER_CONAN)
find_package(RdKafka REQUIRED CONFIG)
else()
include("${USERVER_CMAKE_DIR}/modules/Findlz4.cmake")
include("${USERVER_CMAKE_DIR}/modules/FindSASL2.cmake")
include("${USERVER_CMAKE_DIR}/modules/FindRdKafka.cmake")
endif()

Expand Down
26 changes: 26 additions & 0 deletions cmake/modules/FindSASL2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if(TARGET SASL2::SASL2)
# Maybe already found by mongoc-1.0 config
return()
endif()

_userver_module_begin(
NAME SASL2
DEBIAN_NAMES libsasl2-dev
FORMULA_NAMES cyrus-sasl
PKG_CONFIG_NAMES libsasl2
)

_userver_module_find_include(
NAMES sasl/sasl.h
)

_userver_module_find_library(
NAMES sasl2
PATHS
/usr/lib/x86_64-linux-gnu
/opt/homebrew/lib
)

_userver_module_end()

add_library(SASL2::SASL2 ALIAS SASL2)
5 changes: 5 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class UserverConan(ConanFile):
'grpc/*:ruby_plugin': False,
'grpc/*:csharp_plugin': False,
'grpc/*:objective_c_plugin': False,
'librdkafka/*:ssl': True,
'librdkafka/*:curl': True,
'librdkafka/*:sasl': True,
'librdkafka/*:zlib': True,
'librdkafka/*:zstd': True,
}

def set_version(self):
Expand Down
26 changes: 9 additions & 17 deletions kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
project(userver-kafka CXX)

if(USERVER_CONAN)
find_package(OpenSSL COMPONENTS SSL Crypto REQUIRED CONFIG)
find_package(CURL REQUIRED CONFIG)
find_package(ZLIB REQUIRED CONFIG)

find_package(zstd REQUIRED CONFIG)
# According to https://conan.io/center/recipes/zstd should be
# zstd::libzstd_static, but it does not work that way
if (TARGET zstd::libzstd_static)
add_library(libzstd ALIAS zstd::libzstd_static)
else()
add_library(libzstd ALIAS zstd::libzstd_shared)
endif()

find_package(RdKafka REQUIRED CONFIG)
set_target_properties(RdKafka::rdkafka PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(RdKafka ALIAS RdKafka::rdkafka)

find_package(cyrus-sasl REQUIRED CONFIG)
add_library(sasl2 ALIAS cyrus-sasl::cyrus-sasl)
else()
include(SetupRdKafka)
target_link_libraries(RdKafka
INTERFACE
ZLIB::ZLIB libzstd
lz4::lz4 CURL::libcurl
OpenSSL::SSL OpenSSL::Crypto
SASL2::SASL2
)
endif()

userver_module(kafka
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES_PRIVATE RdKafka sasl2 ZLIB::ZLIB libzstd lz4::lz4 CURL::libcurl OpenSSL::SSL OpenSSL::Crypto
LINK_LIBRARIES_PRIVATE RdKafka
DBTEST_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests"
DBTEST_LINK_LIBRARIES userver::kafka-utest
DBTEST_DATABASES kafka
Expand All @@ -51,6 +42,7 @@ _userver_directory_install(COMPONENT kafka
FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindRdKafka.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlz4.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindSASL2.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
)

Expand Down
2 changes: 1 addition & 1 deletion rabbitmq/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(userver-rabbitmq CXX)

if (USERVER_CONAN)
find_package(amqpcpp)
find_package(amqpcpp REQUIRED CONFIG)
else()
include(SetupAmqpCPP)
endif()
Expand Down
14 changes: 7 additions & 7 deletions universal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ endif()
find_package_required(OpenSSL "libssl-dev")

if (USERVER_CONAN)
find_package(cryptopp REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(fmt REQUIRED)
find_package(cctz REQUIRED)
find_package(zstd REQUIRED)
find_package(cryptopp REQUIRED CONFIG)
find_package(yaml-cpp REQUIRED CONFIG)
find_package(fmt REQUIRED CONFIG)
find_package(cctz REQUIRED CONFIG)
find_package(zstd REQUIRED CONFIG)

find_package(RapidJSON REQUIRED)
find_package(RapidJSON REQUIRED CONFIG)
target_compile_definitions(rapidjson INTERFACE RAPIDJSON_HAS_STDSTRING)
else()
include(SetupCryptoPP)
Expand Down Expand Up @@ -328,7 +328,7 @@ if (USERVER_FEATURE_UTEST)

add_library(${PROJECT_NAME}-internal-ubench INTERFACE)
if (USERVER_CONAN)
find_package(benchmark REQUIRED)
find_package(benchmark REQUIRED CONFIG)
else()
include(SetupGBench)
endif()
Expand Down
2 changes: 1 addition & 1 deletion universal/utest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(userver-universal-utest CXX)

if(USERVER_CONAN)
find_package(GTest REQUIRED)
find_package(GTest REQUIRED CONFIG)
else()
include(SetupGTest)
endif()
Expand Down

0 comments on commit 1956aea

Please sign in to comment.