diff --git a/CMakeLists.txt b/CMakeLists.txt index a86e0b7d70..b90eea6727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,81 +159,17 @@ add_subdirectory(policy) #add_subdirectory(scripts) #add_subdirectory(doc) -if (INSTALL_BROCCOLI) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/aux/broccoli/CMakeLists.txt) - add_subdirectory(aux/broccoli) - else () - message(FATAL_ERROR "Broccoli selected for installation, " - "but the source code does not exist in " - "${CMAKE_CURRENT_SOURCE_DIR}/aux/broccoli") - endif () -endif () +include(CheckOptionalBuildSources) -if (INSTALL_BROCTL) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/aux/broctl/CMakeLists.txt) - add_subdirectory(aux/broctl) - else () - message(FATAL_ERROR "Broctl selected for installation, " - "but the source code does not exist in " - "${CMAKE_CURRENT_SOURCE_DIR}/aux/broctl") - endif () -endif () - -if (INSTALL_AUX_TOOLS) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/aux/bro-aux/CMakeLists.txt) - add_subdirectory(aux/bro-aux) - else () - message(FATAL_ERROR "Bro auxilliary tools selected for installation, " - "but the source code does not exist in " - "${CMAKE_CURRENT_SOURCE_DIR}/aux/bro-aux") - endif () -endif () +CheckOptionalBuildSources(aux/broctl Broctl INSTALL_BROCTL) +CheckOptionalBuildSources(aux/bro-aux Bro-Aux INSTALL_AUX_TOOLS) +CheckOptionalBuildSources(aux/broccoli Broccoli INSTALL_BROCCOLI) ######################################################################## ## Packaging Setup -include(SetPackageVersion) -SetPackageVersion(${VERSION}) -include(SetPackageGenerators) -include(SetPackageFileName) - -set(CPACK_PACKAGE_VENDOR "Lawrence Berkeley National Laboratory") -set(CPACK_PACKAGE_CONTACT "info@bro-ids.org") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY - "The Bro Network Intrusion Detection System") - -# CPack may enforce file name extensions for certain package generators -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README - ${CMAKE_CURRENT_BINARY_DIR}/README.txt - COPYONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING - ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt - COPYONLY) - -set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_BINARY_DIR}/README.txt) -set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt) -set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.txt) -set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/README.txt) - -if (APPLE) - # /usr prefix is hardcoded for PackageMaker generator, but that - # directory may not be ideal for OS X (it's tricky to remove - # packages installed there). So instead we rely on CMAKE_INSTALL_PREFIX - # and set the following variable to workaround the hardcoded /usr prefix - set(CPACK_PACKAGING_INSTALL_PREFIX "/") - set(CPACK_PACKAGE_DEFAULT_LOCATION ${CMAKE_INSTALL_PREFIX}) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - # A prefix of /usr would follow Filesystem Hierarchy Standard. - # For RPM packaging by CPack, /usr should be a default, but - # CMAKE_INSTALL_PREFIX also needs to be set to /usr so that - # the default BROPATH is set right at build time - set(CPACK_RPM_PACKAGE_LICENSE "BSD") -endif () - -# Ignore the build directory -set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_BINARY_DIR} ".git") - -include(CPack) +include(ConfigurePackaging) +ConfigurePackaging(${VERSION}) ######################################################################## ## Build Summary diff --git a/cmake/CheckOptionalBuildSources.cmake b/cmake/CheckOptionalBuildSources.cmake new file mode 100644 index 0000000000..f901d432f6 --- /dev/null +++ b/cmake/CheckOptionalBuildSources.cmake @@ -0,0 +1,21 @@ +# A macro that checks whether optional sources exist and if they do, they +# are added to the build/install process, else a warning is issued +# +# _dir: the subdir of the current source dir in which the optional +# sources are located +# _packageName: a string that identifies the package +# _varName: name of the variable indicating whether package is scheduled +# to be installed + +macro(CheckOptionalBuildSources _dir _packageName _varName) + if (${_varName}) + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeLists.txt) + add_subdirectory(${_dir}) + else () + message(WARNING "${_packageName} source code does not exist in " + "${CMAKE_CURRENT_SOURCE_DIR}/${_dir} " + "so it will not be built or installed") + set(${_varName} false) + endif () + endif () +endmacro(CheckOptionalBuildSources) diff --git a/cmake/ConfigurePackaging.cmake b/cmake/ConfigurePackaging.cmake new file mode 100644 index 0000000000..eaad56dee6 --- /dev/null +++ b/cmake/ConfigurePackaging.cmake @@ -0,0 +1,146 @@ +# A collection of macros to assist in configuring CMake/Cpack +# source and binary packaging + +# Sets CPack version variables by splitting the first macro argument +# using "." as a delimiter. If the length of the split list is +# greater than 2, all remaining elements are tacked on to the patch +# level version. +macro(SetPackageVersion _version) + string(REPLACE "." " " version_numbers ${_version}) + separate_arguments(version_numbers) + + list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MAJOR) + list(REMOVE_AT version_numbers 0) + list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MINOR) + list(REMOVE_AT version_numbers 0) + list(LENGTH version_numbers version_length) + + while (version_length GREATER 0) + list(GET version_numbers 0 patch_level) + if (CPACK_PACKAGE_VERSION_PATCH) + set(CPACK_PACKAGE_VERSION_PATCH + "${CPACK_PACKAGE_VERSION_PATCH}.${patch_level}") + else () + set(CPACK_PACKAGE_VERSION_PATCH ${patch_level}) + endif () + list(REMOVE_AT version_numbers 0) + list(LENGTH version_numbers version_length) + endwhile () +endmacro(SetPackageVersion) + +# Sets the list of desired package types to be created by the make +# package target. A .tar.gz is only made for source packages, and +# binary pacakage format depends on the operating system: +# +# Darwin - PackageMaker +# Linux - RPM if the platform has rpmbuild installed +# DEB is ommitted because CPack does not give enough +# control over how the package is created and lacks support +# for automatic dependency detection. +# +# +# CPACK_GENERATOR is set by this macro +# CPACK_SOURCE_GENERATOR is set by this macro +macro(SetPackageGenerators) + set(CPACK_SOURCE_GENERATOR TGZ) + if (APPLE) + list(APPEND CPACK_GENERATOR PackageMaker) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + find_program(RPMBUILD_EXE rpmbuild) + if (RPMBUILD_EXE) + set(CPACK_GENERATOR ${CPACK_GENERATOR} RPM) + endif () + endif () +endmacro(SetPackageGenerators) + +# Sets CPACK_PACKAGE_FILE_NAME in the following format: +# +# --- +# +# and CPACK_SOURCE_PACKAGE_FILE_NAME as: +# +# - +macro(SetPackageFileName _version) + if (PACKAGE_NAME_PREFIX) + set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") + else () + set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") + endif () + + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_NAME}") + + if (APPLE) + # Only Intel-based Macs are supported. CMAKE_SYSTEM_PROCESSOR may + # return the confusing 'i386' if running a 32-bit kernel, but chances + # are the binary is x86_64 (or more generally 'Intel') compatible. + set(arch "Intel") + else () + set (arch ${CMAKE_SYSTEM_PROCESSOR}) + endif () + + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${arch}") +endmacro(SetPackageFileName) + +# Sets up binary package metadata +macro(SetPackageMetadata) + set(CPACK_PACKAGE_VENDOR "Lawrence Berkeley National Laboratory") + set(CPACK_PACKAGE_CONTACT "info@bro-ids.org") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY + "The Bro Network Intrusion Detection System") + + # CPack may enforce file name extensions for certain package generators + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README + ${CMAKE_CURRENT_BINARY_DIR}/README.txt + COPYONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING + ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt + COPYONLY) + + set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_BINARY_DIR}/README.txt) + set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt) + set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.txt) + set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/README.txt) +endmacro(SetPackageMetadata) + +# Determines the right install location/prefix for binary packages +macro(SetPackageInstallLocation) + if (APPLE) + # /usr prefix is hardcoded for PackageMaker generator, but that + # directory may not be ideal for OS X (it's tricky to remove + # packages installed there). So instead we rely on CMAKE_INSTALL_PREFIX + # and set the following variable to workaround the hardcoded /usr prefix + set(CPACK_PACKAGING_INSTALL_PREFIX "/") + set(CPACK_PACKAGE_DEFAULT_LOCATION ${CMAKE_INSTALL_PREFIX}) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # A prefix of /usr would follow Filesystem Hierarchy Standard. + # For RPM packaging by CPack, /usr should be a default, but + # CMAKE_INSTALL_PREFIX also needs to be set to /usr so that + # the default BROPATH is set right at build time + set(CPACK_RPM_PACKAGE_LICENSE "BSD") + endif () +endmacro(SetPackageInstallLocation) + +# Main macro to configure all the packaging options +macro(ConfigurePackaging _version) + # If this CMake project is a sub-project of another, we will not + # configure the packaging because CPack will fail in the case that + # the parent project has already configured packaging + if (NOT "${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + return() + endif () + + SetPackageVersion(${_version}) + SetPackageGenerators() + SetPackageFileName(${_version}) + SetPackageMetadata() + SetPackageInstallLocation() + + # add default files/directories to ignore for source package + # user may specify others via configure script + list(APPEND CPACK_SOURCE_IGNORE_FILES ${CMAKE_BINARY_DIR} ".git") + + include(CPack) +endmacro(ConfigurePackaging) diff --git a/cmake/SetPackageFileName.cmake b/cmake/SetPackageFileName.cmake deleted file mode 100644 index 759f72ab82..0000000000 --- a/cmake/SetPackageFileName.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Sets CPACK_PACKAGE_FILE name in the following format: -# -# --- -# -# The version must already be set in the VERSION variable - -set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}") -set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_NAME}") -if (APPLE) - # Only Intel-based Macs are supported. CMAKE_SYSTEM_PROCESSOR may - # return the confusing 'i386' if running a 32-bit kernel, but chances - # are the binary is x86_64 (or more generally 'Intel') compatible. - set(arch "Intel") -else () - set (arch ${CMAKE_SYSTEM_PROCESSOR}) -endif () - -set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${arch}") diff --git a/cmake/SetPackageGenerators.cmake b/cmake/SetPackageGenerators.cmake deleted file mode 100644 index edd80ee3d6..0000000000 --- a/cmake/SetPackageGenerators.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Sets the list of desired package types to be created by the make -# package target. A .tar.gz is always made, and depending on the -# operating system, more are added: -# -# Darwin - PackageMaker -# Linux - RPM if the platform has rpmbuild installed -# DEB is ommitted because CPack does not give enough -# control over how the package is created and lacks support -# for automatic dependency detection. -# -# -# CPACK_GENERATOR is set by this module - -set(CPACK_GENERATOR TGZ) -set(CPACK_SOURCE_GENERATOR TGZ) -if (APPLE) - list(APPEND CPACK_GENERATOR PackageMaker) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - find_program(RPMBUILD_EXE rpmbuild) - if (RPMBUILD_EXE) - set(CPACK_GENERATOR ${CPACK_GENERATOR} RPM) - endif () -endif () diff --git a/cmake/SetPackageVersion.cmake b/cmake/SetPackageVersion.cmake deleted file mode 100644 index 19c9d404e3..0000000000 --- a/cmake/SetPackageVersion.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Sets CPack version variables by splitting the first macro argument -# using "." as a delimiter. If the length of the split list is -# greater than 2, all remaining elements are tacked on to the patch -# level version. - -macro(SetPackageVersion _version) - string(REPLACE "." " " version_numbers ${_version}) - separate_arguments(version_numbers) - - list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MAJOR) - list(REMOVE_AT version_numbers 0) - list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MINOR) - list(REMOVE_AT version_numbers 0) - list(LENGTH version_numbers version_length) - - while (version_length GREATER 0) - list(GET version_numbers 0 patch_level) - if (CPACK_PACKAGE_VERSION_PATCH) - set(CPACK_PACKAGE_VERSION_PATCH - "${CPACK_PACKAGE_VERSION_PATCH}.${patch_level}") - else () - set(CPACK_PACKAGE_VERSION_PATCH ${patch_level}) - endif () - list(REMOVE_AT version_numbers 0) - list(LENGTH version_numbers version_length) - endwhile () -endmacro(SetPackageVersion) diff --git a/configure b/configure index ec66a68e98..bdfb554506 100755 --- a/configure +++ b/configure @@ -44,6 +44,12 @@ Usage: $0 [OPTION]... [VAR=VALUE]... --with-geoip=PATH path to the libGeoIP install root --with-perftools=PATH path to Google Perftools install root + Packaging Options (for developers): + --ignore-dirs=PATHS paths to ignore when creating source package + (semicolon delimited and quoted when multiple) + --pkg-name-prefix=NAME use the given name as the package prefix instead + of the default CMake project name + Influential Environment Variables (only on first invocation per build directory): CC C compiler command @@ -79,6 +85,7 @@ append_cache_entry INSTALL_AUX_TOOLS BOOL true append_cache_entry INSTALL_BROCCOLI BOOL true append_cache_entry INSTALL_BROCTL BOOL true append_cache_entry STANDALONE BOOL true +append_cache_entry CPACK_SOURCE_IGNORE_FILES STRING # parse arguments while [ $# -ne 0 ]; do @@ -155,6 +162,12 @@ while [ $# -ne 0 ]; do --with-perftools=*) append_cache_entry GooglePerftools_ROOT_DIR PATH $optarg ;; + --ignore-dirs=*) + append_cache_entry CPACK_SOURCE_IGNORE_FILES STRING $optarg + ;; + --pkg-name-prefix=*) + append_cache_entry PACKAGE_NAME_PREFIX STRING $optarg + ;; *) echo "Invalid option '$1'. Try $0 --help to see available options." exit 1