From 70c5a0ed5a9662d5beae5dc4eee22c94bcdc4629 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sat, 15 Jun 2024 17:47:31 +0200 Subject: [PATCH] build: use the system provided librdkafka if found e.g. buildroot has logic to build librdkafka, so if pkg_check_modules can find a suitable version, then use that one if -DFLB_PREFER_SYSTEM_LIB_KAFKA=Yes. Signed-off-by: Thomas Devoogdt --- CMakeLists.txt | 22 +++++++++++----------- cmake/headers.cmake | 4 ---- cmake/kafka.cmake | 15 +++++++++++++++ plugins/in_kafka/CMakeLists.txt | 3 ++- plugins/out_kafka/CMakeLists.txt | 3 ++- 5 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 cmake/kafka.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e179b7f7316..2f7e649e0de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,7 @@ option(FLB_PREFER_SYSTEM_LIBS "Prefer system libraries" option(FLB_PREFER_SYSTEM_LIB_BACKTRACE "Prefer the libbacktrace system library" ${FLB_PREFER_SYSTEM_LIBS}) option(FLB_PREFER_SYSTEM_LIB_CARES "Prefer the libcares system library" ${FLB_PREFER_SYSTEM_LIBS}) option(FLB_PREFER_SYSTEM_LIB_JEMALLOC "Prefer the libjemalloc system library" ${FLB_PREFER_SYSTEM_LIBS}) +option(FLB_PREFER_SYSTEM_LIB_KAFKA "Prefer the libkafka system library" ${FLB_PREFER_SYSTEM_LIBS}) option(FLB_PREFER_SYSTEM_LIB_LUAJIT "Prefer the libluajit system library" ${FLB_PREFER_SYSTEM_LIBS}) option(FLB_PREFER_SYSTEM_LIB_NGHTTP2 "Prefer the libnghttp2 system library" ${FLB_PREFER_SYSTEM_LIBS}) @@ -923,17 +924,16 @@ if(FLB_BACKTRACE) endif() if(FLB_IN_KAFKA OR FLB_OUT_KAFKA) - FLB_OPTION(RDKAFKA_BUILD_STATIC On) - FLB_OPTION(RDKAFKA_BUILD_EXAMPLES Off) - FLB_OPTION(RDKAFKA_BUILD_TESTS Off) - FLB_OPTION(ENABLE_LZ4_EXT Off) - - # disable Curl - if (FLB_SYSTEM_MACOS) - FLB_OPTION(WITH_CURL Off) - endif() - - add_subdirectory(${FLB_PATH_LIB_RDKAFKA} EXCLUDE_FROM_ALL) + if(FLB_PREFER_SYSTEM_LIB_KAFKA) + find_package(PkgConfig) + pkg_check_modules(KAFKA rdkafka>=2.3.0) + endif() + if(KAFKA_FOUND) + include_directories(${KAFKA_INCLUDE_DIRS}) + link_directories(${KAFKA_LIBRARY_DIRS}) + else() + include(cmake/kafka.cmake) + endif() endif() # Onigmo (Regex Engine) options diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 9f9927cd8b0..fa5fda3b7f7 100755 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -44,10 +44,6 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/lib/monkey/include/monkey/ ) -if(FLB_IN_KAFKA OR FLB_OUT_KAFKA) - include_directories(${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RDKAFKA}/src/) -endif() - if(FLB_UTF8_ENCODER) include_directories(${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_TUTF8E}/include) endif() diff --git a/cmake/kafka.cmake b/cmake/kafka.cmake new file mode 100644 index 00000000000..84caf6f29e7 --- /dev/null +++ b/cmake/kafka.cmake @@ -0,0 +1,15 @@ +FLB_OPTION(RDKAFKA_BUILD_STATIC On) +FLB_OPTION(RDKAFKA_BUILD_EXAMPLES Off) +FLB_OPTION(RDKAFKA_BUILD_TESTS Off) +FLB_OPTION(ENABLE_LZ4_EXT Off) + +# disable Curl +if (FLB_SYSTEM_MACOS) + FLB_OPTION(WITH_CURL Off) +endif() + +include_directories(${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RDKAFKA}/src/) + +add_subdirectory(${FLB_PATH_LIB_RDKAFKA} EXCLUDE_FROM_ALL) + +set(KAFKA_LIBRARIES "rdkafka") diff --git a/plugins/in_kafka/CMakeLists.txt b/plugins/in_kafka/CMakeLists.txt index 696e263fab7..ede0831f9f8 100644 --- a/plugins/in_kafka/CMakeLists.txt +++ b/plugins/in_kafka/CMakeLists.txt @@ -2,5 +2,6 @@ set(src in_kafka.c ) -FLB_PLUGIN(in_kafka "${src}" "rdkafka") +FLB_PLUGIN(in_kafka "${src}" ${KAFKA_LIBRARIES}) +target_include_directories(flb-plugin-in_kafka PUBLIC ${KAFKA_INCLUDEDIR}/librdkafka) target_link_libraries(flb-plugin-in_kafka -lpthread) diff --git a/plugins/out_kafka/CMakeLists.txt b/plugins/out_kafka/CMakeLists.txt index 526910d49a0..01c96529b1c 100644 --- a/plugins/out_kafka/CMakeLists.txt +++ b/plugins/out_kafka/CMakeLists.txt @@ -4,5 +4,6 @@ set(src kafka_topic.c kafka.c) -FLB_PLUGIN(out_kafka "${src}" "rdkafka") +FLB_PLUGIN(out_kafka "${src}" ${KAFKA_LIBRARIES}) +target_include_directories(flb-plugin-out_kafka PUBLIC ${KAFKA_INCLUDEDIR}/librdkafka) target_link_libraries(flb-plugin-out_kafka -lpthread)