From 65d33c553c6bf645315cd70924719b83bb6e5008 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 13:46:59 +0100 Subject: [PATCH 01/59] CMake WIP Not working: - option(... check) - not finished everything (see XXX and FIXME) - still halway converting --- CMakeLists.txt | 711 ++++++++++++++++++++++++++++++++++++++++++++ cmake/Version.cmake | 11 + cmakeconfig.h.in | 12 + 3 files changed, 734 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/Version.cmake create mode 100644 cmakeconfig.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..59b2ec97 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,711 @@ +# nghttp2 - HTTP/2 C Library +# +# Copyright (c) 2012, 2013, 2014, 2015 Tatsuhiro Tsujikawa +# Copyright (c) 2016 Peter Wu +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +cmake_minimum_required(VERSION 3.0) +# XXX using 1.7.90 instead of 1.8.0-DEV +project(nghttp2 VERSION 1.7.90) + +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +include(Version) + +set(PACKAGE_VERSION "${PROJECT_VERSION}") +HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) + +option(ENABLE_WERROR "Turn on compile time warnings") +option(ENABLE_DEBUG "Turn on debug output") +option(ENABLE_THREADS "Turn on threading in apps" ON) +option(ENABLE_APP "Build applications (nghttp, nghttpd, nghttpx and h2load)" + check) +option(ENABLE_HPACK_TOOLS "Build HPACK tools" check) +option(ENABLE_ASIO_LIB "Build C++ libnghttp2_asio library") +option(ENABLE_EXAMPLES "Build examples" check) +option(ENABLE_PYTHON_BINDINGS "Build Python bindings" check) +option(ENABLE_FAILMALLOC "Build failmalloc test program" ON) +option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0 -DENABLE_PYTHON_BINDINGS=0") + +option(WITH_LIBXML2 "Use libxml2" check) +option(WITH_JEMALLOC "Use jemalloc" check) +option(WITH_SPDYLAY "Use spdylay" check) +option(WITH_MRUBY "Use mruby") +option(WITH_NEVERBLEED "Use neverbleed") +set(CYTHON_PATH "" CACHE PATH "Use cython in given path") +set(CYTHON "" CACHE FILEPATH "The Cython executable") + +find_package(PkgConfig 0.20) +# XXX fail only when "ON" instead of "CHECK"? +if(ENABLE_PYTHON_BINDINGS) + find_package(PythonInterp REQUIRED) +endif() +# AM_PATH_PYTHON([2.7],, [:]) + +if(ENABLE_LIB_ONLY) + set(ENABLE_APP OFF) + set(ENABLE_HPACK_TOOLS OFF) + set(ENABLE_EXAMPLES OFF) + set(ENABLE_PYTHON_BINDINGS OFF) +endif() + +if(ENABLE_PYTHON_BINDINGS) + find_package(PythonLibs 2.7 REQUIRED) + # XXX find cython +endif() +# if [test "x$request_python_bindings" != "xno"]; then +# AX_PYTHON_DEVEL([>= '2.7']) +# fi +# +# if test "x${cython_path}" = "x"; then +# AC_CHECK_PROGS([CYTHON], [cython.py cython]) +# else +# CYTHON=${cython_path} +# AC_SUBST([CYTHON]) +# fi + +# +# If we're running GCC or clang define _U_ to be "__attribute__((unused))" +# so we can use _U_ to flag unused function parameters and not get warnings +# about them. Otherwise, define _U_ to be an empty string so that _U_ used +# to flag an unused function parameters will compile with other compilers. +# +# XXX - similar hints for other compilers? +# +if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") + add_definitions( + "-D_U_=__attribute__((unused))" + "-DNGHTTP2_NORETURN=__attribute__((noreturn))" + ) +else() + add_definitions(-D_U_ -DNGHTTP2_NORETURN) +endif() + +include(CheckCXXCompilerFlag) +foreach(_cxx1x_flag "-std=gnu++11" "-std=gnu++0x") + CHECK_CXX_COMPILER_FLAG(${_cxx1x_flag} _cxx1x_flag_supported) + if(_cxx1x_flag_supported) + set(CXX1XCXXFLAGS ${_cxx1x_flag}) + break() + endif() +endforeach() + +include(CMakePushCheckState) +include(CheckCXXSourceCompiles) +cmake_push_check_state() +set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${CXX1XCXXFLAGS}") +# Check that std::future is available. +CHECK_CXX_SOURCE_COMPILES(" +#include +#include +int main() { std::vector> v; }" HAVE_STD_FUTURE) +# Check that std::map::emplace is available for g++-4.7. +CHECK_CXX_SOURCE_COMPILES(" +#include +int main() { std::map().emplace(1, 2); }" HAVE_STD_MAP_EMPLACE) +cmake_pop_check_state() + + +# Checks for libraries. +# +# # Additional libraries required for tests. +# TESTLDADD= +# +# # Additional libraries required for programs under src directory. +# APPLDFLAGS= +# +# case "$host" in +# *android*) +# android_build=yes +# # android does not need -pthread, but needs followng 3 libs for C++ +# APPLDFLAGS="$APPLDFLAGS -lstdc++ -latomic -lsupc++" +# ;; +# *) +# PTHREAD_LDFLAGS="-pthread" +# APPLDFLAGS="$APPLDFLAGS $PTHREAD_LDFLAGS" +# ;; +# esac + +pkg_check_modules(ZLIB zlib>=1.2.3) + +# # dl: openssl requires libdl when it is statically linked. +# case "${host_os}" in +# *bsd*) +# # dlopen is in libc on *BSD +# ;; +# *) +# save_LIBS=$LIBS +# AC_SEARCH_LIBS([dlopen], [dl], [APPLDFLAGS="-ldl $APPLDFLAGS"], [], []) +# LIBS=$save_LIBS +# ;; +# esac + +# XXX put this in FindCUNIT.cmake +pkg_check_modules(CUNIT cunit>=2.1) +# # 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" ]) + +# # libev (for src) +# # libev does not have pkg-config file. Check it in an old way. +# save_LIBS=$LIBS +# # android requires -lm for floor +# AC_CHECK_LIB([ev], [ev_time], [have_libev=yes], [have_libev=no], [-lm]) +# if test "x${have_libev}" = "xyes"; then +# AC_CHECK_HEADER([ev.h], [have_libev=yes], [have_libev=no]) +# if test "x${have_libev}" = "xyes"; then +# LIBEV_LIBS=-lev +# LIBEV_CFLAGS= +# AC_SUBST([LIBEV_LIBS]) +# AC_SUBST([LIBEV_CFLAGS]) +# fi +# fi +# LIBS=$save_LIBS + +# openssl (for src) +pkg_check_modules(OPENSSL openssl>=1.0.1) +# libevent_openssl (for examples) +# 2.0.8 is required because we use evconnlistener_set_error_cb() +pkg_check_modules(LIBEVENT_OPENSSL libevent_openssl>=2.0.8) + +# jansson (for src/nghttp, src/deflatehd and src/inflatehd) +pkg_check_modules(JANSSON jansson>=2.5) +if(JANSSON_FOUND) + set(HAVE_JANSSON 1) +endif() + +# libxml2 (for src/nghttp) +if(WITH_LIBXML2) + find_package(LibXml2 2.7.7 REQUIRED) + set(HAVE_LIBXML2 1) + # XXX fail if WITH_LIBXML2=ON +endif() + +# jemalloc +if(WITH_JEMALLOC) + # FIXME +# have_jemalloc=no +# if test "x${request_jemalloc}" != "xno"; then +# save_LIBS=$LIBS +# AC_SEARCH_LIBS([malloc_stats_print], [jemalloc], [have_jemalloc=yes], [], +# [$PTHREAD_LDFLAGS]) +# +# if test "x${have_jemalloc}" = "xyes"; then +# jemalloc_libs=${ac_cv_search_malloc_stats_print} +# else +# # On Darwin, malloc_stats_print is je_malloc_stats_print +# AC_SEARCH_LIBS([je_malloc_stats_print], [jemalloc], [have_jemalloc=yes], [], +# [$PTHREAD_LDFLAGS]) +# +# if test "x${have_jemalloc}" = "xyes"; then +# jemalloc_libs=${ac_cv_search_je_malloc_stats_print} +# fi +# fi +# +# LIBS=$save_LIBS +# +# if test "x${have_jemalloc}" = "xyes" && +# test "x${jemalloc_libs}" != "xnone required"; then +# JEMALLOC_LIBS=${jemalloc_libs} +# AC_SUBST([JEMALLOC_LIBS]) +# fi +# fi +# +# if test "x${request_jemalloc}" = "xyes" && +# test "x${have_jemalloc}" != "xyes"; then +# AC_MSG_ERROR([jemalloc was requested (--with-jemalloc) but not found]) +# fi +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() + message(STATUS "The SPDY support in nghttpx and h2load will be disabled.") + endif() + # XXX fail if WITH_SPDYLAY=ON +endif() + +# # Check Boost Asio library +# have_asio_lib=no +# +# if test "x${request_asio_lib}" = "xyes"; then +# AX_BOOST_BASE([1.54.0], [have_boost_base=yes], [have_boost_base=no]) +# +# if test "x${have_boost_base}" = "xyes"; then +# AX_BOOST_ASIO() +# AX_BOOST_SYSTEM() +# AX_BOOST_THREAD() +# +# if test "x${ax_cv_boost_asio}" = "xyes" && +# test "x${ax_cv_boost_system}" = "xyes" && +# test "x${ax_cv_boost_thread}" = "xyes"; then +# have_asio_lib=yes +# fi +# fi +# fi +# +# # The nghttp, nghttpd and nghttpx under src depend on zlib, OpenSSL +# # and libev +# enable_app=no +# if test "x${request_app}" != "xno" && +# test "x${have_zlib}" = "xyes" && +# test "x${have_openssl}" = "xyes" && +# test "x${have_libev}" = "xyes"; then +# enable_app=yes +# fi +# +# if test "x${request_app}" = "xyes" && +# test "x${enable_app}" != "xyes"; then +# AC_MSG_ERROR([applications were requested (--enable-app) but dependencies are not met.]) +# fi +# +# AM_CONDITIONAL([ENABLE_APP], [ test "x${enable_app}" = "xyes" ]) +# +# enable_hpack_tools=no +# # HPACK tools requires jansson +# if test "x${request_hpack_tools}" != "xno" && +# test "x${have_jansson}" = "xyes"; then +# enable_hpack_tools=yes +# fi +# +# if test "x${request_hpack_tools}" = "xyes" && +# test "x${enable_hpack_tools}" != "xyes"; then +# AC_MSG_ERROR([HPACK tools were requested (--enable-hpack-tools) but dependencies are not met.]) +# fi +# +# AM_CONDITIONAL([ENABLE_HPACK_TOOLS], [ test "x${enable_hpack_tools}" = "xyes" ]) +# +# # C++ library libnghttp2_asio +# +# enable_asio_lib=no +# if test "x${request_asio_lib}" != "xno" && +# test "x${have_asio_lib}" = "xyes"; then +# enable_asio_lib=yes +# fi +# +# AM_CONDITIONAL([ENABLE_ASIO_LIB], [ test "x${enable_asio_lib}" = "xyes" ]) +# +# # The example programs depend on OpenSSL and libevent_openssl +# enable_examples=no +# if test "x${request_examples}" != "xno" && +# test "x${have_openssl}" = "xyes" && +# test "x${have_libevent_openssl}" = "xyes"; then +# enable_examples=yes +# fi +# +# if test "x${request_examples}" = "xyes" && +# test "x${enable_examples}" != "xyes"; then +# AC_MSG_ERROR([examples were requested (--enable-examples) but dependencies are not met.]) +# fi +# +# AM_CONDITIONAL([ENABLE_EXAMPLES], [ test "x${enable_examples}" = "xyes" ]) +# +# # third-party only be built when needed +# +# enable_third_party=no +# have_mruby=no +# have_neverbleed=no +# if test "x${enable_examples}" = "xyes" || +# test "x${enable_app}" = "xyes" || +# test "x${enable_hpack_tools}" = "xyes" || +# test "x${enable_asio_lib}" = "xyes"; then +# enable_third_party=yes +# +# # mruby (for src/nghttpx) +# if test "x${request_mruby}" = "xyes"; then +# # We are going to build mruby +# have_mruby=yes +# AC_DEFINE([HAVE_MRUBY], [1], [Define to 1 if you have `mruby` library.]) +# LIBMRUBY_LIBS="-lmruby -lm" +# LIBMRUBY_CFLAGS= +# AC_SUBST([LIBMRUBY_LIBS]) +# AC_SUBST([LIBMRUBY_CFLAGS]) +# fi +# +# # neverbleed (for src/nghttpx) +# if test "x${request_neverbleed}" = "xyes"; then +# have_neverbleed=yes +# AC_DEFINE([HAVE_NEVERBLEED], [1], [Define to 1 if you have `neverbleed` library.]) +# fi +# fi +# +# AM_CONDITIONAL([ENABLE_THIRD_PARTY], [ test "x${enable_third_party}" = "xyes" ]) +# AM_CONDITIONAL([HAVE_MRUBY], [test "x${have_mruby}" = "xyes"]) +# AM_CONDITIONAL([HAVE_NEVERBLEED], [test "x${have_neverbleed}" = "xyes"]) +# +# # Python bindings +# enable_python_bindings=no +# if test "x${request_python_bindings}" != "xno" && +# test "x${CYTHON}" != "x" && +# test "x${PYTHON}" != "x:" && +# test "x${have_python_dev}" = "xyes"; then +# enable_python_bindings=yes +# fi +# +# if test "x${request_python_bindings}" = "xyes" && +# test "x${enable_python_bindings}" != "xyes"; then +# AC_MSG_ERROR([python bindings were requested (--enable-python-bindings) but dependencies are not met.]) +# fi +# +# AM_CONDITIONAL([ENABLE_PYTHON_BINDINGS], +# [test "x${enable_python_bindings}" = "xyes"]) +# +# # Produce cython conditional, so that we can distribute generated C +# # source +# AM_CONDITIONAL([HAVE_CYTHON], [test "x${CYTHON}" != "x"]) +# +# # failmalloc tests +# enable_failmalloc=no +# if test "x${request_failmalloc}" = "xyes"; then +# enable_failmalloc=yes +# fi +# +# AM_CONDITIONAL([ENABLE_FAILMALLOC], [ test "x${enable_failmalloc}" = "xyes" ]) +# +# # Checks for header files. +# AC_HEADER_ASSERT +# AC_CHECK_HEADERS([ \ +# arpa/inet.h \ +# fcntl.h \ +# inttypes.h \ +# limits.h \ +# netdb.h \ +# netinet/in.h \ +# pwd.h \ +# stddef.h \ +# stdint.h \ +# stdlib.h \ +# string.h \ +# sys/socket.h \ +# sys/time.h \ +# syslog.h \ +# time.h \ +# unistd.h \ +# ]) +# +# # Checks for typedefs, structures, and compiler characteristics. +# AC_TYPE_SIZE_T +# AC_TYPE_SSIZE_T +# AC_TYPE_UINT8_T +# AC_TYPE_UINT16_T +# AC_TYPE_UINT32_T +# AC_TYPE_UINT64_T +# AC_TYPE_INT8_T +# AC_TYPE_INT16_T +# AC_TYPE_INT32_T +# AC_TYPE_INT64_T +# AC_TYPE_OFF_T +# AC_TYPE_PID_T +# AC_TYPE_UID_T +# AC_CHECK_TYPES([ptrdiff_t]) +# AC_C_BIGENDIAN +# AC_C_INLINE +# AC_SYS_LARGEFILE +# +# AC_CHECK_MEMBER([struct tm.tm_gmtoff], [have_struct_tm_tm_gmtoff=yes], +# [have_struct_tm_tm_gmtoff=no], [[#include ]]) +# +# if test "x$have_struct_tm_tm_gmtoff" = "xyes"; then +# AC_DEFINE([HAVE_STRUCT_TM_TM_GMTOFF], [1], +# [Define to 1 if you have `struct tm.tm_gmtoff` member.]) +# fi +# +# # Check size of pointer to decide we need 8 bytes alignment +# # adjustment. +# AC_CHECK_SIZEOF([int *]) +# +# AC_CHECK_SIZEOF([time_t]) +# +# # Checks for library functions. +# +# # Don't check malloc, since it does not play nicely with C++ stdlib +# # AC_FUNC_MALLOC +# +# AC_FUNC_CHOWN +# AC_FUNC_ERROR_AT_LINE +# AC_FUNC_FORK +# # Don't check realloc, since LeakSanitizer detects memory leak during check +# # AC_FUNC_REALLOC +# AC_FUNC_STRERROR_R +# AC_FUNC_STRNLEN +# +# AC_CHECK_FUNCS([ \ +# _Exit \ +# accept4 \ +# dup2 \ +# getcwd \ +# getpwnam \ +# localtime_r \ +# memchr \ +# memmove \ +# memset \ +# socket \ +# sqrt \ +# strchr \ +# strdup \ +# strerror \ +# strndup \ +# strstr \ +# strtol \ +# strtoul \ +# timegm \ +# ]) +# +# # timerfd_create was added in linux kernel 2.6.25 +# +# AC_CHECK_FUNC([timerfd_create], +# [have_timerfd_create=yes], [have_timerfd_create=no]) +# +# # For cygwin: we can link initgroups, so AC_CHECK_FUNCS succeeds, but +# # cygwin disables initgroups due to feature test macro magic with our +# # configuration. +# AC_CHECK_DECLS([initgroups], [], [], [[#include ]]) +# +# # Checks for epoll availability, primarily for examples/tiny-nghttpd +# AX_HAVE_EPOLL([have_epoll=yes], [have_epoll=no]) +# +# AM_CONDITIONAL([ENABLE_TINY_NGHTTPD], +# [ test "x${have_epoll}" = "xyes" && +# test "x${have_timerfd_create}" = "xyes"]) +# +# save_CFLAGS=$CFLAGS +# save_CXXFLAGS=$CXXFLAGS +# +# CFLAGS= +# CXXFLAGS= +# +# if test "x$werror" != "xno"; then +# # For C compiler +# AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"]) +# AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS="$CFLAGS -Wextra"]) +# AX_CHECK_COMPILE_FLAG([-Werror], [CFLAGS="$CFLAGS -Werror"]) +# AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CFLAGS="$CFLAGS -Wmissing-prototypes"]) +# AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], [CFLAGS="$CFLAGS -Wstrict-prototypes"]) +# AX_CHECK_COMPILE_FLAG([-Wmissing-declarations], [CFLAGS="$CFLAGS -Wmissing-declarations"]) +# AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"]) +# AX_CHECK_COMPILE_FLAG([-Wdeclaration-after-statement], [CFLAGS="$CFLAGS -Wdeclaration-after-statement"]) +# AX_CHECK_COMPILE_FLAG([-Wformat-security], [CFLAGS="$CFLAGS -Wformat-security"]) +# AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"]) +# AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"]) +# AX_CHECK_COMPILE_FLAG([-Winline], [CFLAGS="$CFLAGS -Winline"]) +# AX_CHECK_COMPILE_FLAG([-Wnested-externs], [CFLAGS="$CFLAGS -Wnested-externs"]) +# AX_CHECK_COMPILE_FLAG([-Wfloat-equal], [CFLAGS="$CFLAGS -Wfloat-equal"]) +# AX_CHECK_COMPILE_FLAG([-Wundef], [CFLAGS="$CFLAGS -Wundef"]) +# AX_CHECK_COMPILE_FLAG([-Wendif-labels], [CFLAGS="$CFLAGS -Wendif-labels"]) +# AX_CHECK_COMPILE_FLAG([-Wempty-body], [CFLAGS="$CFLAGS -Wempty-body"]) +# AX_CHECK_COMPILE_FLAG([-Wcast-align], [CFLAGS="$CFLAGS -Wcast-align"]) +# AX_CHECK_COMPILE_FLAG([-Wclobbered], [CFLAGS="$CFLAGS -Wclobbered"]) +# AX_CHECK_COMPILE_FLAG([-Wvla], [CFLAGS="$CFLAGS -Wvla"]) +# AX_CHECK_COMPILE_FLAG([-Wpragmas], [CFLAGS="$CFLAGS -Wpragmas"]) +# AX_CHECK_COMPILE_FLAG([-Wunreachable-code], [CFLAGS="$CFLAGS -Wunreachable-code"]) +# AX_CHECK_COMPILE_FLAG([-Waddress], [CFLAGS="$CFLAGS -Waddress"]) +# AX_CHECK_COMPILE_FLAG([-Wattributes], [CFLAGS="$CFLAGS -Wattributes"]) +# AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"]) +# AX_CHECK_COMPILE_FLAG([-Wshorten-64-to-32], [CFLAGS="$CFLAGS -Wshorten-64-to-32"]) +# +# AX_CHECK_COMPILE_FLAG([-Wconversion], [CFLAGS="$CFLAGS -Wconversion"]) +# AX_CHECK_COMPILE_FLAG([-Wextended-offsetof], [CFLAGS="$CFLAGS -Wextended-offsetof"]) +# AX_CHECK_COMPILE_FLAG([-Wformat-nonliteral], [CFLAGS="$CFLAGS -Wformat-nonliteral"]) +# AX_CHECK_COMPILE_FLAG([-Wlanguage-extension-token], [CFLAGS="$CFLAGS -Wlanguage-extension-token"]) +# AX_CHECK_COMPILE_FLAG([-Wmissing-field-initializers], [CFLAGS="$CFLAGS -Wmissing-field-initializers"]) +# AX_CHECK_COMPILE_FLAG([-Wmissing-noreturn], [CFLAGS="$CFLAGS -Wmissing-noreturn"]) +# AX_CHECK_COMPILE_FLAG([-Wmissing-variable-declarations], [CFLAGS="$CFLAGS -Wmissing-variable-declarations"]) +# # Not used because we cannot change public structs +# # AX_CHECK_COMPILE_FLAG([-Wpadded], [CFLAGS="$CFLAGS -Wpadded"]) +# AX_CHECK_COMPILE_FLAG([-Wsign-conversion], [CFLAGS="$CFLAGS -Wsign-conversion"]) +# # Not used because this basically disallows default case +# # AX_CHECK_COMPILE_FLAG([-Wswitch-enum], [CFLAGS="$CFLAGS -Wswitch-enum"]) +# AX_CHECK_COMPILE_FLAG([-Wunreachable-code-break], [CFLAGS="$CFLAGS -Wunreachable-code-break"]) +# AX_CHECK_COMPILE_FLAG([-Wunused-macros], [CFLAGS="$CFLAGS -Wunused-macros"]) +# AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [CFLAGS="$CFLAGS -Wunused-parameter"]) +# AX_CHECK_COMPILE_FLAG([-Wredundant-decls], [CFLAGS="$CFLAGS -Wredundant-decls"]) +# # Only work with Clang for the moment +# AX_CHECK_COMPILE_FLAG([-Wheader-guard], [CFLAGS="$CFLAGS -Wheader-guard"]) +# +# # For C++ compiler +# AC_LANG_PUSH(C++) +# AX_CHECK_COMPILE_FLAG([-Wall], [CXXFLAGS="$CXXFLAGS -Wall"]) +# AX_CHECK_COMPILE_FLAG([-Werror], [CXXFLAGS="$CXXFLAGS -Werror"]) +# AX_CHECK_COMPILE_FLAG([-Wformat-security], [CXXFLAGS="$CXXFLAGS -Wformat-security"]) +# AC_LANG_POP() +# fi +# +# WARNCFLAGS=$CFLAGS +# WARNCXXFLAGS=$CXXFLAGS +# +# CFLAGS=$save_CFLAGS +# CXXFLAGS=$save_CXXFLAGS +# +# AC_SUBST([WARNCFLAGS]) +# AC_SUBST([WARNCXXFLAGS]) +# +# EXTRACFLAG= +# AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [EXTRACFLAG="-fvisibility=hidden"]) +# +# AC_SUBST([EXTRACFLAG]) +# +# if test "x$debug" != "xno"; then +# AC_DEFINE([DEBUGBUILD], [1], [Define to 1 to enable debug output.]) +# fi +# +# enable_threads=yes +# # Some platform does not have working std::future. We disable +# # threading for those platforms. +# if test "x$threads" != "xyes" || +# test "x$have_std_future" != "xyes"; then +# enable_threads=no +# AC_DEFINE([NOTHREADS], [1], [Define to 1 if you want to disable threads.]) +# fi +# +# # propagate $enable_static to tests/Makefile.am +# AM_CONDITIONAL([ENABLE_STATIC], [test "x$enable_static" = "xyes"]) +# +# AC_SUBST([TESTLDADD]) +# AC_SUBST([APPLDFLAGS]) +# +# AC_CONFIG_FILES([ +# Makefile +# lib/Makefile +# lib/libnghttp2.pc +# lib/includes/Makefile +# lib/includes/nghttp2/nghttp2ver.h +# tests/Makefile +# tests/testdata/Makefile +# third-party/Makefile +# src/Makefile +# src/includes/Makefile +# src/libnghttp2_asio.pc +# examples/Makefile +# python/Makefile +# python/setup.py +# integration-tests/Makefile +# integration-tests/config.go +# integration-tests/setenv +# doc/Makefile +# doc/conf.py +# doc/index.rst +# doc/package_README.rst +# doc/tutorial-client.rst +# doc/tutorial-server.rst +# doc/tutorial-hpack.rst +# doc/nghttpx-howto.rst +# doc/h2load-howto.rst +# doc/libnghttp2_asio.rst +# doc/python-apiref.rst +# doc/building-android-binary.rst +# doc/nghttp2.h.rst +# doc/nghttp2ver.h.rst +# doc/asio_http2.h.rst +# doc/asio_http2_server.h.rst +# doc/asio_http2_client.h.rst +# doc/contribute.rst +# contrib/Makefile +# script/Makefile +# ]) +# AC_OUTPUT +# +# AC_MSG_NOTICE([summary of build options: +# +# Package version: ${VERSION} +# Library version: $LT_CURRENT:$LT_REVISION:$LT_AGE +# Install prefix: ${prefix} +# System types: +# Build: ${build} +# Host: ${host} +# Target: ${target} +# Compiler: +# C compiler: ${CC} +# CFLAGS: ${CFLAGS} +# LDFLAGS: ${LDFLAGS} +# C++ compiler: ${CXX} +# CXXFLAGS: ${CXXFLAGS} +# CXXCPP: ${CXXCPP} +# C preprocessor: ${CPP} +# CPPFLAGS: ${CPPFLAGS} +# WARNCFLAGS: ${WARNCFLAGS} +# CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} +# EXTRACFLAG: ${EXTRACFLAG} +# LIBS: ${LIBS} +# Library: +# Shared: ${enable_shared} +# Static: ${enable_static} +# Python: +# Python: ${PYTHON} +# PYTHON_VERSION: ${PYTHON_VERSION} +# pyexecdir: ${pyexecdir} +# Python-dev: ${have_python_dev} +# PYTHON_CPPFLAGS:${PYTHON_CPPFLAGS} +# PYTHON_LDFLAGS: ${PYTHON_LDFLAGS} +# Cython: ${CYTHON} +# Test: +# CUnit: ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') +# Failmalloc: ${enable_failmalloc} +# Libs: +# OpenSSL: ${have_openssl} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') +# Libxml2: ${have_libxml2} (CFLAGS='${XML_CPPFLAGS}' LIBS='${XML_LIBS}') +# Libev: ${have_libev} (CFLAGS='${LIBEV_CFLAGS}' LIBS='${LIBEV_LIBS}') +# Libevent(SSL): ${have_libevent_openssl} (CFLAGS='${LIBEVENT_OPENSSL_CFLAGS}' LIBS='${LIBEVENT_OPENSSL_LIBS}') +# Spdylay: ${have_spdylay} (CFLAGS='${LIBSPDYLAY_CFLAGS}' LIBS='${LIBSPDYLAY_LIBS}') +# Jansson: ${have_jansson} (CFLAGS='${JANSSON_CFLAGS}' LIBS='${JANSSON_LIBS}') +# Jemalloc: ${have_jemalloc} (LIBS='${JEMALLOC_LIBS}') +# Zlib: ${have_zlib} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') +# Boost CPPFLAGS: ${BOOST_CPPFLAGS} +# Boost LDFLAGS: ${BOOST_LDFLAGS} +# Boost::ASIO: ${BOOST_ASIO_LIB} +# Boost::System: ${BOOST_SYSTEM_LIB} +# Boost::Thread: ${BOOST_THREAD_LIB} +# Third-party: +# http-parser: ${enable_third_party} +# MRuby: ${have_mruby} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') +# Neverbleed: ${have_neverbleed} +# Features: +# Applications: ${enable_app} +# HPACK tools: ${enable_hpack_tools} +# Libnghttp2_asio:${enable_asio_lib} +# Examples: ${enable_examples} +# Python bindings:${enable_python_bindings} +# Threading: ${enable_threads} +# ]) diff --git a/cmake/Version.cmake b/cmake/Version.cmake new file mode 100644 index 00000000..8ac4849c --- /dev/null +++ b/cmake/Version.cmake @@ -0,0 +1,11 @@ +# Converts a version such as 1.2.255 to 0x0102ff +function(HexVersion version_hex_var major minor patch) + math(EXPR version_dec "${major} * 256 * 256 + ${minor} * 256 + ${patch}") + set(version_hex "0x") + foreach(i RANGE 5 0 -1) + math(EXPR num "(${version_dec} >> (4 * ${i})) & 15") + string(SUBSTRING "0123456789abcdef" ${num} 1 num_hex) + set(version_hex "${version_hex}${num_hex}") + endforeach() + set(${version_hex_var} "${version_hex}" PARENT_SCOPE) +endfunction() diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in new file mode 100644 index 00000000..e352ba19 --- /dev/null +++ b/cmakeconfig.h.in @@ -0,0 +1,12 @@ + +/* Define to 1 if you have the `std::map::emplace`. */ +#cmakedefine HAVE_STD_MAP_EMPLACE 1 + +/* Define to 1 if you have `libjansson` library. */ +#cmakedefine HAVE_JANSSON 1 + +/* Define to 1 if you have `libxml2` library. */ +#cmakedefine HAVE_LIBXML2 1 + +/* Define to 1 if you have `spdylay` library. */ +#cmakedefine HAVE_SPDYLAY 1 From 2b63980758d99f9a775e42f217c12182895170d1 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 15:49:39 +0100 Subject: [PATCH 02/59] cmake: more dependency checks --- CMakeLists.txt | 231 ++++++++------------------------------- cmake/FindJemalloc.cmake | 19 ++++ cmake/FindLibev.cmake | 23 ++++ cmakeconfig.h.in | 6 + 4 files changed, 96 insertions(+), 183 deletions(-) create mode 100644 cmake/FindJemalloc.cmake create mode 100644 cmake/FindLibev.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 59b2ec97..0e3253e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,9 +99,10 @@ else() endif() include(CheckCXXCompilerFlag) -foreach(_cxx1x_flag "-std=gnu++11" "-std=gnu++0x") - CHECK_CXX_COMPILER_FLAG(${_cxx1x_flag} _cxx1x_flag_supported) - if(_cxx1x_flag_supported) +foreach(_std gnu++11 gnu++0x) + set(_cxx1x_flag -std=${_std}) + CHECK_CXX_COMPILER_FLAG(${_cxx1x_flag} CXX_STD_${_std}) + if(CXX_STD_${_std}) set(CXX1XCXXFLAGS ${_cxx1x_flag}) break() endif() @@ -186,21 +187,8 @@ pkg_check_modules(CUNIT cunit>=2.1) # # AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) -# # libev (for src) -# # libev does not have pkg-config file. Check it in an old way. -# save_LIBS=$LIBS -# # android requires -lm for floor -# AC_CHECK_LIB([ev], [ev_time], [have_libev=yes], [have_libev=no], [-lm]) -# if test "x${have_libev}" = "xyes"; then -# AC_CHECK_HEADER([ev.h], [have_libev=yes], [have_libev=no]) -# if test "x${have_libev}" = "xyes"; then -# LIBEV_LIBS=-lev -# LIBEV_CFLAGS= -# AC_SUBST([LIBEV_LIBS]) -# AC_SUBST([LIBEV_CFLAGS]) -# fi -# fi -# LIBS=$save_LIBS +# libev (for src) +find_package(Libev) # openssl (for src) pkg_check_modules(OPENSSL openssl>=1.0.1) @@ -223,38 +211,10 @@ endif() # jemalloc if(WITH_JEMALLOC) - # FIXME -# have_jemalloc=no -# if test "x${request_jemalloc}" != "xno"; then -# save_LIBS=$LIBS -# AC_SEARCH_LIBS([malloc_stats_print], [jemalloc], [have_jemalloc=yes], [], -# [$PTHREAD_LDFLAGS]) -# -# if test "x${have_jemalloc}" = "xyes"; then -# jemalloc_libs=${ac_cv_search_malloc_stats_print} -# else -# # On Darwin, malloc_stats_print is je_malloc_stats_print -# AC_SEARCH_LIBS([je_malloc_stats_print], [jemalloc], [have_jemalloc=yes], [], -# [$PTHREAD_LDFLAGS]) -# -# if test "x${have_jemalloc}" = "xyes"; then -# jemalloc_libs=${ac_cv_search_je_malloc_stats_print} -# fi -# fi -# -# LIBS=$save_LIBS -# -# if test "x${have_jemalloc}" = "xyes" && -# test "x${jemalloc_libs}" != "xnone required"; then -# JEMALLOC_LIBS=${jemalloc_libs} -# AC_SUBST([JEMALLOC_LIBS]) -# fi -# fi -# -# if test "x${request_jemalloc}" = "xyes" && -# test "x${have_jemalloc}" != "xyes"; then -# AC_MSG_ERROR([jemalloc was requested (--with-jemalloc) but not found]) -# fi + pkg_check_modules(JEMALLOC jemalloc) + if(NOT JEMALLOC_FOUND) + find_package(jemalloc REQUIRED) + endif() endif() # spdylay (for src/nghttpx and src/h2load) @@ -268,143 +228,48 @@ if(WITH_SPDYLAY) # XXX fail if WITH_SPDYLAY=ON endif() -# # Check Boost Asio library -# have_asio_lib=no -# -# if test "x${request_asio_lib}" = "xyes"; then -# AX_BOOST_BASE([1.54.0], [have_boost_base=yes], [have_boost_base=no]) -# -# if test "x${have_boost_base}" = "xyes"; then -# AX_BOOST_ASIO() -# AX_BOOST_SYSTEM() -# AX_BOOST_THREAD() -# -# if test "x${ax_cv_boost_asio}" = "xyes" && -# test "x${ax_cv_boost_system}" = "xyes" && -# test "x${ax_cv_boost_thread}" = "xyes"; then -# have_asio_lib=yes -# fi -# fi -# fi -# -# # The nghttp, nghttpd and nghttpx under src depend on zlib, OpenSSL -# # and libev -# enable_app=no -# if test "x${request_app}" != "xno" && -# test "x${have_zlib}" = "xyes" && -# test "x${have_openssl}" = "xyes" && -# test "x${have_libev}" = "xyes"; then -# enable_app=yes -# fi -# -# if test "x${request_app}" = "xyes" && -# test "x${enable_app}" != "xyes"; then -# AC_MSG_ERROR([applications were requested (--enable-app) but dependencies are not met.]) -# fi -# -# AM_CONDITIONAL([ENABLE_APP], [ test "x${enable_app}" = "xyes" ]) -# -# enable_hpack_tools=no -# # HPACK tools requires jansson -# if test "x${request_hpack_tools}" != "xno" && -# test "x${have_jansson}" = "xyes"; then -# enable_hpack_tools=yes -# fi -# -# if test "x${request_hpack_tools}" = "xyes" && -# test "x${enable_hpack_tools}" != "xyes"; then -# AC_MSG_ERROR([HPACK tools were requested (--enable-hpack-tools) but dependencies are not met.]) -# fi -# -# AM_CONDITIONAL([ENABLE_HPACK_TOOLS], [ test "x${enable_hpack_tools}" = "xyes" ]) -# -# # C++ library libnghttp2_asio -# -# enable_asio_lib=no -# if test "x${request_asio_lib}" != "xno" && -# test "x${have_asio_lib}" = "xyes"; then -# enable_asio_lib=yes -# fi -# -# AM_CONDITIONAL([ENABLE_ASIO_LIB], [ test "x${enable_asio_lib}" = "xyes" ]) -# -# # The example programs depend on OpenSSL and libevent_openssl -# enable_examples=no -# if test "x${request_examples}" != "xno" && -# test "x${have_openssl}" = "xyes" && -# test "x${have_libevent_openssl}" = "xyes"; then -# enable_examples=yes -# fi -# -# if test "x${request_examples}" = "xyes" && -# test "x${enable_examples}" != "xyes"; then -# AC_MSG_ERROR([examples were requested (--enable-examples) but dependencies are not met.]) -# fi -# -# AM_CONDITIONAL([ENABLE_EXAMPLES], [ test "x${enable_examples}" = "xyes" ]) -# -# # third-party only be built when needed -# -# enable_third_party=no -# have_mruby=no -# have_neverbleed=no -# if test "x${enable_examples}" = "xyes" || -# test "x${enable_app}" = "xyes" || -# test "x${enable_hpack_tools}" = "xyes" || -# test "x${enable_asio_lib}" = "xyes"; then -# enable_third_party=yes -# -# # mruby (for src/nghttpx) -# if test "x${request_mruby}" = "xyes"; then -# # We are going to build mruby -# have_mruby=yes -# AC_DEFINE([HAVE_MRUBY], [1], [Define to 1 if you have `mruby` library.]) -# LIBMRUBY_LIBS="-lmruby -lm" -# LIBMRUBY_CFLAGS= -# AC_SUBST([LIBMRUBY_LIBS]) -# AC_SUBST([LIBMRUBY_CFLAGS]) -# fi -# -# # neverbleed (for src/nghttpx) -# if test "x${request_neverbleed}" = "xyes"; then -# have_neverbleed=yes -# AC_DEFINE([HAVE_NEVERBLEED], [1], [Define to 1 if you have `neverbleed` library.]) -# fi -# fi -# -# AM_CONDITIONAL([ENABLE_THIRD_PARTY], [ test "x${enable_third_party}" = "xyes" ]) -# AM_CONDITIONAL([HAVE_MRUBY], [test "x${have_mruby}" = "xyes"]) -# AM_CONDITIONAL([HAVE_NEVERBLEED], [test "x${have_neverbleed}" = "xyes"]) -# -# # Python bindings -# enable_python_bindings=no +if(ENABLE_ASIO_LIB) + find_package(Boost 1.54.0 REQUIRED system thread) +endif() + +# The nghttp, nghttpd and nghttpx under src depend on zlib, OpenSSL and libev +if(ENABLE_APP AND NOT (ZLIB_FOUND AND OPENSSL_FOUND AND LIBEV_FOUND)) + message(FATAL_ERROR "Applications were requested (ENABLE_APP=1) but dependencies are not met.") +endif() + +# HPACK tools requires jansson +if(ENABLE_HPACK_TOOLS AND NOT HAVE_JANSSON) + message(FATAL_ERROR "HPACK tools were requested (ENABLE_HPACK_TOOLS=1) but dependencies are not met.") +endif() + +# C++ library libnghttp2_asio +if(ENABLE_EXAMPLES AND NOT (OPENSSL_FOUND AND LIBEVENT_OPENSSL_FOUND)) + message(FATAL_ERROR "examples were requested (--enable-examples) but dependencies are not met.") +endif() + +# third-party http-parser only be built when needed +if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB) + set(ENABLE_THIRD_PARTY 1) + # mruby (for src/nghttpx) + if(WITH_MRUBY) + set(HAVE_MRUBY 1) + # XXX add -lmruby and -lm libs + endif() + if(WITH_NEVERBLEED) + set(HAVE_NEVERBLEED 1) + endif() +endif() + +# Python bindings +if(ENABLE_PYTHON_BINDINGS AND NOT CYTHON AND NOT PYTHONLIBS_FOUND) +# XXX PythonInterp and PythonLibs are looked up before, unreachable check? # if test "x${request_python_bindings}" != "xno" && # test "x${CYTHON}" != "x" && # test "x${PYTHON}" != "x:" && # test "x${have_python_dev}" = "xyes"; then -# enable_python_bindings=yes -# fi -# -# if test "x${request_python_bindings}" = "xyes" && -# test "x${enable_python_bindings}" != "xyes"; then -# AC_MSG_ERROR([python bindings were requested (--enable-python-bindings) but dependencies are not met.]) -# fi -# -# AM_CONDITIONAL([ENABLE_PYTHON_BINDINGS], -# [test "x${enable_python_bindings}" = "xyes"]) -# -# # Produce cython conditional, so that we can distribute generated C -# # source -# AM_CONDITIONAL([HAVE_CYTHON], [test "x${CYTHON}" != "x"]) -# -# # failmalloc tests -# enable_failmalloc=no -# if test "x${request_failmalloc}" = "xyes"; then -# enable_failmalloc=yes -# fi -# -# AM_CONDITIONAL([ENABLE_FAILMALLOC], [ test "x${enable_failmalloc}" = "xyes" ]) -# + message(FATAL_ERROR "python bindings were requested (ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.") +endif() + # # Checks for header files. # AC_HEADER_ASSERT # AC_CHECK_HEADERS([ \ diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake new file mode 100644 index 00000000..83db90dc --- /dev/null +++ b/cmake/FindJemalloc.cmake @@ -0,0 +1,19 @@ +# - Try to find jemalloc +# Once done this will define +# JEMALLOC_FOUND - System has jemalloc +# JEMALLOC_INCLUDE_DIRS - The jemalloc include directories +# JEMALLOC_LIBRARIES - The libraries needed to use jemalloc + +find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h) +find_library(JEMALLOC_LIBRARY NAMES jemalloc) + +set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) +set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(jemalloc DEFAULT_MSG + JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR) + +mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY) diff --git a/cmake/FindLibev.cmake b/cmake/FindLibev.cmake new file mode 100644 index 00000000..03a0f53d --- /dev/null +++ b/cmake/FindLibev.cmake @@ -0,0 +1,23 @@ +# - Try to find libev +# Once done this will define +# LIBEV_FOUND - System has libev +# LIBEV_INCLUDE_DIRS - The libev include directories +# LIBEV_LIBRARIES - The libraries needed to use libev + +find_path(LIBEV_INCLUDE_DIR ev.h) +find_library(LIBEV_LIBRARY NAMES ev) + +# Assume that the discovered "ev" library contains ev_time +#include(CheckLibraryExists) +#CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV) + +set(LIBEV_LIBRARIES ${LIBEV_LIBRARY}) +set(LIBEV_INCLUDE_DIRS ${LIBEV_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBEV_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(Libev DEFAULT_MSG + LIBEV_LIBRARY LIBEV_INCLUDE_DIR) + +mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARY) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index e352ba19..ef630402 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -10,3 +10,9 @@ /* Define to 1 if you have `spdylay` library. */ #cmakedefine HAVE_SPDYLAY 1 + +/* Define to 1 if you have `mruby` library. */ +#cmakedefine HAVE_MRUBY 1 + +/* Define to 1 if you have `neverbleed` library. */ +#cmakedefine HAVE_NEVERBLEED 1 From 90f5bf796d6ef549d7904aede2ff2e20b0921b0b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 16:08:07 +0100 Subject: [PATCH 03/59] cmake: check more headers and sizeof --- CMakeLists.txt | 66 +++++++++++++++++++++--------------------------- cmakeconfig.h.in | 6 +++++ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e3253e0..eb53879e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,28 +270,26 @@ if(ENABLE_PYTHON_BINDINGS AND NOT CYTHON AND NOT PYTHONLIBS_FOUND) message(FATAL_ERROR "python bindings were requested (ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.") endif() -# # Checks for header files. -# AC_HEADER_ASSERT -# AC_CHECK_HEADERS([ \ -# arpa/inet.h \ -# fcntl.h \ -# inttypes.h \ -# limits.h \ -# netdb.h \ -# netinet/in.h \ -# pwd.h \ -# stddef.h \ -# stdint.h \ -# stdlib.h \ -# string.h \ -# sys/socket.h \ -# sys/time.h \ -# syslog.h \ -# time.h \ -# unistd.h \ -# ]) -# -# # Checks for typedefs, structures, and compiler characteristics. +# Checks for header files. +# XXX AC_HEADER_ASSERT adds --disable-assert which sets -DNDEBUG +check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) +check_include_file("fcntl.h" HAVE_FCNTL_H) +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file("limits.h" HAVE_LIMITS_H) +check_include_file("netdb.h" HAVE_NETDB_H) +check_include_file("netinet/in.h" HAVE_NETINET_IN_H) +check_include_file("pwd.h" HAVE_PWD_H) +check_include_file("stddef.h" HAVE_STDDEF_H) +check_include_file("stdint.h" HAVE_STDINT_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) +check_include_file("sys/time.h" HAVE_SYS_TIME_H) +check_include_file("syslog.h" HAVE_SYSLOG_H) +check_include_file("time.h" HAVE_TIME_H) +check_include_file("unistd.h" HAVE_UNISTD_H) + +# Checks for typedefs, structures, and compiler characteristics. # AC_TYPE_SIZE_T # AC_TYPE_SSIZE_T # AC_TYPE_UINT8_T @@ -309,21 +307,15 @@ endif() # AC_C_BIGENDIAN # AC_C_INLINE # AC_SYS_LARGEFILE -# -# AC_CHECK_MEMBER([struct tm.tm_gmtoff], [have_struct_tm_tm_gmtoff=yes], -# [have_struct_tm_tm_gmtoff=no], [[#include ]]) -# -# if test "x$have_struct_tm_tm_gmtoff" = "xyes"; then -# AC_DEFINE([HAVE_STRUCT_TM_TM_GMTOFF], [1], -# [Define to 1 if you have `struct tm.tm_gmtoff` member.]) -# fi -# -# # Check size of pointer to decide we need 8 bytes alignment -# # adjustment. -# AC_CHECK_SIZEOF([int *]) -# -# AC_CHECK_SIZEOF([time_t]) -# + +include(CheckStructHasMember) +CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) + +# Check size of pointer to decide we need 8 bytes alignment adjustment. +include(CheckTypeSize) +check_type_size("int *" SIZEOF_INT_P) +check_type_size("time_t" SIZEOF_TIME_T) + # # Checks for library functions. # # # Don't check malloc, since it does not play nicely with C++ stdlib diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index ef630402..bf92330b 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -16,3 +16,9 @@ /* Define to 1 if you have `neverbleed` library. */ #cmakedefine HAVE_NEVERBLEED 1 + +/* sizeof(int *) */ +#cmakedefine SIZEOF_INT_P @SIZEOF_INT_P@ + +/* sizeof(time_t) */ +#cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@ From 5819d03c684467b6767b25d6c92c59b5f128da16 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 17:12:10 +0100 Subject: [PATCH 04/59] cmake: more functions AC_CHECK_TYPES and AC_C_BIGENDIAN were removed because nothing checks the resulting macros... --- CMakeLists.txt | 78 ++++++++++++++---------------------------------- cmakeconfig.h.in | 9 ++++++ 2 files changed, 32 insertions(+), 55 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb53879e..cb6a1bdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,6 +272,7 @@ endif() # Checks for header files. # XXX AC_HEADER_ASSERT adds --disable-assert which sets -DNDEBUG +include(CheckIncludeFile) check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) check_include_file("fcntl.h" HAVE_FCNTL_H) check_include_file("inttypes.h" HAVE_INTTYPES_H) @@ -290,6 +291,8 @@ check_include_file("time.h" HAVE_TIME_H) check_include_file("unistd.h" HAVE_UNISTD_H) # Checks for typedefs, structures, and compiler characteristics. +# XXX The AC_TYPE_* macros would define suitable types if standard headers do +# not define them. No equivalent in cmake... # AC_TYPE_SIZE_T # AC_TYPE_SSIZE_T # AC_TYPE_UINT8_T @@ -303,10 +306,10 @@ check_include_file("unistd.h" HAVE_UNISTD_H) # AC_TYPE_OFF_T # AC_TYPE_PID_T # AC_TYPE_UID_T -# AC_CHECK_TYPES([ptrdiff_t]) -# AC_C_BIGENDIAN +# XXX To support inline for crappy compilers, see https://cmake.org/Wiki/CMakeTestInline # AC_C_INLINE -# AC_SYS_LARGEFILE +# XXX is AC_SYS_LARGEFILE still needed for modern systems? +# add_definitions(-D_FILE_OFFSET_BITS=64) include(CheckStructHasMember) CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) @@ -316,58 +319,23 @@ include(CheckTypeSize) check_type_size("int *" SIZEOF_INT_P) check_type_size("time_t" SIZEOF_TIME_T) -# # Checks for library functions. -# -# # Don't check malloc, since it does not play nicely with C++ stdlib -# # AC_FUNC_MALLOC -# -# AC_FUNC_CHOWN -# AC_FUNC_ERROR_AT_LINE -# AC_FUNC_FORK -# # Don't check realloc, since LeakSanitizer detects memory leak during check -# # AC_FUNC_REALLOC -# AC_FUNC_STRERROR_R -# AC_FUNC_STRNLEN -# -# AC_CHECK_FUNCS([ \ -# _Exit \ -# accept4 \ -# dup2 \ -# getcwd \ -# getpwnam \ -# localtime_r \ -# memchr \ -# memmove \ -# memset \ -# socket \ -# sqrt \ -# strchr \ -# strdup \ -# strerror \ -# strndup \ -# strstr \ -# strtol \ -# strtoul \ -# timegm \ -# ]) -# -# # timerfd_create was added in linux kernel 2.6.25 -# -# AC_CHECK_FUNC([timerfd_create], -# [have_timerfd_create=yes], [have_timerfd_create=no]) -# -# # For cygwin: we can link initgroups, so AC_CHECK_FUNCS succeeds, but -# # cygwin disables initgroups due to feature test macro magic with our -# # configuration. -# AC_CHECK_DECLS([initgroups], [], [], [[#include ]]) -# -# # Checks for epoll availability, primarily for examples/tiny-nghttpd -# AX_HAVE_EPOLL([have_epoll=yes], [have_epoll=no]) -# -# AM_CONDITIONAL([ENABLE_TINY_NGHTTPD], -# [ test "x${have_epoll}" = "xyes" && -# test "x${have_timerfd_create}" = "xyes"]) -# +# Checks for library functions. +include(CheckFunctionExists) +CHECK_FUNCTION_EXISTS(_Exit HAVE__EXIT) +CHECK_FUNCTION_EXISTS(accept4 HAVE_ACCEPT4) + +# timerfd_create was added in linux kernel 2.6.25 +include(CheckSymbolExists) +# XXX does this correctly detect initgroups (un)availability on cygwin? +CHECK_SYMBOL_EXISTS(initgroups grp.h HAVE_DECL_INITGROUPS) + +CHECK_FUNCTION_EXISTS(timerfd_create HAVE_TIMERFD_CREATE) +# Checks for epoll availability, primarily for examples/tiny-nghttpd +CHECK_SYMBOL_EXISTS(epoll_create sys/epoll.h HAVE_EPOLL) +if(HAVE_EPOLL AND HAVE_TIMERFD_CREATE) + set(ENABLE_TINY_NGHTTPD 1) +endif() + # save_CFLAGS=$CFLAGS # save_CXXFLAGS=$CXXFLAGS # diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index bf92330b..1d3c48f7 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -22,3 +22,12 @@ /* sizeof(time_t) */ #cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@ + +/* Define to 1 if you have the `_Exit` function. */ +#cmakedefine HAVE__EXIT 1 + +/* Define to 1 if you have the `accept4` function. */ +#cmakedefine HAVE_ACCEPT4 1 + +/* Define to 1 if you have the `initgroups` function. */ +#define HAVE_DECL_INITGROUPS @HAVE_DECL_INITGROUPS@ From 147e098827e8d0ef32765f5876abd38f473ee7b4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 17:54:30 +0100 Subject: [PATCH 05/59] cmake: test for warning flags --- CMakeLists.txt | 167 ++++++++++++++++------------------ cmake/ExtractValidFlags.cmake | 31 +++++++ cmakeconfig.h.in | 3 + 3 files changed, 111 insertions(+), 90 deletions(-) create mode 100644 cmake/ExtractValidFlags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index cb6a1bdd..b01bb9ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,8 +101,8 @@ endif() include(CheckCXXCompilerFlag) foreach(_std gnu++11 gnu++0x) set(_cxx1x_flag -std=${_std}) - CHECK_CXX_COMPILER_FLAG(${_cxx1x_flag} CXX_STD_${_std}) - if(CXX_STD_${_std}) + check_cxx_compiler_flag(${_cxx1x_flag} CXX_FLAG_-std_${_std}) + if(CXX_FLAG_-std_${_std}) set(CXX1XCXXFLAGS ${_cxx1x_flag}) break() endif() @@ -113,12 +113,12 @@ include(CheckCXXSourceCompiles) cmake_push_check_state() set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${CXX1XCXXFLAGS}") # Check that std::future is available. -CHECK_CXX_SOURCE_COMPILES(" +check_cxx_source_compiles(" #include #include int main() { std::vector> v; }" HAVE_STD_FUTURE) # Check that std::map::emplace is available for g++-4.7. -CHECK_CXX_SOURCE_COMPILES(" +check_cxx_source_compiles(" #include int main() { std::map().emplace(1, 2); }" HAVE_STD_MAP_EMPLACE) cmake_pop_check_state() @@ -312,7 +312,7 @@ check_include_file("unistd.h" HAVE_UNISTD_H) # add_definitions(-D_FILE_OFFSET_BITS=64) include(CheckStructHasMember) -CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) +check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) # Check size of pointer to decide we need 8 bytes alignment adjustment. include(CheckTypeSize) @@ -321,101 +321,88 @@ check_type_size("time_t" SIZEOF_TIME_T) # Checks for library functions. include(CheckFunctionExists) -CHECK_FUNCTION_EXISTS(_Exit HAVE__EXIT) -CHECK_FUNCTION_EXISTS(accept4 HAVE_ACCEPT4) +check_function_exists(_Exit HAVE__EXIT) +check_function_exists(accept4 HAVE_ACCEPT4) # timerfd_create was added in linux kernel 2.6.25 include(CheckSymbolExists) # XXX does this correctly detect initgroups (un)availability on cygwin? -CHECK_SYMBOL_EXISTS(initgroups grp.h HAVE_DECL_INITGROUPS) +check_symbol_exists(initgroups grp.h HAVE_DECL_INITGROUPS) -CHECK_FUNCTION_EXISTS(timerfd_create HAVE_TIMERFD_CREATE) +check_function_exists(timerfd_create HAVE_TIMERFD_CREATE) # Checks for epoll availability, primarily for examples/tiny-nghttpd -CHECK_SYMBOL_EXISTS(epoll_create sys/epoll.h HAVE_EPOLL) +check_symbol_exists(epoll_create sys/epoll.h HAVE_EPOLL) if(HAVE_EPOLL AND HAVE_TIMERFD_CREATE) set(ENABLE_TINY_NGHTTPD 1) endif() -# save_CFLAGS=$CFLAGS -# save_CXXFLAGS=$CXXFLAGS -# -# CFLAGS= -# CXXFLAGS= -# -# if test "x$werror" != "xno"; then -# # For C compiler -# AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"]) -# AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS="$CFLAGS -Wextra"]) -# AX_CHECK_COMPILE_FLAG([-Werror], [CFLAGS="$CFLAGS -Werror"]) -# AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CFLAGS="$CFLAGS -Wmissing-prototypes"]) -# AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], [CFLAGS="$CFLAGS -Wstrict-prototypes"]) -# AX_CHECK_COMPILE_FLAG([-Wmissing-declarations], [CFLAGS="$CFLAGS -Wmissing-declarations"]) -# AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"]) -# AX_CHECK_COMPILE_FLAG([-Wdeclaration-after-statement], [CFLAGS="$CFLAGS -Wdeclaration-after-statement"]) -# AX_CHECK_COMPILE_FLAG([-Wformat-security], [CFLAGS="$CFLAGS -Wformat-security"]) -# AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"]) -# AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"]) -# AX_CHECK_COMPILE_FLAG([-Winline], [CFLAGS="$CFLAGS -Winline"]) -# AX_CHECK_COMPILE_FLAG([-Wnested-externs], [CFLAGS="$CFLAGS -Wnested-externs"]) -# AX_CHECK_COMPILE_FLAG([-Wfloat-equal], [CFLAGS="$CFLAGS -Wfloat-equal"]) -# AX_CHECK_COMPILE_FLAG([-Wundef], [CFLAGS="$CFLAGS -Wundef"]) -# AX_CHECK_COMPILE_FLAG([-Wendif-labels], [CFLAGS="$CFLAGS -Wendif-labels"]) -# AX_CHECK_COMPILE_FLAG([-Wempty-body], [CFLAGS="$CFLAGS -Wempty-body"]) -# AX_CHECK_COMPILE_FLAG([-Wcast-align], [CFLAGS="$CFLAGS -Wcast-align"]) -# AX_CHECK_COMPILE_FLAG([-Wclobbered], [CFLAGS="$CFLAGS -Wclobbered"]) -# AX_CHECK_COMPILE_FLAG([-Wvla], [CFLAGS="$CFLAGS -Wvla"]) -# AX_CHECK_COMPILE_FLAG([-Wpragmas], [CFLAGS="$CFLAGS -Wpragmas"]) -# AX_CHECK_COMPILE_FLAG([-Wunreachable-code], [CFLAGS="$CFLAGS -Wunreachable-code"]) -# AX_CHECK_COMPILE_FLAG([-Waddress], [CFLAGS="$CFLAGS -Waddress"]) -# AX_CHECK_COMPILE_FLAG([-Wattributes], [CFLAGS="$CFLAGS -Wattributes"]) -# AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"]) -# AX_CHECK_COMPILE_FLAG([-Wshorten-64-to-32], [CFLAGS="$CFLAGS -Wshorten-64-to-32"]) -# -# AX_CHECK_COMPILE_FLAG([-Wconversion], [CFLAGS="$CFLAGS -Wconversion"]) -# AX_CHECK_COMPILE_FLAG([-Wextended-offsetof], [CFLAGS="$CFLAGS -Wextended-offsetof"]) -# AX_CHECK_COMPILE_FLAG([-Wformat-nonliteral], [CFLAGS="$CFLAGS -Wformat-nonliteral"]) -# AX_CHECK_COMPILE_FLAG([-Wlanguage-extension-token], [CFLAGS="$CFLAGS -Wlanguage-extension-token"]) -# AX_CHECK_COMPILE_FLAG([-Wmissing-field-initializers], [CFLAGS="$CFLAGS -Wmissing-field-initializers"]) -# AX_CHECK_COMPILE_FLAG([-Wmissing-noreturn], [CFLAGS="$CFLAGS -Wmissing-noreturn"]) -# AX_CHECK_COMPILE_FLAG([-Wmissing-variable-declarations], [CFLAGS="$CFLAGS -Wmissing-variable-declarations"]) -# # Not used because we cannot change public structs -# # AX_CHECK_COMPILE_FLAG([-Wpadded], [CFLAGS="$CFLAGS -Wpadded"]) -# AX_CHECK_COMPILE_FLAG([-Wsign-conversion], [CFLAGS="$CFLAGS -Wsign-conversion"]) -# # Not used because this basically disallows default case -# # AX_CHECK_COMPILE_FLAG([-Wswitch-enum], [CFLAGS="$CFLAGS -Wswitch-enum"]) -# AX_CHECK_COMPILE_FLAG([-Wunreachable-code-break], [CFLAGS="$CFLAGS -Wunreachable-code-break"]) -# AX_CHECK_COMPILE_FLAG([-Wunused-macros], [CFLAGS="$CFLAGS -Wunused-macros"]) -# AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [CFLAGS="$CFLAGS -Wunused-parameter"]) -# AX_CHECK_COMPILE_FLAG([-Wredundant-decls], [CFLAGS="$CFLAGS -Wredundant-decls"]) -# # Only work with Clang for the moment -# AX_CHECK_COMPILE_FLAG([-Wheader-guard], [CFLAGS="$CFLAGS -Wheader-guard"]) -# -# # For C++ compiler -# AC_LANG_PUSH(C++) -# AX_CHECK_COMPILE_FLAG([-Wall], [CXXFLAGS="$CXXFLAGS -Wall"]) -# AX_CHECK_COMPILE_FLAG([-Werror], [CXXFLAGS="$CXXFLAGS -Werror"]) -# AX_CHECK_COMPILE_FLAG([-Wformat-security], [CXXFLAGS="$CXXFLAGS -Wformat-security"]) -# AC_LANG_POP() -# fi -# -# WARNCFLAGS=$CFLAGS -# WARNCXXFLAGS=$CXXFLAGS -# -# CFLAGS=$save_CFLAGS -# CXXFLAGS=$save_CXXFLAGS -# -# AC_SUBST([WARNCFLAGS]) -# AC_SUBST([WARNCXXFLAGS]) -# -# EXTRACFLAG= -# AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [EXTRACFLAG="-fvisibility=hidden"]) -# -# AC_SUBST([EXTRACFLAG]) -# -# if test "x$debug" != "xno"; then -# AC_DEFINE([DEBUGBUILD], [1], [Define to 1 to enable debug output.]) -# fi -# +include(ExtractValidFlags) +if(ENABLE_WERROR) + # For C compiler + extract_valid_c_flags(WARNCFLAGS + -Wall + -Wextra + -Werror + -Wmissing-prototypes + -Wstrict-prototypes + -Wmissing-declarations + -Wpointer-arith + -Wdeclaration-after-statement + -Wformat-security + -Wwrite-strings + -Wshadow + -Winline + -Wnested-externs + -Wfloat-equal + -Wundef + -Wendif-labels + -Wempty-body + -Wcast-align + -Wclobbered + -Wvla + -Wpragmas + -Wunreachable-code + -Waddress + -Wattributes + -Wdiv-by-zero + -Wshorten-64-to-32 + + -Wconversion + -Wextended-offsetof + -Wformat-nonliteral + -Wlanguage-extension-token + -Wmissing-field-initializers + -Wmissing-noreturn + -Wmissing-variable-declarations + # Not used because we cannot change public structs + # -Wpadded + -Wsign-conversion + # Not used because this basically disallows default case + # -Wswitch-enum + -Wunreachable-code-break + -Wunused-macros + -Wunused-parameter + -Wredundant-decls + # Only work with Clang for the moment + -Wheader-guard + ) + + extract_valid_cxx_flags(WARNCXXFLAGS + # For C++ compiler + -Wall + -Werror + -Wformat-security + ) +endif() + +extract_valid_c_flags(EXTRACFLAG + -fvisibility=hidden +) + +if(ENABLE_DEBUG) + set(DEBUGBUILD 1) +endif() + # enable_threads=yes # # Some platform does not have working std::future. We disable # # threading for those platforms. diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake new file mode 100644 index 00000000..47a6c2b2 --- /dev/null +++ b/cmake/ExtractValidFlags.cmake @@ -0,0 +1,31 @@ +# Convenience function that checks the availability +# of certain C or C++ compiler flags and returns the valid ones. + +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +function(extract_valid_c_flags varname) + set(valid_flags "") + foreach(flag IN LISTS ARGN) + string(REGEX REPLACE "[^a-zA-Z0-9_-]+" "_" flag_var ${flag}) + set(flag_var "C_FLAG_${flag_var}") + check_c_compiler_flag("${flag}" "${flag_var}") + if(${flag_var}) + set(valid_flags "${valid_flags} ${flag}") + endif() + endforeach() + set(${varname} "${valid_flags}" PARENT_SCOPE) +endfunction() + +function(extract_valid_cxx_flags varname) + set(valid_flags "") + foreach(flag IN LISTS ARGN) + string(REGEX REPLACE "[^a-zA-Z0-9_-]+" "_" flag_var ${flag}) + set(flag_var "CXX_FLAG_${flag_var}") + check_cxx_compiler_flag("${flag}" "${flag_var}") + if(${flag_var}) + set(valid_flags "${valid_flags} ${flag}") + endif() + endforeach() + set(${varname} "${valid_flags}" PARENT_SCOPE) +endfunction() diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 1d3c48f7..4563df5b 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -31,3 +31,6 @@ /* Define to 1 if you have the `initgroups` function. */ #define HAVE_DECL_INITGROUPS @HAVE_DECL_INITGROUPS@ + +/* Define to 1 to enable debug output. */ +#cmakedefine DEBUGBUILD 1 From 900667a9987a11dfb6cb9df32d371ce350744b1c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 18:06:21 +0100 Subject: [PATCH 06/59] cmake: moar .in file via configure_file --- CMakeLists.txt | 81 ++++++++++++++++++++++++++++-------------------- cmakeconfig.h.in | 5 ++- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b01bb9ee..a15fc90e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,57 +403,72 @@ if(ENABLE_DEBUG) set(DEBUGBUILD 1) endif() -# enable_threads=yes -# # Some platform does not have working std::future. We disable -# # threading for those platforms. -# if test "x$threads" != "xyes" || -# test "x$have_std_future" != "xyes"; then -# enable_threads=no -# AC_DEFINE([NOTHREADS], [1], [Define to 1 if you want to disable threads.]) -# fi -# +# Some platform does not have working std::future. We disable +# threading for those platforms. +if(NOT ENABLE_THREADS OR NOT HAVE_STD_FUTURE) + set(NOTHREADS 1) +endif() + # # propagate $enable_static to tests/Makefile.am # AM_CONDITIONAL([ENABLE_STATIC], [test "x$enable_static" = "xyes"]) # # AC_SUBST([TESTLDADD]) # AC_SUBST([APPLDFLAGS]) -# + +configure_file(cmakeconfig.h.in config.h) +# autotools-compatible names +set(top_srcdir "${CMAKE_SOURCE_DIR}") +set(top_builddir "${CMAKE_BINARY_DIR}") +set(abs_top_srcdir "${CMAKE_SOURCE_DIR}") +set(abs_top_builddir "${CMAKE_BINARY_DIR}") +set(prefix "") +set(exec_prefix "") +set(libdir "") +set(includedir "") +set(bindir "") +set(sbindir "") +set(VERSION "${PACKAGE_VERSION}") +foreach(name + lib/libnghttp2.pc + lib/includes/nghttp2/nghttp2ver.h + src/libnghttp2_asio.pc + python/setup.py + integration-tests/config.go + integration-tests/setenv + doc/conf.py + doc/index.rst + doc/package_README.rst + doc/tutorial-client.rst + doc/tutorial-server.rst + doc/tutorial-hpack.rst + doc/nghttpx-howto.rst + doc/h2load-howto.rst + doc/libnghttp2_asio.rst + doc/python-apiref.rst + doc/building-android-binary.rst + doc/nghttp2.h.rst + doc/nghttp2ver.h.rst + doc/asio_http2.h.rst + doc/asio_http2_server.h.rst + doc/asio_http2_client.h.rst + doc/contribute.rst +) + configure_file("${name}.in" "${name}" @ONLY) +endforeach() + # AC_CONFIG_FILES([ # Makefile # lib/Makefile -# lib/libnghttp2.pc # lib/includes/Makefile -# lib/includes/nghttp2/nghttp2ver.h # tests/Makefile # tests/testdata/Makefile # third-party/Makefile # src/Makefile # src/includes/Makefile -# src/libnghttp2_asio.pc # examples/Makefile # python/Makefile -# python/setup.py # integration-tests/Makefile -# integration-tests/config.go -# integration-tests/setenv # doc/Makefile -# doc/conf.py -# doc/index.rst -# doc/package_README.rst -# doc/tutorial-client.rst -# doc/tutorial-server.rst -# doc/tutorial-hpack.rst -# doc/nghttpx-howto.rst -# doc/h2load-howto.rst -# doc/libnghttp2_asio.rst -# doc/python-apiref.rst -# doc/building-android-binary.rst -# doc/nghttp2.h.rst -# doc/nghttp2ver.h.rst -# doc/asio_http2.h.rst -# doc/asio_http2_server.h.rst -# doc/asio_http2_client.h.rst -# doc/contribute.rst # contrib/Makefile # script/Makefile # ]) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 4563df5b..353ff477 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -30,7 +30,10 @@ #cmakedefine HAVE_ACCEPT4 1 /* Define to 1 if you have the `initgroups` function. */ -#define HAVE_DECL_INITGROUPS @HAVE_DECL_INITGROUPS@ +#cmakedefine01 HAVE_DECL_INITGROUPS /* Define to 1 to enable debug output. */ #cmakedefine DEBUGBUILD 1 + +/* Define to 1 if you want to disable threads. */ +#cmakedefine NOTHREADS 1 From 3842fe175c3abed3b2c2691e2d0a89f8788196af Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 18:19:45 +0100 Subject: [PATCH 07/59] cmake: attempt to get diagnostic output right --- CMakeLists.txt | 164 ++++++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a15fc90e..70584f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,11 @@ cmake_pop_check_state() # esac pkg_check_modules(ZLIB zlib>=1.2.3) +if(ZLIB_FOUND) + set(HAVE_ZLIB 1) +else() + set(HAVE_ZLIB 0) +endif() # # dl: openssl requires libdl when it is statically linked. # case "${host_os}" in @@ -189,17 +194,34 @@ pkg_check_modules(CUNIT cunit>=2.1) # libev (for src) find_package(Libev) +if(Libev_FOUND) + set(HAVE_LIBEV 1) +else() + set(HAVE_LIBEV 0) +endif() # openssl (for src) pkg_check_modules(OPENSSL openssl>=1.0.1) +if(OPENSSL_FOUND) + set(HAVE_OPENSSL 1) +else() + set(HAVE_OPENSSL 0) +endif() # libevent_openssl (for examples) # 2.0.8 is required because we use evconnlistener_set_error_cb() pkg_check_modules(LIBEVENT_OPENSSL libevent_openssl>=2.0.8) +if(LIBEVENT_OPENSSL_FOUND) + set(HAVE_LIBEVENT_OPENSSL 1) +else() + set(HAVE_LIBEVENT_OPENSSL 0) +endif() # jansson (for src/nghttp, src/deflatehd and src/inflatehd) pkg_check_modules(JANSSON jansson>=2.5) if(JANSSON_FOUND) set(HAVE_JANSSON 1) +else() + set(HAVE_JANSSON 0) endif() # libxml2 (for src/nghttp) @@ -207,6 +229,8 @@ if(WITH_LIBXML2) find_package(LibXml2 2.7.7 REQUIRED) set(HAVE_LIBXML2 1) # XXX fail if WITH_LIBXML2=ON +else() + set(HAVE_LIBXML2 0) endif() # jemalloc @@ -215,6 +239,13 @@ if(WITH_JEMALLOC) if(NOT JEMALLOC_FOUND) find_package(jemalloc REQUIRED) endif() + if(JEMALLOC_FOUND) + set(HAVE_JEMALLOC 1) + else() + set(HAVE_JEMALLOC 0) + endif() +else() + set(HAVE_JEMALLOC 0) endif() # spdylay (for src/nghttpx and src/h2load) @@ -223,9 +254,12 @@ if(WITH_SPDYLAY) 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 +else() + set(HAVE_SPDYLAY 0) endif() if(ENABLE_ASIO_LIB) @@ -254,10 +288,17 @@ if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB) if(WITH_MRUBY) set(HAVE_MRUBY 1) # XXX add -lmruby and -lm libs + else() + set(HAVE_MRUBY 0) endif() if(WITH_NEVERBLEED) set(HAVE_NEVERBLEED 1) + else() + set(HAVE_NEVERBLEED 0) endif() +else() + set(HAVE_MRUBY 0) + set(HAVE_NEVERBLEED 0) endif() # Python bindings @@ -473,66 +514,63 @@ endforeach() # script/Makefile # ]) # AC_OUTPUT -# -# AC_MSG_NOTICE([summary of build options: -# -# Package version: ${VERSION} -# Library version: $LT_CURRENT:$LT_REVISION:$LT_AGE -# Install prefix: ${prefix} -# System types: -# Build: ${build} -# Host: ${host} -# Target: ${target} -# Compiler: -# C compiler: ${CC} -# CFLAGS: ${CFLAGS} -# LDFLAGS: ${LDFLAGS} -# C++ compiler: ${CXX} -# CXXFLAGS: ${CXXFLAGS} -# CXXCPP: ${CXXCPP} -# C preprocessor: ${CPP} -# CPPFLAGS: ${CPPFLAGS} -# WARNCFLAGS: ${WARNCFLAGS} -# CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} -# EXTRACFLAG: ${EXTRACFLAG} -# LIBS: ${LIBS} -# Library: -# Shared: ${enable_shared} -# Static: ${enable_static} -# Python: -# Python: ${PYTHON} -# PYTHON_VERSION: ${PYTHON_VERSION} -# pyexecdir: ${pyexecdir} -# Python-dev: ${have_python_dev} -# PYTHON_CPPFLAGS:${PYTHON_CPPFLAGS} -# PYTHON_LDFLAGS: ${PYTHON_LDFLAGS} -# Cython: ${CYTHON} -# Test: -# CUnit: ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') -# Failmalloc: ${enable_failmalloc} -# Libs: -# OpenSSL: ${have_openssl} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') -# Libxml2: ${have_libxml2} (CFLAGS='${XML_CPPFLAGS}' LIBS='${XML_LIBS}') -# Libev: ${have_libev} (CFLAGS='${LIBEV_CFLAGS}' LIBS='${LIBEV_LIBS}') -# Libevent(SSL): ${have_libevent_openssl} (CFLAGS='${LIBEVENT_OPENSSL_CFLAGS}' LIBS='${LIBEVENT_OPENSSL_LIBS}') -# Spdylay: ${have_spdylay} (CFLAGS='${LIBSPDYLAY_CFLAGS}' LIBS='${LIBSPDYLAY_LIBS}') -# Jansson: ${have_jansson} (CFLAGS='${JANSSON_CFLAGS}' LIBS='${JANSSON_LIBS}') -# Jemalloc: ${have_jemalloc} (LIBS='${JEMALLOC_LIBS}') -# Zlib: ${have_zlib} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') -# Boost CPPFLAGS: ${BOOST_CPPFLAGS} -# Boost LDFLAGS: ${BOOST_LDFLAGS} -# Boost::ASIO: ${BOOST_ASIO_LIB} -# Boost::System: ${BOOST_SYSTEM_LIB} -# Boost::Thread: ${BOOST_THREAD_LIB} -# Third-party: -# http-parser: ${enable_third_party} -# MRuby: ${have_mruby} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') -# Neverbleed: ${have_neverbleed} -# Features: -# Applications: ${enable_app} -# HPACK tools: ${enable_hpack_tools} -# Libnghttp2_asio:${enable_asio_lib} -# Examples: ${enable_examples} -# Python bindings:${enable_python_bindings} -# Threading: ${enable_threads} -# ]) + +# XXX - fix list of variables +message(STATUS "summary of build options: + + Package version: ${VERSION} + Library version: $LT_CURRENT:$LT_REVISION:$LT_AGE + Install prefix: ${prefix} + System types: + Build: ${build} + Host: ${host} + Target: ${target} + Compiler: + C compiler: ${CMAKE_C_COMPILER} + CFLAGS: ${CMAKE_C_FLAGS} + C++ compiler: ${CMAKE_CXX_COMPILER} + CXXFLAGS: ${CMAKE_CXX_FLAGS} + WARNCFLAGS: ${WARNCFLAGS} + CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} + EXTRACFLAG: ${EXTRACFLAG} + LIBS: ${LIBS} + Library: + Shared: ${enable_shared} + Static: ${enable_static} + Python: + Python: ${PYTHON} + PYTHON_VERSION: ${PYTHON_VERSION} + pyexecdir: ${pyexecdir} + Python-dev: ${have_python_dev} + PYTHON_CPPFLAGS:${PYTHON_CPPFLAGS} + PYTHON_LDFLAGS: ${PYTHON_LDFLAGS} + Cython: ${CYTHON} + Test: + CUnit: ${HAVE_CUNIT} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') + Failmalloc: ${ENABLE_FAILMALLOC} + Libs: + OpenSSL: ${HAVE_OPENSSL} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') + Libxml2: ${HAVE_LIBXML2} (CFLAGS='${XML_CPPFLAGS}' LIBS='${XML_LIBS}') + Libev: ${HAVE_LIBEV} (CFLAGS='${LIBEV_CFLAGS}' LIBS='${LIBEV_LIBS}') + Libevent(SSL): ${HAVE_LIBEVENT_OPENSSL} (CFLAGS='${LIBEVENT_OPENSSL_CFLAGS}' LIBS='${LIBEVENT_OPENSSL_LIBS}') + Spdylay: ${HAVE_SPDYLAY} (CFLAGS='${LIBSPDYLAY_CFLAGS}' LIBS='${LIBSPDYLAY_LIBS}') + Jansson: ${HAVE_JANSSON} (CFLAGS='${JANSSON_CFLAGS}' LIBS='${JANSSON_LIBS}') + Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBS}') + Zlib: ${HAVE_ZLIB} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') + Boost CPPFLAGS: ${BOOST_CPPFLAGS} + Boost LDFLAGS: ${BOOST_LDFLAGS} + Boost::ASIO: ${BOOST_ASIO_LIB} + Boost::System: ${BOOST_SYSTEM_LIB} + Boost::Thread: ${BOOST_THREAD_LIB} + Third-party: + http-parser: ${ENABLE_THIRD_PARTY} + MRuby: ${HAVE_MRUBY} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') + Neverbleed: ${HAVE_NEVERBLEED} + Features: + Applications: ${ENABLE_APP} + HPACK tools: ${ENABLE_HPACK_TOOLS} + Libnghttp2_asio:${ENABLE_ASIO_LIB} + Examples: ${ENABLE_EXAMPLES} + Python bindings:${ENABLE_PYTHON_BINDINGS} + Threading: ${ENABLE_THREADS} +") From 744e80d5796dde8fa2e3e7288cc906b87000ef7f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 18:42:40 +0100 Subject: [PATCH 08/59] cmake: Fill in auto-tools compatible paths --- CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70584f91..d7164fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,13 +462,15 @@ set(top_srcdir "${CMAKE_SOURCE_DIR}") set(top_builddir "${CMAKE_BINARY_DIR}") set(abs_top_srcdir "${CMAKE_SOURCE_DIR}") set(abs_top_builddir "${CMAKE_BINARY_DIR}") -set(prefix "") -set(exec_prefix "") -set(libdir "") -set(includedir "") -set(bindir "") -set(sbindir "") +# libnghttp2.pc (pkg-config file) +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "\${prefix}") +set(libdir "\${prefix}/lib") +set(includedir "\${prefix}/include") set(VERSION "${PACKAGE_VERSION}") +# For init scripts and systemd service file +set(bindir "${prefix}/bin") +set(sbindir "${prefix}/sbin") foreach(name lib/libnghttp2.pc lib/includes/nghttp2/nghttp2ver.h From 5b21c39bb2b2cb52f280fc9aab81b17858c84a64 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 22:11:14 +0100 Subject: [PATCH 09/59] cmake: add lib, add versioning info, install lib Also remove some headers which were not checked anyway and add macros to cmakeconfig.h.in (based on the headers list in the CMakeLists.txt file). --- CMakeLists.txt | 59 +++++++++++++++++++++++++--------------------- cmakeconfig.h.in | 36 ++++++++++++++++++++++++++++ lib/CMakeLists.txt | 37 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 lib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d7164fa3..06719bf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,12 +26,20 @@ cmake_minimum_required(VERSION 3.0) # XXX using 1.7.90 instead of 1.8.0-DEV project(nghttp2 VERSION 1.7.90) +# See versioning rule: +# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +set(LT_CURRENT 18) +set(LT_REVISION 1) +set(LT_AGE 4) + set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(Version) set(PACKAGE_VERSION "${PROJECT_VERSION}") HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) +include(GNUInstallDirs) + option(ENABLE_WERROR "Turn on compile time warnings") option(ENABLE_DEBUG "Turn on debug output") option(ENABLE_THREADS "Turn on threading in apps" ON) @@ -321,10 +329,6 @@ check_include_file("limits.h" HAVE_LIMITS_H) check_include_file("netdb.h" HAVE_NETDB_H) check_include_file("netinet/in.h" HAVE_NETINET_IN_H) check_include_file("pwd.h" HAVE_PWD_H) -check_include_file("stddef.h" HAVE_STDDEF_H) -check_include_file("stdint.h" HAVE_STDINT_H) -check_include_file("stdlib.h" HAVE_STDLIB_H) -check_include_file("string.h" HAVE_STRING_H) check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) check_include_file("sys/time.h" HAVE_SYS_TIME_H) check_include_file("syslog.h" HAVE_SYSLOG_H) @@ -456,6 +460,7 @@ endif() # AC_SUBST([TESTLDADD]) # AC_SUBST([APPLDFLAGS]) +add_definitions(-DHAVE_CONFIG_H) configure_file(cmakeconfig.h.in config.h) # autotools-compatible names set(top_srcdir "${CMAKE_SOURCE_DIR}") @@ -464,13 +469,13 @@ set(abs_top_srcdir "${CMAKE_SOURCE_DIR}") set(abs_top_builddir "${CMAKE_BINARY_DIR}") # libnghttp2.pc (pkg-config file) set(prefix "${CMAKE_INSTALL_PREFIX}") -set(exec_prefix "\${prefix}") -set(libdir "\${prefix}/lib") -set(includedir "\${prefix}/include") +set(exec_prefix "${CMAKE_INSTALL_PREFIX}") +set(libdir "${CMAKE_INSTALL_LIBDIR}") +set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") set(VERSION "${PACKAGE_VERSION}") # For init scripts and systemd service file -set(bindir "${prefix}/bin") -set(sbindir "${prefix}/sbin") +set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") +set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}") foreach(name lib/libnghttp2.pc lib/includes/nghttp2/nghttp2ver.h @@ -499,29 +504,29 @@ foreach(name configure_file("${name}.in" "${name}" @ONLY) endforeach() -# AC_CONFIG_FILES([ -# Makefile -# lib/Makefile -# lib/includes/Makefile -# tests/Makefile -# tests/testdata/Makefile -# third-party/Makefile -# src/Makefile -# src/includes/Makefile -# examples/Makefile -# python/Makefile -# integration-tests/Makefile -# doc/Makefile -# contrib/Makefile -# script/Makefile -# ]) -# AC_OUTPUT + +add_subdirectory(lib) +#add_subdirectory(lib/includes) +if(0) +add_subdirectory(third-party) +add_subdirectory(src) +#add_subdirectory(src/includes) +add_subdirectory(examples) +add_subdirectory(python) +add_subdirectory(tests) +#add_subdirectory(tests/testdata) +add_subdirectory(integration-tests) +add_subdirectory(doc) +add_subdirectory(contrib) +add_subdirectory(script) +endif() + # XXX - fix list of variables message(STATUS "summary of build options: Package version: ${VERSION} - Library version: $LT_CURRENT:$LT_REVISION:$LT_AGE + Library version: ${LT_CURRENT}:${LT_REVISION}:${LT_AGE} Install prefix: ${prefix} System types: Build: ${build} diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 353ff477..d7db50f3 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -37,3 +37,39 @@ /* Define to 1 if you want to disable threads. */ #cmakedefine NOTHREADS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PWD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 00000000..7b4d5e3e --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,37 @@ +include_directories( + "${CMAKE_BINARY_DIR}" # for config.h + "${CMAKE_CURRENT_SOURCE_DIR}/includes" + "${CMAKE_CURRENT_BINARY_DIR}/includes" +) + +add_definitions(-DBUILDING_NGHTTP2) + +set(NGHTTP2_SOURCES + nghttp2_pq.c nghttp2_map.c nghttp2_queue.c + nghttp2_frame.c + nghttp2_buf.c + nghttp2_stream.c nghttp2_outbound_item.c + nghttp2_session.c nghttp2_submit.c + nghttp2_helper.c + nghttp2_npn.c + nghttp2_hd.c nghttp2_hd_huffman.c nghttp2_hd_huffman_data.c + nghttp2_version.c + nghttp2_priority_spec.c + nghttp2_option.c + nghttp2_callbacks.c + nghttp2_mem.c + nghttp2_http.c +) + +add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) +#target_link_libraries(nghttp2 ...) +set_target_properties(nghttp2 PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" + VERSION ${LT_CURRENT}.${LT_REVISION}.${LT_AGE} + SOVERSION ${LT_CURRENT}) + +install(TARGETS nghttp2 + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") From 90d66ea4a9214d53bbb6acbe098409c4d739167e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 22:15:46 +0100 Subject: [PATCH 10/59] cmake: fix detection of -Werror flag Do not use minus sign in macro names. --- CMakeLists.txt | 10 ++++------ cmake/ExtractValidFlags.cmake | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06719bf8..d435512e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,11 +106,10 @@ else() add_definitions(-D_U_ -DNGHTTP2_NORETURN) endif() -include(CheckCXXCompilerFlag) -foreach(_std gnu++11 gnu++0x) - set(_cxx1x_flag -std=${_std}) - check_cxx_compiler_flag(${_cxx1x_flag} CXX_FLAG_-std_${_std}) - if(CXX_FLAG_-std_${_std}) +include(ExtractValidFlags) +foreach(_cxx1x_flag -std=gnu++11 -std=gnu++0x) + extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag}) + if(_cxx1x_flag_supported) set(CXX1XCXXFLAGS ${_cxx1x_flag}) break() endif() @@ -381,7 +380,6 @@ if(HAVE_EPOLL AND HAVE_TIMERFD_CREATE) set(ENABLE_TINY_NGHTTPD 1) endif() -include(ExtractValidFlags) if(ENABLE_WERROR) # For C compiler extract_valid_c_flags(WARNCFLAGS diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake index 47a6c2b2..3b0b0240 100644 --- a/cmake/ExtractValidFlags.cmake +++ b/cmake/ExtractValidFlags.cmake @@ -7,7 +7,7 @@ include(CheckCXXCompilerFlag) function(extract_valid_c_flags varname) set(valid_flags "") foreach(flag IN LISTS ARGN) - string(REGEX REPLACE "[^a-zA-Z0-9_-]+" "_" flag_var ${flag}) + string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "C_FLAG_${flag_var}") check_c_compiler_flag("${flag}" "${flag_var}") if(${flag_var}) @@ -20,7 +20,7 @@ endfunction() function(extract_valid_cxx_flags varname) set(valid_flags "") foreach(flag IN LISTS ARGN) - string(REGEX REPLACE "[^a-zA-Z0-9_-]+" "_" flag_var ${flag}) + string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "CXX_FLAG_${flag_var}") check_cxx_compiler_flag("${flag}" "${flag_var}") if(${flag_var}) From 7a86758edb233ae496387f65f9f291b6a1eace70 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 22:23:57 +0100 Subject: [PATCH 11/59] cmake: Fix libnghttp2.pc paths Must be absolute instead of relative --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d435512e..184dd2cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -468,8 +468,8 @@ set(abs_top_builddir "${CMAKE_BINARY_DIR}") # libnghttp2.pc (pkg-config file) set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "${CMAKE_INSTALL_PREFIX}") -set(libdir "${CMAKE_INSTALL_LIBDIR}") -set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") +set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") +set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(VERSION "${PACKAGE_VERSION}") # For init scripts and systemd service file set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") From ea6eed10c7579f5ce20169a61580d329252ba935 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 23:06:35 +0100 Subject: [PATCH 12/59] cmake: fix version in soname --- CMakeLists.txt | 2 ++ lib/CMakeLists.txt | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 184dd2cb..7f4c20a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,8 @@ set(LT_AGE 4) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(Version) +math(EXPR LT_SOVERSION "${LT_CURRENT} - ${LT_AGE}") +set(LT_VERSION "${LT_SOVERSION}.${LT_AGE}.${LT_REVISION}") set(PACKAGE_VERSION "${PROJECT_VERSION}") HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7b4d5e3e..d2dc019c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,8 +27,7 @@ add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) #target_link_libraries(nghttp2 ...) set_target_properties(nghttp2 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" - VERSION ${LT_CURRENT}.${LT_REVISION}.${LT_AGE} - SOVERSION ${LT_CURRENT}) + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}) install(TARGETS nghttp2 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") From ccd2d34160507015216036f3c23c804c17ef1fc5 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 11 Feb 2016 23:27:31 +0100 Subject: [PATCH 13/59] cmake: Install headers --- CMakeLists.txt | 4 ++++ lib/CMakeLists.txt | 3 ++- lib/includes/CMakeLists.txt | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 lib/includes/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f4c20a6..35da5f5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -504,6 +504,10 @@ foreach(name configure_file("${name}.in" "${name}" @ONLY) endforeach() +include_directories( + "${CMAKE_BINARY_DIR}" # for config.h +) + add_subdirectory(lib) #add_subdirectory(lib/includes) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d2dc019c..114749b1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,6 @@ +add_subdirectory(includes) + include_directories( - "${CMAKE_BINARY_DIR}" # for config.h "${CMAKE_CURRENT_SOURCE_DIR}/includes" "${CMAKE_CURRENT_BINARY_DIR}/includes" ) diff --git a/lib/includes/CMakeLists.txt b/lib/includes/CMakeLists.txt new file mode 100644 index 00000000..17de2ec6 --- /dev/null +++ b/lib/includes/CMakeLists.txt @@ -0,0 +1,4 @@ +install(FILES + nghttp2/nghttp2.h + "${CMAKE_CURRENT_BINARY_DIR}/nghttp2/nghttp2ver.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nghttp2") From 61bb6428fd2c2fbce0f5c007f1463a799951a76c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 12 Feb 2016 13:12:33 +0100 Subject: [PATCH 14/59] cmake: add third-party and src Remaining work: - integrate mruby and neverbleed - integrate cunit --- CMakeLists.txt | 45 +++--- src/CMakeLists.txt | 270 ++++++++++++++++++++++++++++++++++++ src/includes/CMakeLists.txt | 5 + third-party/CMakeLists.txt | 35 +++++ 4 files changed, 329 insertions(+), 26 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 src/includes/CMakeLists.txt create mode 100644 third-party/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 35da5f5d..05c8c07c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,24 +134,22 @@ cmake_pop_check_state() # Checks for libraries. -# -# # Additional libraries required for tests. -# TESTLDADD= -# -# # Additional libraries required for programs under src directory. -# APPLDFLAGS= -# +# Additional libraries required for tests. +set(TEST_LIBRARIES) +# Additional libraries required for programs under src directory. +set(APP_LIBRARIES) + +set(CMAKE_THREAD_PREFER_PTHREAD 1) +find_package(Threads) +if(CMAKE_USE_PTHREADS_INIT) + list(APPEND APP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) +endif() +# XXX android and C++, is this still needed in cmake? # case "$host" in # *android*) # android_build=yes # # android does not need -pthread, but needs followng 3 libs for C++ # APPLDFLAGS="$APPLDFLAGS -lstdc++ -latomic -lsupc++" -# ;; -# *) -# PTHREAD_LDFLAGS="-pthread" -# APPLDFLAGS="$APPLDFLAGS $PTHREAD_LDFLAGS" -# ;; -# esac pkg_check_modules(ZLIB zlib>=1.2.3) if(ZLIB_FOUND) @@ -160,17 +158,9 @@ else() set(HAVE_ZLIB 0) endif() -# # dl: openssl requires libdl when it is statically linked. -# case "${host_os}" in -# *bsd*) -# # dlopen is in libc on *BSD -# ;; -# *) -# save_LIBS=$LIBS -# AC_SEARCH_LIBS([dlopen], [dl], [APPLDFLAGS="-ldl $APPLDFLAGS"], [], []) -# LIBS=$save_LIBS -# ;; -# esac +# dl: openssl requires libdl when it is statically linked. +# XXX shouldn't ${CMAKE_DL_LIBS} be appended to OPENSSL_LIBRARIES instead of +# APP_LIBRARIES if it is really specific to OpenSSL? # XXX put this in FindCUNIT.cmake pkg_check_modules(CUNIT cunit>=2.1) @@ -211,6 +201,8 @@ endif() # openssl (for src) pkg_check_modules(OPENSSL openssl>=1.0.1) +# for find_package, replace OPENSSL_INCLUDE_DIRS by OPENSSL_INCLUDE_DIR +#find_package(OpenSSL 1.0.1) if(OPENSSL_FOUND) set(HAVE_OPENSSL 1) else() @@ -507,14 +499,15 @@ endforeach() include_directories( "${CMAKE_BINARY_DIR}" # for config.h ) - +# For use in src/CMakeLists.txt +set(PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}") add_subdirectory(lib) #add_subdirectory(lib/includes) -if(0) add_subdirectory(third-party) add_subdirectory(src) #add_subdirectory(src/includes) +if(0) add_subdirectory(examples) add_subdirectory(python) add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..a762b4e3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,270 @@ +add_subdirectory(includes) + +# XXX replace this by lists (WARNCFLAGS_list) +string(REPLACE " " ";" c_flags "${WARNCFLAGS}") +string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") +add_compile_options( + "$<$:${c_flags}>" + "$<$:${cxx_flags}>" +) + +include_directories( + "${CMAKE_SOURCE_DIR}/lib/includes" + "${CMAKE_BINARY_DIR}/lib/includes" + "${CMAKE_SOURCE_DIR}/lib" + "${CMAKE_SOURCE_DIR}/src/includes" + "${CMAKE_SOURCE_DIR}/third-party" + + ${LIBSPDYLAY_INCLUDE_DIRS} + ${LIBXML2_INCLUDE_DIR} + ${LIBEV_INCLUDE_DIRS} + ${OPENSSL_INCLUDE_DIRS} + ${JANSSON_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIRS} +) + +# XXX per-target? +link_libraries( + nghttp2 + ${JEMALLOC_LIBRARIES} + ${LIBSPDYLAY_LIBRARIES} + ${LIBXML2_LIBRARIES} + ${LIBEV_LIBRARIES} + ${OPENSSL_LIBRARIES} + ${JANSSON_LIBRARIES} + ${ZLIB_LIBRARIES} + ${APP_LIBRARIES} +) + +if(ENABLE_APP) + set(HELPER_OBJECTS + util.cc + http2.cc timegm.c app_helper.cc nghttp2_gzip.c + ) + + # nghttp client + set(NGHTTP_SOURCES + ${HELPER_OBJECTS} + nghttp.cc + ssl.cc + ) + if(HAVE_LIBXML2) + list(APPEND NGHTTP_SOURCES HtmlParser.cc) + endif() + + # nghttpd + set(NGHTTPD_SOURCES + ${HELPER_OBJECTS} + nghttpd.cc + ssl.cc + HttpServer.cc + ) + + # h2load + set(H2LOAD_SOURCES + util.cc + http2.cc h2load.cc + timegm.c + ssl.cc + h2load_http2_session.cc + h2load_http1_session.cc + ) + if(HAVE_SPDYLAY) + list(APPEND H2LOAD_SOURCES + h2load_spdy_session.cc + ) + endif() + + + # Common libnhttpx sources (used for nghttpx and unit tests) + set(NGHTTPX_SRCS + util.cc http2.cc timegm.c + app_helper.cc + ssl.cc + shrpx_config.cc + shrpx_accept_handler.cc + shrpx_connection_handler.cc + shrpx_client_handler.cc + shrpx_http2_upstream.cc + shrpx_https_upstream.cc + shrpx_downstream.cc + shrpx_downstream_connection.cc + shrpx_http_downstream_connection.cc + shrpx_http2_downstream_connection.cc + shrpx_http2_session.cc + shrpx_downstream_queue.cc + shrpx_log.cc + shrpx_http.cc + shrpx_io_control.cc + shrpx_ssl.cc + shrpx_worker.cc + shrpx_log_config.cc + shrpx_connect_blocker.cc + shrpx_downstream_connection_pool.cc + shrpx_rate_limit.cc + shrpx_connection.cc + shrpx_memcached_dispatcher.cc + shrpx_memcached_connection.cc + shrpx_worker_process.cc + shrpx_signal.cc + shrpx_router.cc + ) + if(HAVE_SPDYLAY) + list(APPEND NGHTTPX_SRCS + shrpx_spdy_upstream.cc + ) + endif() + if(HAVE_MRUBY) + list(APPEND NGHTTPX_SRCS + shrpx_mruby.cc + shrpx_mruby_module.cc + shrpx_mruby_module_env.cc + shrpx_mruby_module_request.cc + shrpx_mruby_module_response.cc + ) + endif() + add_library(nghttpx STATIC ${NGHTTPX_SRCS}) + + set(NGHTTPX-bin_SOURCES + shrpx.cc + ) + + if(HAVE_MRUBY) + target_include_directories(nghttpx PUBLIC + "${CMAKE_SOURCE_DIR}/third-party/mruby/include" + # ${LIBMRUBY_CFLAGS} + ) + target_link_libraries(nghttpx + # nghttpx_LDADD += -L${top_builddir}/third-party/mruby/build/lib + # XXX find_library or other absolute path? + # ${LIBMRUBY_LIBS} + ) + endif() + + if(HAVE_NEVERBLEED) + target_include_directories(nghttpx PUBLIC + "${CMAKE_SOURCE_DIR}/third-party/neverbleed" + ) + target_link_libraries(nghttpx + # FIXME .la does not work ofc... + "${CMAKE_BINARY_DIR}/third-party/libneverbleed.la" + ) + endif() + + + if(HAVE_CUNIT) + # check_PROGRAMS += nghttpx-unittest + # nghttpx_unittest_SOURCES = shrpx-unittest.cc + # shrpx_ssl_test.cc + # shrpx_downstream_test.cc + # shrpx_config_test.cc + # shrpx_http_test.cc + # http2_test.cc + # util_test.cc + # nghttp2_gzip_test.c + # nghttp2_gzip.c + # buffer_test.cc + # memchunk_test.cc + # template_test.cc + # base64_test.cc + # nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} + # -DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\" + # nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@ + # + # if HAVE_MRUBY + # nghttpx_unittest_CPPFLAGS += + # -I${top_srcdir}/third-party/mruby/include @LIBMRUBY_CFLAGS@ + # nghttpx_unittest_LDADD += + # -L${top_builddir}/third-party/mruby/build/lib @LIBMRUBY_LIBS@ + # endif # HAVE_MRUBY + # + # if HAVE_NEVERBLEED + # nghttpx_unittest_CPPFLAGS += -I${top_srcdir}/third-party/neverbleed + # nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la + # endif # HAVE_NEVERBLEED + # + # TESTS += nghttpx-unittest + endif() + + add_executable(nghttp ${NGHTTP_SOURCES} $) + add_executable(nghttpd ${NGHTTPD_SOURCES} $) + add_executable(nghttpx-bin ${NGHTTPX-bin_SOURCES} $) + target_compile_definitions(nghttpx-bin PUBLIC "-DPKGDATADIR=\"${PKGDATADIR}\"") + set_target_properties(nghttpx-bin PROPERTIES OUTPUT_NAME nghttpx) + target_link_libraries(nghttpx-bin nghttpx) + add_executable(h2load ${H2LOAD_SOURCES} $) + + install(TARGETS nghttp nghttpd nghttpx-bin h2load + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() + +if(ENABLE_HPACK_TOOLS) + set(inflatehd_SOURCES + inflatehd.cc + comp_helper.c + ) + set(deflatehd_SOURCES + deflatehd.cc + comp_helper.c + ) + add_executable(inflatehd ${inflatehd_SOURCES}) + add_executable(deflatehd ${deflatehd_SOURCES}) + install(TARGETS inflatehd deflatehd + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() + +if(ENABLE_ASIO_LIB) + set(NGHTTP2_ASIO_SOURCES + util.cc http2.cc + ssl.cc + timegm.c + asio_common.cc + asio_io_service_pool.cc + asio_server_http2.cc + asio_server_http2_impl.cc + asio_server.cc + asio_server_http2_handler.cc + asio_server_request.cc + asio_server_request_impl.cc + asio_server_response.cc + asio_server_response_impl.cc + asio_server_stream.cc + asio_server_serve_mux.cc + asio_server_request_handler.cc + asio_server_tls_context.cc + asio_client_session.cc + asio_client_session_impl.cc + asio_client_session_tcp_impl.cc + asio_client_session_tls_impl.cc + asio_client_response.cc + asio_client_response_impl.cc + asio_client_request.cc + asio_client_request_impl.cc + asio_client_stream.cc + asio_client_tls_context.cc + ) + + add_library(nghttp2_asio SHARED + ${NGHTTP2_ASIO_SOURCES} + $ + ) + target_include_directories(nghttp2_asio PUBLIC + ${OPENSSL_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} + ) + target_link_libraries(nghttp2_asio + nghttp2 + ${OPENSSL_LIBRARIES} + ${Boost_LIBRARIES} + ) + # XXX use add_compile_options with a list instead of COMPILE_FLAGS + set_target_properties(nghttp2_asio PROPERTIES + COMPILE_FLAGS "${EXTRACFLAG}" + VERSION 1.0.0 SOVERSION 1) + + install(TARGETS nghttp2_asio + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + + install(FILES libnghttp2_asio.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif() diff --git a/src/includes/CMakeLists.txt b/src/includes/CMakeLists.txt new file mode 100644 index 00000000..b4720c65 --- /dev/null +++ b/src/includes/CMakeLists.txt @@ -0,0 +1,5 @@ +install(FILES + nghttp2/asio_http2.h + nghttp2/asio_http2_client.h + nghttp2/asio_http2_server.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nghttp2") diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt new file mode 100644 index 00000000..41308b91 --- /dev/null +++ b/third-party/CMakeLists.txt @@ -0,0 +1,35 @@ +if(ENABLE_THIRD_PARTY) + set(LIBHTTP_PARSER_SOURCES + http-parser/http_parser.c + ) + add_library(http-parser OBJECT ${LIBHTTP_PARSER_SOURCES}) + + if(HAVE_NEVERBLEED) + set(LIBNEVERBLEED_SOURCES + neverbleed/neverbleed.c + ) + add_library(libneverbleed ${LIBNEVERBLEED_SOURCES}) + target_include_directories(libneverbleed PUBLIC ${OPENSSL_INCLUDE_DIRS}) + target_link_libraries(libneverbleed ${OPENSSL_LIBRARIES}) + endif() + + if(HAVE_MRUBY) + ## EXTRA_DIST = build_config.rb mruby/* + + #.PHONY: all-local clean mruby + + #mruby: + # MRUBY_CONFIG="${srcdir}/build_config.rb" \ + # BUILD_DIR="${abs_builddir}/mruby/build" \ + # INSTALL_DIR="${abs_builddir}/mruby/build/install/bin" \ + # CC="${CC}" CXX="${CXX}" LD="${LD}" \ + # CFLAGS="${CPPFLAGS} ${CFLAGS}" CXXFLAGS="${CPPFLAGS} ${CXXFLAGS}" \ + # LDFLAGS="${LDFLAGS}" \ + # "${srcdir}/mruby/minirake" -f "${srcdir}/mruby/Rakefile" + + #all-local: mruby + + #clean-local: + # -rm -rf "${abs_builddir}/mruby/build" + endif() +endif() From 5297136bc0fb37bba3bba6128511e3252936359b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 12 Feb 2016 14:27:38 +0100 Subject: [PATCH 15/59] cmake: use PRIVATE instead of PUBLIC Avoids leaking compile flags to dependents. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05c8c07c..d1857f1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} include(GNUInstallDirs) +# XXX "check" is treated as "OFF" now, consider detecting it first option(ENABLE_WERROR "Turn on compile time warnings") option(ENABLE_DEBUG "Turn on debug output") option(ENABLE_THREADS "Turn on threading in apps" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a762b4e3..1c22321e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,7 +130,7 @@ if(ENABLE_APP) ) if(HAVE_MRUBY) - target_include_directories(nghttpx PUBLIC + target_include_directories(nghttpx PRIVATE "${CMAKE_SOURCE_DIR}/third-party/mruby/include" # ${LIBMRUBY_CFLAGS} ) @@ -142,7 +142,7 @@ if(ENABLE_APP) endif() if(HAVE_NEVERBLEED) - target_include_directories(nghttpx PUBLIC + target_include_directories(nghttpx PRIVATE "${CMAKE_SOURCE_DIR}/third-party/neverbleed" ) target_link_libraries(nghttpx @@ -189,7 +189,7 @@ if(ENABLE_APP) add_executable(nghttp ${NGHTTP_SOURCES} $) add_executable(nghttpd ${NGHTTPD_SOURCES} $) add_executable(nghttpx-bin ${NGHTTPX-bin_SOURCES} $) - target_compile_definitions(nghttpx-bin PUBLIC "-DPKGDATADIR=\"${PKGDATADIR}\"") + target_compile_definitions(nghttpx-bin PRIVATE "-DPKGDATADIR=\"${PKGDATADIR}\"") set_target_properties(nghttpx-bin PROPERTIES OUTPUT_NAME nghttpx) target_link_libraries(nghttpx-bin nghttpx) add_executable(h2load ${H2LOAD_SOURCES} $) @@ -248,7 +248,7 @@ if(ENABLE_ASIO_LIB) ${NGHTTP2_ASIO_SOURCES} $ ) - target_include_directories(nghttp2_asio PUBLIC + target_include_directories(nghttp2_asio PRIVATE ${OPENSSL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) From 55b270587bc4e9a0122b5916d8468c00b66579d3 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 12 Feb 2016 14:28:07 +0100 Subject: [PATCH 16/59] cmake: build examples --- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 examples/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d1857f1e..b0497d9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -508,8 +508,8 @@ add_subdirectory(lib) add_subdirectory(third-party) add_subdirectory(src) #add_subdirectory(src/includes) -if(0) add_subdirectory(examples) +if(0) add_subdirectory(python) add_subdirectory(tests) #add_subdirectory(tests/testdata) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..3802e7ce --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,54 @@ +if(ENABLE_EXAMPLES) + # XXX replace this by lists (WARNCFLAGS_list) + string(REPLACE " " ";" c_flags "${WARNCFLAGS}") + string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") + add_compile_options( + "$<$:${c_flags}>" + "$<$:${cxx_flags}>" + ) + + include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/lib/includes + ${CMAKE_BINARY_DIR}/lib/includes + ${CMAKE_SOURCE_DIR}/src/includes + ${CMAKE_SOURCE_DIR}/third-party + + ${LIBEVENT_OPENSSL_INCLUDE_DIRS} + ${OPENSSL_INCLUDE_DIRS} + ) + + link_libraries( + nghttp2 + ${LIBEVENT_OPENSSL_LIBRARIES} + ${OPENSSL_LIBRARIES} + ${APP_LIBRARIES} + ) + + add_executable(client client.c $) + add_executable(libevent_client libevent-client.c $) + add_executable(libevent_server libevent-server.c $) + add_executable(deflate deflate.c $) + + if(ENABLE_TINY_NGHTTPD) + add_executable(tiny-nghttpd tiny-nghttpd.c $) + endif() + + if(ENABLE_ASIO_LIB) + foreach(name asio-sv asio-sv2 asio-cl asio-cl2) + add_executable(${name} ${name}.cc $) + target_include_directories(${name} PRIVATE + ${OPENSSL_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} + ) + target_link_libraries(${name} + nghttp2 + nghttp2_asio + ${JEMALLOC_LIBRARIES} + ${OPENSSL_LIBRARIES} + ${Boost_LIBRARIES} + ${APP_LIBRARIES} + ) + endforeach() + endif() +endif() From a2ec695ec9e510e66eceb91e75510f32ecbccaba Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 12 Feb 2016 15:24:56 +0100 Subject: [PATCH 17/59] cmake: add python stub Might not be the best approach, maybe use thewtex/cython-cmake-example? --- CMakeLists.txt | 2 +- python/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 python/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b0497d9f..fc054f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -509,8 +509,8 @@ add_subdirectory(third-party) add_subdirectory(src) #add_subdirectory(src/includes) add_subdirectory(examples) -if(0) add_subdirectory(python) +if(0) add_subdirectory(tests) #add_subdirectory(tests/testdata) add_subdirectory(integration-tests) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 00000000..0a035e7c --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,33 @@ +# EXTRA_DIST = cnghttp2.pxd nghttp2.pyx + +# XXX consider https://github.com/thewtex/cython-cmake-example + +if(ENABLE_PYTHON_BINDINGS) + # XXX add ALL? Will always be invoked as target is always out-of-date though. + add_custom_target(python + COMMAND ${PYTHON_EXECUTABLE} setup.py build + DEPENDS nghttp2.c + ) + + add_custom_target(python-install + COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix=${DESTDIR}${CMAKE_INSTALL_PREFIX} + ) + + # XXX cmake does not have an uninstall target, do not bother with this then. + # XXX glob patterns like this will probably not work + #add_custom_target(python-uninstall + # COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/nghttp2.so + # COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/python_nghttp2-*.egg + #) + + # XXX cleaner way to advertise the build artifacts? (note nghttp2.c is cleaned automatically) + add_custom_target(python-clean + COMMAND ${PYTHON_EXECUTABLE} setup.py clean --all + ) + + # XXX CYTHON_EXECUTABLE is not set! + add_custom_command(OUTPUT nghttp2.c + COMMAND ${CYTHON_EXECUTABLE} -o nghttp2.c nghttp2.pyx + DEPENDS nghttp2.pyx + ) +endif() From 15adc23277be3b1ac4fa8738efc38ead48d0c7b6 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 13 Feb 2016 17:47:04 +0100 Subject: [PATCH 18/59] cmake: working doc (sphinx-build), out-of-tree! --- CMakeLists.txt | 11 +- doc/CMakeLists.txt | 312 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 320 insertions(+), 3 deletions(-) create mode 100644 doc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fc054f7f..fdf164fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,9 +64,10 @@ set(CYTHON_PATH "" CACHE PATH "Use cython in given path") set(CYTHON "" CACHE FILEPATH "The Cython executable") find_package(PkgConfig 0.20) +# For Python bindings and documentation +find_package(PythonInterp) # XXX fail only when "ON" instead of "CHECK"? if(ENABLE_PYTHON_BINDINGS) - find_package(PythonInterp REQUIRED) endif() # AM_PATH_PYTHON([2.7],, [:]) @@ -456,8 +457,10 @@ endif() add_definitions(-DHAVE_CONFIG_H) configure_file(cmakeconfig.h.in config.h) # autotools-compatible names -set(top_srcdir "${CMAKE_SOURCE_DIR}") -set(top_builddir "${CMAKE_BINARY_DIR}") +# Sphinx expects relative paths in the .rst files. Use the fact that the files +# below are all one directory level deep. +file(RELATIVE_PATH top_srcdir "${CMAKE_BINARY_DIR}/dir" "${CMAKE_SOURCE_DIR}") +file(RELATIVE_PATH top_builddir "${CMAKE_BINARY_DIR}/dir" "${CMAKE_BINARY_DIR}") set(abs_top_srcdir "${CMAKE_SOURCE_DIR}") set(abs_top_builddir "${CMAKE_BINARY_DIR}") # libnghttp2.pc (pkg-config file) @@ -514,7 +517,9 @@ if(0) add_subdirectory(tests) #add_subdirectory(tests/testdata) add_subdirectory(integration-tests) +endif() add_subdirectory(doc) +if(0) add_subdirectory(contrib) add_subdirectory(script) endif() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 00000000..d05c9461 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,312 @@ +# Generated documents +set(APIDOCS + macros.rst + enums.rst + types.rst + nghttp2_check_header_name.rst + nghttp2_check_header_value.rst + nghttp2_hd_deflate_bound.rst + nghttp2_hd_deflate_change_table_size.rst + nghttp2_hd_deflate_del.rst + nghttp2_hd_deflate_get_dynamic_table_size.rst + nghttp2_hd_deflate_get_max_dynamic_table_size.rst + nghttp2_hd_deflate_get_num_table_entries.rst + nghttp2_hd_deflate_get_table_entry.rst + nghttp2_hd_deflate_hd.rst + nghttp2_hd_deflate_new.rst + nghttp2_hd_deflate_new2.rst + nghttp2_hd_inflate_change_table_size.rst + nghttp2_hd_inflate_del.rst + nghttp2_hd_inflate_end_headers.rst + nghttp2_hd_inflate_get_dynamic_table_size.rst + nghttp2_hd_inflate_get_max_dynamic_table_size.rst + nghttp2_hd_inflate_get_num_table_entries.rst + nghttp2_hd_inflate_get_table_entry.rst + nghttp2_hd_inflate_hd.rst + nghttp2_hd_inflate_new.rst + nghttp2_hd_inflate_new2.rst + nghttp2_is_fatal.rst + nghttp2_nv_compare_name.rst + nghttp2_option_del.rst + nghttp2_option_new.rst + nghttp2_option_set_max_reserved_remote_streams.rst + nghttp2_option_set_no_auto_window_update.rst + nghttp2_option_set_no_http_messaging.rst + nghttp2_option_set_no_recv_client_magic.rst + nghttp2_option_set_peer_max_concurrent_streams.rst + nghttp2_pack_settings_payload.rst + nghttp2_priority_spec_check_default.rst + nghttp2_priority_spec_default_init.rst + nghttp2_priority_spec_init.rst + nghttp2_select_next_protocol.rst + nghttp2_session_callbacks_del.rst + nghttp2_session_callbacks_new.rst + nghttp2_session_callbacks_set_before_frame_send_callback.rst + nghttp2_session_callbacks_set_data_source_read_length_callback.rst + nghttp2_session_callbacks_set_on_begin_frame_callback.rst + nghttp2_session_callbacks_set_on_begin_headers_callback.rst + nghttp2_session_callbacks_set_on_data_chunk_recv_callback.rst + nghttp2_session_callbacks_set_on_frame_not_send_callback.rst + nghttp2_session_callbacks_set_on_frame_recv_callback.rst + nghttp2_session_callbacks_set_on_frame_send_callback.rst + nghttp2_session_callbacks_set_on_header_callback.rst + nghttp2_session_callbacks_set_on_invalid_frame_recv_callback.rst + nghttp2_session_callbacks_set_on_stream_close_callback.rst + nghttp2_session_callbacks_set_recv_callback.rst + nghttp2_session_callbacks_set_select_padding_callback.rst + nghttp2_session_callbacks_set_send_callback.rst + nghttp2_session_callbacks_set_send_data_callback.rst + nghttp2_session_client_new.rst + nghttp2_session_client_new2.rst + nghttp2_session_client_new3.rst + nghttp2_session_consume.rst + nghttp2_session_consume_connection.rst + nghttp2_session_consume_stream.rst + nghttp2_session_create_idle_stream.rst + nghttp2_session_del.rst + nghttp2_session_find_stream.rst + nghttp2_session_get_effective_local_window_size.rst + nghttp2_session_get_effective_recv_data_length.rst + nghttp2_session_get_last_proc_stream_id.rst + nghttp2_session_get_next_stream_id.rst + nghttp2_session_get_outbound_queue_size.rst + nghttp2_session_get_remote_settings.rst + nghttp2_session_get_remote_window_size.rst + nghttp2_session_get_root_stream.rst + nghttp2_session_get_stream_effective_local_window_size.rst + nghttp2_session_get_stream_effective_recv_data_length.rst + nghttp2_session_get_stream_local_close.rst + nghttp2_session_get_stream_remote_close.rst + nghttp2_session_get_stream_remote_window_size.rst + nghttp2_session_get_stream_user_data.rst + nghttp2_session_mem_recv.rst + nghttp2_session_mem_send.rst + nghttp2_session_recv.rst + nghttp2_session_change_stream_priority.rst + nghttp2_session_check_request_allowed.rst + nghttp2_session_check_server_session.rst + nghttp2_session_resume_data.rst + nghttp2_session_send.rst + nghttp2_session_server_new.rst + nghttp2_session_server_new2.rst + nghttp2_session_server_new3.rst + nghttp2_session_set_next_stream_id.rst + nghttp2_session_set_stream_user_data.rst + nghttp2_session_terminate_session.rst + nghttp2_session_terminate_session2.rst + nghttp2_session_upgrade.rst + nghttp2_session_upgrade2.rst + nghttp2_session_want_read.rst + nghttp2_session_want_write.rst + nghttp2_stream_get_first_child.rst + nghttp2_stream_get_next_sibling.rst + nghttp2_stream_get_parent.rst + nghttp2_stream_get_previous_sibling.rst + nghttp2_stream_get_state.rst + nghttp2_stream_get_sum_dependency_weight.rst + nghttp2_stream_get_weight.rst + nghttp2_strerror.rst + nghttp2_submit_data.rst + nghttp2_submit_goaway.rst + nghttp2_submit_headers.rst + nghttp2_submit_ping.rst + nghttp2_submit_priority.rst + nghttp2_submit_push_promise.rst + nghttp2_submit_request.rst + nghttp2_submit_response.rst + nghttp2_submit_rst_stream.rst + nghttp2_submit_settings.rst + nghttp2_submit_shutdown_notice.rst + nghttp2_submit_trailer.rst + nghttp2_submit_window_update.rst + nghttp2_version.rst +) + +# Other .rst files from the source tree that need to be copied +# XXX move them to sources/ and create .in files? +set(RST_FILES + README.rst + programmers-guide.rst + nghttp.1.rst + nghttpd.1.rst + nghttpx.1.rst + h2load.1.rst +) + +# XXX unused for now +set(EXTRA_DIST + mkapiref.py + ${RST_FILES} + ${APIDOCS} + sources/index.rst + sources/tutorial-client.rst + sources/tutorial-server.rst + sources/tutorial-hpack.rst + sources/nghttpx-howto.rst + sources/h2load-howto.rst + sources/libnghttp2_asio.rst + sources/python-apiref.rst + sources/building-android-binary.rst + sources/contribute.rst + _exts/sphinxcontrib/LICENSE.rubydomain + _exts/sphinxcontrib/__init__.py + _exts/sphinxcontrib/rubydomain.py + _themes/sphinx_rtd_theme/__init__.py + _themes/sphinx_rtd_theme/breadcrumbs.html + _themes/sphinx_rtd_theme/footer.html + _themes/sphinx_rtd_theme/layout.html + _themes/sphinx_rtd_theme/layout_old.html + _themes/sphinx_rtd_theme/search.html + _themes/sphinx_rtd_theme/searchbox.html + _themes/sphinx_rtd_theme/static/css/badge_only.css + _themes/sphinx_rtd_theme/static/css/theme.css + _themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf + _themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot + _themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.svg + _themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf + _themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff + _themes/sphinx_rtd_theme/static/js/theme.js + _themes/sphinx_rtd_theme/theme.conf + _themes/sphinx_rtd_theme/versions.html + nghttp.1 + nghttpd.1 + nghttpx.1 + h2load.1 + bash_completion/nghttp + bash_completion/nghttpd + bash_completion/nghttpx + bash_completion/h2load +) + +# Based on Makefile for Sphinx documentation + +# You can set these variables from the command line. +set(SPHINXOPTS) +set(SPHINXBUILD sphinx-build) +set(PAPER) +set(BUILDDIR manual) + +# Internal variables. +set(PAPEROPT_a4 -D latex_paper_size=a4) +set(PAPEROPT_letter -D latex_paper_size=letter) +set(ALLSPHINXOPTS -d ${BUILDDIR}/doctrees ${PAPEROPT_${PAPER}} ${SPHINXOPTS} .) + +# "Please use `make ' where is one of" +# " html to make standalone HTML files" +# " dirhtml to make HTML files named index.html in directories" +# " singlehtml to make a single large HTML file" +# " pickle to make pickle files" +# " json to make JSON files" +# " htmlhelp to make HTML files and a HTML help project" +# " qthelp to make HTML files and a qthelp project" +# " devhelp to make HTML files and a Devhelp project" +# " epub to make an epub" +# " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" +# " latexpdf to make LaTeX files and run them through pdflatex" +# " text to make text files" +# " man to make manual pages" +# " changes to make an overview of all changed/added/deprecated items" +# " linkcheck to check all external links for integrity" +# " doctest to run all doctests embedded in the documentation (if enabled)" + + +# Copy files for out-of-tree builds +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) + set(RST_BUILD_FILES) + foreach(rstfile IN LISTS RST_FILES) + set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${rstfile}") + add_custom_command(OUTPUT "${outfile}" + COMMAND ${CMAKE_COMMAND} -E copy + "${CMAKE_CURRENT_SOURCE_DIR}/${rstfile}" "${outfile}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${rstfile}" + ) + list(APPEND RST_BUILD_FILES "${outfile}") + endforeach() +else() + set(RST_BUILD_FILES "${RST_FILES}") +endif() + +set(apiref_SOURCES + ${CMAKE_BINARY_DIR}/lib/includes/nghttp2/nghttp2ver.h + ${CMAKE_SOURCE_DIR}/lib/includes/nghttp2/nghttp2.h +) +# Generates apiref.rst and other files +add_custom_command( + OUTPUT + apiref.rst + ${APIDOCS} + COMMAND + "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkapiref.py" + apiref.rst macros.rst enums.rst types.rst . + ${apiref_SOURCES} + DEPENDS + ${RST_BUILD_FILES} + ${apiref_SOURCES} +) + + +# Invokes sphinx-build and prints the given messages when completed +function(sphinxbuild builder) + set(echo_commands) + foreach(message IN LISTS ARGN) + list(APPEND echo_commands COMMAND ${CMAKE_COMMAND} -E echo "${message}") + endforeach() + add_custom_target(${builder} + COMMAND "${SPHINXBUILD}" -b ${builder} ${ALLSPHINXOPTS} "${BUILDDIR}/${builder}" + COMMAND ${CMAKE_COMMAND} -E echo + ${echo_commands} + VERBATIM + DEPENDS apiref.rst + ) +endfunction() + +foreach(builder html dirhtml singlehtml) + sphinxbuild(${builder} + "Build finished. The HTML pages are in ${BUILDDIR}/${builder}.") +endforeach() +sphinxbuild(pickle "Build finished; now you can process the pickle files.") +sphinxbuild(json "Build finished; now you can process the JSON files.") +sphinxbuild(htmlhelp + "Build finished; now you can run HTML Help Workshop with the" + ".hhp project file in ${BUILDDIR}/htmlhelp." +) +sphinxbuild(qthelp + "Build finished; now you can run \"qcollectiongenerator\" with the" + ".qhcp project file in ${BUILDDIR}/qthelp, like this:" + "# qcollectiongenerator ${BUILDDIR}/qthelp/nghttp2.qhcp" + "To view the help file:" + "# assistant -collectionFile ${BUILDDIR}/qthelp/nghttp2.qhc" +) +sphinxbuild(devhelp + "Build finished." + "To view the help file:" + "# mkdir -p ~/.local/share/devhelp/nghttp2" + "# ln -s ${BUILDDIR}/devhelp ~/.local/share/devhelp/nghttp2" + "# devhelp" +) +sphinxbuild(epub "Build finished. The epub file is in ${BUILDDIR}/epub.") +sphinxbuild(latex + "Build finished; the LaTeX files are in ${BUILDDIR}/latex." + "Run `make' in that directory to run these through (pdf)latex" + "(use `make latexpdf' here to do that automatically)." +) + +# Invoke the Makefile generated by sphinx +add_custom_target(latexpdf + COMMAND ${CMAKE_COMMAND} -E echo "Running LaTeX files through pdflatex..." + COMMAND make -C "${BUILDDIR}/latex" all-pdf + COMMAND ${CMAKE_COMMAND} -E echo "pdflatex finished; the PDF files are in ${BUILDDIR}/latex." + DEPENDS latex +) + +sphinxbuild(text "Build finished. The text files are in ${BUILDDIR}/text.") +sphinxbuild(man "Build finished. The manual pages are in ${BUILDDIR}/man.") +sphinxbuild(changes "The overview file is in ${BUILDDIR}/changes.") +sphinxbuild(linkcheck + "Link check complete; look for any errors in the above output" + "or in ${BUILDDIR}/linkcheck/output.txt." +) +sphinxbuild(doctest + "Testing of doctests in the sources finished, look at the" + "results in ${BUILDDIR}/doctest/output.txt." +) From 8c562bd38dc833c5823c3f91d116afae3b2cfe05 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 13 Feb 2016 18:09:01 +0100 Subject: [PATCH 19/59] cmake: process contrib/ --- CMakeLists.txt | 4 ++-- contrib/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 contrib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fdf164fd..c898f93d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -469,7 +469,7 @@ set(exec_prefix "${CMAKE_INSTALL_PREFIX}") set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(VERSION "${PACKAGE_VERSION}") -# For init scripts and systemd service file +# For init scripts and systemd service file (in contrib/) set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}") foreach(name @@ -519,8 +519,8 @@ add_subdirectory(tests) add_subdirectory(integration-tests) endif() add_subdirectory(doc) -if(0) add_subdirectory(contrib) +if(0) add_subdirectory(script) endif() diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt new file mode 100644 index 00000000..f598f7ba --- /dev/null +++ b/contrib/CMakeLists.txt @@ -0,0 +1,12 @@ +set(CONFIGFILES + nghttpx-init + nghttpx.service + nghttpx-upstart.conf +) + +# Note that the execute permissions of nghttpx-init is preserved +foreach(name IN LISTS CONFIGFILES) + configure_file("${name}.in" "${name}" @ONLY) +endforeach() + +# set(EXTRA_DIST ${CONFIGFILES} nghttpx-logrotate tlsticketupdate.go) From ee285fa5da5cceadac27e52164815ae1d299a86e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 13 Feb 2016 18:20:09 +0100 Subject: [PATCH 20/59] cmake: process script/ --- CMakeLists.txt | 2 -- script/CMakeLists.txt | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 script/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c898f93d..8cf2656a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -520,9 +520,7 @@ add_subdirectory(integration-tests) endif() add_subdirectory(doc) add_subdirectory(contrib) -if(0) add_subdirectory(script) -endif() # XXX - fix list of variables diff --git a/script/CMakeLists.txt b/script/CMakeLists.txt new file mode 100644 index 00000000..f8988585 --- /dev/null +++ b/script/CMakeLists.txt @@ -0,0 +1,5 @@ +# EXTRA_DIST = README.rst +install( + PROGRAMS fetch-ocsp-response + DESTINATION "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}" +) From 503f0a29a7bc57d404cedf8c0bc36b9db3daa880 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 13 Feb 2016 20:04:33 +0100 Subject: [PATCH 21/59] cmake: add integration-tests --- CMakeLists.txt | 2 +- integration-tests/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++ integration-tests/setenv.in | 9 ++++-- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 integration-tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf2656a..c36ddc60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -516,8 +516,8 @@ add_subdirectory(python) if(0) add_subdirectory(tests) #add_subdirectory(tests/testdata) -add_subdirectory(integration-tests) endif() +add_subdirectory(integration-tests) add_subdirectory(doc) add_subdirectory(contrib) add_subdirectory(script) diff --git a/integration-tests/CMakeLists.txt b/integration-tests/CMakeLists.txt new file mode 100644 index 00000000..bae2d2d8 --- /dev/null +++ b/integration-tests/CMakeLists.txt @@ -0,0 +1,48 @@ +set(GO_FILES + nghttpx_http1_test.go + nghttpx_http2_test.go + nghttpx_spdy_test.go + server_tester.go +) + +# XXX unused +set(EXTRA_DIST + ${GO_FILES} + server.key + server.crt + alt-server.key + alt-server.crt + setenv + req-set-header.rb + resp-set-header.rb + req-return.rb + resp-return.rb +) + +add_custom_target(itprep + COMMAND go get -d -v golang.org/x/net/http2 + COMMAND go get -d -v github.com/tatsuhiro-t/go-nghttp2 + COMMAND go get -d -v github.com/tatsuhiro-t/spdy + COMMAND go get -d -v golang.org/x/net/websocket +) + +# 'go test' requires both config.go and the test files in the same directory. +# For out-of-tree builds, config.go is normally not placed next to the source +# files, so copy the tests to the build directory as a workaround. +set(GO_BUILD_FILES) +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) + foreach(gofile IN LISTS GO_FILES) + set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${gofile}") + add_custom_command(OUTPUT "${outfile}" + COMMAND ${CMAKE_COMMAND} -E copy + "${CMAKE_CURRENT_SOURCE_DIR}/${gofile}" "${outfile}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${gofile}" + ) + list(APPEND GO_BUILD_FILES "${outfile}") + endforeach() +endif() + +add_custom_target(it + COMMAND sh setenv go test -v + DEPENDS ${GO_BUILD_FILES} +) diff --git a/integration-tests/setenv.in b/integration-tests/setenv.in index 2c2d3c95..277b68e7 100644 --- a/integration-tests/setenv.in +++ b/integration-tests/setenv.in @@ -1,6 +1,11 @@ #!/bin/sh -e +libdir="@abs_top_builddir@/lib" +if [ -d "$libdir/.libs" ]; then + libdir="$libdir/.libs" +fi + export CGO_CFLAGS="-I@abs_top_srcdir@/lib/includes -I@abs_top_builddir@/lib/includes" -export CGO_LDFLAGS="-L@abs_top_builddir@/lib/.libs" -export LD_LIBRARY_PATH="@abs_top_builddir@/lib/.libs" +export CGO_LDFLAGS="-L$libdir" +export LD_LIBRARY_PATH="$libdir" "$@" From c96cf1b30393dad529f47502150f0c1edcaf2e24 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 14 Feb 2016 13:22:32 +0100 Subject: [PATCH 22/59] cmake: improve final variable list Remove build/host/target by a single target system name (CMake is different for cross-compiling, you are suggested to set CMAKE_TOOLCHAIN_FILE). Fix various library variables, remove CFLAGS (INCLUDE_DIRS could be used instead though, but I consider that minor information that could be added later if wanted). Fix various variable names (prefix, boost, etc.). --- CMakeLists.txt | 53 ++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c36ddc60..434d3566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -523,56 +523,49 @@ add_subdirectory(contrib) add_subdirectory(script) -# XXX - fix list of variables +# XXX fix shared/static library +# XXX fix python +string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) message(STATUS "summary of build options: Package version: ${VERSION} Library version: ${LT_CURRENT}:${LT_REVISION}:${LT_AGE} - Install prefix: ${prefix} - System types: - Build: ${build} - Host: ${host} - Target: ${target} + Install prefix: ${CMAKE_INSTALL_PREFIX} + Target system: ${CMAKE_SYSTEM_NAME} Compiler: - C compiler: ${CMAKE_C_COMPILER} - CFLAGS: ${CMAKE_C_FLAGS} + C compiler: ${CMAKE_C_COMPILER} + CFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}} C++ compiler: ${CMAKE_CXX_COMPILER} - CXXFLAGS: ${CMAKE_CXX_FLAGS} + CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}} WARNCFLAGS: ${WARNCFLAGS} CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} EXTRACFLAG: ${EXTRACFLAG} - LIBS: ${LIBS} Library: Shared: ${enable_shared} Static: ${enable_static} Python: - Python: ${PYTHON} - PYTHON_VERSION: ${PYTHON_VERSION} + Python: ${PYTHON_EXECUTABLE} + PYTHON_VERSION: ${PYTHON_VERSION_STRING} pyexecdir: ${pyexecdir} Python-dev: ${have_python_dev} - PYTHON_CPPFLAGS:${PYTHON_CPPFLAGS} - PYTHON_LDFLAGS: ${PYTHON_LDFLAGS} - Cython: ${CYTHON} + Cython: ${CYTHON_EXECUTABLE} Test: - CUnit: ${HAVE_CUNIT} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') + CUnit: ${HAVE_CUNIT} (LIBS='${CUNIT_LIBRARIES}') Failmalloc: ${ENABLE_FAILMALLOC} Libs: - OpenSSL: ${HAVE_OPENSSL} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') - Libxml2: ${HAVE_LIBXML2} (CFLAGS='${XML_CPPFLAGS}' LIBS='${XML_LIBS}') - Libev: ${HAVE_LIBEV} (CFLAGS='${LIBEV_CFLAGS}' LIBS='${LIBEV_LIBS}') - Libevent(SSL): ${HAVE_LIBEVENT_OPENSSL} (CFLAGS='${LIBEVENT_OPENSSL_CFLAGS}' LIBS='${LIBEVENT_OPENSSL_LIBS}') - Spdylay: ${HAVE_SPDYLAY} (CFLAGS='${LIBSPDYLAY_CFLAGS}' LIBS='${LIBSPDYLAY_LIBS}') - Jansson: ${HAVE_JANSSON} (CFLAGS='${JANSSON_CFLAGS}' LIBS='${JANSSON_LIBS}') - Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBS}') - Zlib: ${HAVE_ZLIB} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') - Boost CPPFLAGS: ${BOOST_CPPFLAGS} - Boost LDFLAGS: ${BOOST_LDFLAGS} - Boost::ASIO: ${BOOST_ASIO_LIB} - Boost::System: ${BOOST_SYSTEM_LIB} - Boost::Thread: ${BOOST_THREAD_LIB} + OpenSSL: ${HAVE_OPENSSL} (LIBS='${OPENSSL_LIBRARIES}') + 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}') + Jansson: ${HAVE_JANSSON} (LIBS='${JANSSON_LIBRARIES}') + Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBRARIES}') + Zlib: ${HAVE_ZLIB} (LIBS='${ZLIB_LIBRARIES}') + Boost::System: ${Boost_SYSTEM_LIBRARY} + Boost::Thread: ${Boost_THREAD_LIBRARY} Third-party: http-parser: ${ENABLE_THIRD_PARTY} - MRuby: ${HAVE_MRUBY} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') + MRuby: ${HAVE_MRUBY} (LIBS='${LIBMRUBY_LIBRARIES}') Neverbleed: ${HAVE_NEVERBLEED} Features: Applications: ${ENABLE_APP} From cc92ebf4710efd915a980e6927d393f1b7a88482 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Feb 2016 01:12:07 +0100 Subject: [PATCH 23/59] cmake: add auto-detection, improve library search Add auto-detection to the most important features (app, hpack, etc.). Move options to a separate file for easier search. Add cmake-based Libevent, jansson and CUnit search. Move pkg-config handling for Libev and jemalloc to their cmake files. Note: duplicates find_package before including CMakeOptions.txt and when checking for features. Maybe that can be cleaned up later... --- CMakeLists.txt | 108 +++++++++++++++++++++------------------ CMakeOptions.txt | 29 +++++++++++ cmake/FindCUnit.cmake | 40 +++++++++++++++ cmake/FindJansson.cmake | 40 +++++++++++++++ cmake/FindJemalloc.cmake | 35 ++++++++++--- cmake/FindLibev.cmake | 37 ++++++++++---- cmake/FindLibevent.cmake | 100 ++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + 8 files changed, 321 insertions(+), 69 deletions(-) create mode 100644 CMakeOptions.txt create mode 100644 cmake/FindCUnit.cmake create mode 100644 cmake/FindJansson.cmake create mode 100644 cmake/FindLibevent.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 434d3566..a669c4ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,26 +42,30 @@ HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} include(GNUInstallDirs) -# XXX "check" is treated as "OFF" now, consider detecting it first -option(ENABLE_WERROR "Turn on compile time warnings") -option(ENABLE_DEBUG "Turn on debug output") -option(ENABLE_THREADS "Turn on threading in apps" ON) -option(ENABLE_APP "Build applications (nghttp, nghttpd, nghttpx and h2load)" - check) -option(ENABLE_HPACK_TOOLS "Build HPACK tools" check) -option(ENABLE_ASIO_LIB "Build C++ libnghttp2_asio library") -option(ENABLE_EXAMPLES "Build examples" check) -option(ENABLE_PYTHON_BINDINGS "Build Python bindings" check) -option(ENABLE_FAILMALLOC "Build failmalloc test program" ON) -option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0 -DENABLE_PYTHON_BINDINGS=0") +# Auto-detection of features that can be toggled +find_package(OpenSSL 1.0.1 QUIET) +find_package(Libev 4.15 QUIET) +find_package(ZLIB 1.2.3 QUIET) +if(OPENSSL_FOUND AND LIBEV_FOUND AND ZLIB_FOUND) + set(ENABLE_APP_DEFAULT ON) +else() + set(ENABLE_APP_DEFAULT OFF) +endif() +find_package(Jansson 2.5 QUIET) +set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND}) +find_package(Libevent 2.0.8 QUIET COMPONENTS openssl) +set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND}) +# XXX auto-detect python +set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) -option(WITH_LIBXML2 "Use libxml2" check) -option(WITH_JEMALLOC "Use jemalloc" check) -option(WITH_SPDYLAY "Use spdylay" check) -option(WITH_MRUBY "Use mruby") -option(WITH_NEVERBLEED "Use neverbleed") -set(CYTHON_PATH "" CACHE PATH "Use cython in given path") -set(CYTHON "" CACHE FILEPATH "The Cython executable") +find_package(LibXml2 QUIET) +set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) +find_package(Jemalloc QUIET) +set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND}) +find_package(SPDYLAY QUIET) +set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND}) + +include(CMakeOptions.txt) find_package(PkgConfig 0.20) # For Python bindings and documentation @@ -153,19 +157,16 @@ endif() # # android does not need -pthread, but needs followng 3 libs for C++ # APPLDFLAGS="$APPLDFLAGS -lstdc++ -latomic -lsupc++" -pkg_check_modules(ZLIB zlib>=1.2.3) -if(ZLIB_FOUND) - set(HAVE_ZLIB 1) -else() - set(HAVE_ZLIB 0) -endif() - # dl: openssl requires libdl when it is statically linked. # XXX shouldn't ${CMAKE_DL_LIBS} be appended to OPENSSL_LIBRARIES instead of # APP_LIBRARIES if it is really specific to OpenSSL? -# XXX put this in FindCUNIT.cmake -pkg_check_modules(CUNIT cunit>=2.1) +find_package(CUnit 2.1) +if(CUNIT_FOUND) + set(HAVE_CUNIT 1) +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 @@ -193,35 +194,44 @@ pkg_check_modules(CUNIT cunit>=2.1) # # AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) +if(ENABLE_APP) + find_package(OpenSSL 1.0.1 REQUIRED) + find_package(Libev 4.15 REQUIRED) + find_package(ZLIB 1.2.3 REQUIRED) +endif() + +# openssl (for src) +if(OPENSSL_FOUND) + set(HAVE_OPENSSL 1) + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) +else() + set(HAVE_OPENSSL 0) +endif() # libev (for src) -find_package(Libev) -if(Libev_FOUND) +if(LIBEV_FOUND) set(HAVE_LIBEV 1) else() set(HAVE_LIBEV 0) endif() - -# openssl (for src) -pkg_check_modules(OPENSSL openssl>=1.0.1) -# for find_package, replace OPENSSL_INCLUDE_DIRS by OPENSSL_INCLUDE_DIR -#find_package(OpenSSL 1.0.1) -if(OPENSSL_FOUND) - set(HAVE_OPENSSL 1) +if(ZLIB_FOUND) + set(HAVE_ZLIB 1) else() - set(HAVE_OPENSSL 0) + set(HAVE_ZLIB 0) endif() -# libevent_openssl (for examples) -# 2.0.8 is required because we use evconnlistener_set_error_cb() -pkg_check_modules(LIBEVENT_OPENSSL libevent_openssl>=2.0.8) -if(LIBEVENT_OPENSSL_FOUND) + +if(ENABLE_EXAMPLES) + # libevent_openssl (for examples) + # 2.0.8 is required because we use evconnlistener_set_error_cb() + find_package(Libevent 2.0.8 REQUIRED COMPONENTS libevent openssl) + set(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES}) set(HAVE_LIBEVENT_OPENSSL 1) else() set(HAVE_LIBEVENT_OPENSSL 0) endif() -# jansson (for src/nghttp, src/deflatehd and src/inflatehd) -pkg_check_modules(JANSSON jansson>=2.5) -if(JANSSON_FOUND) +if(ENABLE_HPACK_TOOLS) + # jansson (for src/nghttp, src/deflatehd and src/inflatehd) + find_package(Jansson 2.5 REQUIRED) set(HAVE_JANSSON 1) else() set(HAVE_JANSSON 0) @@ -231,17 +241,13 @@ endif() if(WITH_LIBXML2) find_package(LibXml2 2.7.7 REQUIRED) set(HAVE_LIBXML2 1) - # XXX fail if WITH_LIBXML2=ON else() set(HAVE_LIBXML2 0) endif() # jemalloc if(WITH_JEMALLOC) - pkg_check_modules(JEMALLOC jemalloc) - if(NOT JEMALLOC_FOUND) - find_package(jemalloc REQUIRED) - endif() + find_package(Jemalloc REQUIRED) if(JEMALLOC_FOUND) set(HAVE_JEMALLOC 1) else() @@ -281,7 +287,7 @@ endif() # C++ library libnghttp2_asio if(ENABLE_EXAMPLES AND NOT (OPENSSL_FOUND AND LIBEVENT_OPENSSL_FOUND)) - message(FATAL_ERROR "examples were requested (--enable-examples) but dependencies are not met.") + message(FATAL_ERROR "examples were requested (ENABLE_EXAMPLES=1) but dependencies are not met.") endif() # third-party http-parser only be built when needed diff --git a/CMakeOptions.txt b/CMakeOptions.txt new file mode 100644 index 00000000..a90b36ab --- /dev/null +++ b/CMakeOptions.txt @@ -0,0 +1,29 @@ +# Features that can be enabled for cmake (see CMakeLists.txt) + +option(ENABLE_WERROR "Turn on compile time warnings") +option(ENABLE_DEBUG "Turn on debug output") +option(ENABLE_THREADS "Turn on threading in apps" ON) +option(ENABLE_APP "Build applications (nghttp, nghttpd, nghttpx and h2load)" + ${ENABLE_APP_DEFAULT}) +option(ENABLE_HPACK_TOOLS "Build HPACK tools" + ${ENABLE_HPACK_TOOLS_DEFAULT}) +option(ENABLE_ASIO_LIB "Build C++ libnghttp2_asio library") +option(ENABLE_EXAMPLES "Build examples" + ${ENABLE_EXAMPLES_DEFAULT}) +option(ENABLE_PYTHON_BINDINGS "Build Python bindings" + ${ENABLE_PYTHON_BINDINGS_DEFAULT}) +option(ENABLE_FAILMALLOC "Build failmalloc test program" ON) +option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0 -DENABLE_PYTHON_BINDINGS=0") + +option(WITH_LIBXML2 "Use libxml2" + ${WITH_LIBXML2_DEFAULT}) +option(WITH_JEMALLOC "Use jemalloc" + ${WITH_JEMALLOC_DEFAULT}) +option(WITH_SPDYLAY "Use spdylay" + ${WITH_SPDYLAY_DEFAULT}) +option(WITH_MRUBY "Use mruby") +option(WITH_NEVERBLEED "Use neverbleed") +set(CYTHON_PATH "" CACHE PATH "Use cython in given path") +set(CYTHON "" CACHE FILEPATH "The Cython executable") + +# vim: ft=cmake: diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake new file mode 100644 index 00000000..ada87c16 --- /dev/null +++ b/cmake/FindCUnit.cmake @@ -0,0 +1,40 @@ +# - Try to find cunit +# Once done this will define +# CUNIT_FOUND - System has cunit +# CUNIT_INCLUDE_DIRS - The cunit include directories +# CUNIT_LIBRARIES - The libraries needed to use cunit + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_CUNIT QUIET cunit) + +find_path(CUNIT_INCLUDE_DIR + NAMES CUnit/CUnit.h + HINTS ${PC_CUNIT_INCLUDE_DIRS} +) +find_library(CUNIT_LIBRARY + NAMES cunit + HINTS ${PC_CUNIT_LIBRARY_DIRS} +) + +if(CUNIT_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+CU_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${CUNIT_INCLUDE_DIR}/CUnit/CUnit.h" + CUNIT_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + CUNIT_VERSION "${CUNIT_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(CUnit REQUIRED_VARS + CUNIT_LIBRARY CUNIT_INCLUDE_DIR + VERSION_VAR CUNIT_VERSION) + +if(CUNIT_FOUND) + set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) + set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) +endif() + +mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARY) diff --git a/cmake/FindJansson.cmake b/cmake/FindJansson.cmake new file mode 100644 index 00000000..8de971fb --- /dev/null +++ b/cmake/FindJansson.cmake @@ -0,0 +1,40 @@ +# - Try to find jansson +# Once done this will define +# JANSSON_FOUND - System has jansson +# JANSSON_INCLUDE_DIRS - The jansson include directories +# JANSSON_LIBRARIES - The libraries needed to use jansson + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_JANSSON QUIET jansson) + +find_path(JANSSON_INCLUDE_DIR + NAMES jansson.h + HINTS ${PC_JANSSON_INCLUDE_DIRS} +) +find_library(JANSSON_LIBRARY + NAMES jansson + HINTS ${PC_JANSSON_LIBRARY_DIRS} +) + +if(JANSSON_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+JANSSON_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${JANSSON_INCLUDE_DIR}/jansson.h" + JANSSON_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + JANSSON_VERSION "${JANSSON_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(jansson REQUIRED_VARS + JANSSON_LIBRARY JANSSON_INCLUDE_DIR + VERSION_VAR JANSSON_VERSION) + +if(JANSSON_FOUND) + set(JANSSON_LIBRARIES ${JANSSON_LIBRARY}) + set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR}) +endif() + +mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY) diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake index 83db90dc..5b01a721 100644 --- a/cmake/FindJemalloc.cmake +++ b/cmake/FindJemalloc.cmake @@ -4,16 +4,37 @@ # JEMALLOC_INCLUDE_DIRS - The jemalloc include directories # JEMALLOC_LIBRARIES - The libraries needed to use jemalloc -find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h) -find_library(JEMALLOC_LIBRARY NAMES jemalloc) +find_package(PkgConfig QUIET) +pkg_check_modules(PC_JEMALLOC QUIET jemalloc) -set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) -set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) +find_path(JEMALLOC_INCLUDE_DIR + NAMES jemalloc/jemalloc.h + HINTS ${PC_PCJEMALLOC_INCLUDE_DIRS} +) +find_library(JEMALLOC_LIBRARY + NAMES jemalloc + HINTS ${PC_JEMALLOC_LIBRARY_DIRS} +) + +if(JEMALLOC_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+JEMALLOC_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${JEMALLOC_INCLUDE_DIR}/jemalloc/jemalloc.h" + JEMALLOC_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + JEMALLOC_VERSION "${JEMALLOC_VERSION}") + unset(_version_regex) +endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(jemalloc DEFAULT_MSG - JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR) +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(jemalloc REQUIRED_VARS + JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR + VERSION_VAR JEMALLOC_VERSION) + +if(JEMALLOC_FOUND) + set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) + set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) +endif() mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY) diff --git a/cmake/FindLibev.cmake b/cmake/FindLibev.cmake index 03a0f53d..71e45082 100644 --- a/cmake/FindLibev.cmake +++ b/cmake/FindLibev.cmake @@ -4,20 +4,35 @@ # LIBEV_INCLUDE_DIRS - The libev include directories # LIBEV_LIBRARIES - The libraries needed to use libev -find_path(LIBEV_INCLUDE_DIR ev.h) -find_library(LIBEV_LIBRARY NAMES ev) +find_path(LIBEV_INCLUDE_DIR + NAMES ev.h +) +find_library(LIBEV_LIBRARY + NAMES ev +) -# Assume that the discovered "ev" library contains ev_time -#include(CheckLibraryExists) -#CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV) - -set(LIBEV_LIBRARIES ${LIBEV_LIBRARY}) -set(LIBEV_INCLUDE_DIRS ${LIBEV_INCLUDE_DIR}) +if(LIBEV_INCLUDE_DIR) + file(STRINGS "${LIBEV_INCLUDE_DIR}/ev.h" + LIBEV_VERSION_MAJOR REGEX "^#define[ \t]+EV_VERSION_MAJOR[ \t]+[0-9]+") + file(STRINGS "${LIBEV_INCLUDE_DIR}/ev.h" + LIBEV_VERSION_MINOR REGEX "^#define[ \t]+EV_VERSION_MINOR[ \t]+[0-9]+") + string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MAJOR "${LIBEV_VERSION_MAJOR}") + string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MINOR "${LIBEV_VERSION_MINOR}") + set(LIBEV_VERSION "${LIBEV_VERSION_MAJOR}.${LIBEV_VERSION_MINOR}") + unset(LIBEV_VERSION_MINOR) + unset(LIBEV_VERSION_MAJOR) +endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set LIBEV_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(Libev DEFAULT_MSG - LIBEV_LIBRARY LIBEV_INCLUDE_DIR) +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(Libev REQUIRED_VARS + LIBEV_LIBRARY LIBEV_INCLUDE_DIR + VERSION_VAR LIBEV_VERSION) + +if(LIBEV_FOUND) + set(LIBEV_LIBRARIES ${LIBEV_LIBRARY}) + set(LIBEV_INCLUDE_DIRS ${LIBEV_INCLUDE_DIR}) +endif() mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARY) diff --git a/cmake/FindLibevent.cmake b/cmake/FindLibevent.cmake new file mode 100644 index 00000000..4e5af6a9 --- /dev/null +++ b/cmake/FindLibevent.cmake @@ -0,0 +1,100 @@ +# - Try to find libevent +#.rst +# FindLibevent +# ------------ +# +# Find Libevent include directories and libraries. Invoke as:: +# +# find_package(Libevent +# [version] [EXACT] # Minimum or exact version +# [REQUIRED] # Fail if Libevent is not found +# [COMPONENT ...]) # Libraries to look for +# +# Valid components are one or more of:: libevent core extra pthreads openssl. +# Note that 'libevent' contains both core and extra. You must specify one of +# them for the other components. +# +# This module will define the following variables:: +# +# LIBEVENT_FOUND - True if headers and requested libraries were found +# LIBEVENT_INCLUDE_DIRS - Libevent include directories +# LIBEVENT_LIBRARIES - Libevent libraries to be linked +# LIBEVENT__FOUND - Component was found ( is uppercase) +# LIBEVENT__LIBRARY - Library to be linked for Libevent omponent . + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBEVENT QUIET libevent) + +# Look for the Libevent 2.0 or 1.4 headers +find_path(LIBEVENT_INCLUDE_DIR + NAMES + event2/event-config.h + event-config.h + HINTS + ${PC_LIBEVENT_INCLUDE_DIRS} +) +set(_LIBEVENT_REQUIRED_VARS LIBEVENT_INCLUDE_DIR) + +if(LIBEVENT_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+_EVENT_VERSION[ \t]+\"([^\"]+)\".*") + if(EXISTS "${LIBEVENT_INCLUDE_DIR}/event2/event-config.h") + # Libevent 2.0 + file(STRINGS "${LIBEVENT_INCLUDE_DIR}/event2/event-config.h" + LIBEVENT_VERSION REGEX "${_version_regex}") + else() + # Libevent 1.4 + file(STRINGS "${LIBEVENT_INCLUDE_DIR}/event-config.h" + LIBEVENT_VERSION REGEX "${_version_regex}") + endif() + string(REGEX REPLACE "${_version_regex}" "\\1" + LIBEVENT_VERSION "${LIBEVENT_VERSION}") + unset(_version_regex) +endif() + +foreach(COMPONENT ${Libevent_FIND_COMPONENTS}) + set(_LIBEVENT_LIBNAME libevent) + # Note: compare two variables to avoid a CMP0054 policy warning + if(COMPONENT STREQUAL _LIBEVENT_LIBNAME) + set(_LIBEVENT_LIBNAME event) + else() + set(_LIBEVENT_LIBNAME "event_${COMPONENT}") + endif() + string(TOUPPER "${COMPONENT}" COMPONENT) + find_library(LIBEVENT_${COMPONENT}_LIBRARY + NAMES ${_LIBEVENT_LIBNAME} + HINTS ${PC_LIBEVENT_LIBRARY_DIRS} + ) + if(LIBEVENT_${COMPONENT}_LIBRARY) + set(LIBEVENT_${COMPONENT}_FOUND 1) + endif() + list(APPEND _LIBEVENT_REQUIRED_VARS LIBEVENT_${COMPONENT}_LIBRARY) +endforeach() +unset(_LIBEVENT_LIBNAME) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBEVENT_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(LIBEVENT REQUIRED_VARS + ${_LIBEVENT_REQUIRED_VARS} + VERSION_VAR LIBEVENT_VERSION + HANDLE_COMPONENTS) + +if(LIBEVENT_FOUND) + set(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) + set(LIBEVENT_LIBRARIES) + if(NOT Libevent_FIND_QUIETLY) + message(STATUS "Found the following Libevent components:") + endif() + foreach(_COMPONENT ${Libevent_FIND_COMPONENTS}) + string(TOUPPER "${_COMPONENT}" COMPONENT) + if(LIBEVENT_${COMPONENT}_FOUND) + if(NOT Libevent_FIND_QUIETLY) + message(STATUS " ${_COMPONENT}") + endif() + list(APPEND LIBEVENT_LIBRARIES ${LIBEVENT_${COMPONENT}_LIBRARY}) + endif() + endforeach() +endif() + +mark_as_advanced(${_LIBEVENT_REQUIRED_VARS}) +unset(_LIBEVENT_REQUIRED_VARS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c22321e..81c2cb59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories( "${CMAKE_SOURCE_DIR}/src/includes" "${CMAKE_SOURCE_DIR}/third-party" + ${JEMALLOC_INCLUDE_DIRS} ${LIBSPDYLAY_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${LIBEV_INCLUDE_DIRS} From 8c46d9181ff3172427066d5ccde3584f707482b8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Feb 2016 01:57:13 +0100 Subject: [PATCH 24/59] cmake: process tests directory Split the nghttp2 library into objects and a shared library from those objects. This is needed because of symbol visibility. An advantage over the autotools build is that there are no worries about static versus static library builds. Test: cmake $srcdir make nghttpx-unittest main failmalloc make test --- CMakeLists.txt | 6 +---- lib/CMakeLists.txt | 3 ++- src/CMakeLists.txt | 43 ++++++++++++++++++++--------------- tests/CMakeLists.txt | 53 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a669c4ba..938f0c2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,8 +140,6 @@ cmake_pop_check_state() # Checks for libraries. -# Additional libraries required for tests. -set(TEST_LIBRARIES) # Additional libraries required for programs under src directory. set(APP_LIBRARIES) @@ -163,6 +161,7 @@ endif() find_package(CUnit 2.1) if(CUNIT_FOUND) + enable_testing() set(HAVE_CUNIT 1) else() set(HAVE_CUNIT 0) @@ -457,7 +456,6 @@ endif() # # propagate $enable_static to tests/Makefile.am # AM_CONDITIONAL([ENABLE_STATIC], [test "x$enable_static" = "xyes"]) # -# AC_SUBST([TESTLDADD]) # AC_SUBST([APPLDFLAGS]) add_definitions(-DHAVE_CONFIG_H) @@ -519,10 +517,8 @@ add_subdirectory(src) #add_subdirectory(src/includes) add_subdirectory(examples) add_subdirectory(python) -if(0) add_subdirectory(tests) #add_subdirectory(tests/testdata) -endif() add_subdirectory(integration-tests) add_subdirectory(doc) add_subdirectory(contrib) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 114749b1..a7520f5b 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -24,7 +24,8 @@ set(NGHTTP2_SOURCES nghttp2_http.c ) -add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) +add_library(nghttp2-obj OBJECT ${NGHTTP2_SOURCES}) +add_library(nghttp2 SHARED $) #target_link_libraries(nghttp2 ...) set_target_properties(nghttp2 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81c2cb59..4057ac86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,23 +155,30 @@ if(ENABLE_APP) if(HAVE_CUNIT) # check_PROGRAMS += nghttpx-unittest - # nghttpx_unittest_SOURCES = shrpx-unittest.cc - # shrpx_ssl_test.cc - # shrpx_downstream_test.cc - # shrpx_config_test.cc - # shrpx_http_test.cc - # http2_test.cc - # util_test.cc - # nghttp2_gzip_test.c - # nghttp2_gzip.c - # buffer_test.cc - # memchunk_test.cc - # template_test.cc - # base64_test.cc - # nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} - # -DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\" - # nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@ - # + set(NGHTTPX_UNITTEST_SOURCES + shrpx-unittest.cc + shrpx_ssl_test.cc + shrpx_downstream_test.cc + shrpx_config_test.cc + shrpx_http_test.cc + http2_test.cc + util_test.cc + nghttp2_gzip_test.c + nghttp2_gzip.c + buffer_test.cc + memchunk_test.cc + template_test.cc + base64_test.cc + ) + add_executable(nghttpx-unittest EXCLUDE_FROM_ALL + ${NGHTTPX_UNITTEST_SOURCES} + $ + ) + target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) + target_compile_definitions(nghttpx-unittest + PRIVATE "-DNGHTTP2_TESTS_DIR=\"$(CMAKE_SOURCE_DIR)/tests\"" + ) + target_link_libraries(nghttpx-unittest nghttpx ${CUNIT_LIBRARIES}) # if HAVE_MRUBY # nghttpx_unittest_CPPFLAGS += # -I${top_srcdir}/third-party/mruby/include @LIBMRUBY_CFLAGS@ @@ -184,7 +191,7 @@ if(ENABLE_APP) # nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la # endif # HAVE_NEVERBLEED # - # TESTS += nghttpx-unittest + add_test(nghttpx-unittest nghttpx-unittest) endif() add_executable(nghttp ${NGHTTP_SOURCES} $) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..1ffa16c7 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,53 @@ +# XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem +if(HAVE_CUNIT) + # XXX replace this by lists (WARNCFLAGS_list) + string(REPLACE " " ";" c_flags "${WARNCFLAGS}") + add_compile_options(${c_flags}) + + include_directories( + "${CMAKE_SOURCE_DIR}/lib/includes" + "${CMAKE_SOURCE_DIR}/lib" + "${CMAKE_SOURCE_DIR}/src/includes" + "${CMAKE_BINARY_DIR}/lib/includes" + ${CUNIT_INCLUDE_DIRS} + ) + + set(MAIN_SOURCES + main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c + nghttp2_test_helper.c + nghttp2_frame_test.c + nghttp2_stream_test.c + nghttp2_session_test.c + nghttp2_hd_test.c + nghttp2_npn_test.c + nghttp2_helper_test.c + nghttp2_buf_test.c + ) + + add_executable(main EXCLUDE_FROM_ALL + ${MAIN_SOURCES} + $ + ) + target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS}) + target_link_libraries(main ${CUNIT_LIBRARIES}) + add_test(main main) + + if(ENABLE_FAILMALLOC) + set(FAILMALLOC_SOURCES + failmalloc.c failmalloc_test.c + malloc_wrapper.c + nghttp2_test_helper.c + ) + add_executable(failmalloc EXCLUDE_FROM_ALL + ${FAILMALLOC_SOURCES} + $ + ) + target_link_libraries(failmalloc ${CUNIT_LIBRARIES}) + add_test(failmalloc failmalloc) + endif() + + if(ENABLE_APP) + # EXTRA_DIST = end_to_end.py + # TESTS += end_to_end.py + endif() +endif() From 0afc21c9d89f405de5dfbcca59387c245cfbc175 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Feb 2016 10:49:55 +0100 Subject: [PATCH 25/59] cmake: fix compilation in lib Need to add -fPIC to objects that will be put in a shared library. --- lib/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a7520f5b..7b012acb 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -25,8 +25,10 @@ set(NGHTTP2_SOURCES ) add_library(nghttp2-obj OBJECT ${NGHTTP2_SOURCES}) +# Needed because the object files are linked into a shared library. +set_target_properties(nghttp2-obj PROPERTIES + POSITION_INDEPENDENT_CODE ON) add_library(nghttp2 SHARED $) -#target_link_libraries(nghttp2 ...) set_target_properties(nghttp2 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}) From 474ecc4b47a0add2eb6b2716be6125de828b32ab Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Feb 2016 10:50:31 +0100 Subject: [PATCH 26/59] cmake: add neverbleed support --- src/CMakeLists.txt | 17 +++++------------ third-party/CMakeLists.txt | 11 +++++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4057ac86..f5a97a20 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -143,13 +143,7 @@ if(ENABLE_APP) endif() if(HAVE_NEVERBLEED) - target_include_directories(nghttpx PRIVATE - "${CMAKE_SOURCE_DIR}/third-party/neverbleed" - ) - target_link_libraries(nghttpx - # FIXME .la does not work ofc... - "${CMAKE_BINARY_DIR}/third-party/libneverbleed.la" - ) + target_link_libraries(nghttpx neverbleed) endif() @@ -186,11 +180,10 @@ if(ENABLE_APP) # -L${top_builddir}/third-party/mruby/build/lib @LIBMRUBY_LIBS@ # endif # HAVE_MRUBY # - # if HAVE_NEVERBLEED - # nghttpx_unittest_CPPFLAGS += -I${top_srcdir}/third-party/neverbleed - # nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la - # endif # HAVE_NEVERBLEED - # + if(HAVE_NEVERBLEED) + target_link_libraries(nghttpx-unittest neverbleed) + endif() + add_test(nghttpx-unittest nghttpx-unittest) endif() diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 41308b91..f90a5ee0 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -5,12 +5,15 @@ if(ENABLE_THIRD_PARTY) add_library(http-parser OBJECT ${LIBHTTP_PARSER_SOURCES}) if(HAVE_NEVERBLEED) - set(LIBNEVERBLEED_SOURCES + set(NEVERBLEED_SOURCES neverbleed/neverbleed.c ) - add_library(libneverbleed ${LIBNEVERBLEED_SOURCES}) - target_include_directories(libneverbleed PUBLIC ${OPENSSL_INCLUDE_DIRS}) - target_link_libraries(libneverbleed ${OPENSSL_LIBRARIES}) + add_library(neverbleed ${NEVERBLEED_SOURCES}) + target_include_directories(neverbleed PRIVATE ${OPENSSL_INCLUDE_DIRS}) + target_include_directories(neverbleed INTERFACE + "${CMAKE_SOURCE_DIR}/third-party/neverbleed" + ) + target_link_libraries(neverbleed ${OPENSSL_LIBRARIES}) endif() if(HAVE_MRUBY) From f407f7f4062ee13f42606af3182fddf8f887c5cb Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Feb 2016 23:14:27 +0100 Subject: [PATCH 27/59] cmake: add mruby support, fix tests dir mruby is always invoked now (mirrors the autotools behavior). It could be optimized though to only trigger the mruby build when the static library is missing. Also fix typo in NGHTTP2_TESTS_DIR macro definition (detected when invoking the Ninja generator). --- CMakeLists.txt | 4 ++- src/CMakeLists.txt | 22 ++++------------ third-party/CMakeLists.txt | 51 ++++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 938f0c2b..58882726 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,7 +295,9 @@ if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB) # mruby (for src/nghttpx) if(WITH_MRUBY) set(HAVE_MRUBY 1) - # XXX add -lmruby and -lm libs + set(MRUBY_LIBRARY + "${CMAKE_BINARY_DIR}/third-party/mruby/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}mruby${CMAKE_STATIC_LIBRARY_SUFFIX}" + ) else() set(HAVE_MRUBY 0) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5a97a20..47d8124a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,15 +131,7 @@ if(ENABLE_APP) ) if(HAVE_MRUBY) - target_include_directories(nghttpx PRIVATE - "${CMAKE_SOURCE_DIR}/third-party/mruby/include" - # ${LIBMRUBY_CFLAGS} - ) - target_link_libraries(nghttpx - # nghttpx_LDADD += -L${top_builddir}/third-party/mruby/build/lib - # XXX find_library or other absolute path? - # ${LIBMRUBY_LIBS} - ) + target_link_libraries(nghttpx mruby-lib) endif() if(HAVE_NEVERBLEED) @@ -170,16 +162,12 @@ if(ENABLE_APP) ) target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) target_compile_definitions(nghttpx-unittest - PRIVATE "-DNGHTTP2_TESTS_DIR=\"$(CMAKE_SOURCE_DIR)/tests\"" + PRIVATE "-DNGHTTP2_TESTS_DIR=\"${CMAKE_SOURCE_DIR}/tests\"" ) target_link_libraries(nghttpx-unittest nghttpx ${CUNIT_LIBRARIES}) - # if HAVE_MRUBY - # nghttpx_unittest_CPPFLAGS += - # -I${top_srcdir}/third-party/mruby/include @LIBMRUBY_CFLAGS@ - # nghttpx_unittest_LDADD += - # -L${top_builddir}/third-party/mruby/build/lib @LIBMRUBY_LIBS@ - # endif # HAVE_MRUBY - # + if(HAVE_MRUBY) + target_link_libraries(nghttpx-unittest mruby-lib) + endif() if(HAVE_NEVERBLEED) target_link_libraries(nghttpx-unittest neverbleed) endif() diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index f90a5ee0..de5243a1 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -17,22 +17,47 @@ if(ENABLE_THIRD_PARTY) endif() if(HAVE_MRUBY) - ## EXTRA_DIST = build_config.rb mruby/* + # EXTRA_DIST = build_config.rb mruby/* - #.PHONY: all-local clean mruby + set(MRUBY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/mruby/build") + set(MRUBY_LIBRARY + "${CMAKE_STATIC_LIBRARY_PREFIX}mruby${CMAKE_STATIC_LIBRARY_SUFFIX}" + ) - #mruby: - # MRUBY_CONFIG="${srcdir}/build_config.rb" \ - # BUILD_DIR="${abs_builddir}/mruby/build" \ - # INSTALL_DIR="${abs_builddir}/mruby/build/install/bin" \ - # CC="${CC}" CXX="${CXX}" LD="${LD}" \ - # CFLAGS="${CPPFLAGS} ${CFLAGS}" CXXFLAGS="${CPPFLAGS} ${CXXFLAGS}" \ - # LDFLAGS="${LDFLAGS}" \ - # "${srcdir}/mruby/minirake" -f "${srcdir}/mruby/Rakefile" + # The mruby build needs some env vars. Alternatively, look at cmake -P + if(CMAKE_VERSION VERSION_LESS "3.1") + # XXX works only for Unixes? + set(ENV_COMMAND env) + else() + set(ENV_COMMAND ${CMAKE_COMMAND} -E env) + endif() + # Required for the Ninja generator. For older CMake, you first have to + # invoke 'ninja mruby' before building dependents. + if(CMAKE_VERSION VERSION_LESS "3.2") + set(_byproducts) + else() + set(_byproducts BYPRODUCTS "mruby/build/lib/${MRUBY_LIBRARY}") + endif() + add_custom_target(mruby + COMMAND ${ENV_COMMAND} + "MRUBY_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/build_config.rb" + "BUILD_DIR=${MRUBY_BUILD_DIR}" + "INSTALL_DIR=${MRUBY_BUILD_DIR}/install/bin" + "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" + "${CMAKE_CURRENT_SOURCE_DIR}/mruby/minirake" + -f "${CMAKE_CURRENT_SOURCE_DIR}/mruby/Rakefile" + ${_byproducts} + VERBATIM + ) - #all-local: mruby + # Make the mruby library available to others in this project without them + # having to worry about include dirs and the mruby location. + add_library(mruby-lib STATIC IMPORTED GLOBAL) + set_target_properties(mruby-lib PROPERTIES + IMPORTED_LOCATION "${MRUBY_BUILD_DIR}/lib/${MRUBY_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/mruby/include" + ) - #clean-local: - # -rm -rf "${abs_builddir}/mruby/build" + # XXX clean ${CMAKE_CURRENT_BINARY_DIR}/mruby/build endif() endif() From 9bc6dc71132d5d2335ad163b7f1367ab5f8ce5ea Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 12:17:49 +0100 Subject: [PATCH 28/59] cmake: add python support FindCython.cmake was taken from https://github.com/thewtex/cython-cmake-example. The UseCython module works, but since it is lacking an installation target setup.py will be used instead. --- CMakeLists.txt | 60 ++++++++++++++-------------------- CMakeOptions.txt | 2 -- cmake/FindCython.cmake | 44 +++++++++++++++++++++++++ python/CMakeLists.txt | 45 ++++++++++++------------- python/install-python.cmake.in | 10 ++++++ python/setup.py.in | 1 + 6 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 cmake/FindCython.cmake create mode 100644 python/install-python.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 58882726..123902a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,10 @@ HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} include(GNUInstallDirs) +# For Python bindings and documentation +# (Must be called before PythonLibs for matching versions.) +find_package(PythonInterp) + # Auto-detection of features that can be toggled find_package(OpenSSL 1.0.1 QUIET) find_package(Libev 4.15 QUIET) @@ -55,8 +59,13 @@ find_package(Jansson 2.5 QUIET) set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND}) find_package(Libevent 2.0.8 QUIET COMPONENTS openssl) set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND}) -# XXX auto-detect python -set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) +find_package(Cython QUIET) +find_package(PythonLibs QUIET) +if(CYTHON_FOUND AND PYTHONLIBS_FOUND) + set(ENABLE_PYTHON_BINDINGS_DEFAULT ON) +else() + set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) +endif() find_package(LibXml2 QUIET) set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) @@ -68,12 +77,6 @@ set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND}) include(CMakeOptions.txt) find_package(PkgConfig 0.20) -# For Python bindings and documentation -find_package(PythonInterp) -# XXX fail only when "ON" instead of "CHECK"? -if(ENABLE_PYTHON_BINDINGS) -endif() -# AM_PATH_PYTHON([2.7],, [:]) if(ENABLE_LIB_ONLY) set(ENABLE_APP OFF) @@ -82,21 +85,6 @@ if(ENABLE_LIB_ONLY) set(ENABLE_PYTHON_BINDINGS OFF) endif() -if(ENABLE_PYTHON_BINDINGS) - find_package(PythonLibs 2.7 REQUIRED) - # XXX find cython -endif() -# if [test "x$request_python_bindings" != "xno"]; then -# AX_PYTHON_DEVEL([>= '2.7']) -# fi -# -# if test "x${cython_path}" = "x"; then -# AC_CHECK_PROGS([CYTHON], [cython.py cython]) -# else -# CYTHON=${cython_path} -# AC_SUBST([CYTHON]) -# fi - # # If we're running GCC or clang define _U_ to be "__attribute__((unused))" # so we can use _U_ to flag unused function parameters and not get warnings @@ -143,6 +131,18 @@ cmake_pop_check_state() # Additional libraries required for programs under src directory. set(APP_LIBRARIES) +if(ENABLE_PYTHON_BINDINGS) + find_package(Cython REQUIRED) + find_package(PythonLibs REQUIRED) + if(NOT PYTHON_VERSION_STRING STREQUAL PYTHONLIBS_VERSION_STRING) + message(SEND_ERROR + "Python executable and library must have the same version!" + " Found Python ${PYTHON_VERSION_STRING} and" + " PythonLibs ${PYTHONLIBS_VERSION_STRING}" + ) + endif() +endif() + set(CMAKE_THREAD_PREFER_PTHREAD 1) find_package(Threads) if(CMAKE_USE_PTHREADS_INIT) @@ -311,16 +311,6 @@ else() set(HAVE_NEVERBLEED 0) endif() -# Python bindings -if(ENABLE_PYTHON_BINDINGS AND NOT CYTHON AND NOT PYTHONLIBS_FOUND) -# XXX PythonInterp and PythonLibs are looked up before, unreachable check? -# if test "x${request_python_bindings}" != "xno" && -# test "x${CYTHON}" != "x" && -# test "x${PYTHON}" != "x:" && -# test "x${have_python_dev}" = "xyes"; then - message(FATAL_ERROR "python bindings were requested (ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.") -endif() - # Checks for header files. # XXX AC_HEADER_ASSERT adds --disable-assert which sets -DNDEBUG include(CheckIncludeFile) @@ -528,7 +518,6 @@ add_subdirectory(script) # XXX fix shared/static library -# XXX fix python string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) message(STATUS "summary of build options: @@ -550,8 +539,7 @@ message(STATUS "summary of build options: Python: Python: ${PYTHON_EXECUTABLE} PYTHON_VERSION: ${PYTHON_VERSION_STRING} - pyexecdir: ${pyexecdir} - Python-dev: ${have_python_dev} + Library version:${PYTHONLIBS_VERSION_STRING} Cython: ${CYTHON_EXECUTABLE} Test: CUnit: ${HAVE_CUNIT} (LIBS='${CUNIT_LIBRARIES}') diff --git a/CMakeOptions.txt b/CMakeOptions.txt index a90b36ab..1cfde80d 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -23,7 +23,5 @@ option(WITH_SPDYLAY "Use spdylay" ${WITH_SPDYLAY_DEFAULT}) option(WITH_MRUBY "Use mruby") option(WITH_NEVERBLEED "Use neverbleed") -set(CYTHON_PATH "" CACHE PATH "Use cython in given path") -set(CYTHON "" CACHE FILEPATH "The Cython executable") # vim: ft=cmake: diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake new file mode 100644 index 00000000..04aed1f8 --- /dev/null +++ b/cmake/FindCython.cmake @@ -0,0 +1,44 @@ +# Find the Cython compiler. +# +# This code sets the following variables: +# +# CYTHON_EXECUTABLE +# +# See also UseCython.cmake + +#============================================================================= +# Copyright 2011 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +# Use the Cython executable that lives next to the Python executable +# if it is a local installation. +find_package( PythonInterp ) +if( PYTHONINTERP_FOUND ) + get_filename_component( _python_path ${PYTHON_EXECUTABLE} PATH ) + find_program( CYTHON_EXECUTABLE + NAMES cython cython.bat cython3 + HINTS ${_python_path} + ) +else() + find_program( CYTHON_EXECUTABLE + NAMES cython cython.bat cython3 + ) +endif() + + +include( FindPackageHandleStandardArgs ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( Cython REQUIRED_VARS CYTHON_EXECUTABLE ) + +mark_as_advanced( CYTHON_EXECUTABLE ) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0a035e7c..0cfdc9b3 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,33 +1,34 @@ # EXTRA_DIST = cnghttp2.pxd nghttp2.pyx -# XXX consider https://github.com/thewtex/cython-cmake-example - if(ENABLE_PYTHON_BINDINGS) - # XXX add ALL? Will always be invoked as target is always out-of-date though. - add_custom_target(python - COMMAND ${PYTHON_EXECUTABLE} setup.py build + + add_custom_target(python ALL + COMMAND "${PYTHON_EXECUTABLE}" setup.py build + VERBATIM DEPENDS nghttp2.c ) - add_custom_target(python-install - COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix=${DESTDIR}${CMAKE_INSTALL_PREFIX} - ) + configure_file(install-python.cmake.in install-python.cmake ESCAPE_QUOTES @ONLY) + install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-python.cmake") - # XXX cmake does not have an uninstall target, do not bother with this then. - # XXX glob patterns like this will probably not work - #add_custom_target(python-uninstall - # COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/nghttp2.so - # COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/python_nghttp2-*.egg - #) - - # XXX cleaner way to advertise the build artifacts? (note nghttp2.c is cleaned automatically) - add_custom_target(python-clean - COMMAND ${PYTHON_EXECUTABLE} setup.py clean --all - ) - - # XXX CYTHON_EXECUTABLE is not set! add_custom_command(OUTPUT nghttp2.c - COMMAND ${CYTHON_EXECUTABLE} -o nghttp2.c nghttp2.pyx + COMMAND "${CYTHON_EXECUTABLE}" -o nghttp2.c + "${CMAKE_CURRENT_SOURCE_DIR}/nghttp2.pyx" + VERBATIM DEPENDS nghttp2.pyx ) +## This works also, except that the installation target is missing... +# include(UseCython) +# cython_add_module(python_nghttp2 nghttp2.pyx) +# set_target_properties(python_nghttp2 PROPERTIES +# OUTPUT_NAME nghttp2 +# ) +# target_include_directories(python_nghttp2 PRIVATE +# "${CMAKE_SOURCE_DIR}/lib" +# "${CMAKE_SOURCE_DIR}/lib/includes" +# "${CMAKE_BINARY_DIR}/lib/includes" +# ) +# target_link_libraries(python_nghttp2 +# nghttp2 +# ) endif() diff --git a/python/install-python.cmake.in b/python/install-python.cmake.in new file mode 100644 index 00000000..f3edbdb0 --- /dev/null +++ b/python/install-python.cmake.in @@ -0,0 +1,10 @@ +get_filename_component(rootdir "$ENV{DESTDIR}" ABSOLUTE) +if(rootdir STREQUAL "") + set(rootdir /) +endif() +execute_process( + COMMAND "@PYTHON_EXECUTABLE@" setup.py install + --skip-build + --root=${rootdir} --prefix=${CMAKE_INSTALL_PREFIX} + WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@" +) diff --git a/python/setup.py.in b/python/setup.py.in index a2b4851d..93f89964 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -39,6 +39,7 @@ setup( '@top_srcdir@/lib/includes', '@top_builddir@/lib/includes'], library_dirs=['@top_builddir@/lib/.libs', + '@top_builddir@/lib', '@top_builddir@'], libraries=LIBS)], long_description='TBD' From 1b67b2d33e113ed1987df9c10ceb77f8abecb7f0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 12:48:36 +0100 Subject: [PATCH 29/59] 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} From 3dd57e1f594db4e1567ae3fd83e132bf294a175b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 14:01:44 +0100 Subject: [PATCH 30/59] cmake: fix feature availability reporting Some detected libraries were not reported when a feature is disabled. This change removes unnecessary second find_package calls and sets HAVE_xxx immediately based on xxx_FOUND. --- CMakeLists.txt | 118 ++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc6a0b1a..94eed97e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ else() endif() find_package(Jansson 2.5 QUIET) set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND}) -find_package(Libevent 2.0.8 QUIET COMPONENTS openssl) +# 2.0.8 is required because we use evconnlistener_set_error_cb() +find_package(Libevent 2.0.8 QUIET COMPONENTS libevent openssl) set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND}) find_package(Cython QUIET) find_package(PythonLibs QUIET) @@ -67,7 +68,7 @@ else() set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) endif() -find_package(LibXml2 QUIET) +find_package(LibXml2 2.7.7 QUIET) set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) find_package(Jemalloc QUIET) set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND}) @@ -76,6 +77,13 @@ set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND}) include(CMakeOptions.txt) +if(ENABLE_LIB_ONLY AND (ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_EXAMPLES OR + ENABLE_PYTHON_BINDINGS)) + # Remember when disabled options are disabled for later diagnostics. + set(ENABLE_LIB_ONLY_DISABLED_OTHERS 1) +else() + set(ENABLE_LIB_ONLY_DISABLED_OTHERS 0) +endif() if(ENABLE_LIB_ONLY) set(ENABLE_APP OFF) set(ENABLE_HPACK_TOOLS OFF) @@ -130,10 +138,12 @@ cmake_pop_check_state() set(APP_LIBRARIES) if(ENABLE_PYTHON_BINDINGS) - find_package(Cython REQUIRED) - find_package(PythonLibs REQUIRED) + if(NOT (CYTHON_FOUND AND PYTHONLIBS_FOUND)) + message(FATAL_ERROR "python bindings were requested " + "(ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.") + endif() if(NOT PYTHON_VERSION_STRING STREQUAL PYTHONLIBS_VERSION_STRING) - message(SEND_ERROR + message(FATAL_ERROR "Python executable and library must have the same version!" " Found Python ${PYTHON_VERSION_STRING} and" " PythonLibs ${PYTHONLIBS_VERSION_STRING}" @@ -158,83 +168,30 @@ endif() # APP_LIBRARIES if it is really specific to OpenSSL? find_package(CUnit 2.1) -if(CUNIT_FOUND) - enable_testing() - set(HAVE_CUNIT 1) -else() - set(HAVE_CUNIT 0) -endif() - -if(ENABLE_APP) - find_package(OpenSSL 1.0.1 REQUIRED) - find_package(Libev 4.15 REQUIRED) - find_package(ZLIB 1.2.3 REQUIRED) -endif() +enable_testing() +set(HAVE_CUNIT ${CUNIT_FOUND}) # openssl (for src) +set(HAVE_OPENSSL ${OPENSSL_FOUND}) if(OPENSSL_FOUND) - set(HAVE_OPENSSL 1) set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) -else() - set(HAVE_OPENSSL 0) endif() # libev (for src) -if(LIBEV_FOUND) - set(HAVE_LIBEV 1) -else() - set(HAVE_LIBEV 0) -endif() -if(ZLIB_FOUND) - set(HAVE_ZLIB 1) -else() - set(HAVE_ZLIB 0) -endif() - -if(ENABLE_EXAMPLES) - # libevent_openssl (for examples) - # 2.0.8 is required because we use evconnlistener_set_error_cb() - find_package(Libevent 2.0.8 REQUIRED COMPONENTS libevent openssl) +set(HAVE_LIBEV ${LIBEV_FOUND}) +set(HAVE_ZLIB ${ZLIB_FOUND}) +set(HAVE_LIBEVENT_OPENSSL ${LIBEVENT_FOUND}) +if(LIBEVENT_FOUND) + # Must both link the core and openssl libraries. set(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES}) - set(HAVE_LIBEVENT_OPENSSL 1) -else() - set(HAVE_LIBEVENT_OPENSSL 0) endif() - -if(ENABLE_HPACK_TOOLS) - # jansson (for src/nghttp, src/deflatehd and src/inflatehd) - find_package(Jansson 2.5 REQUIRED) - set(HAVE_JANSSON 1) -else() - set(HAVE_JANSSON 0) -endif() - +# jansson (for src/nghttp, src/deflatehd and src/inflatehd) +set(HAVE_JANSSON ${JANSSON_FOUND}) # libxml2 (for src/nghttp) -if(WITH_LIBXML2) - find_package(LibXml2 2.7.7 REQUIRED) - set(HAVE_LIBXML2 1) -else() - set(HAVE_LIBXML2 0) -endif() - +set(HAVE_LIBXML2 ${LIBXML2_FOUND}) # jemalloc -if(WITH_JEMALLOC) - find_package(Jemalloc REQUIRED) - if(JEMALLOC_FOUND) - set(HAVE_JEMALLOC 1) - else() - set(HAVE_JEMALLOC 0) - endif() -else() - set(HAVE_JEMALLOC 0) -endif() - +set(HAVE_JEMALLOC ${JEMALLOC_FOUND}) # spdylay (for src/nghttpx and src/h2load) -if(WITH_SPDYLAY) - find_package(Spdylay 1.3.2 REQUIRED) - set(HAVE_SPDYLAY 1) -else() - set(HAVE_SPDYLAY 0) -endif() +set(HAVE_SPDYLAY ${SPDYLAY_FOUND}) if(ENABLE_ASIO_LIB) find_package(Boost 1.54.0 REQUIRED system thread) @@ -259,19 +216,8 @@ endif() if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB) set(ENABLE_THIRD_PARTY 1) # mruby (for src/nghttpx) - if(WITH_MRUBY) - set(HAVE_MRUBY 1) - set(MRUBY_LIBRARY - "${CMAKE_BINARY_DIR}/third-party/mruby/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}mruby${CMAKE_STATIC_LIBRARY_SUFFIX}" - ) - else() - set(HAVE_MRUBY 0) - endif() - if(WITH_NEVERBLEED) - set(HAVE_NEVERBLEED 1) - else() - set(HAVE_NEVERBLEED 0) - endif() + set(HAVE_MRUBY ${WITH_MRUBY}) + set(HAVE_NEVERBLEED ${WITH_NEVERBLEED}) else() set(HAVE_MRUBY 0) set(HAVE_NEVERBLEED 0) @@ -533,3 +479,7 @@ message(STATUS "summary of build options: Python bindings:${ENABLE_PYTHON_BINDINGS} Threading: ${ENABLE_THREADS} ") +if(ENABLE_LIB_ONLY_DISABLED_OTHERS) + message("Only the library will be built. To build other components " + "(such as applications and examples), set ENABLE_LIB_ONLY=OFF.") +endif() From a909eb6b235bfa5a09f93a0f68cb8f3ab818cf57 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 14:09:10 +0100 Subject: [PATCH 31/59] cmake: fix linking http-parser into shared libs --- third-party/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index de5243a1..f89dc525 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -3,6 +3,8 @@ if(ENABLE_THIRD_PARTY) http-parser/http_parser.c ) add_library(http-parser OBJECT ${LIBHTTP_PARSER_SOURCES}) + set_target_properties(http-parser PROPERTIES + POSITION_INDEPENDENT_CODE ON) if(HAVE_NEVERBLEED) set(NEVERBLEED_SOURCES From f4b2a4ab00c0db8856c71f984a4e86c6b9badaed Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 14:57:05 +0100 Subject: [PATCH 32/59] cmake: always enable warnings without -Werror Warnings are useful, let's enable them by default. --- CMakeLists.txt | 9 +++++++-- cmake/ExtractValidFlags.cmake | 4 +--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94eed97e..13d11b90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -285,12 +285,17 @@ if(HAVE_EPOLL AND HAVE_TIMERFD_CREATE) set(ENABLE_TINY_NGHTTPD 1) endif() +set(WARNCFLAGS) +set(WARNCXXFLAGS) if(ENABLE_WERROR) + extract_valid_c_flags(WARNCFLAGS -Werror) + extract_valid_c_flags(WARNCXXFLAGS -Werror) +endif() +if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") # For C compiler extract_valid_c_flags(WARNCFLAGS -Wall -Wextra - -Werror -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations @@ -338,11 +343,11 @@ if(ENABLE_WERROR) extract_valid_cxx_flags(WARNCXXFLAGS # For C++ compiler -Wall - -Werror -Wformat-security ) endif() +set(EXTRACFLAG) extract_valid_c_flags(EXTRACFLAG -fvisibility=hidden ) diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake index 3b0b0240..8e50d1f0 100644 --- a/cmake/ExtractValidFlags.cmake +++ b/cmake/ExtractValidFlags.cmake @@ -1,11 +1,10 @@ # Convenience function that checks the availability -# of certain C or C++ compiler flags and returns the valid ones. +# of certain C or C++ compiler flags and appends valid ones. include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) function(extract_valid_c_flags varname) - set(valid_flags "") foreach(flag IN LISTS ARGN) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "C_FLAG_${flag_var}") @@ -18,7 +17,6 @@ function(extract_valid_c_flags varname) endfunction() function(extract_valid_cxx_flags varname) - set(valid_flags "") foreach(flag IN LISTS ARGN) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "CXX_FLAG_${flag_var}") From 77e8190b6ccf8de231d802de32df0b798bc05623 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 16:04:01 +0100 Subject: [PATCH 33/59] cmake: fix symbol visibility issues libnghttp2.so was missing -fvisibility=hidden. libnghttp2_asio.so on the other hand had hidden visibility which resulted in no exported symbols and a broken asio client examples. Just build a static nghttp2 library to solve this issue. --- CMakeLists.txt | 6 ------ lib/CMakeLists.txt | 22 ++++++++++++++++------ src/CMakeLists.txt | 1 - tests/CMakeLists.txt | 12 ++++++++---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13d11b90..04fddf55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,11 +347,6 @@ if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") ) endif() -set(EXTRACFLAG) -extract_valid_c_flags(EXTRACFLAG - -fvisibility=hidden -) - if(ENABLE_DEBUG) set(DEBUGBUILD 1) endif() @@ -449,7 +444,6 @@ message(STATUS "summary of build options: CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}} WARNCFLAGS: ${WARNCFLAGS} CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} - EXTRACFLAG: ${EXTRACFLAG} Library: Shared: ${enable_shared} Static: ${enable_static} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7b012acb..a6adc04d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -24,14 +24,24 @@ set(NGHTTP2_SOURCES nghttp2_http.c ) -add_library(nghttp2-obj OBJECT ${NGHTTP2_SOURCES}) +# Public shared library +add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) # Needed because the object files are linked into a shared library. -set_target_properties(nghttp2-obj PROPERTIES - POSITION_INDEPENDENT_CODE ON) -add_library(nghttp2 SHARED $) set_target_properties(nghttp2 PROPERTIES - COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" - VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}) + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + C_VISIBILITY_PRESET hidden +) + +if(HAVE_CUNIT) + # Static library (for unittests because of symbol visibility) + add_library(nghttp2_static STATIC ${NGHTTP2_SOURCES}) + set_target_properties(nghttp2_static PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + ARCHIVE_OUTPUT_NAME nghttp2 + ) +endif() install(TARGETS nghttp2 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08c89b0e..1d6af25c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -248,7 +248,6 @@ if(ENABLE_ASIO_LIB) ) # XXX use add_compile_options with a list instead of COMPILE_FLAGS set_target_properties(nghttp2_asio PROPERTIES - COMPILE_FLAGS "${EXTRACFLAG}" VERSION 1.0.0 SOVERSION 1) install(TARGETS nghttp2_asio diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1ffa16c7..5a641834 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,10 +26,12 @@ if(HAVE_CUNIT) add_executable(main EXCLUDE_FROM_ALL ${MAIN_SOURCES} - $ ) target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_link_libraries(main ${CUNIT_LIBRARIES}) + target_link_libraries(main + nghttp2_static + ${CUNIT_LIBRARIES} + ) add_test(main main) if(ENABLE_FAILMALLOC) @@ -40,9 +42,11 @@ if(HAVE_CUNIT) ) add_executable(failmalloc EXCLUDE_FROM_ALL ${FAILMALLOC_SOURCES} - $ ) - target_link_libraries(failmalloc ${CUNIT_LIBRARIES}) + target_link_libraries(failmalloc + nghttp2_static + ${CUNIT_LIBRARIES} + ) add_test(failmalloc failmalloc) endif() From 4814d14db5db07d709c725a8af66192b0c877bb9 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 16:19:28 +0100 Subject: [PATCH 34/59] cmake: fix installing nghttp2_asio.pc, manpages, README.rst --- CMakeLists.txt | 2 ++ doc/CMakeLists.txt | 18 ++++++++++++++---- src/CMakeLists.txt | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04fddf55..7222365a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -414,6 +414,8 @@ include_directories( # For use in src/CMakeLists.txt set(PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}") +install(FILES README.rst DESTINATION "${CMAKE_INSTALL_DOCDIR}") + add_subdirectory(lib) #add_subdirectory(lib/includes) add_subdirectory(third-party) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index d05c9461..8c65a536 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -122,6 +122,13 @@ set(APIDOCS nghttp2_version.rst ) +set(MAN_PAGES + nghttp.1 + nghttpd.1 + nghttpx.1 + h2load.1 +) + # Other .rst files from the source tree that need to be copied # XXX move them to sources/ and create .in files? set(RST_FILES @@ -168,10 +175,7 @@ set(EXTRA_DIST _themes/sphinx_rtd_theme/static/js/theme.js _themes/sphinx_rtd_theme/theme.conf _themes/sphinx_rtd_theme/versions.html - nghttp.1 - nghttpd.1 - nghttpx.1 - h2load.1 + ${MAN_PAGES} bash_completion/nghttp bash_completion/nghttpd bash_completion/nghttpx @@ -310,3 +314,9 @@ sphinxbuild(doctest "Testing of doctests in the sources finished, look at the" "results in ${BUILDDIR}/doctest/output.txt." ) + +foreach(_man_page IN LISTS MAN_PAGES) + install(FILES ${_man_page} + DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" + ) +endforeach() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1d6af25c..d7e466c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -253,6 +253,6 @@ if(ENABLE_ASIO_LIB) install(TARGETS nghttp2_asio LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") - install(FILES libnghttp2_asio.pc + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() From 9ab5ef3b5bc40028ab3099e41547977d30203566 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 16:29:39 +0100 Subject: [PATCH 35/59] cmake: make find_package non-QUIET Also fix useless MRUBY_LIBRARIES output and add the CMake build type (e.g. Release, Debug, etc.) --- CMakeLists.txt | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7222365a..f7f68b82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,32 +47,32 @@ include(GNUInstallDirs) find_package(PythonInterp) # Auto-detection of features that can be toggled -find_package(OpenSSL 1.0.1 QUIET) -find_package(Libev 4.15 QUIET) -find_package(ZLIB 1.2.3 QUIET) +find_package(OpenSSL 1.0.1) +find_package(Libev 4.15) +find_package(ZLIB 1.2.3) if(OPENSSL_FOUND AND LIBEV_FOUND AND ZLIB_FOUND) set(ENABLE_APP_DEFAULT ON) else() set(ENABLE_APP_DEFAULT OFF) endif() -find_package(Jansson 2.5 QUIET) +find_package(Jansson 2.5) set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND}) # 2.0.8 is required because we use evconnlistener_set_error_cb() -find_package(Libevent 2.0.8 QUIET COMPONENTS libevent openssl) +find_package(Libevent 2.0.8 COMPONENTS libevent openssl) set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND}) -find_package(Cython QUIET) -find_package(PythonLibs QUIET) +find_package(Cython) +find_package(PythonLibs) if(CYTHON_FOUND AND PYTHONLIBS_FOUND) set(ENABLE_PYTHON_BINDINGS_DEFAULT ON) else() set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) endif() -find_package(LibXml2 2.7.7 QUIET) +find_package(LibXml2 2.7.7) set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) -find_package(Jemalloc QUIET) +find_package(Jemalloc) set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND}) -find_package(Spdylay 1.3.2 QUIET) +find_package(Spdylay 1.3.2) set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND}) include(CMakeOptions.txt) @@ -440,6 +440,7 @@ message(STATUS "summary of build options: Install prefix: ${CMAKE_INSTALL_PREFIX} Target system: ${CMAKE_SYSTEM_NAME} Compiler: + Build type: ${CMAKE_BUILD_TYPE} C compiler: ${CMAKE_C_COMPILER} CFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}} C++ compiler: ${CMAKE_CXX_COMPILER} @@ -470,7 +471,7 @@ message(STATUS "summary of build options: Boost::Thread: ${Boost_THREAD_LIBRARY} Third-party: http-parser: ${ENABLE_THIRD_PARTY} - MRuby: ${HAVE_MRUBY} (LIBS='${LIBMRUBY_LIBRARIES}') + MRuby: ${HAVE_MRUBY} Neverbleed: ${HAVE_NEVERBLEED} Features: Applications: ${ENABLE_APP} From 9c874bf9b5d27415860f99a8608a33ac48ad8859 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 18 Feb 2016 14:20:35 +0100 Subject: [PATCH 36/59] cmake: rename nghttpx-bin target to nghttpx `ninja nghttpx` would create the static library, but I expected a binary `nghttpx` instead. Rename the nghttpx target to nghttpx_static and nghttpx-bin to nghttpx. --- src/CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d7e466c3..dfd4a7c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -124,23 +124,23 @@ if(ENABLE_APP) shrpx_mruby_module_response.cc ) endif() - add_library(nghttpx STATIC ${NGHTTPX_SRCS}) + add_library(nghttpx_static STATIC ${NGHTTPX_SRCS}) + set_target_properties(nghttpx_static PROPERTIES ARCHIVE_OUTPUT_NAME nghttpx) set(NGHTTPX-bin_SOURCES shrpx.cc ) if(HAVE_MRUBY) - target_link_libraries(nghttpx mruby-lib) + target_link_libraries(nghttpx_static mruby-lib) endif() if(HAVE_NEVERBLEED) - target_link_libraries(nghttpx neverbleed) + target_link_libraries(nghttpx_static neverbleed) endif() if(HAVE_CUNIT) - # check_PROGRAMS += nghttpx-unittest set(NGHTTPX_UNITTEST_SOURCES shrpx-unittest.cc shrpx_ssl_test.cc @@ -164,7 +164,7 @@ if(ENABLE_APP) target_compile_definitions(nghttpx-unittest PRIVATE "-DNGHTTP2_TESTS_DIR=\"${CMAKE_SOURCE_DIR}/tests\"" ) - target_link_libraries(nghttpx-unittest nghttpx ${CUNIT_LIBRARIES}) + target_link_libraries(nghttpx-unittest nghttpx_static ${CUNIT_LIBRARIES}) if(HAVE_MRUBY) target_link_libraries(nghttpx-unittest mruby-lib) endif() @@ -177,13 +177,12 @@ if(ENABLE_APP) add_executable(nghttp ${NGHTTP_SOURCES} $) add_executable(nghttpd ${NGHTTPD_SOURCES} $) - add_executable(nghttpx-bin ${NGHTTPX-bin_SOURCES} $) - target_compile_definitions(nghttpx-bin PRIVATE "-DPKGDATADIR=\"${PKGDATADIR}\"") - set_target_properties(nghttpx-bin PROPERTIES OUTPUT_NAME nghttpx) - target_link_libraries(nghttpx-bin nghttpx) + add_executable(nghttpx ${NGHTTPX-bin_SOURCES} $) + target_compile_definitions(nghttpx PRIVATE "-DPKGDATADIR=\"${PKGDATADIR}\"") + target_link_libraries(nghttpx nghttpx_static) add_executable(h2load ${H2LOAD_SOURCES} $) - install(TARGETS nghttp nghttpd nghttpx-bin h2load + install(TARGETS nghttp nghttpd nghttpx h2load RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() From d6c3b6e84ca8dde0d8a130440e831d3dc89258eb Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 29 Feb 2016 16:00:08 +0100 Subject: [PATCH 37/59] cmake: fix mruby dependency Ensure that the mruby build is triggered when the surrogate "mruby-lib" target is used. Fixes building nghttpx when mruby is missing. --- third-party/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index f89dc525..cb88533e 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -59,6 +59,7 @@ if(ENABLE_THIRD_PARTY) IMPORTED_LOCATION "${MRUBY_BUILD_DIR}/lib/${MRUBY_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/mruby/include" ) + add_dependencies(mruby-lib mruby) # XXX clean ${CMAKE_CURRENT_BINARY_DIR}/mruby/build endif() From 8bca2d1048b67a442fcdda97092ff26d9bd84fd3 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 29 Feb 2016 16:11:26 +0100 Subject: [PATCH 38/59] cmake: fix libevent binary names Match the output produced by autotools (libevent-client instead of libevent_client). --- examples/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3802e7ce..d9054d11 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -26,8 +26,8 @@ if(ENABLE_EXAMPLES) ) add_executable(client client.c $) - add_executable(libevent_client libevent-client.c $) - add_executable(libevent_server libevent-server.c $) + add_executable(libevent-client libevent-client.c $) + add_executable(libevent-server libevent-server.c $) add_executable(deflate deflate.c $) if(ENABLE_TINY_NGHTTPD) From 5bbcb7148c7d6ef8c690f2c3036f3d4f4380aa23 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 29 Feb 2016 16:13:19 +0100 Subject: [PATCH 39/59] cmake: update .gitignore files --- .gitignore | 15 +++++++++++++++ integration-tests/.gitignore | 1 + 2 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 7ed31ec3..0c969ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,21 @@ missing stamp-h1 test-driver +# cmake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +CTestTestfile.cmake +build.ninja +rules.ninja +.ninja_deps +.ninja_log +lib*.so +lib*.so.* +lib*.a +# generated by "make test" with cmake +Testing/ + # test logs generated by `make check` *.log *.trs diff --git a/integration-tests/.gitignore b/integration-tests/.gitignore index ce6e582a..f40c109a 100644 --- a/integration-tests/.gitignore +++ b/integration-tests/.gitignore @@ -1,2 +1,3 @@ # generated files config.go +setenv From 2c525f24716f1f94b2d6f681a449b17c0e354fe0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 29 Feb 2016 16:20:31 +0100 Subject: [PATCH 40/59] cmake: ignore "make install" artifact --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0c969ce7..e2dc999f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ test-driver CMakeCache.txt CMakeFiles/ cmake_install.cmake +install_manifest.txt CTestTestfile.cmake build.ninja rules.ninja From 618073e2b42b4d72ce05ed15cf61ffefeeefcab5 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 12 Mar 2016 00:57:30 +0100 Subject: [PATCH 41/59] cmake: add "check" target Add a "check" target that builds tests before running them. --- CMakeLists.txt | 8 +++----- src/CMakeLists.txt | 1 + tests/CMakeLists.txt | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7f68b82..7402244b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,9 @@ endif() find_package(CUnit 2.1) enable_testing() set(HAVE_CUNIT ${CUNIT_FOUND}) +if(HAVE_CUNIT) + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) +endif() # openssl (for src) set(HAVE_OPENSSL ${OPENSSL_FOUND}) @@ -357,11 +360,6 @@ if(NOT ENABLE_THREADS OR NOT HAVE_STD_FUTURE) set(NOTHREADS 1) endif() -# # propagate $enable_static to tests/Makefile.am -# AM_CONDITIONAL([ENABLE_STATIC], [test "x$enable_static" = "xyes"]) -# -# AC_SUBST([APPLDFLAGS]) - add_definitions(-DHAVE_CONFIG_H) configure_file(cmakeconfig.h.in config.h) # autotools-compatible names diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfd4a7c9..83903dda 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,6 +173,7 @@ if(ENABLE_APP) endif() add_test(nghttpx-unittest nghttpx-unittest) + add_dependencies(check nghttpx-unittest) endif() add_executable(nghttp ${NGHTTP_SOURCES} $) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a641834..8ce64154 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,6 +33,7 @@ if(HAVE_CUNIT) ${CUNIT_LIBRARIES} ) add_test(main main) + add_dependencies(check main) if(ENABLE_FAILMALLOC) set(FAILMALLOC_SOURCES @@ -48,6 +49,7 @@ if(HAVE_CUNIT) ${CUNIT_LIBRARIES} ) add_test(failmalloc failmalloc) + add_dependencies(check failmalloc) endif() if(ENABLE_APP) From bdb6581990ab46a6ec69499b4f1f244e677489f4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 12 Mar 2016 01:22:00 +0100 Subject: [PATCH 42/59] Add CMake-related files to EXTRA_DIST --- Makefile.am | 14 +++++++++++++- contrib/Makefile.am | 6 +++++- doc/Makefile.am | 1 + examples/Makefile.am | 2 ++ integration-tests/Makefile.am | 1 + lib/Makefile.am | 2 +- lib/includes/Makefile.am | 3 +++ python/Makefile.am | 2 +- script/Makefile.am | 2 +- src/Makefile.am | 2 ++ src/includes/Makefile.am | 2 ++ tests/Makefile.am | 2 ++ third-party/Makefile.am | 4 +++- 13 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index d1a7dd16..a66561f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,19 @@ ACLOCAL_AMFLAGS = -I m4 dist_doc_DATA = README.rst EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-make \ - Dockerfile.android + Dockerfile.android \ + cmakeconfig.h.in \ + CMakeLists.txt \ + CMakeOptions.txt \ + cmake/FindSpdylay.cmake \ + cmake/ExtractValidFlags.cmake \ + cmake/FindJemalloc.cmake \ + cmake/FindLibev.cmake \ + cmake/FindCUnit.cmake \ + cmake/Version.cmake \ + cmake/FindCython.cmake \ + cmake/FindLibevent.cmake \ + cmake/FindJansson.cmake .PHONY: clang-format diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 07829e25..089a79b0 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -23,7 +23,11 @@ configfiles = nghttpx-init nghttpx.service nghttpx-upstart.conf -EXTRA_DIST = $(configfiles:%=%.in) nghttpx-logrotate tlsticketupdate.go +EXTRA_DIST = \ + CMakeLists.txt \ + $(configfiles:%=%.in) \ + nghttpx-logrotate \ + tlsticketupdate.go edit = sed -e 's|@bindir[@]|$(bindir)|g' diff --git a/doc/Makefile.am b/doc/Makefile.am index a9ea4349..777fe226 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -154,6 +154,7 @@ RST_FILES = \ h2load.1.rst EXTRA_DIST = \ + CMakeLists.txt \ mkapiref.py \ $(RST_FILES) \ $(APIDOCS) \ diff --git a/examples/Makefile.am b/examples/Makefile.am index ba00c225..a80949c7 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -21,6 +21,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +EXTRA_DIST = CMakeLists.txt + if ENABLE_EXAMPLES AM_CFLAGS = $(WARNCFLAGS) diff --git a/integration-tests/Makefile.am b/integration-tests/Makefile.am index aab50096..479bfa14 100644 --- a/integration-tests/Makefile.am +++ b/integration-tests/Makefile.am @@ -28,6 +28,7 @@ GO_FILES = \ server_tester.go EXTRA_DIST = \ + CMakeLists.txt \ $(GO_FILES) \ server.key \ server.crt \ diff --git a/lib/Makefile.am b/lib/Makefile.am index 3ea5bed2..017e44a7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -22,7 +22,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SUBDIRS = includes -EXTRA_DIST = Makefile.msvc +EXTRA_DIST = Makefile.msvc CMakeLists.txt AM_CFLAGS = $(WARNCFLAGS) $(EXTRACFLAG) AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes -DBUILDING_NGHTTP2 \ diff --git a/lib/includes/Makefile.am b/lib/includes/Makefile.am index 80af63cc..c07cb4d2 100644 --- a/lib/includes/Makefile.am +++ b/lib/includes/Makefile.am @@ -20,4 +20,7 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +EXTRA_DIST = CMakeLists.txt + nobase_include_HEADERS = nghttp2/nghttp2.h nghttp2/nghttp2ver.h diff --git a/python/Makefile.am b/python/Makefile.am index 43aa5491..2d2edd5a 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -25,7 +25,7 @@ # clean-local in parallel build. .NOTPARALLEL: -EXTRA_DIST = cnghttp2.pxd nghttp2.pyx +EXTRA_DIST = cnghttp2.pxd nghttp2.pyx CMakeLists.txt install-python.cmake.in if ENABLE_PYTHON_BINDINGS diff --git a/script/Makefile.am b/script/Makefile.am index fe5d3652..387f33c5 100644 --- a/script/Makefile.am +++ b/script/Makefile.am @@ -21,5 +21,5 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -EXTRA_DIST = README.rst +EXTRA_DIST = README.rst CMakeLists.txt dist_pkgdata_SCRIPTS = fetch-ocsp-response diff --git a/src/Makefile.am b/src/Makefile.am index 9c2cfa21..5b21aee7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,8 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SUBDIRS = includes +EXTRA_DIST = CMakeLists.txt + bin_PROGRAMS = check_PROGRAMS = TESTS = diff --git a/src/includes/Makefile.am b/src/includes/Makefile.am index abc93c1e..e73d209b 100644 --- a/src/includes/Makefile.am +++ b/src/includes/Makefile.am @@ -21,6 +21,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +EXTRA_DIST = CMakeLists.txt + if ENABLE_ASIO_LIB nobase_include_HEADERS = nghttp2/asio_http2.h nghttp2/asio_http2_client.h \ nghttp2/asio_http2_server.h diff --git a/tests/Makefile.am b/tests/Makefile.am index efcd7a5d..c3e43925 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,8 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SUBDIRS = testdata +EXTRA_DIST = CMakeLists.txt + if HAVE_CUNIT check_PROGRAMS = main diff --git a/third-party/Makefile.am b/third-party/Makefile.am index 6e9bcf27..3b951c8d 100644 --- a/third-party/Makefile.am +++ b/third-party/Makefile.am @@ -23,6 +23,8 @@ AM_CPPFLAGS = @DEFS@ +EXTRA_DIST = CMakeLists.txt + if ENABLE_THIRD_PARTY noinst_LTLIBRARIES = libhttp-parser.la @@ -39,7 +41,7 @@ endif # HAVE_NEVERBLEED if HAVE_MRUBY -EXTRA_DIST = build_config.rb mruby/* +EXTRA_DIST += build_config.rb mruby/* .PHONY: all-local clean mruby From 7f8110601eef397533a272d0b0e9a2e5842431c6 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 12:22:33 +0100 Subject: [PATCH 43/59] cmake: fix compatibility with cmake before 3.3 The COMPILE_LANGUAGE generator expression is only supported since CMake 3.3. Moreover, it does not work with all generators (works with Makefile and Ninja, but not with Visual Studio). target_compile_options would only work if a target does not mix C and C++ sources, since the flags are intended to be set for a specific language, use set_source_files_properties instead. This approach is also less repetitive. Drop the idea of using lists and COMPILE_OPTIONS, set_source_files_properties only understands COMPILE_FLAGS (a single string, not a list). --- examples/CMakeLists.txt | 13 ++++++------- lib/CMakeLists.txt | 1 - src/CMakeLists.txt | 14 ++++++-------- tests/CMakeLists.txt | 1 - 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d9054d11..96fae077 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,11 +1,10 @@ if(ENABLE_EXAMPLES) - # XXX replace this by lists (WARNCFLAGS_list) - string(REPLACE " " ";" c_flags "${WARNCFLAGS}") - string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") - add_compile_options( - "$<$:${c_flags}>" - "$<$:${cxx_flags}>" - ) + file(GLOB c_sources *.c) + set_source_files_properties(${c_sources} PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") + file(GLOB cxx_sources *.cc) + set_source_files_properties(${cxx_sources} PROPERTIES + COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") include_directories( ${CMAKE_SOURCE_DIR} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a6adc04d..ff512a45 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -26,7 +26,6 @@ set(NGHTTP2_SOURCES # Public shared library add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) -# Needed because the object files are linked into a shared library. set_target_properties(nghttp2 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83903dda..5bf8f972 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,11 @@ add_subdirectory(includes) -# XXX replace this by lists (WARNCFLAGS_list) -string(REPLACE " " ";" c_flags "${WARNCFLAGS}") -string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") -add_compile_options( - "$<$:${c_flags}>" - "$<$:${cxx_flags}>" -) +file(GLOB c_sources *.c) +set_source_files_properties(${c_sources} PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +file(GLOB cxx_sources *.cc) +set_source_files_properties(${cxx_sources} PROPERTIES + COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") include_directories( "${CMAKE_SOURCE_DIR}/lib/includes" @@ -246,7 +245,6 @@ if(ENABLE_ASIO_LIB) ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ) - # XXX use add_compile_options with a list instead of COMPILE_FLAGS set_target_properties(nghttp2_asio PROPERTIES VERSION 1.0.0 SOVERSION 1) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ce64154..4250ac3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,5 @@ # XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem if(HAVE_CUNIT) - # XXX replace this by lists (WARNCFLAGS_list) string(REPLACE " " ";" c_flags "${WARNCFLAGS}") add_compile_options(${c_flags}) From a45540fd79d212c39ad016dfeafe00ae5e11af85 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 12:50:33 +0100 Subject: [PATCH 44/59] Lower libev version requirement libev 4.11 seems to build fine as demonstrated by Travis with autotools. --- CMakeLists.txt | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7402244b..fe059292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ find_package(PythonInterp) # Auto-detection of features that can be toggled find_package(OpenSSL 1.0.1) -find_package(Libev 4.15) +find_package(Libev 4.11) find_package(ZLIB 1.2.3) if(OPENSSL_FOUND AND LIBEV_FOUND AND ZLIB_FOUND) set(ENABLE_APP_DEFAULT ON) diff --git a/README.rst b/README.rst index 290c7dd4..0f05d206 100644 --- a/README.rst +++ b/README.rst @@ -63,7 +63,7 @@ To build and run the application programs (``nghttp``, ``nghttpd``, are required: * OpenSSL >= 1.0.1 -* libev >= 4.15 +* libev >= 4.11 * zlib >= 1.2.3 ALPN support requires OpenSSL >= 1.0.2 (released 22 January 2015). From 2b3bc710fc6f8f2a0505eee158698dd5d58f6dbe Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 13:09:37 +0100 Subject: [PATCH 45/59] cmake: fix version checks for external packages The name passed to find_package should match the one that is passed to find_package_handle_standard_args, otherwise the version matching is not properly done. The names are based on the FindXXX.cmake filename. This also simplifies components reporting for Libevent (done by find_package_handle_standard_args) and results in reporting a library instead of include directory when found. --- cmake/FindJansson.cmake | 2 +- cmake/FindJemalloc.cmake | 2 +- cmake/FindLibevent.cmake | 34 ++++++++++++++-------------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/cmake/FindJansson.cmake b/cmake/FindJansson.cmake index 8de971fb..4c4bcb73 100644 --- a/cmake/FindJansson.cmake +++ b/cmake/FindJansson.cmake @@ -28,7 +28,7 @@ endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE # if all listed variables are TRUE and the requested version matches. -find_package_handle_standard_args(jansson REQUIRED_VARS +find_package_handle_standard_args(Jansson REQUIRED_VARS JANSSON_LIBRARY JANSSON_INCLUDE_DIR VERSION_VAR JANSSON_VERSION) diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake index 5b01a721..667d2995 100644 --- a/cmake/FindJemalloc.cmake +++ b/cmake/FindJemalloc.cmake @@ -28,7 +28,7 @@ endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE # if all listed variables are TRUE and the requested version matches. -find_package_handle_standard_args(jemalloc REQUIRED_VARS +find_package_handle_standard_args(Jemalloc REQUIRED_VARS JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR VERSION_VAR JEMALLOC_VERSION) diff --git a/cmake/FindLibevent.cmake b/cmake/FindLibevent.cmake index 4e5af6a9..8f40d9fe 100644 --- a/cmake/FindLibevent.cmake +++ b/cmake/FindLibevent.cmake @@ -20,7 +20,7 @@ # LIBEVENT_INCLUDE_DIRS - Libevent include directories # LIBEVENT_LIBRARIES - Libevent libraries to be linked # LIBEVENT__FOUND - Component was found ( is uppercase) -# LIBEVENT__LIBRARY - Library to be linked for Libevent omponent . +# LIBEVENT__LIBRARY - Library to be linked for Libevent component . find_package(PkgConfig QUIET) pkg_check_modules(PC_LIBEVENT QUIET libevent) @@ -33,7 +33,6 @@ find_path(LIBEVENT_INCLUDE_DIR HINTS ${PC_LIBEVENT_INCLUDE_DIRS} ) -set(_LIBEVENT_REQUIRED_VARS LIBEVENT_INCLUDE_DIR) if(LIBEVENT_INCLUDE_DIR) set(_version_regex "^#define[ \t]+_EVENT_VERSION[ \t]+\"([^\"]+)\".*") @@ -51,6 +50,7 @@ if(LIBEVENT_INCLUDE_DIR) unset(_version_regex) endif() +set(_LIBEVENT_REQUIRED_VARS) foreach(COMPONENT ${Libevent_FIND_COMPONENTS}) set(_LIBEVENT_LIBNAME libevent) # Note: compare two variables to avoid a CMP0054 policy warning @@ -59,42 +59,36 @@ foreach(COMPONENT ${Libevent_FIND_COMPONENTS}) else() set(_LIBEVENT_LIBNAME "event_${COMPONENT}") endif() - string(TOUPPER "${COMPONENT}" COMPONENT) - find_library(LIBEVENT_${COMPONENT}_LIBRARY + string(TOUPPER "${COMPONENT}" COMPONENT_UPPER) + find_library(LIBEVENT_${COMPONENT_UPPER}_LIBRARY NAMES ${_LIBEVENT_LIBNAME} HINTS ${PC_LIBEVENT_LIBRARY_DIRS} ) - if(LIBEVENT_${COMPONENT}_LIBRARY) - set(LIBEVENT_${COMPONENT}_FOUND 1) + if(LIBEVENT_${COMPONENT_UPPER}_LIBRARY) + set(Libevent_${COMPONENT}_FOUND 1) endif() - list(APPEND _LIBEVENT_REQUIRED_VARS LIBEVENT_${COMPONENT}_LIBRARY) + list(APPEND _LIBEVENT_REQUIRED_VARS LIBEVENT_${COMPONENT_UPPER}_LIBRARY) endforeach() unset(_LIBEVENT_LIBNAME) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set LIBEVENT_FOUND to TRUE # if all listed variables are TRUE and the requested version matches. -find_package_handle_standard_args(LIBEVENT REQUIRED_VARS +find_package_handle_standard_args(Libevent REQUIRED_VARS ${_LIBEVENT_REQUIRED_VARS} + LIBEVENT_INCLUDE_DIR VERSION_VAR LIBEVENT_VERSION HANDLE_COMPONENTS) if(LIBEVENT_FOUND) set(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) set(LIBEVENT_LIBRARIES) - if(NOT Libevent_FIND_QUIETLY) - message(STATUS "Found the following Libevent components:") - endif() - foreach(_COMPONENT ${Libevent_FIND_COMPONENTS}) - string(TOUPPER "${_COMPONENT}" COMPONENT) - if(LIBEVENT_${COMPONENT}_FOUND) - if(NOT Libevent_FIND_QUIETLY) - message(STATUS " ${_COMPONENT}") - endif() - list(APPEND LIBEVENT_LIBRARIES ${LIBEVENT_${COMPONENT}_LIBRARY}) - endif() + foreach(COMPONENT ${Libevent_FIND_COMPONENTS}) + string(TOUPPER "${COMPONENT}" COMPONENT_UPPER) + list(APPEND LIBEVENT_LIBRARIES ${LIBEVENT_${COMPONENT_UPPER}_LIBRARY}) + set(LIBEVENT_${COMPONENT_UPPER}_FOUND ${Libevent_${COMPONENT}_FOUND}) endforeach() endif() -mark_as_advanced(${_LIBEVENT_REQUIRED_VARS}) +mark_as_advanced(LIBEVENT_INCLUDE_DIR ${_LIBEVENT_REQUIRED_VARS}) unset(_LIBEVENT_REQUIRED_VARS) From dad222b8f44abe2e62c3d741851712f7697facf8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 16:41:21 +0100 Subject: [PATCH 46/59] cmake: fix jemalloc, libevent include dirs Caught with cmake --warn-uninitialized. --- CMakeLists.txt | 6 +----- cmake/ExtractValidFlags.cmake | 6 ++++-- cmake/FindJemalloc.cmake | 2 +- examples/CMakeLists.txt | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe059292..cf6be263 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ endforeach() include(CMakePushCheckState) include(CheckCXXSourceCompiles) cmake_push_check_state() -set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${CXX1XCXXFLAGS}") +set(CMAKE_REQUIRED_DEFINITIONS "${CXX1XCXXFLAGS}") # Check that std::future is available. check_cxx_source_compiles(" #include @@ -429,7 +429,6 @@ add_subdirectory(contrib) add_subdirectory(script) -# XXX fix shared/static library string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) message(STATUS "summary of build options: @@ -445,9 +444,6 @@ message(STATUS "summary of build options: CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}} WARNCFLAGS: ${WARNCFLAGS} CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} - Library: - Shared: ${enable_shared} - Static: ${enable_static} Python: Python: ${PYTHON_EXECUTABLE} PYTHON_VERSION: ${PYTHON_VERSION_STRING} diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake index 8e50d1f0..ccd57dc8 100644 --- a/cmake/ExtractValidFlags.cmake +++ b/cmake/ExtractValidFlags.cmake @@ -1,10 +1,11 @@ -# Convenience function that checks the availability -# of certain C or C++ compiler flags and appends valid ones. +# Convenience function that checks the availability of certain +# C or C++ compiler flags and returns valid ones as a string. include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) function(extract_valid_c_flags varname) + set(valid_flags) foreach(flag IN LISTS ARGN) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "C_FLAG_${flag_var}") @@ -17,6 +18,7 @@ function(extract_valid_c_flags varname) endfunction() function(extract_valid_cxx_flags varname) + set(valid_flags) foreach(flag IN LISTS ARGN) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) set(flag_var "CXX_FLAG_${flag_var}") diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake index 667d2995..b7815fa0 100644 --- a/cmake/FindJemalloc.cmake +++ b/cmake/FindJemalloc.cmake @@ -9,7 +9,7 @@ pkg_check_modules(PC_JEMALLOC QUIET jemalloc) find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h - HINTS ${PC_PCJEMALLOC_INCLUDE_DIRS} + HINTS ${PC_JEMALLOC_INCLUDE_DIRS} ) find_library(JEMALLOC_LIBRARY NAMES jemalloc diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 96fae077..b4926575 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,7 +13,7 @@ if(ENABLE_EXAMPLES) ${CMAKE_SOURCE_DIR}/src/includes ${CMAKE_SOURCE_DIR}/third-party - ${LIBEVENT_OPENSSL_INCLUDE_DIRS} + ${LIBEVENT_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ) From b092166bc6162302da2890e4cb23c7594082161a Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 17:34:22 +0100 Subject: [PATCH 47/59] cmake: clean more files, fix python dependency Remove generated documentation, python and mruby build artifacts. Note that this does not work for Ninja, Makefile works fine though. --- doc/CMakeLists.txt | 3 +++ python/CMakeLists.txt | 9 +++++++-- third-party/CMakeLists.txt | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 8c65a536..be8078a8 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -249,6 +249,9 @@ add_custom_command( ) + +set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${BUILDDIR}") + # Invokes sphinx-build and prints the given messages when completed function(sphinxbuild builder) set(echo_commands) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0cfdc9b3..8bdfbb3d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,11 +1,10 @@ # EXTRA_DIST = cnghttp2.pxd nghttp2.pyx if(ENABLE_PYTHON_BINDINGS) - add_custom_target(python ALL COMMAND "${PYTHON_EXECUTABLE}" setup.py build VERBATIM - DEPENDS nghttp2.c + DEPENDS nghttp2.c nghttp2 ) configure_file(install-python.cmake.in install-python.cmake ESCAPE_QUOTES @ONLY) @@ -17,6 +16,12 @@ if(ENABLE_PYTHON_BINDINGS) VERBATIM DEPENDS nghttp2.pyx ) + + # Instead of calling "setup.py clean --all", this should do... + set_directory_properties(PROPERTIES + ADDITIONAL_MAKE_CLEAN_FILES "build;python_nghttp2.egg-info" + ) + ## This works also, except that the installation target is missing... # include(UseCython) # cython_add_module(python_nghttp2 nghttp2.pyx) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index cb88533e..7578a857 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -61,6 +61,8 @@ if(ENABLE_THIRD_PARTY) ) add_dependencies(mruby-lib mruby) - # XXX clean ${CMAKE_CURRENT_BINARY_DIR}/mruby/build + set_directory_properties(PROPERTIES + ADDITIONAL_MAKE_CLEAN_FILES mruby/build + ) endif() endif() From 2ddb83206bcec1e355e83fd70ca36c539bf29e71 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 16:19:23 +0100 Subject: [PATCH 48/59] cmake: sync with v1.8.0-63-g37b09f6 Adds missing source files and configure.ac changes since v1.7.0-93-g093eb51. --- CMakeLists.txt | 19 ++++++++++++++----- doc/CMakeLists.txt | 12 ++++++++++++ lib/CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf6be263..c7a0f4c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,14 +23,14 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cmake_minimum_required(VERSION 3.0) -# XXX using 1.7.90 instead of 1.8.0-DEV -project(nghttp2 VERSION 1.7.90) +# XXX using 1.8.90 instead of 1.9.0-DEV +project(nghttp2 VERSION 1.8.90) # See versioning rule: # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -set(LT_CURRENT 18) -set(LT_REVISION 1) -set(LT_AGE 4) +set(LT_CURRENT 19) +set(LT_REVISION 0) +set(LT_AGE 5) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(Version) @@ -280,6 +280,13 @@ check_function_exists(accept4 HAVE_ACCEPT4) include(CheckSymbolExists) # XXX does this correctly detect initgroups (un)availability on cygwin? check_symbol_exists(initgroups grp.h HAVE_DECL_INITGROUPS) +if(NOT HAVE_DECL_INITGROUPS AND HAVE_UNISTD_H) + # FreeBSD declares initgroups() in unistd.h + check_symbol_exists(initgroups unistd.h HAVE_DECL_INITGROUPS2) + if(HAVE_DECL_INITGROUPS2) + set(HAVE_DECL_INITGROUPS 1) + endif() +endif() check_function_exists(timerfd_create HAVE_TIMERFD_CREATE) # Checks for epoll availability, primarily for examples/tiny-nghttpd @@ -341,6 +348,8 @@ if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") -Wredundant-decls # Only work with Clang for the moment -Wheader-guard + # This is required because we pass format string as "const char*. + -Wno-format-nonliteral ) extract_valid_cxx_flags(WARNCXXFLAGS diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index be8078a8..1fa04f4f 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -25,37 +25,48 @@ set(APIDOCS nghttp2_hd_inflate_hd.rst nghttp2_hd_inflate_new.rst nghttp2_hd_inflate_new2.rst + nghttp2_http2_strerror.rst nghttp2_is_fatal.rst nghttp2_nv_compare_name.rst nghttp2_option_del.rst nghttp2_option_new.rst nghttp2_option_set_max_reserved_remote_streams.rst + nghttp2_option_set_no_auto_ping_ack.rst nghttp2_option_set_no_auto_window_update.rst nghttp2_option_set_no_http_messaging.rst nghttp2_option_set_no_recv_client_magic.rst nghttp2_option_set_peer_max_concurrent_streams.rst + nghttp2_option_set_user_recv_extension_type.rst nghttp2_pack_settings_payload.rst nghttp2_priority_spec_check_default.rst nghttp2_priority_spec_default_init.rst nghttp2_priority_spec_init.rst + nghttp2_rcbuf_decref.rst + nghttp2_rcbuf_get_buf.rst + nghttp2_rcbuf_incref.rst nghttp2_select_next_protocol.rst nghttp2_session_callbacks_del.rst nghttp2_session_callbacks_new.rst nghttp2_session_callbacks_set_before_frame_send_callback.rst nghttp2_session_callbacks_set_data_source_read_length_callback.rst + nghttp2_session_callbacks_set_error_callback.rst nghttp2_session_callbacks_set_on_begin_frame_callback.rst nghttp2_session_callbacks_set_on_begin_headers_callback.rst nghttp2_session_callbacks_set_on_data_chunk_recv_callback.rst nghttp2_session_callbacks_set_on_frame_not_send_callback.rst nghttp2_session_callbacks_set_on_frame_recv_callback.rst + nghttp2_session_callbacks_set_on_extension_chunk_recv_callback.rst nghttp2_session_callbacks_set_on_frame_send_callback.rst nghttp2_session_callbacks_set_on_header_callback.rst + nghttp2_session_callbacks_set_on_header_callback2.rst nghttp2_session_callbacks_set_on_invalid_frame_recv_callback.rst nghttp2_session_callbacks_set_on_stream_close_callback.rst + nghttp2_session_callbacks_set_pack_extension_callback.rst nghttp2_session_callbacks_set_recv_callback.rst nghttp2_session_callbacks_set_select_padding_callback.rst nghttp2_session_callbacks_set_send_callback.rst nghttp2_session_callbacks_set_send_data_callback.rst + nghttp2_session_callbacks_set_unpack_extension_callback.rst nghttp2_session_client_new.rst nghttp2_session_client_new2.rst nghttp2_session_client_new3.rst @@ -107,6 +118,7 @@ set(APIDOCS nghttp2_stream_get_weight.rst nghttp2_strerror.rst nghttp2_submit_data.rst + nghttp2_submit_extension.rst nghttp2_submit_goaway.rst nghttp2_submit_headers.rst nghttp2_submit_ping.rst diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ff512a45..17777ec1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -22,6 +22,7 @@ set(NGHTTP2_SOURCES nghttp2_callbacks.c nghttp2_mem.c nghttp2_http.c + nghttp2_rcbuf.c ) # Public shared library diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5bf8f972..3caf0edc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,6 +145,7 @@ if(ENABLE_APP) shrpx_ssl_test.cc shrpx_downstream_test.cc shrpx_config_test.cc + shrpx_worker_test.cc shrpx_http_test.cc http2_test.cc util_test.cc From 4d801cd696424d8bd2fbcff07a953bc461820838 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 12 Mar 2016 23:39:43 +0100 Subject: [PATCH 49/59] travis: add cmake to build matrix Add Nathan's PPA for cmake 3.2.3 (3.0 or newer is required). --- .travis.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0191126e..aa7bafc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ +env: + matrix: + - CI_BUILD=cmake + - CI_BUILD=autotools language: cpp compiler: - clang @@ -7,6 +11,7 @@ addons: apt: sources: - ubuntu-toolchain-r-test + - george-edison55-precise-backports packages: - g++-4.9 - libstdc++-4.9-dev @@ -23,11 +28,14 @@ addons: - libevent-dev - libjansson-dev - libjemalloc-dev + - cmake + - cmake-data before_install: - $CC --version - if [ "$CXX" = "g++" ]; then export CXX="g++-4.9" CC="gcc-4.9"; fi - $CC --version - go version + - cmake --version before_script: # First build spdylay, since integration tests require it. # spdylay is going to be built under third-party/spdylay @@ -40,9 +48,10 @@ before_script: - export SPDYLAY_HOME=$PWD - cd ../.. # Now build nghttp2 - - autoreconf -i + - if [ "$CI_BUILD" = "autotools" ]; then autoreconf -i; fi - git submodule update --init - - ./configure --enable-werror --with-mruby --with-neverbleed LIBSPDYLAY_CFLAGS="-I$SPDYLAY_HOME/lib/includes" LIBSPDYLAY_LIBS="-L$SPDYLAY_HOME/lib/.libs -lspdylay" + - if [ "$CI_BUILD" = "autotools" ]; then ./configure --enable-werror --with-mruby --with-neverbleed LIBSPDYLAY_CFLAGS="-I$SPDYLAY_HOME/lib/includes" LIBSPDYLAY_LIBS="-L$SPDYLAY_HOME/lib/.libs -lspdylay"; fi + - if [ "$CI_BUILD" = "cmake" ]; then cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DSPDYLAY_INCLUDE_DIR="$SPDYLAY_HOME/lib/includes" -DSPDYLAY_LIBRARY="$SPDYLAY_HOME/lib/.libs/libspdylay.so"; fi script: - make - make check From 162b1c5e033fc6b84fd0840ea44d74302eddc7a3 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 15 Mar 2016 00:02:46 +0100 Subject: [PATCH 50/59] cmake: only install ASIO headers when requested --- src/includes/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/includes/CMakeLists.txt b/src/includes/CMakeLists.txt index b4720c65..3d77d6ce 100644 --- a/src/includes/CMakeLists.txt +++ b/src/includes/CMakeLists.txt @@ -1,5 +1,7 @@ -install(FILES - nghttp2/asio_http2.h - nghttp2/asio_http2_client.h - nghttp2/asio_http2_server.h - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nghttp2") +if(ENABLE_ASIO_LIB) + install(FILES + nghttp2/asio_http2.h + nghttp2/asio_http2_client.h + nghttp2/asio_http2_server.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nghttp2") +endif() From 439636c579413fd9c9a3b925c7329ced500dba6b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 15 Mar 2016 13:37:51 +0100 Subject: [PATCH 51/59] cmake: set CMAKE_BUILD_TYPE=RelWithDebInfo by default NOTE: RelWithDebInfo *disables* assertions by default. To keep assertions, use CMAKE_BUILD_TYPE=Debug or CMAKE_BUILD_TYPE=None. --- .travis.yml | 2 +- CMakeLists.txt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa7bafc0..3267434b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ before_script: - if [ "$CI_BUILD" = "autotools" ]; then autoreconf -i; fi - git submodule update --init - if [ "$CI_BUILD" = "autotools" ]; then ./configure --enable-werror --with-mruby --with-neverbleed LIBSPDYLAY_CFLAGS="-I$SPDYLAY_HOME/lib/includes" LIBSPDYLAY_LIBS="-L$SPDYLAY_HOME/lib/.libs -lspdylay"; fi - - if [ "$CI_BUILD" = "cmake" ]; then cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DSPDYLAY_INCLUDE_DIR="$SPDYLAY_HOME/lib/includes" -DSPDYLAY_LIBRARY="$SPDYLAY_HOME/lib/.libs/libspdylay.so"; fi + - if [ "$CI_BUILD" = "cmake" ]; then cmake -DCMAKE_BUILD_TYPE=None -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DSPDYLAY_INCLUDE_DIR="$SPDYLAY_HOME/lib/includes" -DSPDYLAY_LIBRARY="$SPDYLAY_HOME/lib/.libs/libspdylay.so"; fi script: - make - make check diff --git a/CMakeLists.txt b/CMakeLists.txt index c7a0f4c0..29277fac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,17 @@ set(LT_VERSION "${LT_SOVERSION}.${LT_AGE}.${LT_REVISION}") set(PACKAGE_VERSION "${PROJECT_VERSION}") HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + # Note that RelWithDebInfo disables assertions, use Debug or None to keep them. + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE) + + # Include "None" as option to disable any additional (optimization) flags, + # relying on just CMAKE_C_FLAGS and CMAKE_CXX_FLAGS (which are empty by + # default). These strings are presented in cmake-gui. + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "None" "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + include(GNUInstallDirs) # For Python bindings and documentation @@ -227,7 +238,6 @@ else() endif() # Checks for header files. -# XXX AC_HEADER_ASSERT adds --disable-assert which sets -DNDEBUG include(CheckIncludeFile) check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) check_include_file("fcntl.h" HAVE_FCNTL_H) From b348a02b855b29ac9f84ddff9ab6a824ba118160 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 15 Mar 2016 13:58:53 +0100 Subject: [PATCH 52/59] cmake: fix printed C/CXX flags Build type-specific flags are added before other flags, reflect this in the output. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29277fac..dd120821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -458,9 +458,9 @@ message(STATUS "summary of build options: Compiler: Build type: ${CMAKE_BUILD_TYPE} C compiler: ${CMAKE_C_COMPILER} - CFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}} + CFLAGS: ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS} C++ compiler: ${CMAKE_CXX_COMPILER} - CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}} + CXXFLAGS: ${CMAKE_CXX_FLAGS_${_build_type}} ${CMAKE_CXX_FLAGS} WARNCFLAGS: ${WARNCFLAGS} CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} Python: From 0c49e5d56e366a6c1cd5d5006914b290a5bd4bc0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 14:10:42 +0100 Subject: [PATCH 53/59] cmake: enable assertions by default Users can disable this by setting -DCMAKE_C_FLAGS=-DNDEBUG or -DCMAKE_CXX_FLAGS=-DNDEBUG to disable assertions as desired. --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd120821..2f56d7ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,6 @@ set(PACKAGE_VERSION "${PROJECT_VERSION}") HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - # Note that RelWithDebInfo disables assertions, use Debug or None to keep them. set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE) # Include "None" as option to disable any additional (optimization) flags, @@ -102,6 +101,14 @@ if(ENABLE_LIB_ONLY) set(ENABLE_PYTHON_BINDINGS OFF) endif() +# Do not disable assertions based on CMAKE_BUILD_TYPE. +foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo") + foreach(_lang C CXX) + string(TOUPPER "CMAKE_${_lang}_FLAGS_${_build_type}" _var) + string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" "" ${_var} "${${_var}}") + endforeach() +endforeach() + # # If we're running GCC or clang define _U_ to be "__attribute__((unused))" # so we can use _U_ to flag unused function parameters and not get warnings From f8a9a21428357a322473497e24dda849c603fe5f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 14:25:58 +0100 Subject: [PATCH 54/59] cmake: add _U_ and NGHTTP2_NORETURN to config.h Do not add _U_ and NGHTTP2_NORETURN definitions to the command line, instead add it to config.h. This matches what autotools does. --- CMakeLists.txt | 9 ++++----- cmakeconfig.h.in | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f56d7ce..83692e9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,12 +118,11 @@ endforeach() # XXX - similar hints for other compilers? # if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - add_definitions( - "-D_U_=__attribute__((unused))" - "-DNGHTTP2_NORETURN=__attribute__((noreturn))" - ) + set(HINT_UNUSED_PARAM "__attribute__((unused))") + set(HINT_NORETURN "__attribute__((noreturn))") else() - add_definitions(-D_U_ -DNGHTTP2_NORETURN) + set(HINT_UNUSED_PARAM) + set(HINT_NORETURN) endif() include(ExtractValidFlags) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index d7db50f3..3e39463d 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -1,4 +1,10 @@ +/* Hint to the compiler that a function parameter is not used */ +#define _U_ @HINT_UNUSED_PARAM@ + +/* Hint to the compiler that a function never returns */ +#define NGHTTP2_NORETURN @HINT_NORETURN@ + /* Define to 1 if you have the `std::map::emplace`. */ #cmakedefine HAVE_STD_MAP_EMPLACE 1 From f34971774b26ee3b707954c64ee2b822005c98da Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 14:52:42 +0100 Subject: [PATCH 55/59] cmake: use -std=c++11 instead of -std=gnu+11 Matches autotools behavior. The m4_if logic was misread... --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83692e9f..a9dd0385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ else() endif() include(ExtractValidFlags) -foreach(_cxx1x_flag -std=gnu++11 -std=gnu++0x) +foreach(_cxx1x_flag -std=c++11 -std=c++0x) extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag}) if(_cxx1x_flag_supported) set(CXX1XCXXFLAGS ${_cxx1x_flag}) From 3a2a943fe986c4025ce25e448d57c16cd332ab99 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 17:31:54 +0100 Subject: [PATCH 56/59] cmake: do not fail without libxml2 Avoid adding a LIBXML2_LIBRARIES-NOTFOUND to the libraries list when it is not found. Likewise for OpenSSL. --- CMakeLists.txt | 11 ++++++++++- src/CMakeLists.txt | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9dd0385..5da6999a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,10 @@ endif() # openssl (for src) set(HAVE_OPENSSL ${OPENSSL_FOUND}) if(OPENSSL_FOUND) - set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) +else() + set(OPENSSL_INCLUDE_DIRS "") + set(OPENSSL_LIBRARIES "") endif() # libev (for src) set(HAVE_LIBEV ${LIBEV_FOUND}) @@ -208,6 +211,12 @@ endif() set(HAVE_JANSSON ${JANSSON_FOUND}) # libxml2 (for src/nghttp) set(HAVE_LIBXML2 ${LIBXML2_FOUND}) +if(LIBXML2_FOUND) + set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR}) +else() + set(LIBXML2_INCLUDE_DIRS "") + set(LIBXML2_LIBRARIES "") +endif() # jemalloc set(HAVE_JEMALLOC ${JEMALLOC_FOUND}) # spdylay (for src/nghttpx and src/h2load) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3caf0edc..e5b99d8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories( ${JEMALLOC_INCLUDE_DIRS} ${SPDYLAY_INCLUDE_DIRS} - ${LIBXML2_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIRS} ${LIBEV_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} From d10f149161eb4fdb4b9ceedd59eaf9ea3cd6d505 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 17:33:20 +0100 Subject: [PATCH 57/59] cmake: fix Windows support Fix Windows build by defining `ssize_t` when missing and adjusting the install commands. Add support for ENABLE_WERROR=1 while at it. Tested with MSVC 2013 on Windows 7 x64. --- CMakeLists.txt | 27 ++++++++++++++++++--------- cmakeconfig.h.in | 3 +++ lib/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da6999a..3378b187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,11 +267,15 @@ check_include_file("syslog.h" HAVE_SYSLOG_H) check_include_file("time.h" HAVE_TIME_H) check_include_file("unistd.h" HAVE_UNISTD_H) +include(CheckTypeSize) # Checks for typedefs, structures, and compiler characteristics. -# XXX The AC_TYPE_* macros would define suitable types if standard headers do -# not define them. No equivalent in cmake... # AC_TYPE_SIZE_T -# AC_TYPE_SSIZE_T +check_type_size("ssize_t" SIZEOF_SSIZE_T) +if(SIZEOF_SSIZE_T STREQUAL "") + # ssize_t is a signed type in POSIX storing at least -1. + # Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools). + set(ssize_t int) +endif() # AC_TYPE_UINT8_T # AC_TYPE_UINT16_T # AC_TYPE_UINT32_T @@ -292,7 +296,6 @@ include(CheckStructHasMember) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) # Check size of pointer to decide we need 8 bytes alignment adjustment. -include(CheckTypeSize) check_type_size("int *" SIZEOF_INT_P) check_type_size("time_t" SIZEOF_TIME_T) @@ -322,11 +325,17 @@ endif() set(WARNCFLAGS) set(WARNCXXFLAGS) -if(ENABLE_WERROR) - extract_valid_c_flags(WARNCFLAGS -Werror) - extract_valid_c_flags(WARNCXXFLAGS -Werror) -endif() -if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + if(ENABLE_WERROR) + set(WARNCFLAGS /WX) + set(WARNCXXFLAGS /WX) + endif() +else() + if(ENABLE_WERROR) + extract_valid_c_flags(WARNCFLAGS -Werror) + extract_valid_c_flags(WARNCXXFLAGS -Werror) + endif() + # For C compiler extract_valid_c_flags(WARNCFLAGS -Wall diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 3e39463d..fb798f4e 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -5,6 +5,9 @@ /* Hint to the compiler that a function never returns */ #define NGHTTP2_NORETURN @HINT_NORETURN@ +/* Define to `int' if does not define. */ +#cmakedefine ssize_t @ssize_t@ + /* Define to 1 if you have the `std::map::emplace`. */ #cmakedefine HAVE_STD_MAP_EMPLACE 1 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 17777ec1..06253935 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -44,7 +44,7 @@ if(HAVE_CUNIT) endif() install(TARGETS nghttp2 - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5b99d8c..1933e4c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -250,7 +250,7 @@ if(ENABLE_ASIO_LIB) VERSION 1.0.0 SOVERSION 1) install(TARGETS nghttp2_asio - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") From bd253e1bddd065c1d394ae487062851d820df85b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 17 Mar 2016 23:32:07 +0100 Subject: [PATCH 58/59] cmake: fix Windows build with CUnit failmalloc and main tests succesfully pass the test now. --- lib/CMakeLists.txt | 1 + tests/nghttp2_npn_test.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 06253935..c5c9ba9f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -41,6 +41,7 @@ if(HAVE_CUNIT) VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} ARCHIVE_OUTPUT_NAME nghttp2 ) + target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB") endif() install(TARGETS nghttp2 diff --git a/tests/nghttp2_npn_test.c b/tests/nghttp2_npn_test.c index cbd65b71..db7fd9ff 100644 --- a/tests/nghttp2_npn_test.c +++ b/tests/nghttp2_npn_test.c @@ -22,6 +22,9 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ #include "nghttp2_npn_test.h" #include From 08c7656e47ba548c439aaa27b6d476a4410c4639 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 17 Mar 2016 23:34:14 +0100 Subject: [PATCH 59/59] travis: remove -DCMAKE_BUILD_TYPE=None It was added because the default RelWithDebInfo type disabled assertions, but now that -DNDEBUG is removed from its flags, it is not necessary to change the build type anymore. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3267434b..aa7bafc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ before_script: - if [ "$CI_BUILD" = "autotools" ]; then autoreconf -i; fi - git submodule update --init - if [ "$CI_BUILD" = "autotools" ]; then ./configure --enable-werror --with-mruby --with-neverbleed LIBSPDYLAY_CFLAGS="-I$SPDYLAY_HOME/lib/includes" LIBSPDYLAY_LIBS="-L$SPDYLAY_HOME/lib/.libs -lspdylay"; fi - - if [ "$CI_BUILD" = "cmake" ]; then cmake -DCMAKE_BUILD_TYPE=None -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DSPDYLAY_INCLUDE_DIR="$SPDYLAY_HOME/lib/includes" -DSPDYLAY_LIBRARY="$SPDYLAY_HOME/lib/.libs/libspdylay.so"; fi + - if [ "$CI_BUILD" = "cmake" ]; then cmake -DENABLE_WERROR=1 -DWITH_MRUBY=1 -DWITH_NEVERBLEED=1 -DSPDYLAY_INCLUDE_DIR="$SPDYLAY_HOME/lib/includes" -DSPDYLAY_LIBRARY="$SPDYLAY_HOME/lib/.libs/libspdylay.so"; fi script: - make - make check