From d4606bb5cb62cfce4e7d11ddb2eaae03728d48fb Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sun, 9 Jun 2024 16:04:32 +0200 Subject: [PATCH] build: use the system provided c-ares if found e.g. buildroot has logic to build c-ares, so if pkg_check_modules can find a suitable version, then use that one if -DFLB_PREFER_SYSTEM_LIB_CARES=Yes. Note that the CheckIncludeFiles include for wasm is added, since that was done by c-ares otherwise. Signed-off-by: Thomas Devoogdt --- CMakeLists.txt | 31 ++++++++++++++++++++++--------- src/CMakeLists.txt | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7897ebb1f12..e179b7f7316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ option(FLB_RUN_LDCONFIG "Enable execution of ldconfig after installation" No) # Prefer system libraries if available option(FLB_PREFER_SYSTEM_LIBS "Prefer system libraries" No) 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_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}) @@ -459,16 +460,27 @@ else() endif() # C-Ares (DNS library) -FLB_OPTION(CARES_STATIC ON) -FLB_OPTION(CARES_SHARED OFF) -FLB_OPTION(CARES_INSTALL OFF) -FLB_OPTION(CARES_BUILD_TESTS OFF) -FLB_OPTION(CARES_BUILD_TOOLS OFF) -if (FLB_SYSTEM_MACOS) - # macOS SDK always has . - FLB_DEFINITION(CARES_HAVE_ARPA_NAMESER_H) +if(FLB_PREFER_SYSTEM_LIB_CARES) + find_package(PkgConfig) + pkg_check_modules(CARES libcares>=1.0.0) +endif() +if(CARES_FOUND) + include_directories(${CARES_INCLUDE_DIRS}) + link_directories(${CARES_LIBRARY_DIRS}) +else() + FLB_OPTION(CARES_STATIC ON) + FLB_OPTION(CARES_SHARED OFF) + FLB_OPTION(CARES_INSTALL OFF) + FLB_OPTION(CARES_BUILD_TESTS OFF) + FLB_OPTION(CARES_BUILD_TOOLS OFF) + if (FLB_SYSTEM_MACOS) + # macOS SDK always has . + FLB_DEFINITION(CARES_HAVE_ARPA_NAMESER_H) + endif() + add_subdirectory(${FLB_PATH_LIB_CARES})# EXCLUDE_FROM_ALL) + + set(CARES_LIBRARIES "c-ares") endif() -add_subdirectory(${FLB_PATH_LIB_CARES})# EXCLUDE_FROM_ALL) # Chunk I/O FLB_OPTION(CIO_LIB_STATIC ON) @@ -538,6 +550,7 @@ if(FLB_WASM) _Atomic int a; return 0; }" FLB_HAVE_STDATOMIC_H) + include(CheckIncludeFiles) check_include_files(stdatomic.h FLB_HAVE_STDATOMIC_H) if (FLB_HAVE_STDATOMIC_H) enable_language (ASM) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index acf3027eb3b..7cb4b77bbe6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -378,7 +378,7 @@ set(FLB_DEPS ${FLB_PLUGINS} ${FLB_PROXY_PLUGINS} ${extra_libs} - c-ares + ${CARES_LIBRARIES} snappy-c lwrb ${NGHTTP2_LIBRARIES}