mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Changes to allow source packaging via CPack
- Refactored all packaging related stuff into a single CMake module - Build should no longer fail when optional sources (e.g. broctl) do not exist in the source directory, instead a warning is issued - Additional configure options to change packaging behavior
This commit is contained in:
parent
edfdd9d436
commit
fa07bcd233
7 changed files with 186 additions and 138 deletions
|
@ -159,81 +159,17 @@ add_subdirectory(policy)
|
||||||
#add_subdirectory(scripts)
|
#add_subdirectory(scripts)
|
||||||
#add_subdirectory(doc)
|
#add_subdirectory(doc)
|
||||||
|
|
||||||
if (INSTALL_BROCCOLI)
|
include(CheckOptionalBuildSources)
|
||||||
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 ()
|
|
||||||
|
|
||||||
if (INSTALL_BROCTL)
|
CheckOptionalBuildSources(aux/broctl Broctl INSTALL_BROCTL)
|
||||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/aux/broctl/CMakeLists.txt)
|
CheckOptionalBuildSources(aux/bro-aux Bro-Aux INSTALL_AUX_TOOLS)
|
||||||
add_subdirectory(aux/broctl)
|
CheckOptionalBuildSources(aux/broccoli Broccoli INSTALL_BROCCOLI)
|
||||||
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 ()
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
## Packaging Setup
|
## Packaging Setup
|
||||||
|
|
||||||
include(SetPackageVersion)
|
include(ConfigurePackaging)
|
||||||
SetPackageVersion(${VERSION})
|
ConfigurePackaging(${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)
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
## Build Summary
|
## Build Summary
|
||||||
|
|
21
cmake/CheckOptionalBuildSources.cmake
Normal file
21
cmake/CheckOptionalBuildSources.cmake
Normal file
|
@ -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)
|
146
cmake/ConfigurePackaging.cmake
Normal file
146
cmake/ConfigurePackaging.cmake
Normal file
|
@ -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:
|
||||||
|
#
|
||||||
|
# <project_name>-<version>-<OS/platform>-<arch>
|
||||||
|
#
|
||||||
|
# and CPACK_SOURCE_PACKAGE_FILE_NAME as:
|
||||||
|
#
|
||||||
|
# <project_name>-<version>
|
||||||
|
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)
|
|
@ -1,18 +0,0 @@
|
||||||
# Sets CPACK_PACKAGE_FILE name in the following format:
|
|
||||||
#
|
|
||||||
# <project_name>-<version>-<OS/platform>-<arch>
|
|
||||||
#
|
|
||||||
# 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}")
|
|
|
@ -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 ()
|
|
|
@ -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)
|
|
13
configure
vendored
13
configure
vendored
|
@ -44,6 +44,12 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
--with-geoip=PATH path to the libGeoIP install root
|
--with-geoip=PATH path to the libGeoIP install root
|
||||||
--with-perftools=PATH path to Google Perftools 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
|
Influential Environment Variables (only on first invocation
|
||||||
per build directory):
|
per build directory):
|
||||||
CC C compiler command
|
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_BROCCOLI BOOL true
|
||||||
append_cache_entry INSTALL_BROCTL BOOL true
|
append_cache_entry INSTALL_BROCTL BOOL true
|
||||||
append_cache_entry STANDALONE BOOL true
|
append_cache_entry STANDALONE BOOL true
|
||||||
|
append_cache_entry CPACK_SOURCE_IGNORE_FILES STRING
|
||||||
|
|
||||||
# parse arguments
|
# parse arguments
|
||||||
while [ $# -ne 0 ]; do
|
while [ $# -ne 0 ]; do
|
||||||
|
@ -155,6 +162,12 @@ while [ $# -ne 0 ]; do
|
||||||
--with-perftools=*)
|
--with-perftools=*)
|
||||||
append_cache_entry GooglePerftools_ROOT_DIR PATH $optarg
|
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."
|
echo "Invalid option '$1'. Try $0 --help to see available options."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue