From d66d34f9b95537af0c9120f0de1c10704c65998d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 10 Dec 2016 22:16:35 +0900 Subject: [PATCH] Add libc-ares detection to cmake --- CMakeLists.txt | 10 ++++++++++ Makefile.am | 3 ++- cmake/FindLibcares.cmake | 40 ++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 5 +++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 cmake/FindLibcares.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b3bfcfe..1ad8b561 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ find_package(PythonInterp) # Auto-detection of features that can be toggled find_package(OpenSSL 1.0.1) find_package(Libev 4.11) +find_package(Libcares 1.7.5) find_package(ZLIB 1.2.3) if(OPENSSL_FOUND AND LIBEV_FOUND AND ZLIB_FOUND) set(ENABLE_APP_DEFAULT ON) @@ -207,6 +208,14 @@ if(LIBEVENT_FOUND) # Must both link the core and openssl libraries. set(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES}) endif() +# libc-ares (for src) +set(HAVE_LIBCARES ${LIBCARES_FOUND}) +if(LIBCARES_FOUND) + set(LIBCARES_INCLUDE_DIRS ${LIBCARES_INCLUDE_DIR}) +else() + set(LIBCARES_INCLUDE_DIRS "") + set(LIBCARES_LIBRARIES "") +endif() # jansson (for src/nghttp, src/deflatehd and src/inflatehd) set(HAVE_JANSSON ${JANSSON_FOUND}) # libxml2 (for src/nghttp) @@ -499,6 +508,7 @@ message(STATUS "summary of build options: OpenSSL: ${HAVE_OPENSSL} (LIBS='${OPENSSL_LIBRARIES}') Libxml2: ${HAVE_LIBXML2} (LIBS='${LIBXML2_LIBRARIES}') Libev: ${HAVE_LIBEV} (LIBS='${LIBEV_LIBRARIES}') + Libc-ares: ${HAVE_LIBCARES} (LIBS='${LIBCARES_LIBRARIES}') Libevent(SSL): ${HAVE_LIBEVENT_OPENSSL} (LIBS='${LIBEVENT_OPENSSL_LIBRARIES}') Spdylay: ${HAVE_SPDYLAY} (LIBS='${SPDYLAY_LIBRARIES}') Jansson: ${HAVE_JANSSON} (LIBS='${JANSSON_LIBRARIES}') diff --git a/Makefile.am b/Makefile.am index a66561f3..af0e1858 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,8 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-make \ cmake/Version.cmake \ cmake/FindCython.cmake \ cmake/FindLibevent.cmake \ - cmake/FindJansson.cmake + cmake/FindJansson.cmake \ + cmake/FindLibcares.cmake .PHONY: clang-format diff --git a/cmake/FindLibcares.cmake b/cmake/FindLibcares.cmake new file mode 100644 index 00000000..1fe56ce7 --- /dev/null +++ b/cmake/FindLibcares.cmake @@ -0,0 +1,40 @@ +# - Try to find libcares +# Once done this will define +# LIBCARES_FOUND - System has libcares +# LIBCARES_INCLUDE_DIRS - The libcares include directories +# LIBCARES_LIBRARIES - The libraries needed to use libcares + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBCARES QUIET libcares) + +find_path(LIBCARES_INCLUDE_DIR + NAMES ares.h + HINTS ${PC_LIBCARES_INCLUDE_DIRS} +) +find_library(LIBCARES_LIBRARY + NAMES cares + HINTS ${PC_LIBCARES_LIBRARY_DIRS} +) + +if(LIBCARES_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+ARES_VERSION_STR[ \t]+\"([^\"]+)\".*") + file(STRINGS "${LIBCARES_INCLUDE_DIR}/ares_version.h" + LIBCARES_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + LIBCARES_VERSION "${LIBCARES_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBCARES_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(Libcares REQUIRED_VARS + LIBCARES_LIBRARY LIBCARES_INCLUDE_DIR + VERSION_VAR LIBCARES_VERSION) + +if(LIBCARES_FOUND) + set(LIBCARES_LIBRARIES ${LIBCARES_LIBRARY}) + set(LIBCARES_INCLUDE_DIRS ${LIBCARES_INCLUDE_DIR}) +endif() + +mark_as_advanced(LIBCARES_INCLUDE_DIR LIBCARES_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 92b2ab40..0648f6f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ include_directories( ${LIBXML2_INCLUDE_DIRS} ${LIBEV_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} + ${LIBCARES_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ) @@ -31,6 +32,7 @@ link_libraries( ${LIBXML2_LIBRARIES} ${LIBEV_LIBRARIES} ${OPENSSL_LIBRARIES} + ${LIBCARES_LIBRARIES} ${JANSSON_LIBRARIES} ${ZLIB_LIBRARIES} ${APP_LIBRARIES} @@ -112,6 +114,9 @@ if(ENABLE_APP) shrpx_api_downstream_connection.cc shrpx_health_monitor_downstream_connection.cc shrpx_exec.cc + shrpx_dns_resolver.cc + shrpx_dual_dns_resolver.cc + shrpx_dns_tracker.cc xsi_strerror.c ) if(HAVE_SPDYLAY)