1 # nghttp2 - HTTP/2 C Library
3 # Copyright (c) 2012, 2013, 2014, 2015 Tatsuhiro Tsujikawa
4 # Copyright (c) 2016 Peter Wu <peter@lekensteyn.nl>
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 cmake_minimum_required(VERSION 3.0)
26 # XXX using 1.8.90 instead of 1.9.0-DEV
27 project(nghttp2 VERSION 1.41.0)
29 # See versioning rule:
30 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
35 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
38 math(EXPR LT_SOVERSION "${LT_CURRENT} - ${LT_AGE}")
39 set(LT_VERSION "${LT_SOVERSION}.${LT_AGE}.${LT_REVISION}")
40 set(PACKAGE_VERSION "${PROJECT_VERSION}")
41 HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH})
43 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
44 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE)
46 # Include "None" as option to disable any additional (optimization) flags,
47 # relying on just CMAKE_C_FLAGS and CMAKE_CXX_FLAGS (which are empty by
48 # default). These strings are presented in cmake-gui.
49 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
50 "None" "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
53 include(GNUInstallDirs)
55 # For Python bindings and documentation
56 # (Must be called before PythonLibs for matching versions.)
57 find_package(PythonInterp)
59 # Auto-detection of features that can be toggled
60 find_package(OpenSSL 1.0.1)
61 find_package(Libev 4.11)
62 find_package(Libcares 1.7.5)
63 find_package(ZLIB 1.2.3)
64 if(OPENSSL_FOUND AND LIBEV_FOUND AND ZLIB_FOUND)
65 set(ENABLE_APP_DEFAULT ON)
67 set(ENABLE_APP_DEFAULT OFF)
69 find_package(Systemd 209)
70 find_package(Jansson 2.5)
71 set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND})
72 # 2.0.8 is required because we use evconnlistener_set_error_cb()
73 find_package(Libevent 2.0.8 COMPONENTS libevent openssl)
74 set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND})
76 find_package(PythonLibs)
77 if(CYTHON_FOUND AND PYTHONLIBS_FOUND)
78 set(ENABLE_PYTHON_BINDINGS_DEFAULT ON)
80 set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF)
83 find_package(LibXml2 2.6.26)
84 set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND})
85 find_package(Jemalloc)
86 set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND})
87 find_package(Spdylay 1.3.2)
88 set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND})
90 include(CMakeOptions.txt)
92 if(ENABLE_LIB_ONLY AND (ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_EXAMPLES OR
93 ENABLE_PYTHON_BINDINGS))
94 # Remember when disabled options are disabled for later diagnostics.
95 set(ENABLE_LIB_ONLY_DISABLED_OTHERS 1)
97 set(ENABLE_LIB_ONLY_DISABLED_OTHERS 0)
101 set(ENABLE_HPACK_TOOLS OFF)
102 set(ENABLE_EXAMPLES OFF)
103 set(ENABLE_PYTHON_BINDINGS OFF)
106 # Do not disable assertions based on CMAKE_BUILD_TYPE.
107 foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo")
109 string(TOUPPER "CMAKE_${_lang}_FLAGS_${_build_type}" _var)
110 string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " ${_var} "${${_var}}")
114 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
115 set(HINT_NORETURN "__attribute__((noreturn))")
120 include(ExtractValidFlags)
121 foreach(_cxx1x_flag -std=c++14)
122 extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag})
123 if(_cxx1x_flag_supported)
124 set(CXX1XCXXFLAGS ${_cxx1x_flag})
129 include(CMakePushCheckState)
130 include(CheckCXXSourceCompiles)
131 cmake_push_check_state()
132 set(CMAKE_REQUIRED_DEFINITIONS "${CXX1XCXXFLAGS}")
133 # Check that std::future is available.
134 check_cxx_source_compiles("
137 int main() { std::vector<std::future<int>> v; }" HAVE_STD_FUTURE)
138 # Check that std::map::emplace is available for g++-4.7.
139 check_cxx_source_compiles("
141 int main() { std::map<int, int>().emplace(1, 2); }" HAVE_STD_MAP_EMPLACE)
142 cmake_pop_check_state()
145 # Checks for libraries.
146 # Additional libraries required for programs under src directory.
149 if(ENABLE_PYTHON_BINDINGS)
150 if(NOT (CYTHON_FOUND AND PYTHONLIBS_FOUND))
151 message(FATAL_ERROR "python bindings were requested "
152 "(ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.")
154 if(NOT PYTHON_VERSION_STRING STREQUAL PYTHONLIBS_VERSION_STRING)
156 "Python executable and library must have the same version!"
157 " Found Python ${PYTHON_VERSION_STRING} and"
158 " PythonLibs ${PYTHONLIBS_VERSION_STRING}"
163 set(CMAKE_THREAD_PREFER_PTHREAD 1)
164 find_package(Threads)
165 if(CMAKE_USE_PTHREADS_INIT)
166 list(APPEND APP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
168 # XXX android and C++, is this still needed in cmake?
172 # # android does not need -pthread, but needs followng 3 libs for C++
173 # APPLDFLAGS="$APPLDFLAGS -lstdc++ -latomic -lsupc++"
175 # dl: openssl requires libdl when it is statically linked.
176 # XXX shouldn't ${CMAKE_DL_LIBS} be appended to OPENSSL_LIBRARIES instead of
177 # APP_LIBRARIES if it is really specific to OpenSSL?
179 find_package(CUnit 2.1)
181 set(HAVE_CUNIT ${CUNIT_FOUND})
183 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
187 set(HAVE_OPENSSL ${OPENSSL_FOUND})
189 set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
191 set(OPENSSL_INCLUDE_DIRS "")
192 set(OPENSSL_LIBRARIES "")
195 set(HAVE_LIBEV ${LIBEV_FOUND})
196 set(HAVE_ZLIB ${ZLIB_FOUND})
197 set(HAVE_SYSTEMD ${SYSTEMD_FOUND})
198 set(HAVE_LIBEVENT_OPENSSL ${LIBEVENT_FOUND})
200 # Must both link the core and openssl libraries.
201 set(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES})
203 # libc-ares (for src)
204 set(HAVE_LIBCARES ${LIBCARES_FOUND})
206 set(LIBCARES_INCLUDE_DIRS ${LIBCARES_INCLUDE_DIR})
208 set(LIBCARES_INCLUDE_DIRS "")
209 set(LIBCARES_LIBRARIES "")
211 # jansson (for src/nghttp, src/deflatehd and src/inflatehd)
212 set(HAVE_JANSSON ${JANSSON_FOUND})
213 # libxml2 (for src/nghttp)
214 set(HAVE_LIBXML2 ${LIBXML2_FOUND})
216 set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
218 set(LIBXML2_INCLUDE_DIRS "")
219 set(LIBXML2_LIBRARIES "")
222 set(HAVE_JEMALLOC ${JEMALLOC_FOUND})
223 # spdylay (for src/nghttpx and src/h2load)
224 set(HAVE_SPDYLAY ${SPDYLAY_FOUND})
227 find_package(Boost 1.54.0 REQUIRED system thread)
230 # The nghttp, nghttpd and nghttpx under src depend on zlib, OpenSSL and libev
231 if(ENABLE_APP AND NOT (ZLIB_FOUND AND OPENSSL_FOUND AND LIBEV_FOUND))
232 message(FATAL_ERROR "Applications were requested (ENABLE_APP=1) but dependencies are not met.")
235 # HPACK tools requires jansson
236 if(ENABLE_HPACK_TOOLS AND NOT HAVE_JANSSON)
237 message(FATAL_ERROR "HPACK tools were requested (ENABLE_HPACK_TOOLS=1) but dependencies are not met.")
240 # C++ library libnghttp2_asio
241 if(ENABLE_EXAMPLES AND NOT (OPENSSL_FOUND AND LIBEVENT_OPENSSL_FOUND))
242 message(FATAL_ERROR "examples were requested (ENABLE_EXAMPLES=1) but dependencies are not met.")
245 # third-party http-parser only be built when needed
246 if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB)
247 set(ENABLE_THIRD_PARTY 1)
248 # mruby (for src/nghttpx)
249 set(HAVE_MRUBY ${WITH_MRUBY})
250 set(HAVE_NEVERBLEED ${WITH_NEVERBLEED})
253 set(HAVE_NEVERBLEED 0)
256 # Checks for header files.
257 include(CheckIncludeFile)
258 check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
259 check_include_file("fcntl.h" HAVE_FCNTL_H)
260 check_include_file("inttypes.h" HAVE_INTTYPES_H)
261 check_include_file("limits.h" HAVE_LIMITS_H)
262 check_include_file("netdb.h" HAVE_NETDB_H)
263 check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
264 check_include_file("pwd.h" HAVE_PWD_H)
265 check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
266 check_include_file("sys/time.h" HAVE_SYS_TIME_H)
267 check_include_file("syslog.h" HAVE_SYSLOG_H)
268 check_include_file("time.h" HAVE_TIME_H)
269 check_include_file("unistd.h" HAVE_UNISTD_H)
271 include(CheckTypeSize)
272 # Checks for typedefs, structures, and compiler characteristics.
274 check_type_size("ssize_t" SIZEOF_SSIZE_T)
275 if(SIZEOF_SSIZE_T STREQUAL "")
276 # ssize_t is a signed type in POSIX storing at least -1.
277 # Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools).
291 # XXX To support inline for crappy compilers, see https://cmake.org/Wiki/CMakeTestInline
293 # XXX is AC_SYS_LARGEFILE still needed for modern systems?
294 # add_definitions(-D_FILE_OFFSET_BITS=64)
296 include(CheckStructHasMember)
297 check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF)
299 # Check size of pointer to decide we need 8 bytes alignment adjustment.
300 check_type_size("int *" SIZEOF_INT_P)
301 check_type_size("time_t" SIZEOF_TIME_T)
303 # Checks for library functions.
304 include(CheckFunctionExists)
305 check_function_exists(_Exit HAVE__EXIT)
306 check_function_exists(accept4 HAVE_ACCEPT4)
307 check_function_exists(mkostemp HAVE_MKOSTEMP)
309 include(CheckSymbolExists)
310 # XXX does this correctly detect initgroups (un)availability on cygwin?
311 check_symbol_exists(initgroups grp.h HAVE_DECL_INITGROUPS)
312 if(NOT HAVE_DECL_INITGROUPS AND HAVE_UNISTD_H)
313 # FreeBSD declares initgroups() in unistd.h
314 check_symbol_exists(initgroups unistd.h HAVE_DECL_INITGROUPS2)
315 if(HAVE_DECL_INITGROUPS2)
316 set(HAVE_DECL_INITGROUPS 1)
322 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
325 set(WARNCXXFLAGS /WX)
329 extract_valid_c_flags(WARNCFLAGS -Werror)
330 extract_valid_c_flags(WARNCXXFLAGS -Werror)
334 extract_valid_c_flags(WARNCFLAGS
339 -Wmissing-declarations
341 -Wdeclaration-after-statement
364 -Wlanguage-extension-token
365 -Wmissing-field-initializers
367 -Wmissing-variable-declarations
368 # Not used because we cannot change public structs
371 # Not used because this basically disallows default case
373 -Wunreachable-code-break
377 # Only work with Clang for the moment
379 # This is required because we pass format string as "const char*.
380 -Wno-format-nonliteral
383 extract_valid_cxx_flags(WARNCXXFLAGS
390 if(ENABLE_STATIC_CRT)
392 foreach(suffix "" _DEBUG _MINSIZEREL _RELEASE _RELWITHDEBINFO)
393 set(var "CMAKE_${lang}_FLAGS${suffix}")
394 string(REPLACE "/MD" "/MT" ${var} "${${var}}")
403 # Some platform does not have working std::future. We disable
404 # threading for those platforms.
405 if(NOT ENABLE_THREADS OR NOT HAVE_STD_FUTURE)
409 add_definitions(-DHAVE_CONFIG_H)
410 configure_file(cmakeconfig.h.in config.h)
411 # autotools-compatible names
412 # Sphinx expects relative paths in the .rst files. Use the fact that the files
413 # below are all one directory level deep.
414 file(RELATIVE_PATH top_srcdir "${CMAKE_CURRENT_BINARY_DIR}/dir" "${CMAKE_CURRENT_SOURCE_DIR}")
415 file(RELATIVE_PATH top_builddir "${CMAKE_CURRENT_BINARY_DIR}/dir" "${CMAKE_CURRENT_BINARY_DIR}")
416 set(abs_top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
417 set(abs_top_builddir "${CMAKE_CURRENT_BINARY_DIR}")
418 # libnghttp2.pc (pkg-config file)
419 set(prefix "${CMAKE_INSTALL_PREFIX}")
420 set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
421 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
422 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
423 set(VERSION "${PACKAGE_VERSION}")
424 # For init scripts and systemd service file (in contrib/)
425 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
426 set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}")
429 lib/includes/nghttp2/nghttp2ver.h
430 src/libnghttp2_asio.pc
432 integration-tests/config.go
433 integration-tests/setenv
436 doc/package_README.rst
437 doc/tutorial-client.rst
438 doc/tutorial-server.rst
439 doc/tutorial-hpack.rst
440 doc/nghttpx-howto.rst
442 doc/libnghttp2_asio.rst
443 doc/python-apiref.rst
444 doc/building-android-binary.rst
448 doc/asio_http2_server.h.rst
449 doc/asio_http2_client.h.rst
452 configure_file("${name}.in" "${name}" @ONLY)
456 "${CMAKE_CURRENT_BINARY_DIR}" # for config.h
458 # For use in src/CMakeLists.txt
459 set(PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}")
461 install(FILES README.rst DESTINATION "${CMAKE_INSTALL_DOCDIR}")
463 add_subdirectory(lib)
464 #add_subdirectory(lib/includes)
465 add_subdirectory(third-party)
466 add_subdirectory(src)
467 #add_subdirectory(src/includes)
468 add_subdirectory(examples)
469 add_subdirectory(python)
470 add_subdirectory(tests)
471 #add_subdirectory(tests/testdata)
472 add_subdirectory(integration-tests)
473 add_subdirectory(doc)
474 add_subdirectory(contrib)
475 add_subdirectory(script)
478 string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
479 message(STATUS "summary of build options:
481 Package version: ${VERSION}
482 Library version: ${LT_CURRENT}:${LT_REVISION}:${LT_AGE}
483 Install prefix: ${CMAKE_INSTALL_PREFIX}
484 Target system: ${CMAKE_SYSTEM_NAME}
486 Build type: ${CMAKE_BUILD_TYPE}
487 C compiler: ${CMAKE_C_COMPILER}
488 CFLAGS: ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS}
489 C++ compiler: ${CMAKE_CXX_COMPILER}
490 CXXFLAGS: ${CMAKE_CXX_FLAGS_${_build_type}} ${CMAKE_CXX_FLAGS}
491 WARNCFLAGS: ${WARNCFLAGS}
492 CXX1XCXXFLAGS: ${CXX1XCXXFLAGS}
494 Python: ${PYTHON_EXECUTABLE}
495 PYTHON_VERSION: ${PYTHON_VERSION_STRING}
496 Library version:${PYTHONLIBS_VERSION_STRING}
497 Cython: ${CYTHON_EXECUTABLE}
499 CUnit: ${HAVE_CUNIT} (LIBS='${CUNIT_LIBRARIES}')
500 Failmalloc: ${ENABLE_FAILMALLOC}
502 OpenSSL: ${HAVE_OPENSSL} (LIBS='${OPENSSL_LIBRARIES}')
503 Libxml2: ${HAVE_LIBXML2} (LIBS='${LIBXML2_LIBRARIES}')
504 Libev: ${HAVE_LIBEV} (LIBS='${LIBEV_LIBRARIES}')
505 Libc-ares: ${HAVE_LIBCARES} (LIBS='${LIBCARES_LIBRARIES}')
506 Libevent(SSL): ${HAVE_LIBEVENT_OPENSSL} (LIBS='${LIBEVENT_OPENSSL_LIBRARIES}')
507 Spdylay: ${HAVE_SPDYLAY} (LIBS='${SPDYLAY_LIBRARIES}')
508 Jansson: ${HAVE_JANSSON} (LIBS='${JANSSON_LIBRARIES}')
509 Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBRARIES}')
510 Zlib: ${HAVE_ZLIB} (LIBS='${ZLIB_LIBRARIES}')
511 Systemd: ${HAVE_SYSTEMD} (LIBS='${SYSTEMD_LIBRARIES}')
512 Boost::System: ${Boost_SYSTEM_LIBRARY}
513 Boost::Thread: ${Boost_THREAD_LIBRARY}
515 http-parser: ${ENABLE_THIRD_PARTY}
517 Neverbleed: ${HAVE_NEVERBLEED}
519 Applications: ${ENABLE_APP}
520 HPACK tools: ${ENABLE_HPACK_TOOLS}
521 Libnghttp2_asio:${ENABLE_ASIO_LIB}
522 Examples: ${ENABLE_EXAMPLES}
523 Python bindings:${ENABLE_PYTHON_BINDINGS}
524 Threading: ${ENABLE_THREADS}
526 if(ENABLE_LIB_ONLY_DISABLED_OTHERS)
527 message("Only the library will be built. To build other components "
528 "(such as applications and examples), set ENABLE_LIB_ONLY=OFF.")