diff --git a/BuildOptions.cmake b/BuildOptions.cmake index 8ae6129c58..2edc7f64c2 100644 --- a/BuildOptions.cmake +++ b/BuildOptions.cmake @@ -53,9 +53,18 @@ set(ENABLE_PERFTOOLS false # Uncomment to specify a custom prefix that contains the libpcap installation. #set(PCAP_ROOT_DIR path/to/your/pcap) +# Uncomment to specify a custom prefix containing the BinPAC installation. +#set(BinPAC_ROOT_DIR path/to/your/binpac) + +# 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) + +# Comment this if local build of BinPAC should be scheduled for installation +set(BinPAC_SKIP_INSTALL true) + # TODO: more dependencies: -# BinPAC -# # Libmagic # LibGeoIP # Libz diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f6b27cb64..5dd1a01ae1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,25 @@ include_directories(BEFORE ${OPENSSL_INCLUDE_DIR} ${BIND_INCLUDE_DIR}) +# 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 () + # TODO: optional libmagic # TODO: optional libGeoIP # TODO: optional libz @@ -106,7 +125,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) ## Recurse on sub-directories ## -add_subdirectory(binpac) add_subdirectory(src) #add_subdirectory(aux) #add_subdirectory(scripts) @@ -134,7 +152,7 @@ message( "\nlibz: ${use_libz}" "\nlibmagic: ${use_libmagic}" "\nEndace: ${use_endace}" - "\nGoogle perftools: ${summary_perftools}" + "\nGoogle perftools: ${use_perftools}" "\n" "\n================================================================\n" ) diff --git a/cmake/FindBinPAC.cmake b/cmake/FindBinPAC.cmake new file mode 100644 index 0000000000..b64211aade --- /dev/null +++ b/cmake/FindBinPAC.cmake @@ -0,0 +1,52 @@ +# - Try to find BinPAC binary and library +# +# Usage of this module as follows: +# +# find_package(BinPAC) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# BinPAC_ROOT_DIR Set this variable to the root installation of +# BinPAC if the module has problems finding the +# proper installation path. +# +# Variables defined by this module: +# +# BINPAC_FOUND System has BinPAC binary and library +# BinPAC_EXE The binpac executable +# BinPAC_LIBRARY The libbinpac.a library +# BinPAC_INCLUDE_DIR The binpac headers + +find_path(BinPAC_ROOT_DIR + NAMES include/binpac.h +) + +find_file(BinPAC_EXE + NAMES binpac + HINTS ${BinPAC_ROOT_DIR}/bin +) + +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 +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BinPAC DEFAULT_MSG + BinPAC_EXE + BinPAC_LIBRARY + BinPAC_INCLUDE_DIR +) + +mark_as_advanced( + BinPAC_ROOT_DIR + BinPAC_EXE + BinPAC_LIBRARY + BinPAC_INCLUDE_DIR +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 01846daa93..c1d4892932 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/binpac/lib - ${CMAKE_BINARY_DIR}/binpac/lib + ${BinPAC_INCLUDE_DIR} ) macro(REPLACE_YY_PREFIX_TARGET inFile outFile yylexPrefix yyPrefix) @@ -62,9 +61,9 @@ replace_yy_prefix_target(${CMAKE_CURRENT_BINARY_DIR}/p.cc flex_target(Scanner scan.l ${CMAKE_CURRENT_BINARY_DIR}/scan.cc COMPILE_FLAGS "-Pbro") -configure_file (version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c) +configure_file(version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c) -########### next target ############### +########### bifcl target############### set(bifcl_SRCS ${BISON_BIFParser_OUTPUTS} @@ -116,9 +115,9 @@ set(BIF_SRCS smb-rw.bif ) -foreach(bift ${BIF_SRCS}) +foreach (bift ${BIF_SRCS}) bif_target(${bift}) -endforeach(bift) +endforeach () ########## targets that need binpac ########## @@ -127,11 +126,11 @@ macro(BINPAC_TARGET pacFile) get_filename_component(basename ${pacFile} NAME_WE) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.h ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.cc - COMMAND binpac + COMMAND ${BinPAC_EXE} ARGS -d ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${pacFile} - DEPENDS binpac ${pacFile} + DEPENDS ${BinPAC_EXE} ${pacFile} COMMENT "[BINPAC] Processing ${pacFile}" ) list(APPEND ALL_BINPAC_OUTPUTS @@ -178,11 +177,11 @@ set(BINPAC_RPC_AUXSRC ssl-protocol.pac ssl-record-layer.pac ) -foreach(binpact ${BINPAC_SRCS}) +foreach (binpact ${BINPAC_SRCS}) binpac_target(${CMAKE_CURRENT_SOURCE_DIR}/${binpact}) -endforeach(binpact) +endforeach () -########### next target ############### +########### bro target ############### set(dns_SRCS nb_dns.c nb_dns.h) @@ -366,7 +365,7 @@ add_executable(bro ${bro_SRCS}) target_link_libraries(bro m - binpac_lib + ${BinPAC_LIBRARY} ${PCAP_LIBRARY} ${OPENSSL_LIBRARIES} ${BIND_LIBRARY}