From 95ccc2d35c2e0baf0542333c88c4220e17e2a128 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_LIBS=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 | 30 +++++++++++++++++++++--------- src/CMakeLists.txt | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f88aa6ba05b..2f7369c6845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -581,16 +581,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_LIBS) + 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) @@ -660,6 +671,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 6b81f517175..d50d33be706 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -371,7 +371,7 @@ set(FLB_DEPS ${FLB_PLUGINS} ${FLB_PROXY_PLUGINS} ${extra_libs} - c-ares + ${CARES_LIBRARIES} snappy-c lwrb ${NGHTTP2_LIBRARIES}