From 1b67b2d33e113ed1987df9c10ceb77f8abecb7f0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 12:48:36 +0100 Subject: [PATCH] cmake: improve Spdylay detection Auto-detect spdylay availability using CMake, making pkg-config completely optional. --- CMakeLists.txt | 42 ++++------------------------------------- cmake/FindSpdylay.cmake | 40 +++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 4 ++-- 3 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 cmake/FindSpdylay.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 123902a0..dc6a0b1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,13 +71,11 @@ find_package(LibXml2 QUIET) set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) find_package(Jemalloc QUIET) set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND}) -find_package(SPDYLAY QUIET) +find_package(Spdylay 1.3.2 QUIET) set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND}) include(CMakeOptions.txt) -find_package(PkgConfig 0.20) - if(ENABLE_LIB_ONLY) set(ENABLE_APP OFF) set(ENABLE_HPACK_TOOLS OFF) @@ -166,32 +164,6 @@ if(CUNIT_FOUND) else() set(HAVE_CUNIT 0) endif() -# # If pkg-config does not find cunit, check it using AC_CHECK_LIB. We -# # do this because Debian (Ubuntu) lacks pkg-config file for cunit. -# if test "x${have_cunit}" = "xno"; then -# AC_MSG_WARN([${CUNIT_PKG_ERRORS}]) -# AC_CHECK_LIB([cunit], [CU_initialize_registry], -# [have_cunit=yes], [have_cunit=no]) -# if test "x${have_cunit}" = "xyes"; then -# CUNIT_LIBS="-lcunit" -# CUNIT_CFLAGS="" -# AC_SUBST([CUNIT_LIBS]) -# AC_SUBST([CUNIT_CFLAGS]) -# fi -# fi -# if test "x${have_cunit}" = "xyes"; then -# # cunit in Mac OS X requires ncurses. Note that in Mac OS X, test -# # program can be built without -lncurses, but it emits runtime -# # error. -# case "${build}" in -# *-apple-darwin*) -# CUNIT_LIBS="$CUNIT_LIBS -lncurses" -# AC_SUBST([CUNIT_LIBS]) -# ;; -# esac -# fi -# -# AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) if(ENABLE_APP) find_package(OpenSSL 1.0.1 REQUIRED) @@ -258,14 +230,8 @@ endif() # spdylay (for src/nghttpx and src/h2load) if(WITH_SPDYLAY) - pkg_check_modules(LIBSPDYLAY libspdylay>=1.3.2) - if(LIBSPDYLAY_FOUND) - set(HAVE_SPDYLAY 1) - else() - set(HAVE_SPDYLAY 0) - message(STATUS "The SPDY support in nghttpx and h2load will be disabled.") - endif() - # XXX fail if WITH_SPDYLAY=ON + find_package(Spdylay 1.3.2 REQUIRED) + set(HAVE_SPDYLAY 1) else() set(HAVE_SPDYLAY 0) endif() @@ -549,7 +515,7 @@ message(STATUS "summary of build options: Libxml2: ${HAVE_LIBXML2} (LIBS='${LIBXML2_LIBRARIES}') Libev: ${HAVE_LIBEV} (LIBS='${LIBEV_LIBRARIES}') Libevent(SSL): ${HAVE_LIBEVENT_OPENSSL} (LIBS='${LIBEVENT_OPENSSL_LIBRARIES}') - Spdylay: ${HAVE_SPDYLAY} (LIBS='${LIBSPDYLAY_LIBRARIES}') + Spdylay: ${HAVE_SPDYLAY} (LIBS='${SPDYLAY_LIBRARIES}') Jansson: ${HAVE_JANSSON} (LIBS='${JANSSON_LIBRARIES}') Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBRARIES}') Zlib: ${HAVE_ZLIB} (LIBS='${ZLIB_LIBRARIES}') diff --git a/cmake/FindSpdylay.cmake b/cmake/FindSpdylay.cmake new file mode 100644 index 00000000..6a76d28e --- /dev/null +++ b/cmake/FindSpdylay.cmake @@ -0,0 +1,40 @@ +# - Try to find spdylay +# Once done this will define +# SPDYLAY_FOUND - System has spdylay +# SPDYLAY_INCLUDE_DIRS - The spdylay include directories +# SPDYLAY_LIBRARIES - The libraries needed to use spdylay + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_SPDYLAY QUIET libspdylay) + +find_path(SPDYLAY_INCLUDE_DIR + NAMES spdylay/spdylay.h + HINTS ${PC_SPDYLAY_INCLUDE_DIRS} +) +find_library(SPDYLAY_LIBRARY + NAMES spdylay + HINTS ${PC_SPDYLAY_LIBRARY_DIRS} +) + +if(SPDYLAY_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+SPDYLAY_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${SPDYLAY_INCLUDE_DIR}/spdylay/spdylayver.h" + SPDYLAY_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + SPDYLAY_VERSION "${SPDYLAY_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set SPDYLAY_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(Spdylay REQUIRED_VARS + SPDYLAY_LIBRARY SPDYLAY_INCLUDE_DIR + VERSION_VAR SPDYLAY_VERSION) + +if(SPDYLAY_FOUND) + set(SPDYLAY_LIBRARIES ${SPDYLAY_LIBRARY}) + set(SPDYLAY_INCLUDE_DIRS ${SPDYLAY_INCLUDE_DIR}) +endif() + +mark_as_advanced(SPDYLAY_INCLUDE_DIR SPDYLAY_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47d8124a..08c89b0e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories( "${CMAKE_SOURCE_DIR}/third-party" ${JEMALLOC_INCLUDE_DIRS} - ${LIBSPDYLAY_INCLUDE_DIRS} + ${SPDYLAY_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${LIBEV_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} @@ -28,7 +28,7 @@ include_directories( link_libraries( nghttp2 ${JEMALLOC_LIBRARIES} - ${LIBSPDYLAY_LIBRARIES} + ${SPDYLAY_LIBRARIES} ${LIBXML2_LIBRARIES} ${LIBEV_LIBRARIES} ${OPENSSL_LIBRARIES}