diff --git a/BuildOptions.cmake b/BuildOptions.cmake index 306d52cb9d..d30be09bd2 100644 --- a/BuildOptions.cmake +++ b/BuildOptions.cmake @@ -58,7 +58,7 @@ set(ENABLE_PERFTOOLS false # Uncomment to prefer building BinPAC from existing sources rather than # use an existing installation (i.e. you have initialized Bro's BinPAC # git submodule and updated sources local to the Bro source tree) -#set(BinPAC_PREFER_LOCAL_BUILD true) +#set(BinPAC_PREFER_BUILD true) # Comment this if local build of BinPAC should be scheduled for installation set(BinPAC_SKIP_INSTALL true) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98118f0090..569cf8bbb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,25 +70,7 @@ find_package(BISON REQUIRED) find_package(PCAP REQUIRED) find_package(OpenSSL REQUIRED) find_package(BIND REQUIRED) - -# This test is for when the user would like to use rebuild BinPAC -# rather than use an existing installation -if (NOT BinPAC_PREFER_LOCAL_BUILD) - find_package(BinPAC) -endif () - -if (NOT BINPAC_FOUND) - # check if we can build BinPAC locally - if (EXISTS ${CMAKE_SOURCE_DIR}/binpac/CMakeLists.txt) - add_subdirectory(binpac) - # find_package called just to set the _FOUND variable - find_package(BinPAC) - message(STATUS "Building local version of BinPAC") - else () - message(FATAL_ERROR "BinPAC required but it is not installed and" - " the sources to build it are also not found.") - endif () -endif () +find_package(BinPAC REQUIRED) set(HAVE_LIBMAGIC false) find_package(LibMagic) diff --git a/cmake/FindBinPAC.cmake b/cmake/FindBinPAC.cmake index b64211aade..927252c543 100644 --- a/cmake/FindBinPAC.cmake +++ b/cmake/FindBinPAC.cmake @@ -10,6 +10,10 @@ # BinPAC_ROOT_DIR Set this variable to the root installation of # BinPAC if the module has problems finding the # proper installation path. +# BinPAC_PREFER_BUILD Set this to true if BinPAC should be built +# from sources located in the root source +# directory in subidrectory 'binpac'. The +# module will not look for BinPAC elsewhere. # # Variables defined by this module: # @@ -18,24 +22,41 @@ # BinPAC_LIBRARY The libbinpac.a library # BinPAC_INCLUDE_DIR The binpac headers -find_path(BinPAC_ROOT_DIR - NAMES include/binpac.h -) +if (BinPAC_PREFER_BUILD) + # check if we can build BinPAC locally + if (EXISTS ${CMAKE_SOURCE_DIR}/binpac/CMakeLists.txt) + if (NOT BinPAC_EXE) + # Display only first time + message(STATUS "Building local version of BinPAC") + endif () + # BinPAC's CMake project must declare: + # BinPAC_EXE, BinPAC_LIBRARY, BinPAC_INCLUDE_DIR + add_subdirectory(${CMAKE_SOURCE_DIR}/binpac) + else () + message(WARNING "Option to build BinPAC from source selected, " + "but no sources found in ${CMAKE_SOURCE_DIR}/binpac") + endif () +else () + # look for BinPAC in standard locations or user-provided root + find_path(BinPAC_ROOT_DIR + NAMES include/binpac.h + ) -find_file(BinPAC_EXE - NAMES binpac - HINTS ${BinPAC_ROOT_DIR}/bin -) + find_file(BinPAC_EXE + NAMES binpac + HINTS ${BinPAC_ROOT_DIR}/bin + ) -find_library(BinPAC_LIBRARY - NAMES libbinpac.a - HINTS ${BinPAC_ROOT_DIR}/lib -) + find_library(BinPAC_LIBRARY + NAMES libbinpac.a + HINTS ${BinPAC_ROOT_DIR}/lib + ) -find_path(BinPAC_INCLUDE_DIR - NAMES binpac.h - HINTS ${BinPAC_ROOT_DIR}/include -) + find_path(BinPAC_INCLUDE_DIR + NAMES binpac.h + HINTS ${BinPAC_ROOT_DIR}/include + ) +endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(BinPAC DEFAULT_MSG