├── BroPlugin.cmake ├── README ├── .github └── workflows │ └── pre-commit.yml ├── ProhibitInSourceBuild.cmake ├── CommonCMakeConfig.cmake ├── GetArchitecture.cmake ├── SetupRPATH.cmake ├── CheckFunctions.cmake ├── FindCapstats.cmake ├── AddUninstallTarget.cmake ├── ZeekSubdir.cmake ├── FindTraceSummary.cmake ├── zeek-plugin-install-package.sh ├── .pre-commit-config.yaml ├── MAC_PACKAGE_INTRO ├── UserChangedWarning.cmake ├── zeek-plugin-create-package.sh ├── CheckNameserCompat.cmake ├── FindSubnetTree.cmake ├── CheckCompilers.cmake ├── CheckOptionalBuildSources.cmake ├── FindFTS.cmake ├── package_preinstall.sh.in ├── MiscTests.cmake ├── FindJeMalloc.cmake ├── RequireCXXStd.cmake ├── cmake_uninstall.cmake.in ├── CheckTypes.cmake ├── CheckCompilerArch.cmake ├── FindBinPAC.cmake ├── SetDefaultCompileFlags.cmake ├── InstallClobberImmune.cmake ├── FindLibMMDB.cmake ├── PCAPTests.cmake ├── MacDependencyPaths.cmake ├── .cmake-format.json ├── CheckHeaders.cmake ├── FindPrometheusCpp.cmake ├── COPYING ├── FindGooglePerftools.cmake ├── OSSpecific.cmake ├── FindRequiredPackage.cmake ├── Gen-ZAM.cmake ├── package_postupgrade.sh.in ├── ConfigureSpicyBuild.cmake ├── InstallShellScript.cmake ├── FindLibKrb5.cmake ├── InstallSymlink.cmake ├── FindCAres.cmake ├── OpenSSLTests.cmake ├── InstallPackageConfigFile.cmake ├── ChangeMacInstallNames.cmake ├── BinPAC.cmake ├── FindPCAP.cmake ├── ZeekPluginCommon.cmake ├── FindZeek.cmake ├── ZeekBundle.cmake ├── FindKqueue.cmake ├── FindPythonDev.cmake ├── BuiltInSpicyAnalyzer.cmake ├── BifCl.cmake ├── ZeekPluginStatic.cmake ├── ZeekSpicyAnalyzerSupport.cmake ├── FindSpicy.cmake ├── ZeekPlugin.cmake ├── ZeekPluginDynamic.cmake └── ConfigurePackaging.cmake /BroPlugin.cmake: -------------------------------------------------------------------------------- 1 | include(ZeekPlugin) 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a collection of CMake scripts intended to be included as a 2 | git submodule in other repositories related to Zeek (www.zeek.org). 3 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [master] 7 | 8 | jobs: 9 | pre-commit: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3.1.0 13 | - uses: actions/setup-python@v4 14 | - uses: pre-commit/action@v3.0.0 15 | -------------------------------------------------------------------------------- /ProhibitInSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # Prohibit in-source builds. 2 | if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") 3 | message( 4 | FATAL_ERROR 5 | "In-source builds are not allowed. Please use " 6 | "./configure to choose a build directory and " "initialize the build configuration.") 7 | endif () 8 | -------------------------------------------------------------------------------- /CommonCMakeConfig.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) 2 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 3 | 4 | include(CheckCompilers) 5 | include(ProhibitInSourceBuild) 6 | include(AddUninstallTarget) 7 | include(SetupRPATH) 8 | include(SetDefaultCompileFlags) 9 | include(MacDependencyPaths) 10 | -------------------------------------------------------------------------------- /GetArchitecture.cmake: -------------------------------------------------------------------------------- 1 | # Determine a tag for the host architecture (e.g., "linux-x86_64"). 2 | # We run uname ourselves here as CMAKE by default uses -p rather than 3 | # -m. 4 | 5 | execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE) 6 | set(HOST_ARCHITECTURE "${CMAKE_SYSTEM_NAME}-${arch}") 7 | string(TOLOWER ${HOST_ARCHITECTURE} HOST_ARCHITECTURE) 8 | -------------------------------------------------------------------------------- /SetupRPATH.cmake: -------------------------------------------------------------------------------- 1 | # Keep RPATH upon installing so that user doesn't have to ensure the linker 2 | # can find internal/private libraries or libraries external to the build 3 | # directory that were explicitly linked against 4 | if (NOT BINARY_PACKAGING_MODE) 5 | include(GNUInstallDirs) 6 | 7 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 8 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") 9 | endif () 10 | -------------------------------------------------------------------------------- /CheckFunctions.cmake: -------------------------------------------------------------------------------- 1 | include(CheckFunctionExists) 2 | 3 | check_function_exists(getopt_long HAVE_GETOPT_LONG) 4 | check_function_exists(mallinfo HAVE_MALLINFO) 5 | check_function_exists(mallinfo2 HAVE_MALLINFO2) 6 | check_function_exists(strcasestr HAVE_STRCASESTR) 7 | check_function_exists(strerror HAVE_STRERROR) 8 | check_function_exists(strsep HAVE_STRSEP) 9 | check_function_exists(sigset HAVE_SIGSET) 10 | check_function_exists(sigaction HAVE_SIGACTION) 11 | -------------------------------------------------------------------------------- /FindCapstats.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find capstats program 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Capstats) 6 | # 7 | # Variables defined by this module: 8 | # 9 | # CAPSTATS_FOUND capstats binary found 10 | # Capstats_EXE path to the capstats executable binary 11 | 12 | find_program(CAPSTATS_EXE capstats) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args(Capstats DEFAULT_MSG CAPSTATS_EXE) 16 | -------------------------------------------------------------------------------- /AddUninstallTarget.cmake: -------------------------------------------------------------------------------- 1 | if (NOT TARGET uninstall) 2 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in") 3 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" 4 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY) 5 | add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P 6 | ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 7 | endif () 8 | endif () 9 | -------------------------------------------------------------------------------- /ZeekSubdir.cmake: -------------------------------------------------------------------------------- 1 | # Creates a target for a library of objects file in a subdirectory, 2 | # and adds to the global bro_SUBDIR_LIBS. 3 | function (bro_add_subdir_library name) 4 | add_library("bro_${name}" OBJECT ${ARGN}) 5 | set(bro_SUBDIR_LIBS "$" ${bro_SUBDIR_LIBS} CACHE INTERNAL 6 | "subdir libraries") 7 | set(bro_SUBDIR_DEPS "bro_${name}" ${bro_SUBDIR_DEPS} CACHE INTERNAL "subdir dependencies") 8 | endfunction () 9 | -------------------------------------------------------------------------------- /FindTraceSummary.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the trace-summary Python program 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(TraceSummary) 6 | # 7 | # Variables defined by this module: 8 | # 9 | # TRACESUMMARY_FOUND capstats binary found 10 | # TraceSummary_EXE path to the capstats executable binary 11 | 12 | find_program(TRACE_SUMMARY_EXE trace-summary) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args(TraceSummary DEFAULT_MSG TRACE_SUMMARY_EXE) 16 | -------------------------------------------------------------------------------- /zeek-plugin-install-package.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Helper script to install the tarball with a plugin's binary distribution. 4 | # 5 | # Called from ZeekPluginDynamic.cmake. Current directory is the plugin 6 | # build directory. 7 | 8 | if [ $# != 2 ]; then 9 | echo "usage: $(basename $0) " 10 | exit 1 11 | fi 12 | 13 | dst=$2 14 | 15 | if [ ! -d "${dst}" ]; then 16 | echo "Warning: ${dst} does not exist; has Zeek been installed?" 17 | mkdir -p ${dst} 18 | fi 19 | 20 | name=$1 21 | tgz=$(pwd)/$name.tgz 22 | 23 | (cd ${dst} && rm -rf "${name}" && tar xzf ${tgz}) 24 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | # 4 | repos: 5 | - repo: https://github.com/cheshirekow/cmake-format-precommit 6 | rev: v0.6.13 7 | hooks: 8 | - id: cmake-format 9 | exclude: '^(FindBISON|FindOpenSSL|FindPackageHandleStandardArgs|FindPackageMessage|SelectLibraryConfigurations|conan).cmake$' 10 | 11 | - repo: https://github.com/pre-commit/pre-commit-hooks 12 | rev: v5.0.0 13 | hooks: 14 | - id: trailing-whitespace 15 | exclude: '^(FindOpenSSL|conan).cmake$' 16 | 17 | - repo: https://github.com/maxwinterstein/shfmt-py 18 | rev: v3.11.0.2 19 | hooks: 20 | - id: shfmt 21 | args: ["-w", "-i", "4", "-ci"] 22 | -------------------------------------------------------------------------------- /MAC_PACKAGE_INTRO: -------------------------------------------------------------------------------- 1 | This package will install @CMAKE_PROJECT_NAME@ into the following location: 2 | 3 | @CMAKE_INSTALL_PREFIX@ 4 | 5 | You may choose to update your PATH environment variable: 6 | 7 | # For Bash 8 | export PATH=@CMAKE_INSTALL_PREFIX@/bin:$PATH 9 | 10 | # For CSH 11 | setenv PATH @CMAKE_INSTALL_PREFIX@/bin:$PATH 12 | 13 | If you have more than one volume, please choose the install 14 | destination as the one that contains the root filesystem. 15 | 16 | If you have existing configuration files that are modified or 17 | otherwise different from the version included in the package, 18 | this installer will attempt to prevent overwirting them, 19 | but its also advisable to make your own backups of important 20 | files before proceeding. 21 | -------------------------------------------------------------------------------- /UserChangedWarning.cmake: -------------------------------------------------------------------------------- 1 | # Show warning when installing user is different from the one that configured, 2 | # except when the install is root. 3 | if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") 4 | install( 5 | CODE " 6 | if (NOT \"$ENV{USER}\" STREQUAL \"\$ENV{USER}\" AND 7 | NOT \"\$ENV{USER}\" STREQUAL root) 8 | message(STATUS \"WARNING: Install is being performed by user \" 9 | \"'\$ENV{USER}', but the build directory was configured by \" 10 | \"user '$ENV{USER}'. This may result in a permissions error \" 11 | \"when writing the install manifest, but you can ignore it \" 12 | \"and consider the installation as successful if you don't \" 13 | \"care about the install manifest.\") 14 | endif () 15 | ") 16 | endif () 17 | -------------------------------------------------------------------------------- /zeek-plugin-create-package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Helper script creating a tarball with a plugin's binary distribution. We'll 4 | # also leave a MANIFEST in place with all files part of the tar ball. 5 | # 6 | # Called from ZeekPluginDynamic.cmake. Current directory is the plugin 7 | # build directory. 8 | 9 | if [ $# -ne 1 ]; then 10 | echo "usage: $(basename "$0") " 11 | exit 1 12 | fi 13 | 14 | name=$1 15 | shift 16 | 17 | DIST=dist/${name} 18 | mkdir -p "${DIST}" 19 | 20 | # Copy files to be distributed to temporary location. 21 | cp -RL __zeek_plugin__ lib scripts "${DIST}" 22 | 23 | tgz=${name}-$( (test -e ../VERSION && head -1 ../VERSION) || echo 0.0).tar.gz 24 | 25 | rm -f "${name}".tgz "${tgz}" 26 | 27 | tar czf "dist/${tgz}" -C dist "${name}" 28 | 29 | rm -rf "${DIST}" 30 | 31 | ln -s "dist/${tgz}" "${name}.tgz" 32 | -------------------------------------------------------------------------------- /CheckNameserCompat.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCSourceCompiles) 2 | 3 | # Check whether the namser compatibility header is required 4 | # This can be the case on the Darwin platform 5 | 6 | set(CMAKE_REQUIRED_INCLUDES ${BIND_INCLUDE_DIR}) 7 | 8 | check_c_source_compiles( 9 | " 10 | #include 11 | int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }" have_nameser_header) 12 | 13 | if (NOT have_nameser_header AND NOT MSVC) 14 | check_c_source_compiles( 15 | " 16 | #include 17 | #include 18 | int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }" 19 | NEED_NAMESER_COMPAT_H) 20 | if (NOT NEED_NAMESER_COMPAT_H) 21 | message(FATAL_ERROR "Asynchronous DNS support compatibility check failed.") 22 | endif () 23 | endif () 24 | 25 | set(CMAKE_REQUIRED_INCLUDES) 26 | -------------------------------------------------------------------------------- /FindSubnetTree.cmake: -------------------------------------------------------------------------------- 1 | # - Determine if the SubnetTree Python module is available 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Python REQUIRED COMPONENTS Interpreter) 6 | # find_package(SubnetTree) 7 | # 8 | # Variables defined by this module: 9 | # 10 | # SUBNETTREE_FOUND Python successfully imports SubnetTree module 11 | 12 | if (NOT SUBNETTREE_FOUND) 13 | execute_process(COMMAND "${Python_EXECUTABLE}" -c "import SubnetTree" 14 | RESULT_VARIABLE SUBNETTREE_IMPORT_RESULT) 15 | 16 | if (SUBNETTREE_IMPORT_RESULT) 17 | # python returned non-zero exit status 18 | set(SUBNETTREE_PYTHON_MODULE false) 19 | else () 20 | set(SUBNETTREE_PYTHON_MODULE true) 21 | endif () 22 | endif () 23 | 24 | include(FindPackageHandleStandardArgs) 25 | find_package_handle_standard_args(SubnetTree DEFAULT_MSG SUBNETTREE_PYTHON_MODULE) 26 | -------------------------------------------------------------------------------- /CheckCompilers.cmake: -------------------------------------------------------------------------------- 1 | # Aborts the configuration if no C or C++ compiler is found, depending 2 | # on whether a previous call to the project() macro was supplied either 3 | # language as a requirement. 4 | 5 | if (NOT CMAKE_C_COMPILER AND DEFINED CMAKE_C_COMPILER) 6 | message(FATAL_ERROR "Could not find prerequisite C compiler") 7 | endif () 8 | 9 | if (NOT CMAKE_CXX_COMPILER AND DEFINED CMAKE_CXX_COMPILER) 10 | message(FATAL_ERROR "Could not find prerequisite C++ compiler") 11 | endif () 12 | 13 | if (WIN32 AND NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") 14 | message( 15 | FATAL_ERROR "Could not find prerequisite C compiler for Windows platform. MSVC is required") 16 | endif () 17 | 18 | if (WIN32 AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") 19 | message( 20 | FATAL_ERROR 21 | "Could not find prerequisite C++ compiler for Windows platform. MSVC is required") 22 | endif () 23 | -------------------------------------------------------------------------------- /CheckOptionalBuildSources.cmake: -------------------------------------------------------------------------------- 1 | # A macro that checks whether optional sources exist and if they do, they 2 | # are added to the build/install process, else a warning is issued 3 | # 4 | # _dir: the subdir of the current source dir in which the optional 5 | # sources are located 6 | # _packageName: a string that identifies the package 7 | # _varName: name of the variable indicating whether package is scheduled 8 | # to be installed 9 | 10 | macro (CheckOptionalBuildSources _dir _packageName _varName) 11 | if (${_varName}) 12 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeLists.txt) 13 | add_subdirectory(${_dir}) 14 | else () 15 | message(WARNING "${_packageName} source code does not exist in " 16 | "${CMAKE_CURRENT_SOURCE_DIR}/${_dir} " 17 | "so it will not be built or installed") 18 | set(${_varName} false) 19 | endif () 20 | endif () 21 | endmacro (CheckOptionalBuildSources) 22 | -------------------------------------------------------------------------------- /FindFTS.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find FTS library and headers 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(FTS) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # FTS_ROOT_DIR Set this variable to the root installation of 11 | # FTS if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # FTS_FOUND System has FTS library 17 | # FTS_LIBRARY The FTS library 18 | # FTS_INCLUDE_DIR The FTS headers 19 | 20 | find_path(FTS_ROOT_DIR NAMES include/fts.h) 21 | 22 | find_library(FTS_LIBRARY NAMES fts HINTS ${FTS_ROOT_DIR}/lib) 23 | 24 | find_path(FTS_INCLUDE_DIR NAMES fts.h HINTS ${FTS_ROOT_DIR}/include) 25 | 26 | include(FindPackageHandleStandardArgs) 27 | find_package_handle_standard_args(FTS DEFAULT_MSG FTS_LIBRARY FTS_INCLUDE_DIR) 28 | 29 | mark_as_advanced(FTS_ROOT_DIR FTS_LIBRARY FTS_INCLUDE_DIR) 30 | -------------------------------------------------------------------------------- /package_preinstall.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script is meant to be used by binary packages pre-installation. 4 | # Variables between @ symbols are replaced by CMake at configure time. 5 | 6 | configFiles="@INSTALLED_CONFIG_FILES@" 7 | backupNamesFile=/tmp/zeek_install_backups 8 | 9 | # Checks if a config file exists in a default location and makes a backup 10 | # so that a modified version is not clobbered 11 | backupFile() { 12 | origFile="$1" 13 | 14 | if [ -e ${origFile} ]; then 15 | # choose a file suffix that doesn't already exist 16 | ver=1 17 | while [ -e ${origFile}.${ver} ]; do 18 | ver=$((ver + 1)) 19 | done 20 | 21 | backupFile=${origFile}.${ver} 22 | 23 | cp -p ${origFile} ${backupFile} 24 | 25 | # the post upgrade script will check whether the installed 26 | # config file actually differs from existing version 27 | # and delete unnecessary backups 28 | echo "${backupFile}" >>${backupNamesFile} 29 | fi 30 | } 31 | 32 | for file in ${configFiles}; do 33 | backupFile "${file}" 34 | done 35 | -------------------------------------------------------------------------------- /MiscTests.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCXXSourceCompiles) 2 | include(CheckCSourceCompiles) 3 | 4 | # This autoconf variable is obsolete; it's portable to assume C89 and signal 5 | # handlers returning void 6 | set(RETSIGTYPE "void") 7 | set(RETSIGVAL "") 8 | 9 | check_c_source_compiles( 10 | " 11 | #include 12 | #include 13 | extern int socket(int, int, int); 14 | extern int connect(int, const struct sockaddr *, int); 15 | extern int send(int, const void *, int, int); 16 | extern int recvfrom(int, void *, int, int, struct sockaddr *, int *); 17 | int main() { return 0; } 18 | " 19 | DO_SOCK_DECL) 20 | if (DO_SOCK_DECL) 21 | message(STATUS "socket() and friends need explicit declaration") 22 | endif () 23 | 24 | check_cxx_source_compiles( 25 | " 26 | #include 27 | #include 28 | extern \"C\" { 29 | int openlog(const char* ident, int logopt, int facility); 30 | int syslog(int priority, const char* message_fmt, ...); 31 | int closelog(); 32 | } 33 | int main() { return 0; } 34 | " 35 | SYSLOG_INT) 36 | if (SYSLOG_INT) 37 | message(STATUS "syslog prototypes need declaration") 38 | endif () 39 | -------------------------------------------------------------------------------- /FindJeMalloc.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find jemalloc headers and libraries. 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(JeMalloc) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # JEMALLOC_ROOT_DIR Set this variable to the root installation of 11 | # jemalloc if the module has problems finding 12 | # the proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # JEMALLOC_FOUND System has jemalloc libs/headers 17 | # JEMALLOC_LIBRARIES The jemalloc library/libraries 18 | # JEMALLOC_INCLUDE_DIR The location of jemalloc headers 19 | 20 | find_path(JEMALLOC_ROOT_DIR NAMES include/jemalloc/jemalloc.h) 21 | 22 | find_library(JEMALLOC_LIBRARIES NAMES jemalloc HINTS ${JEMALLOC_ROOT_DIR}/lib) 23 | 24 | find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h HINTS ${JEMALLOC_ROOT_DIR}/include) 25 | 26 | include(FindPackageHandleStandardArgs) 27 | find_package_handle_standard_args(JeMalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR) 28 | 29 | mark_as_advanced(JEMALLOC_ROOT_DIR JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR) 30 | -------------------------------------------------------------------------------- /RequireCXXStd.cmake: -------------------------------------------------------------------------------- 1 | # Check for a specific C++ standard level, and require the compiler to 2 | # support that via some CMake settings. 3 | 4 | if (DEFINED ZEEK_CXX_STD) 5 | return() 6 | endif () 7 | 8 | # Require a specific C++ standard and set the proper flag when creating targets. 9 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 10 | set(CMAKE_CXX_STANDARD 20) 11 | 12 | # Disable using extensions provided by various compilers. Notably this keeps us 13 | # setting it to c++20 instead of gnu++20 with GCC. 14 | set(CMAKE_CXX_EXTENSIONS OFF) 15 | 16 | set(_old_cmake_required_flags "${CMAKE_REQUIRED_FLAGS}") 17 | if (MSVC) 18 | set(CMAKE_REQUIRED_FLAGS "/std:c++20") 19 | else () 20 | set(CMAKE_REQUIRED_FLAGS "-std=c++20") 21 | endif () 22 | 23 | include(CheckCXXSourceCompiles) 24 | 25 | # The header is a good baseline version of C++20 support for us 26 | # since we can use it to determine support for various features in other 27 | # places. 28 | set(cxx_std_testcode "#include 29 | int main() { }") 30 | 31 | check_cxx_source_compiles("${cxx_std_testcode}" cxx_std_works) 32 | 33 | set(CMAKE_REQUIRED_FLAGS "${_old_cmake_required_flags}") 34 | 35 | if (cxx_std_works) 36 | set(ZEEK_CXX_STD cxx_std_20) 37 | else () 38 | message(FATAL_ERROR "failed using C++20 for compilation") 39 | endif () 40 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | function(uninstall_manifest manifestPath) 2 | file(READ "${manifestPath}" files) 3 | string(REGEX REPLACE "\n" ";" files "${files}") 4 | foreach (file ${files}) 5 | set(fileName $ENV{DESTDIR}${file}) 6 | 7 | if (EXISTS "${fileName}" OR IS_SYMLINK "${fileName}") 8 | message(STATUS "Uninstalling: ${fileName}") 9 | 10 | execute_process( 11 | COMMAND "@CMAKE_COMMAND@" -E remove "${fileName}" 12 | OUTPUT_VARIABLE rm_out 13 | RESULT_VARIABLE rm_retval 14 | ) 15 | 16 | if (NOT ${rm_retval} EQUAL 0) 17 | message(FATAL_ERROR "Problem when removing: ${fileName}") 18 | endif () 19 | else () 20 | message(STATUS "Does not exist: ${fileName}") 21 | endif () 22 | 23 | endforeach () 24 | endfunction(uninstall_manifest) 25 | 26 | file(GLOB install_manifests @CMAKE_CURRENT_BINARY_DIR@/install_manifest*.txt) 27 | 28 | if (install_manifests) 29 | foreach (manifest ${install_manifests}) 30 | uninstall_manifest(${manifest}) 31 | endforeach () 32 | else () 33 | message(FATAL_ERROR "Cannot find any install manifests in: " 34 | "\"@CMAKE_CURRENT_BINARY_DIR@/install_manifest*.txt\"") 35 | endif () 36 | -------------------------------------------------------------------------------- /CheckTypes.cmake: -------------------------------------------------------------------------------- 1 | include(CheckTypeSize) 2 | 3 | check_type_size("long int" SIZEOF_LONG_INT) 4 | check_type_size("long long" SIZEOF_LONG_LONG) 5 | check_type_size("void *" SIZEOF_VOID_P) 6 | 7 | # checks existence of ${_type}, and if it does not, sets CMake variable ${_var} 8 | # to alternative type, ${_alt_type} 9 | macro (CheckType _type _alt_type _var) 10 | # don't perform check if we have a result from a previous CMake run 11 | if (NOT HAVE_${_var}) 12 | check_type_size(${_type} ${_var}) 13 | if (NOT ${_var}) 14 | set(${_var} ${_alt_type}) 15 | else () 16 | unset(${_var}) 17 | unset(${_var} CACHE) 18 | endif () 19 | endif () 20 | endmacro ( 21 | CheckType 22 | _type 23 | _alt_type 24 | _var) 25 | 26 | set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h) 27 | CheckType(int32_t int int32_t) 28 | CheckType(u_int32_t u_int u_int32_t) 29 | CheckType(u_int16_t u_short u_int16_t) 30 | CheckType(u_int8_t u_char u_int8_t) 31 | set(CMAKE_EXTRA_INCLUDE_FILES) 32 | 33 | set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) 34 | CheckType(socklen_t int socklen_t) 35 | set(CMAKE_EXTRA_INCLUDE_FILES) 36 | 37 | set(CMAKE_EXTRA_INCLUDE_FILES netinet/in.h netinet/ip6.h) 38 | check_type_size("struct ip6_opt" IP6_OPT) 39 | check_type_size("struct ip6_ext" IP6_EXT) 40 | set(CMAKE_EXTRA_INCLUDE_FILES) 41 | -------------------------------------------------------------------------------- /CheckCompilerArch.cmake: -------------------------------------------------------------------------------- 1 | # Findm the name of the architecture that we compile to. Currently 2 | # this is used for highwayhash - but may be generally useful. 3 | 4 | include(CheckCSourceCompiles) 5 | 6 | check_c_source_compiles( 7 | " 8 | #if defined(__x86_64__) || defined(_M_X64) 9 | int main() { return 0; } 10 | #else 11 | #error wrongarch 12 | #endif 13 | " 14 | test_arch_x64) 15 | check_c_source_compiles( 16 | " 17 | #if defined(__aarch64__) || defined(__arm64__) 18 | int main() { return 0; } 19 | #else 20 | #error wrongarch 21 | #endif 22 | " 23 | test_arch_aarch64) 24 | check_c_source_compiles( 25 | " 26 | #if defined(__arm__) || defined(__ARM_NEON__) || defined(__ARM_NEON) 27 | int main() { return 0; } 28 | #else 29 | #error wrongarch 30 | #endif 31 | " 32 | test_arch_arm) 33 | check_c_source_compiles( 34 | " 35 | #if defined(__powerpc64__) || defined(_M_PPC) 36 | int main() { return 0; } 37 | #else 38 | #error wrongarch 39 | #endif 40 | " 41 | test_arch_power) 42 | 43 | if (test_arch_x64) 44 | set(COMPILER_ARCHITECTURE "x86_64") 45 | elseif (test_arch_aarch64) 46 | set(COMPILER_ARCHITECTURE "aarch64") 47 | elseif (test_arch_arm) 48 | set(COMPILER_ARCHITECTURE "arm") 49 | elseif (test_arch_power) 50 | set(COMPILER_ARCHITECTURE "power") 51 | else () 52 | set(COMPILER_ARCHITECTURE "portable") 53 | endif () 54 | 55 | message(STATUS "Determined target architecture (for hashing): ${COMPILER_ARCHITECTURE}") 56 | -------------------------------------------------------------------------------- /FindBinPAC.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find BinPAC binary and library 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(BinPAC) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # BinPAC_ROOT_DIR Set this variable to the root installation of 11 | # BinPAC if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # BINPAC_FOUND System has BinPAC binary and library 17 | # BinPAC_EXE The binpac executable 18 | # BinPAC_LIBRARY The libbinpac.a library 19 | # BinPAC_INCLUDE_DIR The binpac headers 20 | 21 | # look for BinPAC in standard locations or user-provided root 22 | find_path(BinPAC_ROOT_DIR NAMES include/binpac.h include/binpac/binpac.h) 23 | 24 | find_program(BinPAC_EXE NAMES binpac HINTS ${BinPAC_ROOT_DIR}/bin) 25 | 26 | find_library(BinPAC_LIBRARY NAMES binpac libbinpac.a HINTS ${BinPAC_ROOT_DIR}/lib) 27 | 28 | find_path(BinPAC_INCLUDE_DIR NAMES binpac.h HINTS ${BinPAC_ROOT_DIR}/include 29 | ${BinPAC_ROOT_DIR}/include/binpac) 30 | 31 | include(FindPackageHandleStandardArgs) 32 | find_package_handle_standard_args(BinPAC DEFAULT_MSG BinPAC_EXE BinPAC_LIBRARY BinPAC_INCLUDE_DIR) 33 | 34 | mark_as_advanced(BinPAC_ROOT_DIR BinPAC_EXE BinPAC_LIBRARY BinPAC_INCLUDE_DIR) 35 | -------------------------------------------------------------------------------- /SetDefaultCompileFlags.cmake: -------------------------------------------------------------------------------- 1 | # Set up the default flags and CMake build type once during the configuration 2 | # of the top-level CMake project. 3 | 4 | if (MSVC) 5 | return() 6 | endif () 7 | 8 | if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") 9 | set(EXTRA_COMPILE_FLAGS "-Wall -Wno-unused -funsigned-char") 10 | set(EXTRA_COMPILE_FLAGS_CXX "-Wno-register -Werror=vla -funsigned-char") 11 | 12 | if (NOT CMAKE_BUILD_TYPE) 13 | if (ENABLE_DEBUG) 14 | set(CMAKE_BUILD_TYPE Debug) 15 | else () 16 | set(CMAKE_BUILD_TYPE RelWithDebInfo) 17 | endif () 18 | endif () 19 | 20 | string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type_upper) 21 | 22 | if ("${_build_type_upper}" STREQUAL "DEBUG") 23 | if (ENABLE_COVERAGE) 24 | set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} --coverage -fprofile-update=atomic") 25 | set(EXTRA_LD_FLAGS "${EXTRA_LD_FLAGS} --coverage -fprofile-update=atomic") 26 | endif () 27 | # manual add of -g works around its omission in FreeBSD's CMake port 28 | set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -g -DDEBUG -DBRO_DEBUG") 29 | endif () 30 | 31 | # Compiler flags may already exist in CMake cache (e.g. when specifying 32 | # CFLAGS environment variable before running cmake for the the first time) 33 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}") 34 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS} ${EXTRA_COMPILE_FLAGS_CXX}") 35 | endif () 36 | -------------------------------------------------------------------------------- /InstallClobberImmune.cmake: -------------------------------------------------------------------------------- 1 | # Determines at `make install` time if a file, typically a configuration 2 | # file placed in $PREFIX/etc, shouldn't be installed to prevent overwrite 3 | # of an existing file. 4 | # 5 | # _srcfile: the file to install 6 | # _dstfile: the absolute file name after installation 7 | 8 | macro (InstallClobberImmune _srcfile _dstfile) 9 | install( 10 | CODE " 11 | set(_destfile \"${_dstfile}\") 12 | if (NOT \"\$ENV{DESTDIR}\" STREQUAL \"\") 13 | # prepend install root prefix with install-time DESTDIR 14 | set(_destfile \"\$ENV{DESTDIR}/${_dstfile}\") 15 | endif () 16 | if (EXISTS \${_destfile}) 17 | message(STATUS \"Skipping: \${_destfile} (already exists)\") 18 | execute_process(COMMAND \"${CMAKE_COMMAND}\" -E compare_files 19 | ${_srcfile} \${_destfile} RESULT_VARIABLE _diff) 20 | if (NOT \"\${_diff}\" STREQUAL \"0\") 21 | message(STATUS \"Installing: \${_destfile}.example\") 22 | configure_file(${_srcfile} \${_destfile}.example COPYONLY) 23 | endif () 24 | else () 25 | message(STATUS \"Installing: \${_destfile}\") 26 | # install() is not scriptable within install(), and 27 | # configure_file() is the next best thing 28 | configure_file(${_srcfile} \${_destfile} COPYONLY) 29 | # TODO: create additional install_manifest files? 30 | endif () 31 | ") 32 | endmacro (InstallClobberImmune) 33 | -------------------------------------------------------------------------------- /FindLibMMDB.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libmaxminddb headers and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(LibMMDB) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # LibMMDB_ROOT_DIR Set this variable to the root installation of 11 | # libmaxminddb if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # LibMMDB_FOUND System has libmaxminddb libraries and headers 17 | # LibMMDB_LIBRARY The libmaxminddb library 18 | # LibMMDB_INCLUDE_DIR The location of libmaxminddb headers 19 | 20 | find_path(LibMMDB_ROOT_DIR NAMES include/maxminddb.h) 21 | 22 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 23 | # the static version of the library is preferred on OS X for the 24 | # purposes of making packages (libmaxminddb doesn't ship w/ OS X) 25 | set(libmmdb_names libmaxminddb.a maxminddb) 26 | else () 27 | set(libmmdb_names maxminddb) 28 | endif () 29 | 30 | find_library(LibMMDB_LIBRARY NAMES ${libmmdb_names} HINTS ${LibMMDB_ROOT_DIR}/lib) 31 | 32 | find_path(LibMMDB_INCLUDE_DIR NAMES maxminddb.h HINTS ${LibMMDB_ROOT_DIR}/include) 33 | 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(LibMMDB DEFAULT_MSG LibMMDB_LIBRARY LibMMDB_INCLUDE_DIR) 36 | 37 | mark_as_advanced(LibMMDB_ROOT_DIR LibMMDB_LIBRARY LibMMDB_INCLUDE_DIR) 38 | -------------------------------------------------------------------------------- /PCAPTests.cmake: -------------------------------------------------------------------------------- 1 | include(CheckFunctionExists) 2 | include(CheckSymbolExists) 3 | include(CheckCSourceCompiles) 4 | include(CheckIncludeFiles) 5 | 6 | set(PCAP_OS_LIBRARIES) 7 | if (MSVC) 8 | set(PCAP_OS_LIBRARIES ws2_32.lib Crypt32.lib ${OPENSSL_LIBRARIES}) 9 | endif () 10 | set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIR}) 11 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${PCAP_OS_LIBRARIES}) 12 | 13 | cmake_policy(PUSH) 14 | 15 | if (POLICY CMP0075) 16 | # It's fine that check_include_files links against CMAKE_REQUIRED_LIBRARIES 17 | cmake_policy(SET CMP0075 NEW) 18 | endif () 19 | 20 | check_include_files(pcap-int.h HAVE_PCAP_INT_H) 21 | 22 | cmake_policy(POP) 23 | 24 | check_symbol_exists(pcap_freecode pcap.h HAVE_LIBPCAP_PCAP_FREECODE) 25 | if (NOT HAVE_LIBPCAP_PCAP_FREECODE) 26 | set(DONT_HAVE_LIBPCAP_PCAP_FREECODE true) 27 | message(STATUS "No implementation for pcap_freecode()") 28 | endif () 29 | 30 | if (DONT_HAVE_LIBPCAP_PCAP_FREECODE AND NOT HAVE_PCAP_INT_H) 31 | message(FATAL_ERROR "pcap-int.h required to implement pcap_freecode() internally") 32 | endif () 33 | 34 | check_symbol_exists(DLT_PPP_SERIAL pcap.h HAVE_DLT_PPP_SERIAL) 35 | if (NOT HAVE_DLT_PPP_SERIAL) 36 | set(DLT_PPP_SERIAL 50) 37 | endif () 38 | 39 | check_symbol_exists(DLT_NFLOG pcap.h HAVE_DLT_NFLOG) 40 | if (NOT HAVE_DLT_NFLOG) 41 | set(DLT_NFLOG 239) 42 | endif () 43 | 44 | check_symbol_exists(DLT_LINUX_SLL2 pcap.h HAVE_DLT_LINUX_SLL2) 45 | if (NOT HAVE_DLT_LINUX_SLL2) 46 | set(DONT_HAVE_LIBPCAP_DLT_LINUX_SLL2 true) 47 | message(STATUS "No DLT_LINUX_SLL2 support in libpcap") 48 | endif () 49 | 50 | set(CMAKE_REQUIRED_INCLUDES) 51 | set(CMAKE_REQUIRED_LIBRARIES) 52 | -------------------------------------------------------------------------------- /MacDependencyPaths.cmake: -------------------------------------------------------------------------------- 1 | # As of CMake 2.8.3, Fink and MacPorts search paths are appended to the 2 | # default search prefix paths, but the nicer thing would be if they are 3 | # prepended to the default, so that is fixed here. 4 | 5 | # Prepend the default search path locations, in case for some reason the 6 | # ports/brew/fink executables are not found. 7 | # If they are found, the actual paths will be pre-pended again below. 8 | list(PREPEND CMAKE_PREFIX_PATH /usr/local) 9 | list(PREPEND CMAKE_PREFIX_PATH /opt/local) 10 | list(PREPEND CMAKE_PREFIX_PATH /sw) 11 | 12 | if (APPLE AND "${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") 13 | find_program(MAC_PORTS_BIN ports) 14 | find_program(MAC_HBREW_BIN brew) 15 | find_program(MAC_FINK_BIN fink) 16 | 17 | if (MAC_PORTS_BIN) 18 | list(PREPEND CMAKE_PREFIX_PATH ${MAC_PORTS_BIN}) # MacPorts 19 | endif () 20 | 21 | if (MAC_HBREW_BIN) 22 | execute_process(COMMAND ${MAC_HBREW_BIN} "--prefix" OUTPUT_VARIABLE BREW_PREFIX 23 | OUTPUT_STRIP_TRAILING_WHITESPACE) 24 | # Homebrew, if linked 25 | list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}) 26 | # Homebrew OpenSSL 27 | list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/openssl) 28 | # Homebrew Bison 29 | list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/bison/bin) 30 | # Homebrew Flex 31 | list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/flex/bin) 32 | # Homebrew actor-framework 33 | list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/actor-framework) 34 | endif () 35 | 36 | if (MAC_FINK_BIN) 37 | list(PREPEND CMAKE_PREFIX_PATH /sw) # Fink 38 | endif () 39 | 40 | endif () 41 | -------------------------------------------------------------------------------- /.cmake-format.json: -------------------------------------------------------------------------------- 1 | { 2 | "parse": { 3 | "additional_commands": { 4 | "CheckIPProto": { 5 | "kwargs": { 6 | "_proto": "*" 7 | } 8 | }, 9 | "CheckType": { 10 | "kwargs": { 11 | "_type": "*", 12 | "_alt_type": "*", 13 | "_var": "*" 14 | } 15 | }, 16 | "SetPackageVersion": { 17 | "kwargs": { 18 | "_version": "*" 19 | } 20 | }, 21 | "SetPackageFileName": { 22 | "kwargs": { 23 | "_version": "*" 24 | } 25 | }, 26 | "SetPackageInstallScripts": { 27 | "kwargs": { 28 | "VERSION": "*" 29 | } 30 | }, 31 | "ConfigurePackaging": { 32 | "kwargs": { 33 | "_version": "*" 34 | } 35 | }, 36 | "SetPackageGenerators": {}, 37 | "SetPackageMetadata": {}, 38 | "FindRequiredPackage": { 39 | "kwargs": { 40 | "packageName": "*" 41 | } 42 | }, 43 | "InstallClobberImmune": { 44 | "kwargs": { 45 | "_srcfile": "*", 46 | "_dstfile": "*" 47 | } 48 | }, 49 | "InstallPackageConfigFile": { 50 | "kwargs": { 51 | "_srcfile": "*", 52 | "_dstdir": "*", 53 | "_dstfilename": "*" 54 | } 55 | }, 56 | "InstallShellScript": { 57 | "kwargs": { 58 | "_srcfile": "*", 59 | "_dstfile": "*" 60 | } 61 | }, 62 | "InstallSymLink": { 63 | "kwargs": { 64 | "_filepath": "*", 65 | "_sympath": "*" 66 | } 67 | } 68 | } 69 | }, 70 | "format": { 71 | "line_width": 100, 72 | "tab_size": 4, 73 | "separate_ctrl_name_with_space": true, 74 | "max_subgroups_hwrap": 3, 75 | "line_ending": "unix" 76 | }, 77 | "markup": { 78 | "enable_markup": false 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /CheckHeaders.cmake: -------------------------------------------------------------------------------- 1 | include(CheckIncludeFiles) 2 | include(CheckStructHasMember) 3 | include(CheckSymbolExists) 4 | 5 | check_include_files(getopt.h HAVE_GETOPT_H) 6 | check_include_files(memory.h HAVE_MEMORY_H) 7 | check_include_files("netinet/ether.h" HAVE_NETINET_ETHER_H) 8 | check_include_files("sys/socket.h;netinet/in.h;net/if.h;netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H) 9 | check_include_files("sys/socket.h;netinet/in.h;net/if.h;netinet/ip6.h" HAVE_NETINET_IP6_H) 10 | check_include_files("sys/socket.h;net/if.h;net/ethernet.h" HAVE_NET_ETHERNET_H) 11 | check_include_files(sys/ethernet.h HAVE_SYS_ETHERNET_H) 12 | check_include_files(net/ethertypes.h HAVE_NET_ETHERTYPES_H) 13 | check_include_files(sys/time.h HAVE_SYS_TIME_H) 14 | check_include_files("time.h;sys/time.h" TIME_WITH_SYS_TIME) 15 | check_include_files(os-proto.h HAVE_OS_PROTO_H) 16 | 17 | check_struct_has_member(HISTORY_STATE entries "stdio.h;readline/readline.h" 18 | HAVE_READLINE_HISTORY_ENTRIES) 19 | check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H) 20 | check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H) 21 | 22 | if (HAVE_READLINE_READLINE_H AND HAVE_READLINE_HISTORY_H AND HAVE_READLINE_HISTORY_ENTRIES) 23 | set(HAVE_READLINE true) 24 | endif () 25 | 26 | check_struct_has_member("struct sockaddr_in" sin_len "netinet/in.h" SIN_LEN) 27 | 28 | macro (CheckIPProto _proto) 29 | check_symbol_exists(IPPROTO_${_proto} netinet/in.h HAVE_IPPROTO_${_proto}) 30 | endmacro (CheckIPProto _proto) 31 | 32 | CheckIPProto(HOPOPTS) 33 | CheckIPProto(IPV6) 34 | CheckIPProto(IPV4) 35 | CheckIPProto(ROUTING) 36 | CheckIPProto(FRAGMENT) 37 | CheckIPProto(ESP) 38 | CheckIPProto(AH) 39 | CheckIPProto(ICMPV6) 40 | CheckIPProto(NONE) 41 | CheckIPProto(DSTOPTS) 42 | -------------------------------------------------------------------------------- /FindPrometheusCpp.cmake: -------------------------------------------------------------------------------- 1 | set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/auxil/prometheus-cpp") 2 | set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") 3 | 4 | # Reset this to prevent Prometheus from using the internal zeek value and thus building 5 | # shared libraries instead of static ones. 6 | set(_sharedlibs ${BUILD_SHARED_LIBS}) 7 | set(BUILD_SHARED_LIBS OFF) 8 | 9 | # The -DDEBUG flag from SetDefaultCompileFlags causes civetweb in prometheus-cpp 10 | # to output a bunch of debugging information. Remove it from the flags before 11 | # allowing them to pass through to the prometheus-cpp build. 12 | set(_cxxflags ${CMAKE_CXX_FLAGS}) 13 | set(_cflags ${CMAKE_C_FLAGS}) 14 | 15 | string(REPLACE "-DDEBUG" "" CMAKE_CXX_FLAGS "${_cxxflags}") 16 | string(REPLACE "-DDEBUG" "" CMAKE_C_FLAGS "${_cflags}") 17 | 18 | option(ENABLE_PUSH "" OFF) 19 | option(ENABLE_TESTING "" OFF) 20 | option(GENERATE_PKGCONFIG "" OFF) 21 | option(CIVETWEB_ENABLE_DEBUG_TOOLS "" OFF) 22 | 23 | message("\n==================| prometheus-cpp Config Summary |====================\n") 24 | add_subdirectory(auxil/prometheus-cpp EXCLUDE_FROM_ALL) 25 | message("=========================================================================\n ") 26 | 27 | # The prometheus symbols are brought by broker, which links the libraries in statically 28 | # before Zeek links. We can skip linking them in ourselves as long as we are linking 29 | # against broker. 30 | #set(zeekdeps ${zeekdeps} prometheus-cpp::core prometheus-cpp::pull) 31 | 32 | include_directories(BEFORE ${prometheuscpp_src}/pull/include ${prometheuscpp_src}/core/include) 33 | include_directories(BEFORE ${prometheuscpp_build}/pull/include ${prometheuscpp_build}/core/include) 34 | 35 | set(BUILD_SHARED_LIBS ${_sharedlibs}) 36 | set(CMAKE_CXX_FLAGS ${_cxxflags}) 37 | set(CMAKE_C_FLAGS ${_cflags}) 38 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 1995-2017, The Regents of the University of California 2 | through the Lawrence Berkeley National Laboratory and the 3 | International Computer Science Institute. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | (1) Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | (2) Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | (3) Neither the name of the University of California, Lawrence Berkeley 16 | National Laboratory, U.S. Dept. of Energy, International Computer 17 | Science Institute, nor the names of contributors may be used to endorse 18 | or promote products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | 33 | Note that some files in the distribution may carry their own copyright 34 | notices. 35 | -------------------------------------------------------------------------------- /FindGooglePerftools.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find GooglePerftools headers and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(GooglePerftools) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # GooglePerftools_ROOT_DIR Set this variable to the root installation of 11 | # GooglePerftools if the module has problems finding 12 | # the proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # GOOGLEPERFTOOLS_FOUND System has GooglePerftools libs/headers 17 | # TCMALLOC_FOUND System has GooglePerftools tcmalloc library 18 | # GooglePerftools_LIBRARIES The GooglePerftools libraries 19 | # GooglePerftools_LIBRARIES_DEBUG The GooglePerftools libraries for heap checking. 20 | # GooglePerftools_INCLUDE_DIR The location of GooglePerftools headers 21 | 22 | find_path(GooglePerftools_ROOT_DIR NAMES include/google/heap-profiler.h) 23 | 24 | find_library(GooglePerftools_LIBRARIES_DEBUG NAMES tcmalloc_and_profiler 25 | HINTS ${GooglePerftools_ROOT_DIR}/lib) 26 | 27 | find_library(GooglePerftools_LIBRARIES NAMES tcmalloc tcmalloc_minimal 28 | HINTS ${GooglePerftools_ROOT_DIR}/lib) 29 | 30 | find_path(GooglePerftools_INCLUDE_DIR NAMES google/heap-profiler.h 31 | HINTS ${GooglePerftools_ROOT_DIR}/include) 32 | 33 | include(FindPackageHandleStandardArgs) 34 | find_package_handle_standard_args(GooglePerftools DEFAULT_MSG GooglePerftools_LIBRARIES 35 | GooglePerftools_LIBRARIES_DEBUG GooglePerftools_INCLUDE_DIR) 36 | find_package_handle_standard_args(tcmalloc DEFAULT_MSG GooglePerftools_LIBRARIES) 37 | 38 | mark_as_advanced(GooglePerftools_ROOT_DIR GooglePerftools_LIBRARIES GooglePerftools_LIBRARIES_DEBUG 39 | GooglePerftools_INCLUDE_DIR) 40 | -------------------------------------------------------------------------------- /OSSpecific.cmake: -------------------------------------------------------------------------------- 1 | if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 2 | 3 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") 4 | 5 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 6 | set(HAVE_DARWIN true) 7 | 8 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 9 | set(HAVE_LINUX true) 10 | 11 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Solaris") 12 | set(SOCKET_LIBS nsl socket) 13 | 14 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "osf") 15 | # Workaround ip_hl vs. ip_vhl problem in netinet/ip.h 16 | add_definitions(-D__STDC__=2) 17 | 18 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "irix") 19 | list(APPEND CMAKE_C_FLAGS -xansi -signed -g3) 20 | list(APPEND CMAKE_CXX_FLAGS -xansi -signed -g3) 21 | 22 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "ultrix") 23 | list(APPEND CMAKE_C_FLAGS -std1 -g3) 24 | list(APPEND CMAKE_CXX_FLAGS -std1 -g3) 25 | include(CheckCSourceCompiles) 26 | check_c_source_compiles( 27 | " 28 | #include 29 | int main() { 30 | void c(const struct a *); 31 | return 0; 32 | } 33 | " 34 | have_ultrix_const) 35 | if (NOT have_ultrix_const) 36 | set(NEED_ULTRIX_CONST_HACK true) 37 | endif () 38 | 39 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "hpux" OR ${CMAKE_SYSTEM_NAME} MATCHES "HP-UX") 40 | include(CheckCSourceCompiles) 41 | set(CMAKE_REQUIRED_FLAGS -Aa) 42 | set(CMAKE_REQUIRED_DEFINITIONS -D_HPUX_SOURCE) 43 | check_c_source_compiles( 44 | " 45 | #include 46 | int main() { 47 | int frob(int, char *); 48 | return 0; 49 | } 50 | " 51 | have_ansi_prototypes) 52 | set(CMAKE_REQUIRED_FLAGS) 53 | set(CMAKE_REQUIRED_DEFINITIONS) 54 | 55 | if (have_ansi_prototypes) 56 | add_definitions(-D_HPUX_SOURCE) 57 | list(APPEND CMAKE_C_FLAGS -Aa) 58 | list(APPEND CMAKE_CXX_FLAGS -Aa) 59 | endif () 60 | 61 | if (NOT have_ansi_prototypes) 62 | message(FATAL_ERROR "Can't get HPUX compiler to handle ANSI prototypes") 63 | endif () 64 | endif () 65 | -------------------------------------------------------------------------------- /FindRequiredPackage.cmake: -------------------------------------------------------------------------------- 1 | # A wrapper macro around the standard CMake find_package macro that 2 | # facilitates displaying better error messages by default, or even 3 | # accepting custom error messages on a per package basis. 4 | # 5 | # If a package is not found, then the MISSING_PREREQS variable gets 6 | # set to true and either a default or custom error message appended 7 | # to MISSING_PREREQ_DESCS. 8 | # 9 | # The caller can use these variables to display a list of any missing 10 | # packages and abort the build/configuration if there were any. 11 | # 12 | # Use as follows: 13 | # 14 | # include(FindRequiredPackage) 15 | # FindRequiredPackage(Perl) 16 | # FindRequiredPackage(FLEX "You need to install flex (Fast Lexical Analyzer)") 17 | # 18 | # if (MISSING_PREREQS) 19 | # foreach (prereq ${MISSING_PREREQ_DESCS}) 20 | # message(SEND_ERROR ${prereq}) 21 | # endforeach () 22 | # message(FATAL_ERROR "Configuration aborted due to missing prerequisites") 23 | # endif () 24 | 25 | macro (FindRequiredPackage packageName) 26 | message(DEPRECATION "Remove in v7.1. Use find_package's REQUIRED argument instead.") 27 | 28 | string(TOUPPER ${packageName} upperPackageName) 29 | if ((DEFINED ${upperPackageName}_ROOT_DIR) AND (DEFINED CMAKE_PREFIX_PATH)) 30 | set(CMAKE_PREFIX_SAVE ${CMAKE_PREFIX_PATH}) 31 | unset(CMAKE_PREFIX_PATH) 32 | find_package(${packageName}) 33 | set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_SAVE}) 34 | else () 35 | find_package(${packageName}) 36 | endif () 37 | string(TOUPPER ${packageName} canonPackageName) 38 | if (NOT ${canonPackageName}_FOUND) 39 | set(MISSING_PREREQS true) 40 | 41 | set(customDesc) 42 | foreach (descArg ${ARGN}) 43 | set(customDesc "${customDesc} ${descArg}") 44 | endforeach () 45 | 46 | if (customDesc) 47 | # append the custom error message that was provided as an argument 48 | list(APPEND MISSING_PREREQ_DESCS ${customDesc}) 49 | else () 50 | list(APPEND MISSING_PREREQ_DESCS 51 | " Could not find prerequisite package '${packageName}'") 52 | endif () 53 | endif () 54 | endmacro (FindRequiredPackage) 55 | -------------------------------------------------------------------------------- /Gen-ZAM.cmake: -------------------------------------------------------------------------------- 1 | # A macro to define a command that uses the gen-zam templator to produce 2 | # C++ headers from an input template file. The outputs are returned in 3 | # GEN_ZAM_OUTPUT_H. 4 | # 5 | # The macro also creates a target that can be used to define depencencies on the 6 | # generated files. The name of the target includes the input template directory 7 | # to make it unique, and is added automatically to bro_ALL_GENERATED_OUTPUTS. 8 | macro (gen_zam_target gzInputDir) 9 | get_filename_component(gzInputBasename "${gzInputDir}" NAME) 10 | 11 | set(target "gen-zam-${gzInputBasename}") 12 | string(REGEX REPLACE "/" "-" target "${target}") 13 | 14 | set(GEN_ZAM_OUTPUT_H 15 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-AssignFlavorsDefs.h 16 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Conds.h 17 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-DirectDefs.h 18 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-EvalDefs.h 19 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-EvalMacros.h 20 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC1.h 21 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC2.h 22 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC3.h 23 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsV.h 24 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsC1.h 25 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsC2.h 26 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsV.h 27 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-MethodDecls.h 28 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-MethodDefs.h 29 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Op1FlavorsDefs.h 30 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpSideEffects.h 31 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpsDefs.h 32 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpsNamesDefs.h 33 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Vec1EvalDefs.h 34 | ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Vec2EvalDefs.h) 35 | 36 | if (GEN_ZAM_EXE_PATH) 37 | set(GEN_ZAM_EXE ${GEN_ZAM_EXE_PATH}) 38 | else () 39 | set(GEN_ZAM_EXE "gen-zam") 40 | endif () 41 | 42 | add_custom_command( 43 | OUTPUT ${GEN_ZAM_OUTPUT_H} 44 | COMMAND ${GEN_ZAM_EXE} ARGS ${GEN_ZAM_SRC} 45 | DEPENDS ${GEN_ZAM_SRC} ${GEN_ZAM_EXE} 46 | COMMENT "[gen-zam] Generating ZAM operations" 47 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 48 | 49 | add_custom_target(${target} DEPENDS ${GEN_ZAM_OUTPUT_H}) 50 | add_dependencies(zeek_autogen_files ${target}) 51 | endmacro (gen_zam_target) 52 | -------------------------------------------------------------------------------- /package_postupgrade.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script is meant to be used by binary packages post-installation. 4 | # Variables between @ symbols are replaced by CMake at configure time. 5 | 6 | backupNamesFile=/tmp/zeek_install_backups 7 | version=@VERSION@ 8 | sampleFiles="" 9 | 10 | # check whether it's safe to remove backup configuration files that 11 | # the most recent package install created 12 | 13 | if [ -e ${backupNamesFile} ]; then 14 | backupFileList=$(cat ${backupNamesFile}) 15 | 16 | for backupFile in ${backupFileList}; do 17 | origFileName=$(echo ${backupFile} | sed 's/\(.*\)\..*/\1/') 18 | 19 | diff ${origFileName} ${backupFile} >/dev/null 2>&1 20 | 21 | if [ $? -eq 0 ]; then 22 | # if the installed version and the backup version don't differ 23 | # then we can remove the backup version and the example file 24 | rm ${backupFile} 25 | rm ${origFileName}.example 26 | else 27 | # The backup file differs from the newly installed version, 28 | # since we can't tell if the backup version has been modified 29 | # by the user, we should restore it to its original location 30 | # and rename the new version appropriately. 31 | 32 | sampleFiles="${sampleFiles}\n${origFileName}.example" 33 | 34 | mv ${backupFile} ${origFileName} 35 | fi 36 | 37 | done 38 | 39 | rm ${backupNamesFile} 40 | fi 41 | 42 | if [ -n "${sampleFiles}" ]; then 43 | # Use some apple script to display a message to user 44 | /usr/bin/osascript < 20 | int main() { return 0; } 21 | " 22 | including_ssl_h_works) 23 | 24 | if (NOT including_ssl_h_works) 25 | message(FATAL_ERROR "OpenSSL test failure. See CmakeError.log for details.") 26 | endif () 27 | 28 | if (OPENSSL_VERSION VERSION_LESS "0.9.7") 29 | message(FATAL_ERROR "OpenSSL >= v0.9.7 required") 30 | endif () 31 | 32 | check_include_files(openssl/kdf.h OPENSSL_HAVE_KDF_H) 33 | 34 | check_cxx_source_compiles( 35 | " 36 | #include 37 | int main() { 38 | const unsigned char** cpp = 0; 39 | X509** x =0; 40 | d2i_X509(x, cpp, 0); 41 | return 0; 42 | } 43 | " 44 | OPENSSL_D2I_X509_USES_CONST_CHAR) 45 | 46 | if (NOT OPENSSL_D2I_X509_USES_CONST_CHAR) 47 | # double check that it compiles without const 48 | check_cxx_source_compiles( 49 | " 50 | #include 51 | int main() { 52 | unsigned char** cpp = 0; 53 | X509** x =0; 54 | d2i_X509(x, cpp, 0); 55 | return 0; 56 | } 57 | " 58 | OPENSSL_D2I_X509_USES_CHAR) 59 | if (NOT OPENSSL_D2I_X509_USES_CHAR) 60 | message(FATAL_ERROR "Can't determine if openssl_d2i_x509() takes const char parameter") 61 | endif () 62 | endif () 63 | 64 | if (NOT CMAKE_CROSSCOMPILING AND NOT MSVC) 65 | check_c_source_runs( 66 | " 67 | #include 68 | #include 69 | #include 70 | int main() { 71 | printf(\"-- OpenSSL Library version: %s\\\\n\", SSLeay_version(SSLEAY_VERSION)); 72 | printf(\"-- OpenSSL Header version: %s\\\\n\", OPENSSL_VERSION_TEXT); 73 | if (SSLeay() == OPENSSL_VERSION_NUMBER) { 74 | return 0; 75 | } 76 | return -1; 77 | } 78 | " 79 | OPENSSL_CORRECT_VERSION_NUMBER) 80 | 81 | if (NOT OPENSSL_CORRECT_VERSION_NUMBER) 82 | message(FATAL_ERROR "OpenSSL library version does not match headers") 83 | endif () 84 | endif () 85 | 86 | set(CMAKE_REQUIRED_INCLUDES) 87 | set(CMAKE_REQUIRED_LIBRARIES) 88 | -------------------------------------------------------------------------------- /InstallPackageConfigFile.cmake: -------------------------------------------------------------------------------- 1 | include(InstallClobberImmune) 2 | 3 | # This macro can be used to install configuration files which 4 | # users are expected to modify after installation. It will: 5 | # 6 | # - If binary packaging is enabled: 7 | # Install the file in the typical CMake fashion, but append to the 8 | # INSTALLED_CONFIG_FILES cache variable for use with the Mac package's 9 | # pre/post install scripts 10 | # 11 | # - If binary packaging is not enabled: 12 | # Install the script in a way such that it will check at `make install` 13 | # time whether the file does not exist. See InstallClobberImmune.cmake 14 | # 15 | # - Always create a target "install-example-configs" which installs an 16 | # example version of the config file. 17 | # 18 | # _srcfile: the absolute path to the file to install 19 | # _dstdir: absolute path to the directory in which to install the file 20 | # _dstfilename: how to (re)name the file inside _dstdir 21 | 22 | macro (InstallPackageConfigFile _srcfile _dstdir _dstfilename) 23 | set(_dstfile ${_dstdir}/${_dstfilename}) 24 | 25 | if (BINARY_PACKAGING_MODE) 26 | # If packaging mode is enabled, always install the distribution's 27 | # version of the file. The Mac package's pre/post install scripts 28 | # or native functionality of RPMs will take care of not clobbering it. 29 | install(FILES ${_srcfile} DESTINATION ${_dstdir} RENAME ${_dstfilename}) 30 | # This cache variable is what the Mac package pre/post install scripts 31 | # use to avoid clobbering user-modified config files 32 | set(INSTALLED_CONFIG_FILES "${INSTALLED_CONFIG_FILES} ${_dstfile}" CACHE STRING "" FORCE) 33 | 34 | # Additionally, the Mac PackageMaker packages don't have any automatic 35 | # handling of configuration file conflicts so install an example file 36 | # that the post install script will cleanup in the case it's extraneous 37 | if (APPLE) 38 | install(FILES ${_srcfile} DESTINATION ${_dstdir} RENAME ${_dstfilename}.example) 39 | endif () 40 | else () 41 | # Have `make install` check at run time whether the file does not exist 42 | InstallClobberImmune(${_srcfile} ${_dstfile}) 43 | endif () 44 | 45 | if (NOT TARGET install-example-configs) 46 | add_custom_target(install-example-configs COMMENT "Installed example configuration files") 47 | endif () 48 | 49 | # Replace characters disallowed in target names (per CMP0037) with '.'. 50 | string(REGEX REPLACE "[^A-Za-z0-9_.+-]" "." _flatsrc ${_srcfile}) 51 | 52 | set(_example ${_dstfile}.example) 53 | 54 | add_custom_target( 55 | install-example-config-${_flatsrc} COMMAND "${CMAKE_COMMAND}" -E copy ${_srcfile} 56 | \${DESTDIR}${_example} 57 | COMMENT "Installing ${_example}") 58 | 59 | add_dependencies(install-example-configs install-example-config-${_flatsrc}) 60 | 61 | endmacro (InstallPackageConfigFile) 62 | -------------------------------------------------------------------------------- /ChangeMacInstallNames.cmake: -------------------------------------------------------------------------------- 1 | # Calling this macro with the name of a list variable will modify that 2 | # list such that any third party libraries that do not come with a 3 | # vanilla Mac OS X system will be replaced by an adjusted library that 4 | # has an install_name relative to the location of any executable that 5 | # links to it. 6 | # 7 | # Also, it will schedule the modified libraries for installation in a 8 | # 'support_libs' subdirectory of the CMAKE_INSTALL_PREFIX. 9 | # 10 | # The case of third party libraries depending on other third party 11 | # libraries is currently not handled by this macro. 12 | # 13 | # Ex. 14 | # 15 | # set(libs /usr/lib/libz.dylib 16 | # /usr/lib/libssl.dylib 17 | # /usr/local/lib/libmagic.dylib 18 | # /usr/local/lib/libGeoIP.dylib 19 | # /usr/local/lib/somestaticlib.a) 20 | # 21 | # include(ChangeMacInstallNames) 22 | # ChangeMacInstallNames(libs) 23 | # 24 | # Should result in ${libs} containing: 25 | # /usr/lib/libz.dylib 26 | # /usr/lib/libssl.dylib 27 | # ${Zeek_BINARY_DIR}/darwin_support_libs/libmagic.dylib 28 | # ${Zeek_BINARY_DIR}/darwin_support_libs/libGeoIP.dylib 29 | # /usr/local/lib/somestaticlib.a 30 | # 31 | # such that we can now do: 32 | # 33 | # add_executable(some_exe ${srcs}) 34 | # target_link_libraries(some_exe ${libs}) 35 | # 36 | # Any binary packages created from such a build should be self-contained 37 | # and provide working installs on vanilla OS X systems. 38 | 39 | macro (ChangeMacInstallNames libListVar) 40 | if (APPLE) 41 | find_program(INSTALL_NAME_TOOL install_name_tool) 42 | 43 | set(MAC_INSTALL_NAME_DEPS) 44 | set(SUPPORT_BIN_DIR ${Zeek_BINARY_DIR}/darwin_support_libs) 45 | set(SUPPORT_INSTALL_DIR support_libs) 46 | 47 | file(MAKE_DIRECTORY ${SUPPORT_BIN_DIR}) 48 | 49 | foreach (_lib ${${libListVar}}) 50 | # only care about install_name for shared libraries that are 51 | # not shipped in Apple's vanilla OS X installs 52 | string(REGEX MATCH ^/usr/lib/* apple_provided_lib ${_lib}) 53 | string(REGEX MATCH dylib$ is_shared_lib ${_lib}) 54 | 55 | if (NOT apple_provided_lib AND is_shared_lib) 56 | get_filename_component(_libname ${_lib} NAME) 57 | set(_adjustedLib ${SUPPORT_BIN_DIR}/${_libname}) 58 | set(_tmpLib ${Zeek_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}) 59 | 60 | # make a tempory copy so we can adjust permissions 61 | configure_file(${_lib} ${_tmpLib} COPYONLY) 62 | 63 | # copy to build directory with correct write permissions 64 | file(COPY ${_tmpLib} DESTINATION ${SUPPORT_BIN_DIR} 65 | FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) 66 | 67 | # remove the old library from the list provided as macro 68 | # argument and add the new library with modified install_name 69 | list(REMOVE_ITEM ${libListVar} ${_lib}) 70 | list(APPEND ${libListVar} ${_adjustedLib}) 71 | 72 | # update the install target to install the third party libs 73 | # with modified install_name 74 | install(FILES ${_adjustedLib} DESTINATION ${SUPPORT_INSTALL_DIR}) 75 | 76 | # perform the install_name change 77 | execute_process( 78 | COMMAND install_name_tool -id 79 | @executable_path/../${SUPPORT_INSTALL_DIR}/${_libname} ${_adjustedLib}) 80 | endif () 81 | endforeach () 82 | endif () 83 | endmacro () 84 | -------------------------------------------------------------------------------- /BinPAC.cmake: -------------------------------------------------------------------------------- 1 | if (NOT TARGET Zeek::BinPAC) 2 | message(FATAL_ERROR "BinPAC.cmake needs Zeek::BinPAC") 3 | endif () 4 | 5 | # A macro to define a command that uses the BinPac compiler to 6 | # produce C++ code that implements a protocol parser/analyzer. 7 | # The outputs are returned in BINPAC_OUTPUT_{CC,H}. 8 | # Additional dependencies are pulled from BINPAC_AUXSRC. 9 | function (binpac_target pacFile) 10 | 11 | set(BinPAC_addl_args "") 12 | 13 | if (ZEEK_PLUGIN_INTERNAL_BUILD) 14 | # Ensure that for plugins included via --include-plugins, the Zeek's 15 | # source tree paths are added to binpac's include path as well. 16 | set(BinPAC_addl_args 17 | "-I;${CMAKE_SOURCE_DIR};-I;${CMAKE_SOURCE_DIR}/src;-I;${CMAKE_SOURCE_DIR}/src/include") 18 | # Add a dependency on the target when building Zeek to make sure the 19 | # executable actually exists. 20 | set(binpacDep Zeek::BinPAC) 21 | endif () 22 | 23 | # Add ZEEK_SOURCE_DIR and ZEEK_SOURCE_DIR/src to BinPAC_addl_args. This 24 | # variable is defined in the main CMake file. 25 | if (ZEEK_SOURCE_DIR) 26 | list(APPEND BinPAC_addl_args -I "${ZEEK_SOURCE_DIR}" -I "${ZEEK_SOURCE_DIR}/src") 27 | endif () 28 | 29 | # Add ZEEK_CMAKE_INSTALL_PREFIX to BinPAC_addl_args if it exists. This 30 | # variable is present when loading ZeekPlugin.cmake. 31 | if (ZEEK_CMAKE_INSTALL_PREFIX) 32 | list(APPEND BinPAC_addl_args -I "${ZEEK_CMAKE_INSTALL_PREFIX}/include") 33 | endif () 34 | 35 | # Add BinPAC_INCLUDE_DIR to BinPAC_addl_args if it exists. This variable is 36 | # present when finding BinPAC via FindBinPAC.cmake. 37 | if (BinPAC_INCLUDE_DIR) 38 | # Note: this variable may be a list. 39 | foreach (dir ${BinPAC_INCLUDE_DIR}) 40 | list(APPEND BinPAC_addl_args -I "${dir}") 41 | endforeach () 42 | endif () 43 | 44 | get_filename_component(basename ${pacFile} NAME_WE) 45 | set(pacBaseName "${CMAKE_CURRENT_BINARY_DIR}/${basename}") 46 | set(hdr_file ${pacBaseName}_pac.h) 47 | set(src_file ${pacBaseName}_pac.cc) 48 | 49 | if (NOT MSVC) 50 | set_property(SOURCE ${src_file} APPEND_STRING PROPERTY COMPILE_FLAGS 51 | "-Wno-tautological-compare") 52 | endif () 53 | 54 | set(target "pac-${CMAKE_CURRENT_BINARY_DIR}/${pacFile}") 55 | 56 | # Make sure to escape a bunch of special characters in the path before trying to use it as a 57 | # regular expression below. 58 | string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_path "${PROJECT_BINARY_DIR}/src/") 59 | 60 | string(REGEX REPLACE "${escaped_path}" "" target "${target}") 61 | string(REGEX REPLACE "/" "-" target "${target}") 62 | string(REGEX REPLACE ":" "" target "${target}") 63 | add_custom_command( 64 | OUTPUT "${hdr_file}" "${src_file}" 65 | COMMAND 66 | Zeek::BinPAC -q -d ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} -I 67 | ${CMAKE_CURRENT_SOURCE_DIR}/src ${BinPAC_addl_args} 68 | ${CMAKE_CURRENT_SOURCE_DIR}/${pacFile} 69 | DEPENDS ${binpacDep} ${pacFile} ${BINPAC_AUXSRC} ${ARGN} 70 | COMMENT "[BINPAC] Processing ${CMAKE_CURRENT_SOURCE_DIR}/${pacFile}") 71 | add_custom_target(${target} DEPENDS "${hdr_file}" "${src_file}") 72 | 73 | # Make paths to generated visible at the caller. 74 | set(BINPAC_OUTPUT_H "${hdr_file}" PARENT_SCOPE) 75 | set(BINPAC_OUTPUT_CC "${src_file}" PARENT_SCOPE) 76 | 77 | # When building Zeek, this target bundles all auto-generated files. 78 | if (TARGET zeek_autogen_files) 79 | add_dependencies(zeek_autogen_files ${target}) 80 | endif () 81 | endfunction () 82 | -------------------------------------------------------------------------------- /FindPCAP.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libpcap include dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(PCAP) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # PCAP_ROOT_DIR Set this variable to the root installation of 11 | # libpcap if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # PCAP_FOUND System has libpcap, include and library dirs found 17 | # PCAP_INCLUDE_DIR The libpcap include directories. 18 | # PCAP_LIBRARY The libpcap library (possibly includes a thread 19 | # library e.g. required by pf_ring's libpcap) 20 | # HAVE_PF_RING If a found version of libpcap supports PF_RING 21 | 22 | find_path(PCAP_ROOT_DIR NAMES include/pcap.h Include/pcap.h) 23 | 24 | # If this is MSVC and a different root path was provided to cmake, add the vcpkg paths to 25 | # the list of ignored paths for the rest of this file. This prevents cmake from preferring 26 | # vcpkg over the path requested. 27 | set(_old_cmake_ignore_path ${CMAKE_IGNORE_PATH}) 28 | string(FIND "${PCAP_ROOT_DIR}" "vcpkg" _is_vcpkg_root) 29 | if (MSVC AND _is_vcpkg_root LESS 0) 30 | set(CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include) 31 | list(APPEND CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib) 32 | list(APPEND CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib) 33 | endif () 34 | 35 | find_path(PCAP_INCLUDE_DIR NAMES pcap.h HINTS ${PCAP_ROOT_DIR}/include ${PCAP_ROOT_DIR}/Include) 36 | 37 | if (MSVC AND COMPILER_ARCHITECTURE STREQUAL "x86_64") 38 | set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib/x64) 39 | else () 40 | set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib) 41 | endif () 42 | 43 | if (MSVC) 44 | find_library(PCAP_LIBRARY NAMES pcap_static wpcap HINTS ${_pcap_lib_hint_path}) 45 | else () 46 | find_library(PCAP_LIBRARY NAMES pcap wpcap HINTS ${_pcap_lib_hint_path}) 47 | endif () 48 | 49 | include(FindPackageHandleStandardArgs) 50 | find_package_handle_standard_args(PCAP DEFAULT_MSG PCAP_LIBRARY PCAP_INCLUDE_DIR) 51 | 52 | include(CheckCSourceCompiles) 53 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) 54 | check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) 55 | set(CMAKE_REQUIRED_LIBRARIES) 56 | 57 | # check if linking against libpcap also needs to link against a thread library 58 | if (NOT PCAP_LINKS_SOLO) 59 | find_package(Threads) 60 | if (THREADS_FOUND) 61 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) 62 | check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) 63 | set(CMAKE_REQUIRED_LIBRARIES) 64 | endif () 65 | if (THREADS_FOUND AND PCAP_NEEDS_THREADS) 66 | set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) 67 | list(REMOVE_DUPLICATES _tmp) 68 | set(PCAP_LIBRARY ${_tmp} CACHE STRING "Libraries needed to link against libpcap" FORCE) 69 | else () 70 | message(FATAL_ERROR "Couldn't determine how to link against libpcap") 71 | endif () 72 | endif () 73 | 74 | string(FIND "${PCAP_LIBRARY}" "wpcap" _pcap_lib_is_wpcap) 75 | if (_pcap_lib_is_wpcap GREATER_EQUAL 0) 76 | set(HAVE_WPCAP TRUE) 77 | endif () 78 | 79 | include(CheckFunctionExists) 80 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) 81 | check_function_exists(pcap_get_pfring_id HAVE_PF_RING) 82 | check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND) 83 | set(CMAKE_REQUIRED_LIBRARIES) 84 | 85 | mark_as_advanced(PCAP_ROOT_DIR PCAP_INCLUDE_DIR PCAP_LIBRARY) 86 | set(CMAKE_IGNORE_PATH ${_old_cmake_ignore_path}) 87 | -------------------------------------------------------------------------------- /ZeekPluginCommon.cmake: -------------------------------------------------------------------------------- 1 | ## A set of functions for defining Zeek plugins. 2 | ## 3 | ## This set is used by both static and dynamic plugins via 4 | ## ZeekPluginStatic and ZeekPluginDynamic, respectively. 5 | 6 | include(RequireCXXStd) 7 | 8 | # Begins a plugin definition, giving its namespace and name as the arguments. 9 | # The DISABLE_CPP_TESTS option disables unit test support. When not provided, 10 | # unit-testing is enabled when Zeek supports it, and disabled otherwise. 11 | macro (zeek_plugin_begin ns name) 12 | zeek_get_plugin_target(_plugin_lib ${ns} ${name}) 13 | if (ZEEK_PLUGIN_BUILD_DYNAMIC) 14 | add_library(${_plugin_lib} MODULE) 15 | else () 16 | add_library(${_plugin_lib} OBJECT) 17 | endif () 18 | set(_plugin_name "${ns}::${name}") 19 | set(_plugin_name_plain "${name}") 20 | set(_plugin_ns "${ns}") 21 | set(_plugin_cpp "") 22 | set(_plugin_dist "") 23 | set(_plugin_scripts "") 24 | set(_plugin_link_libs "") 25 | set(_plugin_bif_files "") 26 | set(_plugin_pac_args "") 27 | 28 | target_compile_features(${_plugin_lib} PRIVATE ${ZEEK_CXX_STD}) 29 | set_target_properties(${_plugin_lib} PROPERTIES CXX_EXTENSIONS OFF) 30 | endmacro () 31 | 32 | # Adds specified .zeek scripts to a plugin 33 | # scripts will be added to the distribution regardless of this 34 | # but adding them explicitly allows tracking changes in scripts 35 | # when building dist 36 | macro (zeek_plugin_scripts) 37 | list(APPEND _plugin_scripts ${ARGV}) 38 | endmacro () 39 | 40 | # Adds *.cc files to a plugin. 41 | macro (zeek_plugin_cc) 42 | list(APPEND _plugin_cpp ${ARGV}) 43 | endmacro () 44 | 45 | # Adds a *.pac file to a plugin. Further *.pac files may given that 46 | # it depends on. 47 | macro (zeek_plugin_pac) 48 | list(APPEND _plugin_pac_args PAC ${ARGN}) 49 | endmacro () 50 | 51 | # Add additional files that should be included into the binary plugin distribution. 52 | # Ignored for static plugins. 53 | macro (zeek_plugin_dist_files) 54 | list(APPEND _plugin_dist ${ARGV}) 55 | endmacro () 56 | 57 | # Link an additional library to the plugin's library. 58 | macro (zeek_plugin_link_library) 59 | list(APPEND _plugin_link_libs ${ARGV}) 60 | endmacro () 61 | 62 | # Adds *.bif files to a plugin. 63 | macro (zeek_plugin_bif) 64 | list(APPEND _plugin_bif_files ${ARGV}) 65 | endmacro () 66 | 67 | # Ends a plugin definition. 68 | macro (zeek_plugin_end) 69 | zeek_add_plugin( 70 | ${_plugin_ns} 71 | ${_plugin_name_plain} 72 | SOURCES 73 | ${_plugin_cpp} 74 | DEPENDENCIES 75 | ${_plugin_link_libs} 76 | BIFS 77 | ${_plugin_bif_files} 78 | DIST_FILES 79 | ${_plugin_dist} 80 | SCRIPT_FILES 81 | ${_plugin_scripts} 82 | ${_plugin_pac_args}) 83 | 84 | if (POLICY CMP0110) 85 | cmake_policy(SET CMP0110 NEW) 86 | endif () 87 | 88 | # Scan relevant files for TEST_CASE macros and generate CTest targets. 89 | # This is similar to the logic in Zeek's src/CMakeLists.txt. 90 | if (_plugin_cpp_tests) 91 | set(test_cases "") 92 | foreach (cc_file ${_plugin_cpp_test_sources}) 93 | file(STRINGS ${cc_file} test_case_lines REGEX "TEST_CASE") 94 | foreach (line ${test_case_lines}) 95 | string(REGEX REPLACE "TEST_CASE\\(\"(.+)\"\\)" "\\1" test_case "${line}") 96 | list(APPEND test_cases "${test_case}") 97 | endforeach () 98 | endforeach () 99 | list(LENGTH test_cases num_test_cases) 100 | if (${num_test_cases} GREATER 0) 101 | foreach (test_case ${test_cases}) 102 | add_test(NAME "${test_case}" COMMAND zeek --test "--test-case=${test_case}") 103 | endforeach () 104 | endif () 105 | endif () 106 | endmacro () 107 | 108 | # -- wrappers for legacy bro_* function names ---------------------------------- 109 | 110 | macro (bro_plugin_begin) 111 | message(DEPRECATION "please use zeek_add_plugin instead") 112 | zeek_plugin_begin(${ARGV}) 113 | endmacro () 114 | 115 | macro (bro_plugin_cc) 116 | zeek_plugin_cc(${ARGV}) 117 | endmacro () 118 | 119 | macro (bro_plugin_pac) 120 | zeek_plugin_pac(${ARGV}) 121 | endmacro () 122 | 123 | macro (bro_plugin_dist_files) 124 | zeek_plugin_dist_files(${ARGV}) 125 | endmacro () 126 | 127 | macro (bro_plugin_link_library) 128 | zeek_plugin_link_library(${ARGV}) 129 | endmacro () 130 | 131 | macro (bro_plugin_bif) 132 | zeek_plugin_bif(${ARGV}) 133 | endmacro () 134 | 135 | macro (bro_plugin_end) 136 | zeek_plugin_end(${ARGV}) 137 | endmacro () 138 | -------------------------------------------------------------------------------- /FindZeek.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. 2 | # 3 | # CMake helpers to find Zeek and build Zeek plugins. 4 | # 5 | # To have this find Zeek, either set PATH to contain zeek-config, set 6 | # ZEEK_ROOT_DIR to the Zeek installation, or set ZEEK_CONFIG to the binary. 7 | # 8 | # Output: 9 | # ZEEK_FOUND true if Zeek has been found 10 | # 11 | # If ZEEK_FOUND is true: 12 | # 13 | # ZEEK_CONFIG Path to Zeek configuration. 14 | # ZEEK_CXX_FLAGS C++ flags to compile a Zeek plugin. 15 | # ZEEK_CMAKE_DIR Path to Zeek's CMake files. 16 | # ZEEK_INCLUDE_DIRS Path to Zeek's headers. 17 | # ZEEK_PLUGIN_DIR Path to Zeek's plugin directory. 18 | # ZEEK_PREFIX Path to Zeek's installation prefix. 19 | # ZEEK_VERSION Version string of Zeek. 20 | # ZEEK_VERSION_NUMBER Numerical version of Zeek. 21 | # ZEEK_DEBUG_BUILD true if Zeek was build in debug mode 22 | # ZEEK_EXE Path to zeek executale 23 | # BifCl_EXE Path to bifcl 24 | 25 | ### Functions 26 | 27 | # Configure build against Zeek. 28 | macro (configure) 29 | if (ZEEK_PLUGIN_INTERNAL_BUILD) 30 | configure_static_build_inside_zeek() 31 | else () 32 | configure_standard_build() 33 | endif () 34 | 35 | if ("${ZEEK_BUILD_TYPE}" STREQUAL "debug") 36 | set(ZEEK_DEBUG_BUILD yes) 37 | else () 38 | set(ZEEK_DEBUG_BUILD no) 39 | endif () 40 | endmacro () 41 | 42 | # Checks that the Zeek version it at least the given version. 43 | function (zeek_require_version version) 44 | string(REGEX MATCH "([0-9]*)\.([0-9]*)\.([0-9]*).*" _ ${version}) 45 | math(EXPR version_number "${CMAKE_MATCH_1} * 10000 + ${CMAKE_MATCH_2} * 100 + ${CMAKE_MATCH_3}") 46 | if ("${ZEEK_VERSION_NUMBER}" LESS "${version_number}") 47 | message( 48 | FATAL_ERROR "Package requires at least Zeek version ${version}, have ${ZEEK_VERSION}") 49 | endif () 50 | endfunction () 51 | 52 | # Runs `zeek-config` and stores its result in the given output variable. 53 | function (run_zeek_config output) 54 | execute_process(COMMAND "${zeek_config}" ${ARGN} OUTPUT_VARIABLE output_ 55 | OUTPUT_STRIP_TRAILING_WHITESPACE) 56 | set(${output} "${output_}" PARENT_SCOPE) 57 | endfunction () 58 | 59 | # Prints a summary of detected Zeek. 60 | function (zeek_print_summary) 61 | message("\n====================| Spicy-side Zeek Installation Summary |====================" 62 | "\n" "\nFound Zeek: ${HAVE_ZEEK}") 63 | 64 | if (HAVE_ZEEK) 65 | message("\nVersion: ${ZEEK_VERSION} (${ZEEK_VERSION_NUMBER})" 66 | "\nPrefix: ${ZEEK_PREFIX}" 67 | "\nBuild type: ${ZEEK_BUILD_TYPE}") 68 | else () 69 | message("\n Make sure zeek-config is in your PATH, or set ZEEK_CONFIG to its location.") 70 | endif () 71 | 72 | message("\n========================================================================\n") 73 | endfunction () 74 | 75 | ### Main 76 | 77 | ### Find zeek-config 78 | if (NOT ZEEK_CONFIG) 79 | set(ZEEK_CONFIG "$ENV{ZEEK_CONFIG}") 80 | endif () 81 | 82 | if (ZEEK_CONFIG) 83 | if (EXISTS "${ZEEK_CONFIG}") 84 | set(zeek_config "${ZEEK_CONFIG}") 85 | else () 86 | message(STATUS "'${ZEEK_CONFIG}' does not exist") 87 | endif () 88 | else () 89 | find_program(zeek_config zeek-config HINTS ${ZEEK_ROOT_DIR}/bin $ENV{ZEEK_ROOT_DIR}/bin 90 | /usr/local/zeek/bin /usr/local/bro/bin) 91 | endif () 92 | 93 | if (NOT zeek_config) 94 | message(STATUS "Cannot determine location of Zeek installation") 95 | set(HAVE_ZEEK no) 96 | else () 97 | message(STATUS "Found zeek-config: ${zeek_config}") 98 | set(HAVE_ZEEK yes) 99 | set(ZEEK_CONFIG "${zeek_config}" CACHE FILEPATH "" FORCE) 100 | 101 | ### Determine properties. 102 | 103 | run_zeek_config(ZEEK_INCLUDE_DIRS "--include_dir") 104 | run_zeek_config(ZEEK_CMAKE_DIR "--cmake_dir") 105 | run_zeek_config(ZEEK_PREFIX "--prefix") 106 | run_zeek_config(ZEEK_PLUGIN_DIR "--plugin_dir") 107 | run_zeek_config(ZEEK_VERSION "--version") 108 | run_zeek_config(ZEEK_BUILD_TYPE "--build_type") 109 | 110 | string(REPLACE ":" ";" ZEEK_INCLUDE_DIRS "${ZEEK_INCLUDE_DIRS}") 111 | 112 | # Copied from Zeek to generate numeric version number. 113 | string(REGEX REPLACE "[.-]" " " version_numbers "${ZEEK_VERSION}") 114 | # cmake-lint: disable=E1120 115 | separate_arguments(version_numbers) 116 | list(GET version_numbers 0 VERSION_MAJOR) 117 | list(GET version_numbers 1 VERSION_MINOR) 118 | list(GET version_numbers 2 VERSION_PATCH) 119 | set(VERSION_MAJ_MIN "${VERSION_MAJOR}.${VERSION_MINOR}") 120 | math(EXPR ZEEK_VERSION_NUMBER 121 | "${VERSION_MAJOR} * 10000 + ${VERSION_MINOR} * 100 + ${VERSION_PATCH}") 122 | 123 | find_program(BifCl_EXE bifcl HINTS ${ZEEK_PREFIX}/bin NO_DEFAULT_PATH) 124 | find_program(ZEEK_EXE zeek HINTS ${ZEEK_PREFIX}/bin NO_DEFAULT_PATH) 125 | 126 | if (ZEEK_EXE) 127 | get_filename_component(ZEEK_ROOT_DIR ${ZEEK_EXE} PATH) 128 | get_filename_component(ZEEK_ROOT_DIR ${ZEEK_ROOT_DIR} PATH) 129 | endif () 130 | endif () 131 | 132 | include(FindPackageHandleStandardArgs) 133 | find_package_handle_standard_args(Zeek DEFAULT_MSG HAVE_ZEEK) 134 | 135 | set(ZEEK_FOUND "${ZEEK_FOUND}" CACHE BOOL "") 136 | mark_as_advanced(ZEEK_FOUND) 137 | mark_as_advanced(ZEEK_ROOT_DIR) 138 | -------------------------------------------------------------------------------- /ZeekBundle.cmake: -------------------------------------------------------------------------------- 1 | # CMake dependencies. 2 | include(FetchContent) 3 | 4 | # Users may override this path to place the compiled packages elsewhere. 5 | set(ZEEK_BUNDLE_PREFIX "${PROJECT_BINARY_DIR}/zeek-bundle" 6 | CACHE STRING "Path to the Zeek packages cache directory") 7 | 8 | # Opt-in to changed CMake behavior for fetching ZIP files. 9 | if (POLICY CMP0135) 10 | cmake_policy(SET CMP0135 NEW) 11 | endif () 12 | 13 | # Tries to find a package in the Zeek package cache. 14 | function (ZeekBundle_Find name) 15 | find_package(${name} CONFIG QUIET NO_DEFAULT_PATH HINTS ${ZEEK_BUNDLE_PREFIX}) 16 | if (${name}_FOUND) 17 | set(ZeekBundle_FOUND ON PARENT_SCOPE) 18 | else () 19 | set(ZeekBundle_FOUND OFF PARENT_SCOPE) 20 | endif () 21 | endfunction () 22 | 23 | # Runs the build and install steps for an external project. 24 | function (ZeekBundle_BuildStep name type binDir) 25 | # Build the external project. 26 | message(STATUS "Building bundled project: ${name} as ${type}") 27 | execute_process( 28 | COMMAND "${CMAKE_COMMAND}" --build "${binDir}" --config ${type} 29 | OUTPUT_FILE "${binDir}/build${type}.out" 30 | ERROR_FILE "${binDir}/build${type}.err" 31 | RESULT_VARIABLE buildResult) 32 | if (NOT buildResult EQUAL 0) 33 | file(READ "${binDir}/build${type}.err" cmakeErr) 34 | message(FATAL_ERROR "Failed to build ${name}:\n\n${cmakeErr}") 35 | endif () 36 | # Install the external project. 37 | message(STATUS "Installing bundled project: ${name} as ${type}") 38 | execute_process( 39 | COMMAND "${CMAKE_COMMAND}" --build "${binDir}" --config ${type} --target install 40 | OUTPUT_FILE "${binDir}/install${type}.out" 41 | ERROR_FILE "${binDir}/install${type}.err" 42 | RESULT_VARIABLE installResult) 43 | if (NOT installResult EQUAL 0) 44 | file(READ "${binDir}/install${type}.err" cmakeErr) 45 | message(FATAL_ERROR "Failed to install ${name}:\n\n${cmakeErr}") 46 | endif () 47 | endfunction () 48 | 49 | # Builds an external project at configure time. 50 | function (ZeekBundle_Build name srcDir binDir) 51 | # Extra arguments are passed as CMake options to the external project. 52 | set(cmakeArgs "") 53 | foreach (arg IN LISTS ARGN) 54 | list(APPEND cmakeArgs "-D${arg}") 55 | endforeach () 56 | # Make sure we can build debug and release versions of the project separately. 57 | list(APPEND cmakeArgs "-DCMAKE_DEBUG_POSTFIX=d") 58 | # Run CMake for the external project. 59 | message(STATUS "Configuring bundled project: ${name}") 60 | execute_process( 61 | COMMAND 62 | "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" ${cmakeArgs} -DBUILD_SHARED_LIBS=OFF 63 | -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DENABLE_TESTING=OFF 64 | "-DCMAKE_INSTALL_PREFIX=${ZEEK_BUNDLE_PREFIX}" "${srcDir}" 65 | WORKING_DIRECTORY "${binDir}" 66 | OUTPUT_FILE "${binDir}/cmake.out" 67 | ERROR_FILE "${binDir}/cmake.err" 68 | RESULT_VARIABLE cmakeResult) 69 | if (NOT cmakeResult EQUAL 0) 70 | file(READ "${binDir}/cmake.err" cmakeErr) 71 | message(FATAL_ERROR "Failed to configure external project ${name}:\n\n${cmakeErr}") 72 | endif () 73 | get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 74 | if (isMultiConfig) 75 | zeekbundle_buildstep(${name} Debug ${binDir}) 76 | zeekbundle_buildstep(${name} Release ${binDir}) 77 | else () 78 | # On Windows, we cannot mix debug and release libraries. 79 | if (WIN32) 80 | zeekbundle_buildstep(${name} ${CMAKE_BUILD_TYPE} ${binDir}) 81 | else () 82 | zeekbundle_buildstep(${name} Release ${binDir}) 83 | endif () 84 | endif () 85 | 86 | endfunction () 87 | 88 | # Adds a bundled package to Zeek. 89 | # 90 | # Usage: 91 | # ZeekBundle_Add( 92 | # NAME 93 | # FETCH (URL | GIT_REPOSITORY GIT_TAG | SOURCE_DIR ) 94 | # [CONFIGURE ] 95 | # ) 96 | function (ZeekBundle_Add) 97 | # Parse the function arguments. 98 | cmake_parse_arguments(arg "" "NAME" "FETCH;CONFIGURE" ${ARGN}) 99 | if (NOT arg_NAME) 100 | message(FATAL_ERROR "ZeekBundle_Add: mandatory argument NAME is missing!") 101 | endif () 102 | if (NOT arg_FETCH) 103 | message(FATAL_ERROR "ZeekBundle_Add: mandatory argument FETCH is missing!") 104 | endif () 105 | # Use find_package if the user explicitly requested the package. 106 | if (DEFINED ${arg_NAME}_ROOT) 107 | message(STATUS "ZeekBundle: use system library for ${arg_NAME}") 108 | find_package( 109 | ${arg_NAME} 110 | CONFIG 111 | QUIET 112 | REQUIRED 113 | NO_DEFAULT_PATH 114 | PATHS 115 | ${${arg_NAME}_ROOT}) 116 | return() 117 | endif () 118 | # Check if we already have the package. 119 | zeekbundle_find(${arg_NAME}) 120 | if (ZeekBundle_FOUND) 121 | return() 122 | endif () 123 | # Fetch the package by delegating to FetchContent. 124 | FetchContent_Declare(dl_${arg_NAME} ${arg_FETCH}) 125 | string(TOLOWER "dl_${arg_NAME}" internalName) 126 | FetchContent_Populate(${internalName} SOURCE_DIR ${arg_FETCH}) 127 | file(MAKE_DIRECTORY "${${internalName}_BINARY_DIR}") 128 | # Build the package and verify that it was found. 129 | zeekbundle_build(${arg_NAME} "${${internalName}_SOURCE_DIR}" "${${internalName}_BINARY_DIR}" 130 | ${arg_CONFIGURE}) 131 | find_package( 132 | ${arg_NAME} 133 | CONFIG 134 | QUIET 135 | REQUIRED 136 | NO_DEFAULT_PATH 137 | PATHS 138 | ${ZEEK_BUNDLE_PREFIX}) 139 | endfunction () 140 | -------------------------------------------------------------------------------- /FindKqueue.cmake: -------------------------------------------------------------------------------- 1 | include(CheckFunctionExists) 2 | 3 | # First check whether the system has kqueue built-in. Prefer that over everything else. 4 | check_function_exists(kqueue HAVE_KQUEUE) 5 | 6 | if (NOT HAVE_KQUEUE) 7 | 8 | # If the user passed in a path for libkqueue, see if we can find a copy of it there. 9 | # If they didn't pass one, build our local copy of it. 10 | if (LIBKQUEUE_ROOT_DIR) 11 | 12 | find_path(LIBKQUEUE_ROOT_DIR NAMES "include/sys/event.h") 13 | 14 | # Prefer linking statically but look for a shared library version too. 15 | find_library( 16 | LIBKQUEUE_LIBRARIES NAMES "libkqueue${CMAKE_STATIC_LIBRARY_SUFFIX}" 17 | "libkqueue${CMAKE_SHARED_LIBRARY_SUFFIX}" 18 | HINTS ${LIBKQUEUE_ROOT_DIR}/lib) 19 | 20 | find_path(LIBKQUEUE_INCLUDE_DIRS NAMES "sys/event.h" 21 | HINTS ${LIBKQUEUE_ROOT_DIR}/include/kqueue) 22 | 23 | include(FindPackageHandleStandardArgs) 24 | find_package_handle_standard_args(LIBKQUEUE DEFAULT_MSG LIBKQUEUE_LIBRARIES 25 | LIBKQUEUE_INCLUDE_DIRS) 26 | 27 | mark_as_advanced(LIBKQUEUE_ROOT_DIR LIBKQUEUE_LIBRARIES LIBKQUEUE_INCLUDE_DIRS) 28 | 29 | set(HAVE_KQUEUE true) 30 | else () 31 | 32 | set(kqueue_build "${CMAKE_CURRENT_BINARY_DIR}/libkqueue-build") 33 | set(kqueue_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/libkqueue") 34 | set(kqueue_ep "${CMAKE_CURRENT_BINARY_DIR}/libkqueue-ep") 35 | 36 | if (MSVC) 37 | set(LIBKQUEUE_NAME "kqueue_static") 38 | set(WIN_CONFIG -DCMAKE_POLICY_DEFAULT_CMP0091=NEW 39 | -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}) 40 | set(kqueue_static_lib 41 | "${kqueue_build}/kqueueStatic/${LIBKQUEUE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") 42 | else () 43 | set(LIBKQUEUE_NAME "libkqueue") 44 | set(kqueue_static_lib "${kqueue_build}/${LIBKQUEUE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") 45 | endif () 46 | 47 | include(ExternalProject) 48 | 49 | if (${CMAKE_VERSION} VERSION_LESS "3.2.0") 50 | # Build byproducts is just required by the Ninja generator 51 | # though it's not available before CMake 3.2 ... 52 | if (${CMAKE_GENERATOR} STREQUAL Ninja) 53 | message(FATAL_ERROR "Ninja generator requires CMake >= 3.2") 54 | endif () 55 | 56 | set(build_byproducts_arg) 57 | else () 58 | set(build_byproducts_arg BUILD_BYPRODUCTS ${kqueue_static_lib}) 59 | endif () 60 | 61 | ExternalProject_Add( 62 | project_kqueue 63 | PREFIX "${kqueue_ep}" 64 | BINARY_DIR "${kqueue_build}" 65 | DOWNLOAD_COMMAND "" 66 | CONFIGURE_COMMAND "" 67 | BUILD_COMMAND "" 68 | INSTALL_COMMAND "" ${build_byproducts_arg}) 69 | 70 | if (${CMAKE_VERSION} VERSION_LESS "3.4.0") 71 | set(use_terminal_arg) 72 | else () 73 | set(use_terminal_arg USES_TERMINAL 1) 74 | endif () 75 | 76 | ExternalProject_Add_Step( 77 | project_kqueue project_kqueue_build_step 78 | COMMAND ${CMAKE_MAKE_PROGRAM} 79 | COMMENT "Building libkqueue" 80 | WORKING_DIRECTORY ${kqueue_build} 81 | ALWAYS 1 82 | ${use_terminal_arg}) 83 | 84 | if (CMAKE_TOOLCHAIN_FILE) 85 | set(toolchain_arg -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) 86 | else () 87 | set(toolchain_arg) 88 | endif () 89 | 90 | if (CMAKE_C_COMPILER_LAUNCHER) 91 | set(cmake_c_compiler_launcher_arg 92 | -DCMAKE_C_COMPILER_LAUNCHER:path=${CMAKE_C_COMPILER_LAUNCHER}) 93 | else () 94 | set(cmake_c_compiler_launcher_arg) 95 | endif () 96 | 97 | if (CMAKE_CXX_COMPILER_LAUNCHER) 98 | set(cmake_cxx_compiler_launcher_arg 99 | -DCMAKE_CXX_COMPILER_LAUNCHER:path=${CMAKE_CXX_COMPILER_LAUNCHER}) 100 | else () 101 | set(cmake_cxx_compiler_launcher_arg) 102 | endif () 103 | 104 | execute_process( 105 | COMMAND 106 | ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${toolchain_arg} 107 | ${cmake_c_compiler_launcher_arg} ${cmake_cxx_compiler_launcher_arg} 108 | -DCMAKE_BUILD_TYPE:string=${CMAKE_BUILD_TYPE} ${WIN_CONFIG} ${kqueue_src} 109 | WORKING_DIRECTORY ${kqueue_build} 110 | RESULT_VARIABLE kqueue_cmake_result 111 | ERROR_VARIABLE KQUEUE_CMAKE_OUTPUT 112 | OUTPUT_VARIABLE KQUEUE_CMAKE_OUTPUT 113 | ERROR_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE) 114 | 115 | message("\n********** Begin libkqueue External Project CMake Output ************") 116 | message("\n${KQUEUE_CMAKE_OUTPUT}") 117 | message("\n*********** End libkqueue External Project CMake Output *************") 118 | message("\n") 119 | 120 | if (kqueue_cmake_result) 121 | message(FATAL_ERROR "libkqueue CMake configuration failed") 122 | endif () 123 | 124 | add_library(libkqueue_a STATIC IMPORTED) 125 | set_property(TARGET libkqueue_a PROPERTY IMPORTED_LOCATION ${kqueue_static_lib}) 126 | add_dependencies(libkqueue_a project_kqueue) 127 | 128 | set(HAVE_KQUEUE true) 129 | set(LIBKQUEUE_LIBRARIES libkqueue_a CACHE STRING "libkqueue libs" FORCE) 130 | set(LIBKQUEUE_INCLUDE_DIRS "${kqueue_src}/include;${kqueue_build}/include" 131 | CACHE INTERNAL "libkqueue includes" FORCE) 132 | endif () 133 | endif () 134 | 135 | if (NOT HAVE_KQUEUE) 136 | message(FATAL_ERROR "Failed to find a working version of kqueue.") 137 | endif () 138 | -------------------------------------------------------------------------------- /FindPythonDev.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Python include dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(PythonDev) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # PYTHON_EXECUTABLE If this is set to a path to a Python interpreter 11 | # then this module attempts to infer the path to 12 | # python-config from it 13 | # PYTHON_CONFIG Set this variable to the location of python-config 14 | # if the module has problems finding the proper 15 | # installation path. 16 | # 17 | # Variables defined by this module: 18 | # 19 | # PYTHONDEV_FOUND System has Python dev headers/libraries 20 | # PYTHON_INCLUDE_DIR The Python include directories. 21 | # PYTHON_LIBRARIES The Python libraries and linker flags. 22 | 23 | include(FindPackageHandleStandardArgs) 24 | 25 | if (CMAKE_CROSSCOMPILING) 26 | find_package(PythonLibs) 27 | if (PYTHON_INCLUDE_PATH AND NOT PYTHON_INCLUDE_DIR) 28 | set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}") 29 | endif () 30 | find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_INCLUDE_DIR PYTHON_LIBRARIES) 31 | 32 | return() 33 | endif () 34 | 35 | if (PYTHON_EXECUTABLE) 36 | # Get the real path so that we can reliably find the correct python-config 37 | # (e.g. some systems may have a "python" symlink, but not a "python-config" 38 | # symlink). 39 | get_filename_component(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}" REALPATH) 40 | get_filename_component(PYTHON_EXECUTABLE_DIR "${PYTHON_EXECUTABLE}" DIRECTORY) 41 | get_filename_component(PYTHON_EXECUTABLE_NAME "${PYTHON_EXECUTABLE}" NAME) 42 | 43 | if (EXISTS ${PYTHON_EXECUTABLE}-config) 44 | set(PYTHON_CONFIG ${PYTHON_EXECUTABLE}-config CACHE PATH "" FORCE) 45 | # Avoid assumption that python-config is associated with python3 if 46 | # python3 co-exists in a directory that also contains python2 stuff 47 | elseif ( 48 | EXISTS ${PYTHON_EXECUTABLE_DIR}/python-config 49 | AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2 50 | AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2.7 51 | AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2-config 52 | AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2.7-config) 53 | set(PYTHON_CONFIG ${PYTHON_EXECUTABLE_DIR}/python-config CACHE PATH "" FORCE) 54 | endif () 55 | else () 56 | find_program( 57 | PYTHON_CONFIG 58 | NAMES python3-config 59 | python3.11-config 60 | python3.10-config 61 | python3.9-config 62 | python3.8-config 63 | python3.7-config 64 | python-config) 65 | endif () 66 | 67 | # The OpenBSD python packages have python-config's that don't reliably 68 | # report linking flags that will work. 69 | if (PYTHON_CONFIG AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") 70 | # Try `--ldflags --embed` first and fallback to `--ldflags` if it fails. 71 | # Python 3.8+ introduced the `--embed` flag in relation to this: 72 | # https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build 73 | # Note that even if this FindPythonDev script could technically apply to 74 | # either embedded or extension use cases, the `--embed` flag only adds 75 | # a `-lpython` and it's generally safe to link libpython in both cases. 76 | # The only downside to doing that against an extension when it's not 77 | # strictly necessary is losing the ability to mix-and-match debug/release 78 | # modes between Python and extensions and that's not a feature to typically 79 | # care about. 80 | execute_process( 81 | COMMAND "${PYTHON_CONFIG}" --ldflags --embed 82 | RESULT_VARIABLE _python_config_result 83 | OUTPUT_VARIABLE PYTHON_LIBRARIES 84 | OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) 85 | 86 | if (NOT ${_python_config_result} EQUAL 0) 87 | execute_process( 88 | COMMAND "${PYTHON_CONFIG}" --ldflags 89 | RESULT_VARIABLE _python_config_result 90 | OUTPUT_VARIABLE PYTHON_LIBRARIES 91 | OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) 92 | endif () 93 | 94 | string(STRIP "${PYTHON_LIBRARIES}" PYTHON_LIBRARIES) 95 | 96 | execute_process(COMMAND "${PYTHON_CONFIG}" --includes OUTPUT_VARIABLE PYTHON_INCLUDE_DIR 97 | OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) 98 | 99 | string(REGEX REPLACE "^[-I]" "" PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}") 100 | string(REGEX REPLACE "[ ]-I" " " PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}") 101 | separate_arguments(PYTHON_INCLUDE_DIR) 102 | 103 | find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_CONFIG PYTHON_INCLUDE_DIR 104 | PYTHON_LIBRARIES) 105 | else () 106 | if (${CMAKE_VERSION} VERSION_LESS "3.12.0") 107 | find_package(PythonLibs) 108 | 109 | if (PYTHON_INCLUDE_PATH AND NOT PYTHON_INCLUDE_DIR) 110 | set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}") 111 | endif () 112 | else () 113 | # Expect this branch to be used mostly in macOS where the system 114 | # default Python 3 installation is not easily/consistently detected 115 | # by CMake. CMake 3.12+ is required, but it's expected that macOS 116 | # users are getting a recent version from homebrew/etc anyway. 117 | find_package(Python3 COMPONENTS Development) 118 | 119 | if (Python3_INCLUDE_DIRS AND NOT PYTHON_INCLUDE_DIR) 120 | set(PYTHON_INCLUDE_DIR "${Python3_INCLUDE_DIRS}") 121 | endif () 122 | 123 | if (Python3_LIBRARIES AND NOT PYTHON_LIBRARIES) 124 | set(PYTHON_LIBRARIES "${Python3_LIBRARIES}") 125 | endif () 126 | endif () 127 | 128 | find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_INCLUDE_DIR PYTHON_LIBRARIES) 129 | endif () 130 | -------------------------------------------------------------------------------- /BuiltInSpicyAnalyzer.cmake: -------------------------------------------------------------------------------- 1 | # Add target to build an analyzer. 2 | # 3 | # Usage: 4 | # 5 | # spicy_add_analyzer( 6 | # NAME 7 | # SOURCES ... 8 | # [MODULES ...] 9 | # ) 10 | # 11 | # `MODULES` can be used to specify which modules are part of this this 12 | # analyzer. If not specified, its values is assumed to be identical to `NAME`. 13 | 14 | set(ZEEK_LEGACY_ANALYZERS CACHE INTERNAL "") 15 | set(ZEEK_SKIPPED_ANALYZERS CACHE INTERNAL "") 16 | include(RequireCXXStd) 17 | 18 | # Force Spicy include directories to the front of the include paths. 19 | # 20 | # While in principal we could use normal CMake target-based dependencies to 21 | # inherit Spicy include directories if not building against an external Spicy, 22 | # this still only appends include directories to the end of the list of include 23 | # paths. This means that if any include prefix added before also contains 24 | # another Spicy installation (possible if e.g., a required dependency was 25 | # installed into a prefix which contains another Spicy installation) we prefer 26 | # picking up that one when searching for a Spicy header. This functions 27 | # explicitly pushes Spicy include directories to the front. 28 | function (prefer_configured_spicy_include_dirs target) 29 | # Nothing to do if we are building against an externally built Spicy. 30 | if (SPICY_ROOT_DIR) 31 | return() 32 | endif () 33 | 34 | foreach (_lib IN ITEMS hilti-rt-objects spicy-rt-objects hilti-objects spicy-objects) 35 | get_target_property(_inc_dirs ${_lib} INCLUDE_DIRECTORIES) 36 | target_include_directories(${target} BEFORE PRIVATE ${_inc_dirs}) 37 | endforeach () 38 | endfunction () 39 | 40 | function (spicy_add_analyzer) 41 | set(options) 42 | set(oneValueArgs NAME LEGACY) 43 | set(multiValueArgs SOURCES MODULES) 44 | 45 | cmake_parse_arguments(PARSE_ARGV 0 SPICY_ANALYZER "${options}" "${oneValueArgs}" 46 | "${multiValueArgs}") 47 | 48 | if (NOT DEFINED SPICY_ANALYZER_NAME) 49 | message(FATAL_ERROR "NAME is required") 50 | endif () 51 | 52 | if (USE_SPICY_ANALYZERS) 53 | set(SPICYZ_FLAGS "") 54 | string(TOLOWER "${SPICY_ANALYZER_NAME}" NAME_LOWER) 55 | 56 | set(generated_sources ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}___linker__.cc 57 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}_spicy_init.cc) 58 | 59 | # CXX files given to SOURCES are added to the lib target 60 | # separately from generated_sources. 61 | set(cxx_sources ${SPICY_ANALYZER_SOURCES}) 62 | list(FILTER cxx_sources INCLUDE REGEX ".*\.cc$") 63 | 64 | if (NOT DEFINED SPICY_ANALYZER_MODULES) 65 | list(APPEND generated_sources 66 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}_${SPICY_ANALYZER_NAME}.cc) 67 | list(APPEND generated_sources 68 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}_spicy_hooks_${SPICY_ANALYZER_NAME}.cc) 69 | else () 70 | foreach (module ${SPICY_ANALYZER_MODULES}) 71 | list(APPEND generated_sources 72 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}_${module}.cc) 73 | list(APPEND generated_sources 74 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER}_spicy_hooks_${module}.cc) 75 | endforeach () 76 | endif () 77 | 78 | if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.27") 79 | set_source_files_properties(${generated_sources} PROPERTIES SKIP_LINTING ON) 80 | endif () 81 | 82 | add_custom_command( 83 | OUTPUT ${generated_sources} 84 | DEPENDS ${SPICY_ANALYZER_SOURCES} spicyz 85 | COMMENT "Compiling ${SPICY_ANALYZER_NAME} analyzer" 86 | COMMAND 87 | ${CMAKE_COMMAND} -E env 88 | "ZEEK_SPICY_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/scripts/spicy" 89 | ASAN_OPTIONS=$ENV{ASAN_OPTIONS}:detect_leaks=0 $ -L 90 | ${spicy_SOURCE_DIR}/hilti/lib -L ${spicy_SOURCE_DIR}/spicy/lib -x 91 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME_LOWER} ${SPICYZ_FLAGS} ${SPICY_ANALYZER_SOURCES} 92 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 93 | 94 | set(lib "spicy_${SPICY_ANALYZER_NAME}") 95 | add_library(${lib} OBJECT ${generated_sources} ${cxx_sources}) 96 | target_compile_features(${lib} PRIVATE ${ZEEK_CXX_STD}) 97 | set_target_properties(${lib} PROPERTIES CXX_EXTENSIONS OFF) 98 | 99 | target_include_directories(${lib} PRIVATE ${SPICY_PLUGIN_PATH}/include 100 | ${SPICY_PLUGIN_BINARY_PATH}/include) 101 | target_compile_definitions(${lib} PRIVATE HILTI_MANUAL_PREINIT) 102 | target_link_libraries(${lib} hilti spicy $) 103 | prefer_configured_spicy_include_dirs(${lib}) 104 | 105 | # Feed into the main Zeek target(s). 106 | zeek_target_link_libraries(${lib}) 107 | 108 | if (SPICY_ROOT_DIR) 109 | target_include_directories(${lib} PRIVATE ${SPICY_ROOT_DIR}/include) 110 | endif () 111 | 112 | # Install Spicy grammars into a default search path of Spicy. 113 | # This allows users importing the file relatively easily. 114 | set(_SPIYC_SOURCES ${SPICY_ANALYZER_SOURCES}) 115 | list(FILTER _SPIYC_SOURCES INCLUDE REGEX "\.spicy$") 116 | install(FILES ${_SPIYC_SOURCES} DESTINATION ${CMAKE_INSTALL_DATADIR}/spicy/${NAME_LOWER}) 117 | 118 | elseif (SPICY_ANALYZER_LEGACY) 119 | message( 120 | STATUS 121 | "Warning: Using unmaintained legacy analyzer for ${SPICY_ANALYZER_NAME} because Spicy is not available" 122 | ) 123 | list(APPEND ZEEK_LEGACY_ANALYZERS "${SPICY_ANALYZER_NAME}") 124 | set(ZEEK_LEGACY_ANALYZERS "${ZEEK_LEGACY_ANALYZERS}" CACHE INTERNAL "") 125 | add_subdirectory(legacy) 126 | else () 127 | message( 128 | STATUS 129 | "Warning: Disabling analyzer for ${SPICY_ANALYZER_NAME} because Spicy is not available" 130 | ) 131 | list(APPEND ZEEK_SKIPPED_ANALYZERS "${SPICY_ANALYZER_NAME}") 132 | set(ZEEK_SKIPPED_ANALYZERS "${ZEEK_SKIPPED_ANALYZERS}" CACHE INTERNAL "") 133 | endif () 134 | 135 | endfunction () 136 | -------------------------------------------------------------------------------- /BifCl.cmake: -------------------------------------------------------------------------------- 1 | if (NOT TARGET Zeek::BifCl) 2 | message(FATAL_ERROR "BifCl.cmake needs Zeek::BifCl") 3 | endif () 4 | 5 | # A macro to define a command that uses the BIF compiler to produce C++ 6 | # segments and Zeek language declarations from a .bif file. The outputs 7 | # are returned in BIF_OUTPUT_{CC,H,BRO}. By default, it runs bifcl in 8 | # alternative mode (-a; suitable for standalone compilation). If 9 | # an additional parameter "standard" is given, it runs it in standard mode 10 | # for inclusion in NetVar.*. If an additional parameter "plugin" is given, 11 | # it runs it in plugin mode (-p). In the latter case, one more argument 12 | # is required with the plugin's name. 13 | # 14 | # The macro also creates a target that can be used to define depencencies on 15 | # the generated files. The name of the target depends on the mode and includes 16 | # a normalized path to the input bif to make it unique. The target is added 17 | # automatically to bro_ALL_GENERATED_OUTPUTS. 18 | macro (bif_target bifInput) 19 | set(target "") 20 | get_filename_component(bifInputBasename "${bifInput}" NAME) 21 | 22 | set(BRO_PLUGIN_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib") 23 | set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif") 24 | 25 | if ("${ARGV1}" STREQUAL "standard") 26 | set(bifcl_args "") 27 | set(target "bif-std-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}") 28 | set(bifOutputs 29 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_def 30 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_h 31 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_init 32 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_def 33 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_h 34 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_init) 35 | set(BIF_OUTPUT_CC ${bifInputBasename}.func_def ${bifInputBasename}.func_init 36 | ${bifInputBasename}.netvar_def ${bifInputBasename}.netvar_init) 37 | set(BIF_OUTPUT_H ${bifInputBasename}.func_h ${bifInputBasename}.netvar_h) 38 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) 39 | 40 | # Register this BIF in the base BIFs load script. 41 | file(APPEND "${CMAKE_BINARY_DIR}/scripts/base/bif/__load__.zeek" 42 | "@load ./${bifInputBasename}.zeek\n") 43 | 44 | elseif ("${ARGV1}" STREQUAL "plugin") 45 | set(plugin_name ${ARGV2}) 46 | set(plugin_name_canon ${ARGV3}) 47 | set(plugin_is_static ${ARGV4}) 48 | set(target "bif-plugin-${plugin_name_canon}-${bifInputBasename}") 49 | set(bifcl_args "-p;${plugin_name}") 50 | set(bifOutputs 51 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.h 52 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.cc 53 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.init.cc 54 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.register.cc) 55 | 56 | if (plugin_is_static) 57 | set(BIF_OUTPUT_CC ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.cc 58 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.init.cc) 59 | # Register the generated C++ files. 60 | file(APPEND "${CMAKE_BINARY_DIR}/src/__all__.bif.cc" 61 | "#include \"${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.register.cc\"\n") 62 | else () 63 | set(BIF_OUTPUT_CC 64 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.cc 65 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.init.cc 66 | ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.register.cc) 67 | endif () 68 | 69 | set(BIF_OUTPUT_H ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.h) 70 | 71 | if (NOT ZEEK_PLUGIN_BUILD_DYNAMIC) 72 | set(BIF_OUTPUT_BRO 73 | ${CMAKE_BINARY_DIR}/scripts/base/bif/plugins/${plugin_name_canon}.${bifInputBasename}.zeek 74 | ) 75 | # Register this BIF in the plugins BIFs load script. 76 | file(APPEND "${CMAKE_BINARY_DIR}/scripts/base/bif/plugins/__load__.zeek" 77 | "@load ./${plugin_name_canon}.${bifInputBasename}.zeek\n") 78 | else () 79 | set(BIF_OUTPUT_BRO ${BRO_PLUGIN_BIF}/${bifInputBasename}.zeek) 80 | endif () 81 | 82 | else () 83 | # Alternative mode. These will get compiled in automatically. 84 | set(bifcl_args "-s") 85 | set(target "bif-alt-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}") 86 | set(bifOutputs ${bifInputBasename}.h ${bifInputBasename}.cc ${bifInputBasename}.init.cc) 87 | set(BIF_OUTPUT_CC ${bifInputBasename}.cc) 88 | set(BIF_OUTPUT_H ${bifInputBasename}.h) 89 | 90 | # In order be able to run Zeek from the build directory, the 91 | # generated Zeek script needs to be inside a directory tree 92 | # named the same way it will be referenced from an @load. 93 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) 94 | 95 | # Register this BIF in the builtin-plugins BIFs load script. 96 | file(APPEND "${CMAKE_BINARY_DIR}/scripts/base/bif/__load__.zeek" 97 | "@load ./${bifInputBasename}.zeek\n") 98 | 99 | # Register the generated C++ files. 100 | file(APPEND "${CMAKE_BINARY_DIR}/src/__all__.bif.cc" 101 | "#include \"${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.cc\"\n") 102 | file(APPEND "${CMAKE_BINARY_DIR}/src/__all__.bif.init.cc" 103 | "#include \"${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.init.cc\"\n") 104 | 105 | endif () 106 | 107 | # Make sure to escape a bunch of special characters in the path before trying to use it as a 108 | # regular expression below. 109 | string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_path "${CMAKE_BINARY_DIR}/src/") 110 | 111 | string(REGEX REPLACE "${escaped_path}" "" target "${target}") 112 | string(REGEX REPLACE "/" "-" target "${target}") 113 | string(REGEX REPLACE ":" "" target "${target}") 114 | 115 | add_custom_command( 116 | OUTPUT ${bifOutputs} ${BIF_OUTPUT_BRO} 117 | COMMAND Zeek::BifCl ${bifcl_args} ${CMAKE_CURRENT_SOURCE_DIR}/${bifInput} 118 | COMMAND "${CMAKE_COMMAND}" -E copy ${bifInputBasename}.zeek ${BIF_OUTPUT_BRO} 119 | COMMAND "${CMAKE_COMMAND}" -E remove -f ${bifInputBasename}.zeek 120 | DEPENDS ${bifInput} Zeek::BifCl 121 | COMMENT "[BIFCL] Processing ${CMAKE_CURRENT_SOURCE_DIR}/${bifInput}") 122 | add_custom_target(${target} DEPENDS ${bifOutputs} ${BIF_OUTPUT_BRO}) 123 | 124 | if (ZEEK_PLUGIN_INTERNAL_BUILD) 125 | # Note: target is defined in Zeek's top-level CMake. 126 | add_dependencies(zeek_autogen_files ${target}) 127 | endif () 128 | endmacro (bif_target) 129 | -------------------------------------------------------------------------------- /ZeekPluginStatic.cmake: -------------------------------------------------------------------------------- 1 | include(BifCl) 2 | include(BinPAC) 3 | include(RequireCXXStd) 4 | 5 | # Sets `target` to contain the CMake target name for a static plugin. 6 | macro (zeek_get_static_plugin_target target ns name) 7 | set(${target} "plugin-${ns}-${name}") 8 | endmacro () 9 | 10 | # Implements the statically linked version of zeek_add_plugin. 11 | function (zeek_add_static_plugin ns name) 12 | # Helper variables. 13 | zeek_get_static_plugin_target(target_name ${ns} ${name}) 14 | set(full_name "${ns}::${name}") 15 | set(canon_name "${ns}_${name}") 16 | 17 | # Create the target if no begin function has been used. 18 | if (NOT TARGET ${target_name}) 19 | add_library(${target_name} OBJECT) 20 | 21 | target_compile_features(${target_name} PRIVATE ${ZEEK_CXX_STD}) 22 | set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF) 23 | endif () 24 | add_dependencies(${target_name} zeek_autogen_files) 25 | 26 | # Skip zeek-version.h when including zeek-config.h for statically build 27 | # plugins (they are always builtin) *except* if the current scope is tagged 28 | # with ZEEK_BUILDING_EXTRA_PLUGINS (this is the case when building plugins 29 | # from BUILTIN_PLUGIN_LIST). 30 | if (NOT ZEEK_BUILDING_EXTRA_PLUGINS) 31 | target_compile_definitions(${target_name} PRIVATE ZEEK_CONFIG_SKIP_VERSION_H) 32 | endif () 33 | 34 | # Parse arguments (note: DIST_FILES and SCRIPT_FILES are ignored in static builds). 35 | set(fn_varargs INCLUDE_DIRS DEPENDENCIES SOURCES BIFS DIST_FILES PAC) 36 | cmake_parse_arguments(FN_ARGS "" "" "${fn_varargs}" ${ARGN}) 37 | 38 | # Take care of compiling BIFs. 39 | if (FN_ARGS_BIFS) 40 | # Generate the targets and add the .cc files. 41 | foreach (bif ${FN_ARGS_BIFS}) 42 | bif_target(${bif} "plugin" ${full_name} ${canon_name} ON) 43 | target_sources(${target_name} PRIVATE ${BIF_OUTPUT_CC}) 44 | endforeach () 45 | endif () 46 | 47 | # Take care of PAC files. 48 | zeek_next_pac_block(at_end pacInputs pacRemainder ${ARGN}) 49 | while (NOT at_end) 50 | binpac_target(${pacInputs}) 51 | target_sources(${target_name} PRIVATE ${BINPAC_OUTPUT_CC}) 52 | zeek_next_pac_block(at_end pacInputs pacRemainder ${pacRemainder}) 53 | endwhile () 54 | 55 | if (BUILD_WITH_WERROR) 56 | if (MSVC) 57 | # TODO: This is disabled for now because there a bunch of known 58 | # compiler warnings on Windows that we don't have good fixes for. 59 | #set(WERROR_FLAG "/WX") 60 | else () 61 | set(WERROR_FLAG "-Werror") 62 | 63 | # With versions >=13.0 GCC gained `-Warray-bounds` which reports false 64 | # positives, see e.g., https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273. 65 | if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0) 66 | list(APPEND WERROR_FLAG "-Wno-error=array-bounds") 67 | endif () 68 | 69 | # With versions >=11.0 GCC is retruning false positives for -Wrestrict. See 70 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366. It's more prevalent 71 | # building with -std=c++20. 72 | if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0) 73 | list(APPEND WERROR_FLAG "-Wno-error=restrict") 74 | endif () 75 | endif () 76 | endif () 77 | 78 | # Pass compiler flags, paths and dependencies to the target. 79 | target_link_libraries(${target_name} PRIVATE $) 80 | target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 81 | target_compile_options(${target_name} PRIVATE ${WERROR_FLAG}) 82 | 83 | # Per convention, plugins have their headers and sources under src/ and 84 | # legacy/external plugins expect this to auto-magically be available as 85 | # include path. 86 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src) 87 | target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) 88 | endif () 89 | 90 | # Add user-defined extra include directories. If a path is outside of the current 91 | # project source dir, add it as a system path so that clang-tidy can easily ignore 92 | # it. 93 | if (FN_ARGS_INCLUDE_DIRS) 94 | foreach (_include_dir ${FN_ARGS_INCLUDE_DIRS}) 95 | # In CMake 3.20, this can use cmake_path(IS_PREFIX). 96 | string(FIND "${PROJECT_SOURCE_DIR}" "${_include_dir}" _is_project_prefixed) 97 | if (_is_project_prefixed EQUAL 0) 98 | target_include_directories(${target_name} PRIVATE ${_include_dir}) 99 | else () 100 | target_include_directories(${target_name} SYSTEM PRIVATE ${_include_dir}) 101 | endif () 102 | endforeach () 103 | endif () 104 | 105 | # Add extra dependencies. 106 | if (FN_ARGS_DEPENDENCIES) 107 | target_link_libraries(${target_name} PRIVATE ${FN_ARGS_DEPENDENCIES}) 108 | endif () 109 | 110 | # Add the sources for the plugin. 111 | if (FN_ARGS_SOURCES) 112 | target_sources(${target_name} PRIVATE ${FN_ARGS_SOURCES}) 113 | endif () 114 | 115 | # Setup for the load/preload scripts. 116 | set(preload_script ${canon_name}/__preload__.zeek) 117 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/__preload__.zeek) 118 | file(APPEND ${CMAKE_BINARY_DIR}/scripts/builtin-plugins/__preload__.zeek 119 | "\n@load ${preload_script}") 120 | endif () 121 | set(load_script ${canon_name}/__load__.zeek) 122 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/__load__.zeek) 123 | file(APPEND ${CMAKE_BINARY_DIR}/scripts/builtin-plugins/__load__.zeek 124 | "\n@load ${load_script}") 125 | endif () 126 | 127 | # Install the scripts. 128 | get_filename_component(plugin_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) 129 | if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scripts") 130 | install( 131 | DIRECTORY ./scripts/ 132 | DESTINATION "${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins/${canon_name}" 133 | FILES_MATCHING 134 | PATTERN "*.zeek" 135 | PATTERN "*.sig" 136 | PATTERN "*.fp") 137 | 138 | # Make a plugin directory and symlink the scripts directory into it 139 | # so that the development ZEEKPATH will work too. 140 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/scripts/builtin-plugins) 141 | execute_process( 142 | COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/scripts" 143 | "${CMAKE_BINARY_DIR}/scripts/builtin-plugins/${canon_name}") 144 | endif () 145 | 146 | # Feed into the main Zeek target(s). 147 | zeek_target_link_libraries(${target_name}) 148 | 149 | if (NOT ZEEK_BUILDING_EXTRA_PLUGINS) 150 | # Add IWYU and clang-tidy to the target if enabled. 151 | zeek_target_add_linters(${target_name}) 152 | endif () 153 | endfunction () 154 | -------------------------------------------------------------------------------- /ZeekSpicyAnalyzerSupport.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details. 2 | # 3 | # Helpers for building analyzers. This is can be included from analyzer packages. 4 | # 5 | # Needs SPICYZ to point to the "spicyz" binary in either CMake or environment. 6 | 7 | include(GNUInstallDirs) 8 | 9 | # Add target to build an analyzer. 10 | # 11 | # Usage: 12 | # 13 | # spicy_add_analyzer( 14 | # NAME 15 | # [SOURCES ...] 16 | # [PACKAGE_NAME ] 17 | # [SCRIPTS ...] 18 | # [CXX_LINK ...] 19 | # [ENV ...] 20 | # ) 21 | function (spicy_add_analyzer) 22 | set(options) 23 | set(oneValueArgs NAME PACKAGE_NAME) 24 | set(multiValueArgs ENV SOURCES SCRIPTS CXX_LINK) 25 | 26 | cmake_parse_arguments(PARSE_ARGV 0 SPICY_ANALYZER "${options}" "${oneValueArgs}" 27 | "${multiValueArgs}") 28 | 29 | # We also support the legacy behavior where the first arg is 30 | # the analyzer NAME and all remaining arguments are SOURCES. 31 | if (SPICY_ANALYZER_UNPARSED_ARGUMENTS) 32 | if (SPICY_ANALYZER_NAME OR SPICY_ANALYZER_SOURCES OR SPICY_ANALYZER_SCRIPTS) 33 | message(FATAL_ERROR "named an unnamed arguments cannot be mixed") 34 | endif () 35 | 36 | list(GET ARGN 0 SPICY_ANALYZER_NAME) 37 | list(POP_FRONT ARGN) 38 | 39 | set(SPICY_ANALYZER_SOURCES ${ARGN}) 40 | endif () 41 | 42 | if (NOT DEFINED SPICY_ANALYZER_NAME) 43 | message(FATAL_ERROR "NAME is required") 44 | endif () 45 | 46 | string(TOLOWER "${SPICY_ANALYZER_NAME}" NAME_LOWER) 47 | set(OUTPUT "${SPICY_MODULE_OUTPUT_DIR_BUILD}/${NAME_LOWER}.hlto") 48 | 49 | # list(TRANSFORM SPICY_ANALYZER_CXX_LINK PREPEND "--cxx-link ") 50 | foreach (cxx_link ${SPICY_ANALYZER_CXX_LINK}) 51 | list(APPEND CXX_LINK "--cxx-link") 52 | list(APPEND CXX_LINK ${cxx_link}) 53 | endforeach () 54 | 55 | # Create a link for backwards compatibility with older zkg packages. 56 | file(CREATE_LINK "." ${SPICY_MODULE_OUTPUT_DIR_BUILD}/spicy-modules SYMBOLIC) 57 | 58 | add_custom_command( 59 | OUTPUT ${OUTPUT} 60 | DEPENDS ${SPICY_ANALYZER_SOURCES} ${SPICYZ} ${SPICY_ANALYZER_CXX_LINK} 61 | COMMENT "Compiling ${SPICY_ANALYZER_NAME} analyzer" 62 | COMMAND 63 | ${CMAKE_COMMAND} -E env ASAN_OPTIONS=$ENV{ASAN_OPTIONS}:detect_leaks=0 64 | ${SPICY_ANALYZER_ENV} ${SPICYZ} -o ${OUTPUT} ${_SPICYZ_FLAGS} ${SPICY_ANALYZER_SOURCES} 65 | ${CXX_LINK} 66 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 67 | 68 | add_custom_target(${SPICY_ANALYZER_NAME} ALL DEPENDS ${OUTPUT} 69 | COMMENT "Preparing dependencies of ${SPICY_ANALYZER_NAME}") 70 | 71 | if (SPICY_MODULE_OUTPUT_DIR_INSTALL) 72 | install(FILES ${OUTPUT} DESTINATION "${SPICY_MODULE_OUTPUT_DIR_INSTALL}") 73 | endif () 74 | 75 | if (SPICY_SCRIPTS_OUTPUT_DIR_INSTALL AND DEFINED SPICY_ANALYZER_SCRIPTS) 76 | if (NOT DEFINED SPICY_ANALYZER_PACKAGE_NAME) 77 | message(FATAL_ERROR "SCRIPTS argument requires PACKAGE_NAME") 78 | endif () 79 | install( 80 | FILES ${SPICY_ANALYZER_SCRIPTS} 81 | DESTINATION 82 | "${SPICY_SCRIPTS_OUTPUT_DIR_INSTALL}/${SPICY_ANALYZER_PACKAGE_NAME}/${NAME_LOWER}") 83 | endif () 84 | 85 | get_property(tmp GLOBAL PROPERTY __spicy_included_analyzers) 86 | list(APPEND tmp "${SPICY_ANALYZER_NAME}") 87 | set_property(GLOBAL PROPERTY __spicy_included_analyzers "${tmp}") 88 | endfunction () 89 | 90 | # Flag that analyzer is *not* being built. This is purely informational: 91 | # the cmake output will contain a corresponding note. Arguments are the 92 | # name of the analyzers and a descriptive string explaining why it's 93 | # being skipped. 94 | function (spicy_skip_analyzer name reason) 95 | get_property(tmp GLOBAL PROPERTY __spicy_skipped_analyzers) 96 | list(APPEND tmp "${name} ${reason}") 97 | set_property(GLOBAL PROPERTY __spicy_skipped_analyzers "${tmp}") 98 | endfunction () 99 | 100 | # Prints a summary of configured analyzers. 101 | function (print_analyzers) 102 | message("\n======================| Spicy Analyzer Summary |======================") 103 | 104 | message( 105 | "\nspicy-config: ${SPICY_CONFIG}" 106 | "\nzeek-config: ${ZEEK_CONFIG}" 107 | "\nSpicy compiler: ${SPICYZ}" 108 | "\nModule directory: ${SPICY_MODULE_OUTPUT_DIR_INSTALL}" 109 | "\nScripts directory: ${SPICY_SCRIPTS_OUTPUT_DIR_INSTALL}" 110 | "\nPlugin version: " 111 | "${ZEEK_SPICY_PLUGIN_VERSION} (${ZEEK_SPICY_PLUGIN_VERSION_NUMBER})") 112 | 113 | if (NOT SPICYZ) 114 | message("\n Make sure spicyz is in your PATH, or set SPICYZ to its location.") 115 | endif () 116 | 117 | get_property(included GLOBAL PROPERTY __spicy_included_analyzers) 118 | message("\nAvailable analyzers:\n") 119 | foreach (x ${included}) 120 | message(" ${x}") 121 | endforeach () 122 | 123 | get_property(skipped GLOBAL PROPERTY __spicy_skipped_analyzers) 124 | if (skipped) 125 | message("\nSkipped analyzers:\n") 126 | foreach (x ${skipped}) 127 | message(" ${x}") 128 | endforeach () 129 | endif () 130 | 131 | message("\n========================================================================\n") 132 | endfunction () 133 | 134 | ### Main 135 | 136 | set(SPICYZ_FLAGS "" CACHE STRING "Additional flags for spicyz") 137 | 138 | set_property(GLOBAL PROPERTY __spicy_included_analyzers) 139 | set_property(GLOBAL PROPERTY __spicy_skipped_analyzers) 140 | 141 | if (NOT SPICYZ) 142 | set(SPICYZ "$ENV{SPICYZ}") 143 | endif () 144 | 145 | if (SPICYZ) 146 | message(STATUS "Using spicyz: ${SPICYZ}") 147 | 148 | add_executable(spicyz IMPORTED) 149 | set_property(TARGET spicyz PROPERTY IMPORTED_LOCATION "${SPICYZ}") 150 | 151 | string(REPLACE " " ";" _SPICYZ_FLAGS "${SPICYZ_FLAGS}") 152 | 153 | # Allow passing further SPICYZ_FLAGS via environment variable. 154 | string(REPLACE " " ";" _spicyz_flags_env "$ENV{SPICYZ_FLAGS}") 155 | if (_spicyz_flags_env) 156 | list(APPEND _SPICYZ_FLAGS ${_spicyz_flags_env}) 157 | endif () 158 | 159 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 160 | list(APPEND _SPICYZ_FLAGS "-d") 161 | endif () 162 | 163 | message(STATUS "Using spicyz with flags: ${_SPICYZ_FLAGS}") 164 | 165 | set(SPICY_MODULE_OUTPUT_DIR_BUILD "${PROJECT_BINARY_DIR}") 166 | 167 | execute_process(COMMAND "${SPICYZ}" "--print-module-path" OUTPUT_VARIABLE output 168 | OUTPUT_STRIP_TRAILING_WHITESPACE) 169 | set(SPICY_MODULE_OUTPUT_DIR_INSTALL "${output}" CACHE STRING "") 170 | 171 | execute_process(COMMAND "${SPICYZ}" "--version" OUTPUT_VARIABLE output 172 | OUTPUT_STRIP_TRAILING_WHITESPACE) 173 | set(ZEEK_SPICY_PLUGIN_VERSION "${output}" CACHE STRING "") 174 | 175 | execute_process(COMMAND "${SPICYZ}" "--version-number" OUTPUT_VARIABLE output 176 | OUTPUT_STRIP_TRAILING_WHITESPACE) 177 | set(ZEEK_SPICY_PLUGIN_VERSION_NUMBER "${output}" CACHE STRING "") 178 | else () 179 | message(WARNING "spicyz: not specified") 180 | endif () 181 | -------------------------------------------------------------------------------- /FindSpicy.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details. 2 | # 3 | # CMake helpers to find Spicy and build Spicy code. 4 | # 5 | # To have this find the Spicy toolchain, either set PATH to contain 6 | # spicy-config, set SPICY_ROOT_DIR to the Spicy installation, or set 7 | # SPICY_CONFIG to the binary. 8 | # 9 | # Output: 10 | # SPICY_FOUND true if Spicy has been found 11 | # 12 | # If SPICY_FOUND is true: 13 | # 14 | # SPICYC full path to spicyc 15 | # SPICY_BUILD_MODE Spicy's debug/release build mode 16 | # SPICY_INCLUDE_DIRS_RUNTIME Spicy C++ include directories for the runtime 17 | # SPICY_INCLUDE_DIRS_TOOLCHAIN Spicy C++ include directories for the toolchain 18 | # SPICY_CXX_LIBRARY_DIRS_TOOLCHAIN Spicy C++ library directories 19 | # SPICY_CXX_LIBRARY_DIRS_RUNTIME Spicy C++ library directories 20 | # SPICY_CXX_FLAGS Spicy C++ flags with include directories 21 | # SPICY_PREFIX Spicy installation prefix 22 | # SPICY_VERSION Spicy version as a string 23 | # SPICY_VERSION_NUMBER Spicy version as a numerical value 24 | # SPICY_CMAKE_PATH Spicy cmake directory 25 | # SPICY_HAVE_TOOLCHAIN True if the compiler is available 26 | 27 | ### Functions 28 | 29 | # Configure build against Spicy. 30 | macro (configure) 31 | ### Find spicy-config 32 | if (NOT SPICY_CONFIG) 33 | set(SPICY_CONFIG "$ENV{SPICY_CONFIG}") 34 | endif () 35 | 36 | if (SPICY_CONFIG) 37 | if (EXISTS "${SPICY_CONFIG}") 38 | set(spicy_config "${SPICY_CONFIG}") 39 | else () 40 | message(STATUS "'${SPICY_CONFIG}' does not exist") 41 | endif () 42 | else () 43 | # Attempt to find `spicy-config` only with configured paths. 44 | find_program( 45 | spicy_config spicy-config 46 | HINTS ${SPICY_ROOT_DIR}/bin 47 | ${SPICY_ROOT_DIR}/build/bin 48 | $ENV{SPICY_ROOT_DIR}/bin 49 | $ENV{SPICY_ROOT_DIR}/build/bin 50 | # Try build directory of Spicy distribution we may be part of. 51 | ${PROJECT_SOURCE_DIR}/../../build/bin 52 | NO_DEFAULT_PATH) 53 | 54 | # If above search was not successful attempt to find the program in 55 | # builtin search paths. CMake's `find_program` will only execute a new 56 | # search if the output variable `spicy-config` is unset. 57 | find_program(spicy_config spicy-config) 58 | endif () 59 | 60 | if (NOT spicy_config) 61 | message(STATUS "cannot determine location of Spicy installation") 62 | set(HAVE_SPICY no) 63 | else () 64 | message(STATUS "Found spicy-config: ${spicy_config}") 65 | set(HAVE_SPICY yes) 66 | set(SPICY_CONFIG "${spicy_config}" CACHE FILEPATH "") 67 | 68 | ### Determine properties. 69 | 70 | run_spicy_config(SPICYC "--spicyc") 71 | run_spicy_config(SPICY_BUILD_MODE "--build") 72 | run_spicy_config(SPICY_PREFIX "--prefix") 73 | run_spicy_config(SPICY_VERSION "--version") 74 | run_spicy_config(SPICY_VERSION_NUMBER "--version-number") 75 | run_spicy_config(SPICY_CMAKE_PATH "--cmake-path") 76 | run_spicy_config(SPICY_HAVE_TOOLCHAIN "--have-toolchain") 77 | 78 | run_spicy_config(SPICY_INCLUDE_DIRS_RUNTIME --include-dirs) 79 | string(REPLACE " " ";" SPICY_INCLUDE_DIRS_RUNTIME "${SPICY_INCLUDE_DIRS_RUNTIME}") 80 | 81 | run_spicy_config(SPICY_LIBRARY_DIRS_RUNTIME --libdirs-cxx-runtime) 82 | string(REPLACE " " ";" SPICY_LIBRARY_DIRS_RUNTIME "${SPICY_LIBRARY_DIRS_RUNTIME}") 83 | 84 | run_spicy_config(SPICY_INCLUDE_DIRS_TOOLCHAIN --include-dirs-toolchain) 85 | string(REPLACE " " ";" SPICY_INCLUDE_DIRS_TOOLCHAIN "${SPICY_INCLUDE_DIRS_TOOLCHAIN}") 86 | 87 | run_spicy_config(SPICY_LIBRARY_DIRS_TOOLCHAIN --libdirs-cxx-toolchain) 88 | string(REPLACE " " ";" SPICY_LIBRARY_DIRS_TOOLCHAIN "${SPICY_LIBRARY_DIRS_TOOLCHAIN}") 89 | 90 | find_library( 91 | HILTI_LIBRARY 92 | NAMES hilti 93 | NO_DEFAULT_PATH 94 | HINTS "${SPICY_LIBRARY_DIRS_TOOLCHAIN}" "${SPICY_LIBRARY_DIRS_RUNTIME}") 95 | 96 | find_library( 97 | SPICY_LIBRARY 98 | NAMES spicy 99 | NO_DEFAULT_PATH 100 | HINTS "${SPICY_LIBRARY_DIRS_TOOLCHAIN}" "${SPICY_LIBRARY_DIRS_RUNTIME}") 101 | 102 | add_library(hilti SHARED IMPORTED GLOBAL) 103 | set_target_properties(hilti PROPERTIES IMPORTED_LOCATION "${HILTI_LIBRARY}") 104 | target_include_directories(hilti BEFORE INTERFACE ${HILTI_INCLUDE_DIRS_TOOLCHAIN} 105 | ${HILTI_INCLUDE_DIRS_RUNTIME}) 106 | 107 | add_library(spicy SHARED IMPORTED GLOBAL) 108 | set_target_properties(spicy PROPERTIES IMPORTED_LOCATION "${SPICY_LIBRARY}") 109 | target_include_directories(spicy BEFORE INTERFACE ${SPICY_INCLUDE_DIRS_TOOLCHAIN} 110 | ${SPICY_INCLUDE_DIRS_RUNTIME}) 111 | endif () 112 | endmacro () 113 | 114 | # Checks that the Spicy version it at least the given version. 115 | function (spicy_require_version version) 116 | string(REGEX MATCH "([0-9]*)\.([0-9]*)\.([0-9]*).*" _ ${version}) 117 | math(EXPR version_number "${CMAKE_MATCH_1} * 10000 + ${CMAKE_MATCH_2} * 100 + ${CMAKE_MATCH_3}") 118 | if ("${SPICY_VERSION_NUMBER}" LESS "${version_number}") 119 | message( 120 | FATAL_ERROR "Package requires at least Spicy version ${version}, have ${SPICY_VERSION}") 121 | endif () 122 | endfunction () 123 | 124 | # Helper to link with `--whole-archive/-force-load`. 125 | # 126 | # This is adapted from https://github.com/horance-liu/flink.cmake 127 | # 128 | # With CMake >= 3.24, we could instead use LINK_LIBRARY, see 129 | # https://cmake.org/cmake/help/v3.24/manual/cmake-generator-expressions.7.html#genex:LINK_LIBRARY 130 | macro (spicy_get_runtime_libraries out debug) 131 | if (debug) 132 | set(hilti_rt ${HILTI_LIBRARY_RT_DEBUG}) 133 | set(spicy_rt ${SPICY_LIBRARY_RT_DEBUG}) 134 | else () 135 | set(hilti_rt ${HILTI_LIBRARY_RT}) 136 | set(spicy_rt ${SPICY_LIBRARY_RT}) 137 | endif () 138 | 139 | if (MSVC) 140 | set(${out} "/WHOLEARCHIVE:${hilti_rt};/WHOLEARCHIVE:${spicy_rt}") 141 | elseif (APPLE) 142 | set(${out} "-Wl,-force_load;${hilti_rt};-Wl,-force_load;${spicy_rt}") 143 | else () 144 | set(${out} "-Wl,--whole-archive;${hilti_rt};${spicy_rt};-Wl,--no-whole-archive") 145 | endif () 146 | endmacro () 147 | 148 | # Runs `spicy-config` and stores its result in the given output variable. 149 | function (run_spicy_config output) 150 | execute_process(COMMAND "${spicy_config}" ${ARGN} OUTPUT_VARIABLE output_ 151 | OUTPUT_STRIP_TRAILING_WHITESPACE) 152 | string(STRIP "${output_}" output_) 153 | set(${output} "${output_}" PARENT_SCOPE) 154 | endfunction () 155 | 156 | # Prints a summary of detected Spicy. 157 | function (spicy_print_summary) 158 | message("\n====================| Spicy Installation Summary |====================" "\n" 159 | "\nFound Spicy: ${HAVE_SPICY}") 160 | 161 | if (HAVE_SPICY) 162 | message( 163 | "\nVersion: ${SPICY_VERSION} (${SPICY_VERSION_NUMBER})" 164 | "\nPrefix: ${SPICY_PREFIX}" 165 | "\nBuild type: ${SPICY_BUILD_MODE}" 166 | "\nHave toolchain: ${SPICY_HAVE_TOOLCHAIN}" 167 | "\nSpicy compiler: ${SPICYC}") 168 | else () 169 | message( 170 | "\n Make sure spicy-config is in your PATH, or set SPICY_CONFIG to its location.") 171 | endif () 172 | 173 | message("\n========================================================================\n") 174 | endfunction () 175 | 176 | ### Main 177 | 178 | if (NOT HAVE_SPICY) 179 | configure() 180 | endif () 181 | 182 | include(FindPackageHandleStandardArgs) 183 | find_package_handle_standard_args(Spicy DEFAULT_MSG HAVE_SPICY SPICY_CONFIG) 184 | -------------------------------------------------------------------------------- /ZeekPlugin.cmake: -------------------------------------------------------------------------------- 1 | # This function wraps the find_package call for Zeek to allow us to override 2 | # variables such as CMAKE_PREFIX_PATH in the function scope without changing the 3 | # variable at directory scope. The function also locates dependencies for 4 | # dynamic plugins like BinPAC and BifCl. 5 | function (zeek_plugin_bootstrapping) 6 | # Plugins that build against the source tree set ZEEK_DIST. Here, we have our 7 | # package file plus ZeekPluginConfig.cmake to help out. 8 | if (ZEEK_DIST) 9 | message("-- Using ZEEK_DIST: ${ZEEK_DIST}") 10 | find_package(Zeek REQUIRED CONFIG NO_DEFAULT_PATH PATHS "${ZEEK_DIST}/build") 11 | return() 12 | endif () 13 | # When building plugins against an installed Zeek, this file must be installed 14 | # alongside this script. It provides the variables ZEEK_CMAKE_CONFIG_DIR and 15 | # ZEEK_CMAKE_INSTALL_PREFIX. 16 | include(ZeekPluginBootstrap) 17 | # When looking for dependencies, make sure to look into the install prefix. 18 | list(PREPEND CMAKE_PREFIX_PATH "${ZEEK_CMAKE_INSTALL_PREFIX}") 19 | # We also needs to find Broker, which we usually can find through the install 20 | # prefix. Plugins may also set BROKER_ROOT_DIR to help find Broker, which we 21 | # forward to the actual CMake variable if present. 22 | if (NOT Broker_DIR AND BROKER_ROOT_DIR) 23 | set(Broker_DIR "${BROKER_ROOT_DIR}") 24 | endif () 25 | # Load the CMake package for Zeek. This pulls in dependencies as well as 26 | # targets such as Zeek::DynamicPluginBase. 27 | find_package(Zeek REQUIRED CONFIG NO_DEFAULT_PATH PATHS "${ZEEK_CMAKE_CONFIG_DIR}") 28 | # Find BinPAC via Zeek's FindBinPAC.cmake script. 29 | if (NOT TARGET Zeek::BinPAC) 30 | find_package(BinPAC REQUIRED) 31 | add_executable(Zeek::BinPAC IMPORTED) 32 | set_property(TARGET Zeek::BinPAC PROPERTY IMPORTED_LOCATION "${BinPAC_EXE}") 33 | endif () 34 | # Find BifCl. This should be located under ZEEK_CMAKE_INSTALL_PREFIX/bin. 35 | if (NOT TARGET Zeek::BifCl) 36 | list(PREPEND CMAKE_PROGRAM_PATH "${ZEEK_CMAKE_INSTALL_PREFIX}/bin") 37 | find_program(ZeekBifClPath bifcl) 38 | if (NOT ZeekBifClPath) # Note: CMake > 3.18 has REQUIRED for find_program. 39 | message( 40 | FATAL_ERROR 41 | "failed to find bifcl, please add hints to CMAKE_PREFIX_PATH or CMAKE_PROGRAM_PATH" 42 | ) 43 | endif () 44 | message(STATUS "Found BifCl at ${ZeekBifClPath}") 45 | add_executable(Zeek::BifCl IMPORTED) 46 | set_property(TARGET Zeek::BifCl PROPERTY IMPORTED_LOCATION "${ZeekBifClPath}") 47 | endif () 48 | # For historic reasons, we also automagically add /cmake (if it 49 | # exists) to CMAKE_MODULE_PATH. 50 | if (EXISTS "${PROJECT_SOURCE_DIR}/cmake") 51 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 52 | set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) 53 | endif () 54 | # Another historic quirk: force CMAKE_EXPORT_COMPILE_COMMANDS to ON. 55 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON 56 | CACHE PATH "Configures whether to write a compile database." FORCE) 57 | 58 | # When CMAKE_BUILD_TYPE is not set, use the one from Zeek. 59 | if (NOT CMAKE_BUILD_TYPE) 60 | message(STATUS "Setting plugin CMAKE_BUILD_TYPE to ${ZEEK_CMAKE_BUILD_TYPE}") 61 | set(CMAKE_BUILD_TYPE "${ZEEK_CMAKE_BUILD_TYPE}" 62 | CACHE STRING "Configures the CMAKE_BUILD_TYPE for the plugin." FORCE) 63 | endif () 64 | endfunction () 65 | 66 | # Make sure BifCl and BinPAC are available. 67 | if (NOT ZEEK_PLUGIN_INTERNAL_BUILD) 68 | zeek_plugin_bootstrapping() 69 | endif () 70 | 71 | include(BifCl) 72 | include(BinPAC) 73 | 74 | # Wrapper include file that loads the macros for building a Zeek 75 | # plugin either statically or dynamically, depending on whether 76 | # we're building as part of the main Zeek source tree, or externally. 77 | 78 | # Utility function for zeek_add_*plugin functions. Those functions use 79 | # cmake_parse_arguments, which lumps together all arguments for the 'PAC' 80 | # sections into one array. This function simply allows us to traverse all 'PAC' 81 | # sections individually. 82 | # 83 | # Usage example: 84 | # 85 | # zeek_next_pac_block(at_end pacInputs pacRemainder ${args}) 86 | # while (NOT at_end) 87 | # message(STATUS "inputs ${pacInputs}") 88 | # message(STATUS "pacRemainder ${pacRemainder}") 89 | # zeek_next_pac_block(at_end pacInputs pacRemainder ${pacRemainder}) 90 | # endwhile() 91 | function (zeek_next_pac_block at_end inputs remainder) 92 | # Sanity checking. 93 | list(LENGTH ARGN n) 94 | if (n EQUAL "0") 95 | set(${at_end} ON PARENT_SCOPE) 96 | return() 97 | endif () 98 | # List of separators, i.e., keywords recognized by zeek_add_*plugin functions. 99 | set(separators INCLUDE_DIRS DEPENDENCIES SOURCES BIFS DIST_FILES PAC) 100 | # Seek to the first PAC block. 101 | set(i 0) 102 | foreach (arg ${ARGN}) 103 | math(EXPR i "${i}+1") 104 | if (arg STREQUAL "PAC") 105 | break() 106 | endif () 107 | endforeach () 108 | # Bail out if no block was found. 109 | if (i EQUAL n) 110 | set(${at_end} ON PARENT_SCOPE) 111 | return() 112 | endif () 113 | # Fill the result list. 114 | set(j ${i}) 115 | list(SUBLIST ARGN ${i} -1 subArgs) 116 | set(res "") 117 | foreach (arg ${subArgs}) 118 | if (arg IN_LIST separators) 119 | break() 120 | endif () 121 | list(APPEND res ${arg}) 122 | math(EXPR j "${j}+1") 123 | endforeach () 124 | if (j EQUAL n) 125 | set(unusedArgs "") 126 | else () 127 | list(SUBLIST ARGN ${j} -1 unusedArgs) 128 | endif () 129 | # Fill the result variables. 130 | set(${at_end} OFF PARENT_SCOPE) 131 | set(${inputs} ${res} PARENT_SCOPE) 132 | set(${remainder} ${unusedArgs} PARENT_SCOPE) 133 | endfunction () 134 | 135 | include(ZeekPluginStatic) 136 | include(ZeekPluginDynamic) 137 | 138 | if (NOT ZEEK_PLUGIN_INTERNAL_BUILD AND ${CMAKE_MINIMUM_REQUIRED_VERSION} VERSION_LESS 3.15.0) 139 | message( 140 | FATAL_ERROR 141 | "Plugin requires CMake ${CMAKE_MINIMUM_REQUIRED_VERSION} which is less than Zeek's requirement (3.15.0). Please update cmake_minimum_required VERSION to 3.15 or higher." 142 | ) 143 | endif () 144 | 145 | if (ZEEK_PLUGIN_INTERNAL_BUILD AND NOT ZEEK_PLUGIN_BUILD_DYNAMIC) 146 | set(ZEEK_PLUGIN_BUILD_DYNAMIC OFF) 147 | elseif (NOT ZEEK_PLUGIN_BUILD_DYNAMIC) 148 | set(ZEEK_PLUGIN_BUILD_DYNAMIC ON) 149 | endif () 150 | 151 | # Sets `target` to contain the CMake target name for a plugin. 152 | macro (zeek_get_plugin_target var ns name) 153 | if (ZEEK_PLUGIN_BUILD_DYNAMIC) 154 | zeek_get_dynamic_plugin_target(${var} ${ns} ${name}) 155 | else () 156 | zeek_get_static_plugin_target(${var} ${ns} ${name}) 157 | endif () 158 | endmacro () 159 | 160 | # Usage: 161 | # zeek_add_plugin( 162 | # 163 | # 164 | # [INCLUDE_DIRS ...] 165 | # [DEPENDENCIES ...] 166 | # [DIST_FILES ...] 167 | # [SCRIPT_FILES ...] 168 | # [SOURCES ...] 169 | # [BIFS ...] 170 | # [[PAC ...] ... ] 171 | # ) 172 | # * INCLUDE_DIRS: 173 | # Adds additional include directories for building the plugin. By default, the 174 | # function adds `CMAKE_CURRENT_BINARY_DIR` as additional include directory. 175 | # * DEPENDENCIES: 176 | # Adds additional CMake targets as extra dependencies. 177 | # * DIST_FILES: 178 | # Adds additional files to install alongside the plugin when building a 179 | # dynamic plugin. Ignored when building static plugins. 180 | # * SCRIPT_FILES: 181 | # Marks the given script files as dependencies for the tarball when building 182 | # a dynamic plugin. This is currently for dependency tracking only - the 183 | # plugin's whole script directory is included in the resulting tarball 184 | # regardless of the files provided here. Ignored when building static plugins. 185 | # * SOURCES: 186 | # List of C++ files for compiling the plugin. 187 | # * BIFS: 188 | # List of BIF files (*.bif) for compiling the plugin. 189 | # * PAC: 190 | # Adds a BinPAC parser to the plugin. The function accepts multiple `PAC` 191 | # blocks. Each block defines a single BinPAC parser. 192 | function (zeek_add_plugin ns name) 193 | if (ZEEK_PLUGIN_BUILD_DYNAMIC) 194 | zeek_add_dynamic_plugin(${ns} ${name} ${ARGV}) 195 | else () 196 | zeek_add_static_plugin(${ns} ${name} ${ARGV}) 197 | endif () 198 | endfunction () 199 | 200 | include(ZeekPluginCommon) 201 | -------------------------------------------------------------------------------- /ZeekPluginDynamic.cmake: -------------------------------------------------------------------------------- 1 | include(GetArchitecture) 2 | include(RequireCXXStd) 3 | 4 | # Sets `target` to contain the CMake target name for a dynamic plugin. 5 | macro (zeek_get_dynamic_plugin_target target ns name) 6 | set(${target} "${ns}_${name}") 7 | endmacro () 8 | 9 | # Implements the dynamically linked version of zeek_add_plugin. 10 | function (zeek_add_dynamic_plugin ns name) 11 | # Sanity check: need ZEEK_PLUGIN_SCRIPTS_PATH. 12 | if (NOT EXISTS "${ZEEK_PLUGIN_SCRIPTS_PATH}") 13 | message( 14 | FATAL_ERROR 15 | "Cannot build dynamic plugins: ZEEK_PLUGIN_SCRIPTS_PATH is undefined or invalid") 16 | endif () 17 | 18 | # Helper variables. 19 | zeek_get_dynamic_plugin_target(target_name ${ns} ${name}) 20 | set(full_name "${ns}::${name}") 21 | set(canon_name "${ns}_${name}") 22 | set(base_dir "${CMAKE_CURRENT_BINARY_DIR}") 23 | set(lib_dir "${base_dir}/lib") 24 | set(bif_dir "${lib_dir}/bif") 25 | set(readme "${base_dir}/README") 26 | set(scripts_bin "${base_dir}/scripts") 27 | set(scripts_src "${CMAKE_CURRENT_SOURCE_DIR}/scripts") 28 | 29 | # Create the target if no begin function has been used. 30 | if (NOT TARGET ${target_name}) 31 | add_library(${target_name} MODULE) 32 | 33 | target_compile_features(${target_name} PRIVATE ${ZEEK_CXX_STD}) 34 | set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF) 35 | endif () 36 | 37 | # Place library file into the 'lib' directory, drop default-generated file 38 | # prefix and override the default file name to include the architecture. 39 | set_target_properties( 40 | ${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${lib_dir}" PREFIX "" 41 | LIBRARY_OUTPUT_NAME "${ns}-${name}.${HOST_ARCHITECTURE}") 42 | 43 | # Parse arguments (note: DIST_FILES and SCRIPT_FILES are ignored in static builds). 44 | set(fn_varargs 45 | INCLUDE_DIRS 46 | DEPENDENCIES 47 | SOURCES 48 | BIFS 49 | DIST_FILES 50 | SCRIPT_FILES 51 | PAC) 52 | cmake_parse_arguments(FN_ARGS "" "" "${fn_varargs}" ${ARGN}) 53 | 54 | # Take care of compiling BIFs. 55 | if (FN_ARGS_BIFS) 56 | # Generate the targets and add the .cc files. 57 | foreach (bif ${FN_ARGS_BIFS}) 58 | bif_target(${bif} "plugin" ${full_name} ${canon_name} OFF) 59 | target_sources(${target_name} PRIVATE ${BIF_OUTPUT_CC}) 60 | endforeach () 61 | # Generate __load__.zeek when building the plugin outside of Zeek. 62 | if (ZEEK_PLUGIN_INTERNAL_BUILD) 63 | set(loader_target ${target_name}_bif_loader) 64 | bro_bif_create_loader(${loader_target} ${FN_ARGS_BIFS}) 65 | add_dependencies(${target_name} ${loader_target}) 66 | else () 67 | set(load_script "${bif_dir}/__load__.zeek") 68 | file(WRITE ${load_script} "# Warning, this is an autogenerated file!\n") 69 | foreach (bif ${FN_ARGS_BIFS}) 70 | get_filename_component(file_name ${bif} NAME) 71 | file(APPEND ${load_script} "@load ./${file_name}.zeek\n") 72 | endforeach () 73 | endif () 74 | endif () 75 | 76 | # Take care of PAC files. 77 | zeek_next_pac_block(at_end pacInputs pacRemainder ${ARGN}) 78 | while (NOT at_end) 79 | binpac_target(${pacInputs}) 80 | target_sources(${target_name} PRIVATE ${BINPAC_OUTPUT_CC}) 81 | zeek_next_pac_block(at_end pacInputs pacRemainder ${pacRemainder}) 82 | endwhile () 83 | 84 | # Add user-defined extra include directories. 85 | if (FN_ARGS_INCLUDE_DIRS) 86 | target_include_directories(${target_name} PRIVATE ${FN_ARGS_INCLUDE_DIRS}) 87 | endif () 88 | 89 | # Add user-defined extra dependencies. 90 | if (FN_ARGS_DEPENDENCIES) 91 | target_link_libraries(${target_name} PRIVATE ${FN_ARGS_DEPENDENCIES}) 92 | endif () 93 | 94 | # Add the sources for the plugin. 95 | if (FN_ARGS_SOURCES) 96 | target_sources(${target_name} PRIVATE ${FN_ARGS_SOURCES}) 97 | endif () 98 | 99 | # Add extra dependencies when compiling with MSVC. 100 | if (MSVC) 101 | target_link_libraries(${target_name} ws2_32) 102 | endif () 103 | 104 | # Pass compiler flags, paths and dependencies to the target. 105 | target_link_libraries(${target_name} PRIVATE Zeek::DynamicPluginBase) 106 | target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 107 | 108 | # Per convention, plugins have their headers and sources under src/ and 109 | # legacy/external plugins expect this to auto-magically be available as 110 | # include path. 111 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src) 112 | target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) 113 | endif () 114 | 115 | # Link scripts into the build directory (if present). 116 | if (IS_DIRECTORY "${scripts_src}") 117 | set(symlink_target ${target_name}_symlink) 118 | add_custom_target(${symlink_target} COMMAND "${CMAKE_COMMAND}" -E create_symlink 119 | "${scripts_src}" "${scripts_bin}") 120 | add_dependencies(${target_name} ${symlink_target}) 121 | endif () 122 | 123 | # Add BinPAC_INCLUDE_DIR for picking up paths from FindBinPAC.cmake. 124 | if (BinPAC_INCLUDE_DIR) 125 | target_include_directories(${target_name} PRIVATE ${BinPAC_INCLUDE_DIR}) 126 | endif () 127 | 128 | # Write the 'magic' __zeek_plugin__ file. We can do that once during CMake 129 | # invocation since it won't change. 130 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/__zeek_plugin__" "${full_name}\n") 131 | 132 | # Stop here unless building 3rd party plugins. 133 | if (ZEEK_PLUGIN_INTERNAL_BUILD) 134 | return() 135 | endif () 136 | 137 | # Plugins may set BRO_PLUGIN_INSTALL_ROOT to override the default 138 | # installation directory. Otherwise, we use ZEEK_PLUGIN_DIR from Zeek. 139 | if (BRO_PLUGIN_INSTALL_ROOT) 140 | set(install_dir "${BRO_PLUGIN_INSTALL_ROOT}") 141 | else () 142 | set(install_dir ${ZEEK_PLUGIN_DIR}) 143 | endif () 144 | 145 | # Create the binary install package. 146 | set(dist_tarball_dir ${CMAKE_CURRENT_BINARY_DIR}/dist/${canon_name}) 147 | set(dist_tarball_name ${canon_name}.tgz) 148 | set(dist_tarball_path ${CMAKE_CURRENT_BINARY_DIR}/${dist_tarball_name}) 149 | message(STATUS "Install prefix for plugin ${canon_name}: ${install_dir}") 150 | message(STATUS "Tarball path for plugin ${canon_name}: ${dist_tarball_path}") 151 | add_custom_command(OUTPUT ${dist_tarball_path} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 152 | COMMENT "Building binary plugin package: ${dist_tarball_path}") 153 | 154 | # Handle dist files: Pre-place user provided dist files into the 155 | # directory that zeek-plugin-create-package.sh will tar up. Previously, 156 | # the zeek-plugin-create-package.sh script had done this itself. 157 | # 158 | # This computes the relative path of individual DIST_FILES to the 159 | # PROJECT_SOURCE_DIR (last project() invocation) and uses the 160 | # resulting path in the tarball. 161 | foreach (df ${FN_ARGS_DIST_FILES}) 162 | get_filename_component(df_src "${df}" ABSOLUTE) 163 | 164 | if (NOT EXISTS "${df_src}") 165 | # This was silently ignored previously. 166 | message(WARNING "The file ${df} (${df_src}) given to DIST_FILES does not exist") 167 | continue() 168 | endif () 169 | 170 | file(RELATIVE_PATH df_dist ${PROJECT_SOURCE_DIR} ${df_src}) 171 | 172 | add_custom_command( 173 | OUTPUT ${dist_tarball_path} 174 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${df} 175 | ${dist_tarball_dir}/${df_dist} 176 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${df} 177 | APPEND) 178 | endforeach () 179 | 180 | add_custom_command( 181 | OUTPUT ${dist_tarball_path} 182 | COMMAND ${ZEEK_PLUGIN_SCRIPTS_PATH}/zeek-plugin-create-package.sh ${canon_name} 183 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 184 | DEPENDS ${target_name} ${FN_ARGS_SCRIPT_FILES} 185 | APPEND) 186 | 187 | add_custom_target(${target_name}_tarball ALL DEPENDS ${dist_tarball_path}) 188 | 189 | # Tell CMake to install our tarball. Note: This usually runs from our 190 | # plugin-support skeleton. 191 | install( 192 | CODE "execute_process( 193 | COMMAND ${ZEEK_PLUGIN_SCRIPTS_PATH}/zeek-plugin-install-package.sh ${canon_name} \$ENV{DESTDIR}/${install_dir} 194 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 195 | COMMAND_ECHO STDOUT 196 | )") 197 | endfunction () 198 | -------------------------------------------------------------------------------- /ConfigurePackaging.cmake: -------------------------------------------------------------------------------- 1 | # A collection of macros to assist in configuring CMake/Cpack 2 | # source and binary packaging 3 | 4 | # Sets CPack version variables by splitting the first macro argument 5 | # using "." or "-" as a delimiter. If the length of the split list is 6 | # greater than 2, all remaining elements are tacked on to the patch 7 | # level version. Not that the version set by the macro is internal 8 | # to binary packaging, the file name of our package will reflect the 9 | # exact version number. 10 | macro (SetPackageVersion _version) 11 | string(REGEX REPLACE "[.-]" " " version_numbers ${_version}) 12 | separate_arguments(version_numbers) 13 | 14 | list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MAJOR) 15 | list(REMOVE_AT version_numbers 0) 16 | list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MINOR) 17 | list(REMOVE_AT version_numbers 0) 18 | list(LENGTH version_numbers version_length) 19 | 20 | while (version_length GREATER 0) 21 | list(GET version_numbers 0 patch_level) 22 | if (CPACK_PACKAGE_VERSION_PATCH) 23 | set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}.${patch_level}") 24 | else () 25 | set(CPACK_PACKAGE_VERSION_PATCH ${patch_level}) 26 | endif () 27 | list(REMOVE_AT version_numbers 0) 28 | list(LENGTH version_numbers version_length) 29 | endwhile () 30 | 31 | if (APPLE) 32 | # Mac PackageMaker package requires only numbers in the versioning 33 | string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_MAJOR 34 | ${CPACK_PACKAGE_VERSION_MAJOR}) 35 | string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_MINOR 36 | ${CPACK_PACKAGE_VERSION_MINOR}) 37 | if (CPACK_PACKAGE_VERSION_PATCH) 38 | string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_PATCH 39 | ${CPACK_PACKAGE_VERSION_PATCH}) 40 | endif () 41 | endif () 42 | 43 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 44 | # RPM version accepts letters, but not dashes. 45 | string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) 46 | string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) 47 | if (CPACK_PACKAGE_VERSION_PATCH) 48 | string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_PATCH 49 | ${CPACK_PACKAGE_VERSION_PATCH}) 50 | endif () 51 | endif () 52 | 53 | # Minimum supported OS X version 54 | set(CPACK_OSX_PACKAGE_VERSION 10.5) 55 | endmacro (SetPackageVersion) 56 | 57 | # Sets the list of desired package types to be created by the make 58 | # package target. A .tar.gz is only made for source packages, and 59 | # binary pacakage format depends on the operating system: 60 | # 61 | # Darwin - PackageMaker 62 | # Linux - RPM if the platform has rpmbuild installed 63 | # DEB if the platform has dpkg-shlibdeps installed 64 | # 65 | # CPACK_GENERATOR is set by this macro 66 | # CPACK_SOURCE_GENERATOR is set by this macro 67 | macro (SetPackageGenerators) 68 | set(CPACK_SOURCE_GENERATOR TGZ) 69 | #set(CPACK_GENERATOR TGZ) 70 | if (APPLE) 71 | list(APPEND CPACK_GENERATOR PackageMaker) 72 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 73 | find_program(RPMBUILD_EXE rpmbuild) 74 | find_program(DPKGSHLIB_EXE dpkg-shlibdeps) 75 | if (RPMBUILD_EXE) 76 | set(CPACK_GENERATOR ${CPACK_GENERATOR} RPM) 77 | endif () 78 | if (DPKGSHLIB_EXE) 79 | set(CPACK_GENERATOR ${CPACK_GENERATOR} DEB) 80 | set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS true) 81 | endif () 82 | endif () 83 | endmacro (SetPackageGenerators) 84 | 85 | # Sets CPACK_PACKAGE_FILE_NAME in the following format: 86 | # 87 | # --- 88 | # 89 | # and CPACK_SOURCE_PACKAGE_FILE_NAME as: 90 | # 91 | # - 92 | macro (SetPackageFileName _version) 93 | if (PACKAGE_NAME_PREFIX) 94 | set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") 95 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") 96 | else () 97 | set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") 98 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") 99 | endif () 100 | 101 | set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_NAME}") 102 | 103 | if (APPLE) 104 | # Only Intel-based Macs are supported. CMAKE_SYSTEM_PROCESSOR may 105 | # return the confusing 'i386' if running a 32-bit kernel, but chances 106 | # are the binary is x86_64 (or more generally 'Intel') compatible. 107 | set(arch "Intel") 108 | else () 109 | set(arch ${CMAKE_SYSTEM_PROCESSOR}) 110 | endif () 111 | 112 | set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${arch}") 113 | endmacro (SetPackageFileName) 114 | 115 | # Sets up binary package metadata 116 | macro (SetPackageMetadata) 117 | if (NOT CPACK_PACKAGE_VENDOR) 118 | set(CPACK_PACKAGE_VENDOR "International Computer Science Institute") 119 | endif () 120 | 121 | if (NOT CPACK_PACKAGE_CONTACT) 122 | set(CPACK_PACKAGE_CONTACT "info@zeek.org") 123 | endif () 124 | 125 | if (NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) 126 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Zeek Network Security Monitor") 127 | endif () 128 | 129 | # CPack may enforce file name extensions for certain package generators 130 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/README.txt 131 | COPYONLY) 132 | 133 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/COPYING) 134 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt 135 | COPYONLY) 136 | elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me) 137 | # Zeek plugin skeletons have a placeholder file. Just use 138 | # it even if it hasn't actually been changed. 139 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me 140 | ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt COPYONLY) 141 | endif () 142 | 143 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/MAC_PACKAGE_INTRO) 144 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MAC_PACKAGE_INTRO 145 | ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) 146 | else () 147 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README 148 | ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) 149 | endif () 150 | 151 | set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_BINARY_DIR}/README.txt) 152 | set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt) 153 | set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.txt) 154 | set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) 155 | 156 | if (NOT CPACK_RPM_PACKAGE_LICENSE) 157 | set(CPACK_RPM_PACKAGE_LICENSE "BSD") 158 | endif () 159 | 160 | if (NOT CPACK_RPM_PACKAGE_GROUP) 161 | set(CPACK_RPM_PACKAGE_GROUP "Applications/System") 162 | endif () 163 | 164 | # If we're building a dynamic Zeek plugin, exclude various additional paths 165 | # already provided by our Zeek packages. 166 | if (ZEEK_PLUGIN_BUILD_DYNAMIC) 167 | set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION 168 | /opt 169 | /var 170 | /var/opt 171 | ${CMAKE_INSTALL_PREFIX} 172 | ${BRO_CONFIG_PREFIX} 173 | ${BRO_CONFIG_PREFIX}/lib 174 | ${BRO_CONFIG_PREFIX}/lib/zeek 175 | ${BRO_CONFIG_PLUGIN_DIR}) 176 | else () 177 | set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /opt /var /var/opt) 178 | endif () 179 | endmacro (SetPackageMetadata) 180 | 181 | # Sets pre and post install scripts for PackageMaker packages. 182 | # The main functionality that such scripts offer is a way to make backups 183 | # of "configuration" files that a user may have modified. 184 | # Note that RPMs already have a robust mechanism for dealing with 185 | # user-modified files, so we do not need this additional functionality 186 | macro (SetPackageInstallScripts VERSION) 187 | 188 | if (INSTALLED_CONFIG_FILES) 189 | # Remove duplicates from the list of installed config files 190 | separate_arguments(INSTALLED_CONFIG_FILES) 191 | list(REMOVE_DUPLICATES INSTALLED_CONFIG_FILES) 192 | # Space delimit the list again 193 | foreach (_file ${INSTALLED_CONFIG_FILES}) 194 | set(_tmp "${_tmp} ${_file}") 195 | endforeach () 196 | set(INSTALLED_CONFIG_FILES "${_tmp}" CACHE STRING "" FORCE) 197 | endif () 198 | 199 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 200 | # DEB packages can automatically handle configuration files 201 | # if provided in a "conffiles" file in the packaging 202 | set(conffiles_file ${CMAKE_CURRENT_BINARY_DIR}/conffiles) 203 | if (INSTALLED_CONFIG_FILES) 204 | string(REPLACE " " ";" conffiles ${INSTALLED_CONFIG_FILES}) 205 | endif () 206 | file(WRITE ${conffiles_file} "") 207 | foreach (_file ${conffiles}) 208 | file(APPEND ${conffiles_file} "${_file}\n") 209 | endforeach () 210 | 211 | list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/conffiles) 212 | 213 | # RPMs don't need any explicit direction regarding config files. 214 | 215 | # Leaving the set of installed config files empty will just 216 | # bypass the logic in the default pre/post install scripts and let 217 | # the RPMs/DEBs do their own thing (regarding backups, etc.) 218 | # when upgrading packages. 219 | set(INSTALLED_CONFIG_FILES "") 220 | endif () 221 | 222 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in) 223 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in 224 | ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh @ONLY) 225 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in 226 | ${CMAKE_CURRENT_BINARY_DIR}/preinst @ONLY) 227 | set(CPACK_PREFLIGHT_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) 228 | set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) 229 | list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/preinst) 230 | endif () 231 | 232 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in) 233 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in 234 | ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh @ONLY) 235 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in 236 | ${CMAKE_CURRENT_BINARY_DIR}/postinst @ONLY) 237 | set(CPACK_POSTUPGRADE_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) 238 | set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) 239 | list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/postinst) 240 | endif () 241 | endmacro (SetPackageInstallScripts) 242 | 243 | # Main macro to configure all the packaging options 244 | macro (ConfigurePackaging _version) 245 | SetPackageVersion(${_version}) 246 | SetPackageGenerators() 247 | SetPackageFileName(${_version}) 248 | SetPackageMetadata() 249 | SetPackageInstallScripts(${_version}) 250 | 251 | set(CPACK_SET_DESTDIR true) 252 | set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) 253 | 254 | # add default files/directories to ignore for source package 255 | # user may specify others via configure script 256 | list(APPEND CPACK_SOURCE_IGNORE_FILES ${PROJECT_BINARY_DIR} ".git") 257 | 258 | include(CPack) 259 | endmacro (ConfigurePackaging) 260 | --------------------------------------------------------------------------------