diff --git a/BuildOptions.cmake b/BuildOptions.cmake
deleted file mode 100644
index a14120fe88..0000000000
--- a/BuildOptions.cmake
+++ /dev/null
@@ -1,73 +0,0 @@
-#--------------------------------------------------------------------#
-# #
-# Bro - Build Setup #
-# #
-#--------------------------------------------------------------------#
-
-##
-## Installation Settings
-##
-
-# The installation directory
-# TODO: add to configure wrapper as '--prefix'
-set(CMAKE_INSTALL_PREFIX /usr/local/bro
- CACHE STRING "Installation directory" FORCE)
-
-# The installation directory for Bro policy files
-# TODO: add to configure wrapper as '--datadir'
-set(DATADIR /usr/local/bro/share/bro
- CACHE STRING "Installation directory for Bro policy files" FORCE)
-
-##
-## Optional Features
-##
-
-# TODO: add to configure wrapper as '--enable-debug'
-set(ENABLE_DEBUG false
- CACHE STRING "Compile with debugging symbols" FORCE)
-
-# TODO: add to configure wrapper as '--enable-release'
-set(ENABLE_RELEASE false
- CACHE STRING "Use -O3 compiler optimizations" FORCE)
-
-# TODO: add to configure wrapper as '--bro-v6'
-# Eventually, this should be always on and won't be needed as an option
-set(BROv6 false
- CACHE STRING "enable IPv6 processing" FORCE)
-
-# TODO: add to configure wrapper as '--enable-perftools'
-set(ENABLE_PERFTOOLS false
- CACHE STRING "use Google's perftools" FORCE)
-
-##
-## Configure Dependencies for Non-Standard Paths
-##
-
-# Uncomment to specify a custom prefix containing the OpenSSL installation.
-#set(OPENSSL_ROOT_DIR path/to/your/openssl)
-
-# Uncomment to specify a custom prefix containing the BIND installation.
-#set(BIND_ROOT_DIR path/to/your/bind)
-
-# 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_BUILD true)
-
-# Comment this if local build of BinPAC should be scheduled for installation
-set(BinPAC_SKIP_INSTALL true)
-
-# Uncomment to specify a custom prefix containing the libmagic installation.
-#set(LibMagic_ROOT_DIR path/to/your/libmagic)
-
-# Uncomment to specify a custom prefix containing the libGeoIP installation.
-#set(LibGeoIP_ROOT_DIR path/to/your/libGeoIP)
-
-# Uncomment to specify a custom prefix containing Google Perftools installation.
-#set(GooglePerftools_ROOT_DIR path/to/your/google-perftools)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a6cb59387e..c791105b33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,27 +7,24 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# Prohibit in-source builds.
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" source_build)
if (source_build)
- message(FATAL_ERROR "In-source builds are not allowed\n."
- "Please create a separate build directory and invoke cmake from there.")
+ message(FATAL_ERROR "In-source builds are not allowed. Please use "
+ "./configure to choose a build directory and "
+ "initialize the build configuration.")
endif ()
-# If the build configuration file does not exist, copy it over.
-set(build_config BuildOptions.cmake)
-find_file(build_config_file
+find_file(build_options_file
NAMES BuildOptions.cmake
PATHS ${CMAKE_BINARY_DIR}
- DOC "Build configuration"
+ DOC "Build Options"
NO_DEFAULT_PATH
)
-if (NOT build_config_file)
- message("No build configuration found, using default.")
- configure_file(${CMAKE_SOURCE_DIR}/${build_config}
- ${CMAKE_BINARY_DIR}/${build_config}
- )
+if (NOT build_options_file)
+ message(FATAL_ERROR "Build options file not found, please use "
+ "${CMAKE_SOURCE_DIR}/configure to generate one.")
endif ()
mark_as_advanced(build_config_file)
-include(${CMAKE_BINARY_DIR}/${build_config})
+include(${build_options_file})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
@@ -37,18 +34,24 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
project(Bro)
-set(CMAKE_C_FLAGS "-W -Wall -Wno-unused")
-set(CMAKE_CXX_FLAGS "-W -Wall -Wno-unused")
+if (ENABLE_DEBUG AND ENABLE_RELEASE)
+ set(CMAKE_BUILD_TYPE RelWithDebInfo)
+elseif (ENABLE_DEBUG AND NOT ENABLE_RELEASE)
+ set(CMAKE_BUILD_TYPE Debug)
+elseif (NOT ENABLE_DEBUG AND ENABLE_RELEASE)
+ set(CMAKE_BUILD_TYPE Release)
+endif ()
+
+set(EXTRA_COMPILE_FLAGS "-Wall -Wno-unused")
if (ENABLE_DEBUG)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEBUG -g")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -g")
+ set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DDEBUG")
endif ()
-if (ENABLE_RELEASE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
-endif ()
+# Compiler flags may already exist in CMake cache (e.g. when specifying
+# CFLAGS environment variable before running cmake for the the first time)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS}")
##
## Dependency Configuration
@@ -146,6 +149,10 @@ add_subdirectory(policy)
## Build Summary
##
+if (CMAKE_BUILD_TYPE)
+ string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType)
+endif ()
+
message(
"\n====================| Bro Build Summary |====================="
"\n"
@@ -154,8 +161,11 @@ message(
"\nDebug mode: ${ENABLE_DEBUG}"
"\nRelease mode: ${ENABLE_RELEASE}"
"\n"
- "\nCFLAGS: ${CMAKE_C_FLAGS}"
- "\nCXXFLAGS: ${CMAKE_CXX_FLAGS}"
+ "\nCC: ${CMAKE_C_COMPILER}"
+ "\nCFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BuildType}}"
+ "\nCXX: ${CMAKE_CXX_COMPILER}"
+ "\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BuildType}}"
+ "\nCPP: ${CMAKE_CXX_COMPILER}"
"\n"
"\nBroccoli: ${use_broccoli}"
"\nBroctl: ${use_broctl}"
diff --git a/INSTALL b/INSTALL
index 87d7c6e68a..c4f17753c6 100644
--- a/INSTALL
+++ b/INSTALL
@@ -52,22 +52,22 @@ installation time:
Installation
============
-To build and install into /usr/local:
+To build and install into /usr/local/bro:
> ./configure
+ > cd build
> make
> make install
-This will install the Bro binary into /usr/local/bin/bro and the policy
-files into /usr/local/share/bro.
+This will perform an out-of-source build into the build directory using the
+default build options and then install binaries into /usr/local/bro/bin
-As usual you can specify a different installation directory with
+You can specify a different installation directory with
- > ./configure --prefix=
".
+ > ./configure --prefix=.
Run "./configure --help" for more options.
-
Running Bro
===========
diff --git a/configure b/configure
new file mode 100755
index 0000000000..45f38ad667
--- /dev/null
+++ b/configure
@@ -0,0 +1,238 @@
+#!/bin/sh
+# Convenience wrapper for easily viewing/setting options that
+# the project's CMake scripts will recognize
+
+# check for `cmake` command
+type -P cmake &>/dev/null || {
+ echo "\
+This package requires CMake, please install it first, then you may
+use this configure script to access CMake equivalent functionality.\
+" >&2;
+ exit 1;
+}
+
+usage="\
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+ Build Directory:
+ --builddir=DIR place build files in directory [build]
+
+ Installation Directories:
+ --prefix=PREFIX installation directory [/usr/local/bro]
+ --datadir=PATH policy file installation directory
+ [PREFIX/share/bro]
+
+ Optional Features:
+ --enable-debug compile with debugging symbols
+ --enable-release compile with optimizations
+ --enable-brov6 enable IPv6 processing
+ --enable-perftools use Google's perftools
+ --build-binpac build BinPAC from source located in
+ 'binpac' subdirectory
+ --install-binpac if --build-binpac, this option adds
+ BinPAC build files to the install target
+
+ Required Packages in Non-Standard Locations:
+ --with-openssl=PATH path to OpenSSL install root
+ --with-bind=PATH path to BIND install root
+ --with-pcap=PATH path to libpcap install root
+ --with-binpac=PATH path to BinPAC install root
+
+ Optional Packages in Non-Standard Locations:
+ --with-libmagic=PATH path to libmagic install root
+ --with-geoip=PATH path to the libGeoIP install root
+ --with-perftools=PATH path to Google Perftools install root
+
+ Influential Environment Variables (only on first invocation
+ per build directory):
+ CC C compiler command
+ CFLAGS C compiler flags
+ CXX C++ compiler command
+ CXXFLAGS C++ compiler flags
+"
+
+sourcedir=`dirname $0`
+if [ "$sourcedir" == "." ]; then
+ sourcedir=`pwd`
+fi
+
+# set defaults
+builddir=build
+prefix=/usr/local/bro
+datadir=$prefix/share/bro
+debug=false
+release=false
+use_IPv6=false
+enable_perftools=false
+build_binpac=false
+skip_binpac_install=true
+
+# parse arguments
+while [ $# -ne 0 ]; do
+ case "$1" in
+ -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) optarg= ;;
+ esac
+
+ case "$1" in
+ --help|-h)
+ echo "${usage}" 1>&2
+ exit 1
+ ;;
+ --builddir=*)
+ builddir=$optarg
+ ;;
+ --prefix=*)
+ if [ "$datadir" == "${prefix}/share/bro" ]; then
+ # User has not explicitly set datadir, so re-root
+ # it to the chosen prefix
+ datadir=$optarg/share/bro
+ fi
+ prefix=$optarg
+ ;;
+ --datadir=*)
+ datadir=$optarg
+ ;;
+ --enable-debug)
+ debug=true
+ ;;
+ --enable-release)
+ release=true
+ ;;
+ --enable-brov6)
+ use_IPv6=true
+ ;;
+ --enable-perftools)
+ enable_perftools=true
+ ;;
+ --build-binpac)
+ if [ -f $sourcedir/binpac/CMakeLists.txt ]; then
+ build_binpac=true
+ else
+ echo "Error: BinPAC source not found in $sourcedir/binpac" >&2
+ exit 1
+ fi
+ ;;
+ --install-binpac)
+ skip_binpac_install=false
+ ;;
+ --with-openssl=*)
+ openssl_root=$optarg
+ ;;
+ --with-bind=*)
+ bind_root=$optarg
+ ;;
+ --with-pcap=*)
+ pcap_root=$optarg
+ ;;
+ --with-binpac=*)
+ binpac_root=$optarg
+ ;;
+ --with-libmagic=*)
+ libmagic_root=$optarg
+ ;;
+ --with-geoip=*)
+ geoip_root=$optarg
+ ;;
+ --with-perftools=*)
+ perftools_root=$optarg
+ ;;
+ *)
+ echo "Invalid option '$1'. Try $0 --help to see available options."
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Create build directory
+mkdir -p $builddir
+
+# Create a build options file in the build directory w/ selected options
+BuildOptionsFile=$builddir/BuildOptions.cmake
+
+cat > $BuildOptionsFile << EOF
+#######################################################################
+#
+# Bro - Build Setup
+#
+#######################################################################
+
+#######################################################################
+# Installation Directories
+#######################################################################
+
+set(CMAKE_INSTALL_PREFIX $prefix
+ CACHE STRING "installation directory" FORCE)
+
+set(DATADIR $datadir
+ CACHE STRING "installation directory for Bro policy files" FORCE)
+
+#######################################################################
+# Optional Features
+#######################################################################
+
+set(ENABLE_DEBUG $debug
+ CACHE STRING "compile with debugging symbols" FORCE)
+
+set(ENABLE_RELEASE $release
+ CACHE STRING "use compiler optimizations" FORCE)
+
+set(BROv6 $use_IPv6
+ CACHE STRING "enable IPv6 processing" FORCE)
+
+set(ENABLE_PERFTOOLS $enable_perftools
+ CACHE STRING "use Google's perftools" FORCE)
+
+# If the following option is set to true, then instead of searching for
+# an installation of BinPac, it will be downloaded into the 'binpac'
+# subdirectory if necessary and then built
+set(BinPAC_PREFER_BUILD $build_binpac
+ CACHE STRING "retrieve and build BinPAC dependency from source" FORCE)
+
+set(BinPAC_SKIP_INSTALL $skip_binpac_install
+ CACHE STRING "don't install BinPAC if built from source" FORCE)
+
+#######################################################################
+# Packages in Non-Standard Locations
+# Uncomment/edit options below in order to aid the CMake
+# configuration scripts in finding dependencies that are installed
+# in atypical locations.
+#######################################################################
+
+EOF
+
+# Function to set a CMake cache variable that act as a hint for
+# finding packages in non-standard locations.
+# $1 argument is the name of the CMake hint variable
+# $2 argument is path to use as the hint variable's value
+# if empty, then a dummy value is used and the option
+# is commented out of the build options file
+add_search_path_hint () {
+if [ -z "$2" ]; then
+ comment="#"
+ path=/insert/your/path/here
+else
+ comment=""
+ path=$2
+fi
+cat >> $BuildOptionsFile << EOF
+${comment}set($1 $path
+${comment} CACHE STRING "Non-Standard install root" FORCE)
+
+EOF
+}
+
+add_search_path_hint OPENSSL_ROOT_DIR ${openssl_root}
+add_search_path_hint BIND_ROOT_DIR ${bind_root}
+add_search_path_hint PCAP_ROOT_DIR ${pcap_root}
+add_search_path_hint BinPAC_ROOT_DIR ${binpac_root}
+add_search_path_hint LibMagic_ROOT_DIR ${libmagic_root}
+add_search_path_hint LibGeoIP_ROOT_DIR ${geoip_root}
+add_search_path_hint GooglePerftools_ROOT_DIR ${perftools_root}
+
+echo "Build Directory : $builddir"
+echo "Build Options : $BuildOptionsFile"
+echo "Source Directory: $sourcedir"
+cd $builddir
+cmake $sourcedir