From 49be8371f5c781c6fc33b14f84c02a55c70731a8 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sat, 9 Nov 2024 19:52:39 +0100 Subject: [PATCH] build: use the system provided msgpack if found Signed-off-by: Thomas Devoogdt --- CMakeLists.txt | 16 +++++++++++----- cmake/headers.cmake | 1 - cmake/msgpack.cmake | 10 ++++++++++ plugins/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 cmake/msgpack.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fedabdaf66..42192a174c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,7 @@ option(FLB_PREFER_SYSTEM_LIB_CARES "Prefer the libcares system library" 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_MSGPACK "Prefer the libmsgpack system library" ${FLB_PREFER_SYSTEM_LIBS}) option(FLB_PREFER_SYSTEM_LIB_NGHTTP2 "Prefer the libnghttp2 system library" ${FLB_PREFER_SYSTEM_LIBS}) # Enable all features @@ -450,11 +451,16 @@ FLB_OPTION(FLUENT_PROTO_METRICS ON) add_subdirectory(${FLB_PATH_LIB_FLUENT_OTEL} EXCLUDE_FROM_ALL) # MsgPack options -option(MSGPACK_ENABLE_CXX OFF) -option(MSGPACK_ENABLE_SHARED OFF) -option(MSGPACK_BUILD_TESTS OFF) -option(MSGPACK_BUILD_EXAMPLES OFF) -add_subdirectory(${FLB_PATH_LIB_MSGPACK} EXCLUDE_FROM_ALL) +if(FLB_PREFER_SYSTEM_LIB_MSGPACK) + find_package(PkgConfig) + pkg_check_modules(MSGPACK msgpack>=4.0.0) +endif() +if(MSGPACK_FOUND) + include_directories(${MSGPACK_INCLUDE_DIRS}) + link_directories(${MSGPACK_LIBRARY_DIRS}) +else() + include(cmake/msgpack.cmake) +endif() # MPack add_definitions(-DMPACK_EXTENSIONS=1) diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 5280d8e8bbe..e58251e4a75 100755 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -16,7 +16,6 @@ include_directories( ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CO} ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RBTREE} - ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MSGPACK}/include # Chunk I/O generate headers also in the binary path ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CHUNKIO}/include diff --git a/cmake/msgpack.cmake b/cmake/msgpack.cmake new file mode 100644 index 00000000000..6211e31f302 --- /dev/null +++ b/cmake/msgpack.cmake @@ -0,0 +1,10 @@ +# msgpack cmake +option(MSGPACK_ENABLE_CXX OFF) +option(MSGPACK_ENABLE_SHARED OFF) +option(MSGPACK_BUILD_TESTS OFF) +option(MSGPACK_BUILD_EXAMPLES OFF) +include_directories( + ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MSGPACK}/include +) +add_subdirectory(${FLB_PATH_LIB_MSGPACK} EXCLUDE_FROM_ALL) +set(MSGPACK_LIBRARIES "msgpack-c-static") diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 200a09b449c..8b67f40f41f 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -182,7 +182,7 @@ endmacro() macro(FLB_PLUGIN name src deps) add_library(flb-plugin-${name} STATIC ${src}) add_sanitizers(flb-plugin-${name}) - target_link_libraries(flb-plugin-${name} fluent-bit-static msgpack-c-static ${deps}) + target_link_libraries(flb-plugin-${name} fluent-bit-static ${MSGPACK_LIBRARIES} ${deps}) endmacro() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2dcdd9a4ee..3a9f3ce2f21 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -377,7 +377,7 @@ set(FLB_DEPS ctraces-static mk_core jsmn - msgpack-c-static + ${MSGPACK_LIBRARIES} mpack-static chunkio-static miniz