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.
This commit is contained in:
Peter Wu 2016-02-16 14:01:44 +01:00
parent 1b67b2d33e
commit 3dd57e1f59
1 changed files with 34 additions and 84 deletions

View File

@ -57,7 +57,8 @@ else()
endif() endif()
find_package(Jansson 2.5 QUIET) find_package(Jansson 2.5 QUIET)
set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND}) 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}) set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND})
find_package(Cython QUIET) find_package(Cython QUIET)
find_package(PythonLibs QUIET) find_package(PythonLibs QUIET)
@ -67,7 +68,7 @@ else()
set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF) set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF)
endif() endif()
find_package(LibXml2 QUIET) find_package(LibXml2 2.7.7 QUIET)
set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND}) set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND})
find_package(Jemalloc QUIET) find_package(Jemalloc QUIET)
set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND}) set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND})
@ -76,6 +77,13 @@ set(WITH_SPDYLAY_DEFAULT ${SPDYLAY_FOUND})
include(CMakeOptions.txt) 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) if(ENABLE_LIB_ONLY)
set(ENABLE_APP OFF) set(ENABLE_APP OFF)
set(ENABLE_HPACK_TOOLS OFF) set(ENABLE_HPACK_TOOLS OFF)
@ -130,10 +138,12 @@ cmake_pop_check_state()
set(APP_LIBRARIES) set(APP_LIBRARIES)
if(ENABLE_PYTHON_BINDINGS) if(ENABLE_PYTHON_BINDINGS)
find_package(Cython REQUIRED) if(NOT (CYTHON_FOUND AND PYTHONLIBS_FOUND))
find_package(PythonLibs REQUIRED) 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) if(NOT PYTHON_VERSION_STRING STREQUAL PYTHONLIBS_VERSION_STRING)
message(SEND_ERROR message(FATAL_ERROR
"Python executable and library must have the same version!" "Python executable and library must have the same version!"
" Found Python ${PYTHON_VERSION_STRING} and" " Found Python ${PYTHON_VERSION_STRING} and"
" PythonLibs ${PYTHONLIBS_VERSION_STRING}" " PythonLibs ${PYTHONLIBS_VERSION_STRING}"
@ -158,83 +168,30 @@ endif()
# APP_LIBRARIES if it is really specific to OpenSSL? # APP_LIBRARIES if it is really specific to OpenSSL?
find_package(CUnit 2.1) find_package(CUnit 2.1)
if(CUNIT_FOUND) enable_testing()
enable_testing() set(HAVE_CUNIT ${CUNIT_FOUND})
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()
# openssl (for src) # openssl (for src)
set(HAVE_OPENSSL ${OPENSSL_FOUND})
if(OPENSSL_FOUND) if(OPENSSL_FOUND)
set(HAVE_OPENSSL 1)
set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
else()
set(HAVE_OPENSSL 0)
endif() endif()
# libev (for src) # libev (for src)
if(LIBEV_FOUND) set(HAVE_LIBEV ${LIBEV_FOUND})
set(HAVE_LIBEV 1) set(HAVE_ZLIB ${ZLIB_FOUND})
else() set(HAVE_LIBEVENT_OPENSSL ${LIBEVENT_FOUND})
set(HAVE_LIBEV 0) if(LIBEVENT_FOUND)
endif() # Must both link the core and openssl libraries.
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(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES}) set(LIBEVENT_OPENSSL_LIBRARIES ${LIBEVENT_LIBRARIES})
set(HAVE_LIBEVENT_OPENSSL 1)
else()
set(HAVE_LIBEVENT_OPENSSL 0)
endif() endif()
# jansson (for src/nghttp, src/deflatehd and src/inflatehd)
if(ENABLE_HPACK_TOOLS) set(HAVE_JANSSON ${JANSSON_FOUND})
# 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()
# libxml2 (for src/nghttp) # libxml2 (for src/nghttp)
if(WITH_LIBXML2) set(HAVE_LIBXML2 ${LIBXML2_FOUND})
find_package(LibXml2 2.7.7 REQUIRED)
set(HAVE_LIBXML2 1)
else()
set(HAVE_LIBXML2 0)
endif()
# jemalloc # jemalloc
if(WITH_JEMALLOC) set(HAVE_JEMALLOC ${JEMALLOC_FOUND})
find_package(Jemalloc REQUIRED)
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) # spdylay (for src/nghttpx and src/h2load)
if(WITH_SPDYLAY) set(HAVE_SPDYLAY ${SPDYLAY_FOUND})
find_package(Spdylay 1.3.2 REQUIRED)
set(HAVE_SPDYLAY 1)
else()
set(HAVE_SPDYLAY 0)
endif()
if(ENABLE_ASIO_LIB) if(ENABLE_ASIO_LIB)
find_package(Boost 1.54.0 REQUIRED system thread) 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) if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB)
set(ENABLE_THIRD_PARTY 1) set(ENABLE_THIRD_PARTY 1)
# mruby (for src/nghttpx) # mruby (for src/nghttpx)
if(WITH_MRUBY) set(HAVE_MRUBY ${WITH_MRUBY})
set(HAVE_MRUBY 1) set(HAVE_NEVERBLEED ${WITH_NEVERBLEED})
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()
else() else()
set(HAVE_MRUBY 0) set(HAVE_MRUBY 0)
set(HAVE_NEVERBLEED 0) set(HAVE_NEVERBLEED 0)
@ -533,3 +479,7 @@ message(STATUS "summary of build options:
Python bindings:${ENABLE_PYTHON_BINDINGS} Python bindings:${ENABLE_PYTHON_BINDINGS}
Threading: ${ENABLE_THREADS} 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()