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()
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()
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()
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()