diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a9864279..496d300d15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,4 @@ -######################################################################## -## CMake Configuration - +######################################################################## ## CMake Configuration cmake_minimum_required(VERSION 2.8 FATAL_ERROR) # Prohibit in-source builds. @@ -46,6 +44,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}") ######################################################################## ## Dependency Configuration +include(FindRequiredPackage) + # Check cache value first to avoid displaying "Found sed" messages everytime if (NOT SED_EXE) find_program(SED_EXE sed) @@ -56,17 +56,24 @@ if (NOT SED_EXE) endif () endif () -find_package(Perl REQUIRED) -find_package(FLEX REQUIRED) -find_package(BISON REQUIRED) -find_package(PCAP REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(BIND REQUIRED) +FindRequiredPackage(Perl) +FindRequiredPackage(FLEX) +FindRequiredPackage(BISON) +FindRequiredPackage(PCAP) +FindRequiredPackage(OpenSSL) +FindRequiredPackage(BIND) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/aux/binpac/CMakeLists.txt) add_subdirectory(aux/binpac) endif () -find_package(BinPAC REQUIRED) +FindRequiredPackage(BinPAC) + +if (MISSING_PREREQS) + foreach (prereq ${MISSING_PREREQ_DESCS}) + message(SEND_ERROR ${prereq}) + endforeach () + message(FATAL_ERROR "Configuration aborted due to missing prerequisites") +endif () include_directories(BEFORE ${PCAP_INCLUDE_DIR} diff --git a/cmake/FindLibGeoIP.cmake b/cmake/FindLibGeoIP.cmake index 4d2bc3d7d6..ef8529e2e3 100644 --- a/cmake/FindLibGeoIP.cmake +++ b/cmake/FindLibGeoIP.cmake @@ -13,7 +13,7 @@ # # Variables defined by this module: # -# LIBGeoIP_FOUND System has GeoIP libraries and headers +# LIBGEOIP_FOUND System has GeoIP libraries and headers # LibGeoIP_LIBRARY The GeoIP library # LibGeoIP_INCLUDE_DIR The location of GeoIP headers diff --git a/cmake/FindOpenSSL.cmake b/cmake/FindOpenSSL.cmake index 353961ffc7..599a846f0a 100644 --- a/cmake/FindOpenSSL.cmake +++ b/cmake/FindOpenSSL.cmake @@ -13,7 +13,7 @@ # # Variables defined by this module: # -# OpenSSL_FOUND System has openssl, include and library dirs found +# OPENSSL_FOUND System has openssl, include and library dirs found # OpenSSL_INCLUDE_DIR The openssl include directories. # OpenSSL_LIBRARIES The openssl libraries. # OpenSSL_CYRPTO_LIBRARY The openssl crypto library. diff --git a/cmake/FindRequiredPackage.cmake b/cmake/FindRequiredPackage.cmake new file mode 100644 index 0000000000..ff76b646cc --- /dev/null +++ b/cmake/FindRequiredPackage.cmake @@ -0,0 +1,44 @@ +# A wrapper macro around the standard CMake find_package macro that +# facilitates displaying better error messages by default, or even +# accepting custom error messages on a per package basis. +# +# If a package is not found, then the MISSING_PREREQS variable gets +# set to true and either a default or custom error message appended +# to MISSING_PREREQ_DESCS. +# +# The caller can use these variables to display a list of any missing +# packages and abort the build/configuration if there were any. +# +# Use as follows: +# +# include(FindRequiredPackage) +# FindRequiredPackage(Perl) +# FindRequiredPackage(FLEX "You need to install flex (Fast Lexical Analyzer)") +# +# if (MISSING_PREREQS) +# foreach (prereq ${MISSING_PREREQ_DESCS}) +# message(SEND_ERROR ${prereq}) +# endforeach () +# message(FATAL_ERROR "Configuration aborted due to missing prerequisites") +# endif () + +macro(FindRequiredPackage packageName) + find_package(${packageName}) + string(TOUPPER ${packageName} canonPackageName) + if (NOT ${canonPackageName}_FOUND) + set(MISSING_PREREQS true) + + set(customDesc) + foreach (descArg ${ARGN}) + set(customDesc "${customDesc} ${descArg}") + endforeach () + + if (customDesc) + # append the custom error message that was provided as an argument + list(APPEND MISSING_PREREQ_DESCS ${customDesc}) + else () + list(APPEND MISSING_PREREQ_DESCS + " Could not find prerequisite package '${packageName}'") + endif () + endif () +endmacro(FindRequiredPackage)