Skip to content

Commit

Permalink
build: use the system provided librdkafka if found
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ThomasDevoogdt committed Jun 15, 2024
1 parent d4606bb commit 70c5a0e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions cmake/kafka.cmake
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion plugins/in_kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion plugins/out_kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 70c5a0e

Please sign in to comment.