Skip to content

Commit

Permalink
cmake: improve Spdylay detection
Browse files Browse the repository at this point in the history
Auto-detect spdylay availability using CMake, making pkg-config
completely optional.
  • Loading branch information
Lekensteyn committed Feb 16, 2016
1 parent 9bc6dc7 commit 1b67b2d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
42 changes: 4 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}')
Expand Down
40 changes: 40 additions & 0 deletions cmake/FindSpdylay.cmake
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -28,7 +28,7 @@ include_directories(
link_libraries(
nghttp2
${JEMALLOC_LIBRARIES}
${LIBSPDYLAY_LIBRARIES}
${SPDYLAY_LIBRARIES}
${LIBXML2_LIBRARIES}
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
Expand Down

0 comments on commit 1b67b2d

Please sign in to comment.