capstats-0.31/000755 000765 000024 00000000000 14246446227 013226 5ustar00timstaff000000 000000 capstats-0.31/.update-changes.cfg000644 000765 000024 00000000202 14246446227 016647 0ustar00timstaff000000 000000 # Automatically adapt version in files. function new_version_hook { version=$1 replace_version_in_rst README $version } capstats-0.31/capstats.8000644 000765 000024 00000006037 14246446227 015147 0ustar00timstaff000000 000000 .\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH CAPSTATS 8 "January 15, 2010" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME capstats \- print statistics about the current load on a network interface .SH SYNOPSIS .B capstats .RI "[ options ] -i " "interface" .br .SH DESCRIPTION This manual page documents briefly the .B capstats command. .PP .B capstats is a program that prints statistics about the current load on a network interface using libpcap. It reports statistics per time interval and/or for the tool's total run-time. Here's an example output with output in one-second intervals until CTRL-C is hit: .ad l >capstats -i eth0 -I 1 .br 1186620936.890567 pkts=12747 kpps=12.6 kbytes=10807 mbps=87.5 nic_pkts=12822 nic_drops=0 u=960 t=11705 i=58 o=24 nonip=0 .br 1186620937.901490 pkts=13558 kpps=13.4 kbytes=11329 mbps=91.8 nic_pkts=13613 nic_drops=0 u=1795 t=24339 i=119 o=52 nonip=0 .br 1186620938.912399 pkts=14771 kpps=14.6 kbytes=13659 mbps=110.7 nic_pkts=14781 nic_drops=0 u=2626 t=38154 i=185 o=111 nonip=0 .br 1186620939.012446 pkts=1332 kpps=13.3 kbytes=1129 mbps=92.6 nic_pkts=1367 nic_drops=0 u=2715 t=39387 i=194 o=112 nonip=0 .br === Total .br 1186620939.012483 pkts=42408 kpps=13.5 kbytes=36925 mbps=96.5 nic_pkts=1 nic_drops=0 u=2715 t=39387 i=194 o=112 nonip=0 .ad b .SH OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. .TP .BI "\-i, \-\-interface " interface .RI "Listen on " interface .TP .B \-d, \-\-dag Use native DAG API if capstats was built with DAG support. .TP .BI "\-f, \-\-filter " filter BPF filter .TP .BI "\-I, \-\-interval " secs Stats logging interval .TP .B \-l, \-\-syslog Use syslog rather than print to stderr .TP .BI "\-n, \-\-number " count .RI "Stop after outputting " count " intervals" .TP .B "\-p, \-\-payload" n Verifies that packets' payloads consist entirely of bytes of the given value. .TP .B "\-q, \-\-quiet" count Suppress output, exit code indicates >= count packets received. .TP .BI "\-S, \-\-size " size Verify packets to have given size .TP .BI "\-s, \-\-snaplen " size .RI "Use pcap snaplen " size .TP .B \-v, \-\-version Print version and exit .TP .BI "\-w, \-\-write " filename .RI "Write packets to " filename .SH SEE ALSO .BR tcpdump (8), .br .SH AUTHOR capstats was written by Robin Sommer .PP This manual page was written by Justin Azoff , for the Debian project (but may be used by others). capstats-0.31/INSTALL000644 000765 000024 00000001540 14246446227 014257 0ustar00timstaff000000 000000 Prerequisites ============= capstats relies on the following libraries and tools, which need to be installed before you begin: * A C++ compiler * Libpcap headers and libraries Network traffic capture library * CMake 2.6.3 or greater CMake is a cross-platform, open-source build system, typically not installed by default. See http://www.cmake.org for more information regarding CMake and the installation steps below for how to use it to build this distribution. CMake generates native Makefiles that depend on GNU Make by default. Installation ============ To build and install into /usr/local: > ./configure > make > make install This will perform an out-of-source build into the build directory using the default build options and then install the capstats binary into /usr/local/bin. capstats-0.31/CMakeLists.txt000644 000765 000024 00000003753 14246446227 015776 0ustar00timstaff000000 000000 cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(capstats C CXX) include(cmake/CommonCMakeConfig.cmake) file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.cc.in ${CMAKE_CURRENT_BINARY_DIR}/version.cc) ######################################################################## ## Dependency Configuration include(FindRequiredPackage) FindRequiredPackage(PCAP) if (MISSING_PREREQS) foreach (prereq ${MISSING_PREREQ_DESCS}) message(SEND_ERROR ${prereq}) endforeach () message(FATAL_ERROR "Configuration aborted due to missing prerequisites") endif () include_directories(BEFORE ${PCAP_INCLUDE_DIR} ) ######################################################################## ## System Introspection if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(HAVE_LINUX true) endif () configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) ######################################################################## ## Build Summary if (CMAKE_BUILD_TYPE) string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType) endif () message( "\n=================| capstats Build Summary |===================" "\n" "\nInstall prefix: ${CMAKE_INSTALL_PREFIX}" "\nDebug mode: ${ENABLE_DEBUG}" "\n" "\nCXX: ${CMAKE_CXX_COMPILER}" "\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BuildType}}" "\nCPP: ${CMAKE_CXX_COMPILER}" "\n" "\n================================================================\n" ) ######################################################################## ## capstats target add_executable(capstats capstats.cc ${CMAKE_CURRENT_BINARY_DIR}/version.cc) target_link_libraries(capstats ${PCAP_LIBRARY}) install(TARGETS capstats DESTINATION bin) include(UserChangedWarning) capstats-0.31/cmake/000755 000765 000024 00000000000 14246446227 014306 5ustar00timstaff000000 000000 capstats-0.31/configure000755 000765 000024 00000005566 14246446227 015151 0ustar00timstaff000000 000000 #!/bin/sh # Convenience wrapper for easily viewing/setting options that # the project's CMake scripts will recognize set -e command="$0 $*" # check for `cmake` command type cmake > /dev/null 2>&1 || { echo "\ This package requires CMake, please install it first, then you may use this configure script to access CMake equivalent functionality.\ " >&2; exit 1; } usage="\ Usage: $0 [OPTION]... [VAR=VALUE]... Build Directory: --builddir=DIR place build files in directory [build] Installation Directories: --prefix=PREFIX installation directory [/usr/local] Optional Features: --enable-debug compile in debugging mode Required Packages in Non-Standard Locations: --with-pcap=PATH path to libpcap install root Influential Environment Variables (only on first invocation per build directory): CC C compiler command CFLAGS C compiler flags CXX C++ compiler command CXXFLAGS C++ compiler flags " sourcedir="$( cd "$( dirname "$0" )" && pwd )" # Function to append a CMake cache entry definition to the # CMakeCacheEntries variable # $1 is the cache entry variable name # $2 is the cache entry variable type # $3 is the cache entry variable value append_cache_entry () { CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3" } # set defaults builddir=build CMakeCacheEntries="" append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local append_cache_entry ENABLE_DEBUG BOOL false # parse arguments while [ $# -ne 0 ]; do case "$1" in -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg= ;; esac case "$1" in --help|-h) echo "${usage}" 1>&2 exit 1 ;; --builddir=*) builddir=$optarg ;; --prefix=*) append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg ;; --enable-debug) append_cache_entry ENABLE_DEBUG BOOL true ;; --with-pcap=*) append_cache_entry PCAP_ROOT_DIR PATH $optarg ;; *) echo "Invalid option '$1'. Try $0 --help to see available options." exit 1 ;; esac shift done if [ -d $builddir ]; then # If build directory exists, check if it has a CMake cache if [ -f $builddir/CMakeCache.txt ]; then # If the CMake cache exists, delete it so that this configuration # is not tainted by a previous one rm -f $builddir/CMakeCache.txt fi else # Create build directory mkdir -p $builddir fi echo "Build Directory : $builddir" echo "Source Directory: $sourcedir" cd $builddir cmake $CMakeCacheEntries $sourcedir echo "# This is the command used to configure this build" > config.status echo $command >> config.status chmod u+x config.status capstats-0.31/Makefile000644 000765 000024 00000004307 14246446227 014672 0ustar00timstaff000000 000000 # # A simple static wrapper for a number of standard Makefile targets, # mostly just forwarding to build/Makefile. This is provided only for # convenience and supports only a subset of what CMake's Makefile # to offer. For more, execute that one directly. # BUILD=build REPO=$$(cd $(CURDIR) && basename $$(git config --get remote.origin.url | sed 's/^[^:]*://g')) VERSION_FULL=$(REPO)-$$(cd $(CURDIR) && cat VERSION) VERSION_MIN=$(REPO)-$$(cd $(CURDIR) && cat VERSION)-minimal GITDIR=$$(test -f .git && echo $$(cut -d" " -f2 .git) || echo .git) all: configured $(MAKE) -C $(BUILD) $@ install: configured $(MAKE) -C $(BUILD) $@ clean: configured $(MAKE) -C $(BUILD) $@ # The COPYFILE_DISABLE flag used in the tar command below is an undocumented feature # of the tar binary on macOS. It causes tar to avoid including any of the special files # that macOS litters around the repository directory, such as ._ resource files, none # of which should be included in the distribution packages. dist: @test -e ../$(VERSION_FULL) && rm -ri ../$(VERSION_FULL) || true @cp -R . ../$(VERSION_FULL) @for i in . $$(git submodule foreach -q --recursive realpath --relative-to=$$(pwd) .); do ((cd ../$(VERSION_FULL)/$$i && test -f .git && cp -R $(GITDIR) .gitnew && rm -f .git && mv .gitnew .git && sed -i.bak -e 's#[[:space:]]*worktree[[:space:]]*=[[:space:]]*.*##g' .git/config) || true); done @for i in . $$(git submodule foreach -q --recursive realpath --relative-to=$$(pwd) .); do (cd ../$(VERSION_FULL)/$$i && git reset -q --hard && git clean -ffdxq); done @(cd ../$(VERSION_FULL) && find . -name \.git\* | xargs rm -rf) @(cd ../$(VERSION_FULL) && find . -name \.idea -type d | xargs rm -rf) @(cd ../$(VERSION_FULL) && find . -name build\* -type d | xargs rm -rf) @mv ../$(VERSION_FULL) . @COPYFILE_DISABLE=true tar -czf $(VERSION_FULL).tar.gz $(VERSION_FULL) @echo Package: $(VERSION_FULL).tar.gz @rm -rf $(VERSION_FULL) distclean: rm -rf $(BUILD) docs: README rst2html.py README >README.html .PHONY : configured configured: @test -d $(BUILD) || ( echo "Error: No build/ directory found. Did you run configure?" && exit 1 ) @test -e $(BUILD)/Makefile || ( echo "Error: No build/Makefile found. Did you run configure?" && exit 1 ) capstats-0.31/CHANGES000644 000765 000024 00000010132 14246446227 014216 0ustar00timstaff000000 000000 0.31 | 2022-06-01 09:30:14 -0700 * Release 0.31 0.30-6 | 2022-01-27 14:50:07 -0700 * Have `make dist` cleanup a few more wayward files before tarring (Tim Wojtulewicz, Corelight) * Update cmake submodule to latest master (Tim Wojtulewicz, Corelight) 0.30 | 2020-12-07 18:26:38 +0000 * Release 0.30 * Remove unnecessary files. (Johanna Amann, Corelight) 0.29-6 | 2020-12-02 11:09:23 -0800 * Update minimum required CMake to 3.5 (Jon Siwek, Corelight) 0.29 | 2020-07-23 10:12:22 -0700 * Release 0.29 0.28 | 2020-02-05 21:29:18 -0800 * Release 0.28 0.27-7 | 2019-10-28 18:07:59 -0700 * Move CMake project() after cmake_minimum_required() (Jon Siwek, Corelight) 0.27 | 2019-06-12 15:05:40 -0700 * Release 0.27 0.26-4 | 2018-12-20 10:24:47 -0600 * Update README (Jon Siwek, Corelight) 0.26-2 | 2018-12-07 16:29:44 -0600 * Update github/download link (Jon Siwek, Corelight) * Update submodules to use github.com/zeek (Jon Siwek, Corelight) 0.26 | 2018-08-31 15:26:46 -0500 * Improve `make dist` (Jon Siwek, Corelight) 0.25-5 | 2018-05-15 15:37:19 +0000 * Updating submodule. 0.25 | 2017-05-26 08:27:56 -0500 * Release 0.25. 0.24-2 | 2016-12-24 11:06:37 +0100 * Fix the "-p" and "--write" command-line options. (Daniel Thayer) 0.24 | 2016-10-27 14:43:34 -0700 * Release 0.24. 0.23 | 2016-06-30 16:55:31 -0700 * Add README.rst -> README symlink. Addresses BIT-1413 (Vlad Grigorescu) 0.22 | 2015-04-27 08:25:19 -0700 * Release 0.22 0.21 | 2014-04-03 15:53:51 -0700 * Release 0.21 0.20 | 2013-10-14 09:24:55 -0700 * Release. 0.19-4 | 2013-10-07 17:07:40 -0700 * Fix getopt_long() usage. (Daniel Thayer) * Updating copyright notice. (Robin Sommer) * Fix for setting REPO in Makefile. (Robin Sommer) 0.19 | 2013-09-23 20:22:43 -0700 * Update 'make dist' target. (Jon Siwek) * Correct a few errors in the README. (Daniel Thayer) * s/bro-ids.org/bro.org/g. (Robin Sommer) 0.18 | 2012-08-01 13:57:19 -0500 * Fix configure script to exit with non-zero status on error (Jon Siwek) 0.17 | 2012-07-05 12:53:52 -0700 * Raise minimum required CMake version to 2.6.3 (Jon Siwek) 0.16 | 2012-01-09 16:11:02 -0800 * Submodule README conformity changes. (Jon Siwek) * Fix parallel make portability. (Jon Siwek) 0.15 | 2011-10-25 17:41:31 -0700 * Make dist now cleans the copied source (Jon Siwek) 0.14-26 | 2011-10-14 15:09:34 -0700 * Distribution cleanup. (Robin Sommer) 0.14-25 | 2011-10-14 15:06:20 -0700 * Distribution cleanup. (Jon Siwek and Robin Sommer) * config.h wasn't being configured by CMake correctly (Jon Siwek) * Adding 'C' language to CMake project as some configure checks depend on it. (Jon Siwek) 0.14-14 | 2011-09-04 08:55:48 -0700 * FindPCAP now links against thread library when necessary (e.g. PF_RING's libpcap). (Jon Siwek) * Install binaries with an RPATH. (Jon Siwek) * Workaround for FreeBSD CMake port missing debug flags. (Jon Siwek) 0.14-5 | 2011-07-24 08:28:06 -0700 * Fixing memory initialization error. (David Binderman) 0.14-3 | 2011-03-14 17:41:03 -0700 * CMake tuning. (Jon Siwek) 0.14-2 | 2011-02-01 12:38:34 -0800 * Linking directly to the found pcap library. (Jon Siwek) 0.14 | 2011-01-28 11:09:04 -0800 * Fix for compiling on OpenBSD and NetBSD. (Kevin Lo) * Converting README from AsciiDoc to REST. (Robin Sommer) * Ported to CMake. (Jon Siwek) * New CHANGES format. 0.13 * Do not output anything to syslog if not explicitly enabled. * New option -q suppresses all normal output but exits with status code 0 if at least n packets have been received, and 1 otherwise. 0.12 * New option --select/-N which for live pcap input uses select() to check for new packets. This is primarily for testing purposes and shouldn't produce any different results. The code mimics pretty closely how the Bro NIDS uses select() on pcap file handles. * Fix disabling option -d when compiled without DAG support. (Justin Azoff) * autotools compatibility fixes. * Man page contributed by Justin Azoff. 0.11 * Fixed potential segfault. 0.1 * Initial release capstats-0.31/config.h.in000644 000765 000024 00000000067 14246446227 015254 0ustar00timstaff000000 000000 /* We are on a Linux system */ #cmakedefine HAVE_LINUX capstats-0.31/README000644 000765 000024 00000007062 14246446227 014113 0ustar00timstaff000000 000000 .. -*- mode: rst-mode -*- .. .. Version number is filled in automatically. .. |version| replace:: 0.31 =============================================== capstats - A tool to get some NIC statistics. =============================================== .. rst-class:: opening capstats is a small tool to collect statistics on the current load of a network interface, using either `libpcap `_ or the native interface for `Endace's `_. It reports statistics per time interval and/or for the tool's total run-time. Download -------- You can find the latest capstats release for download at https://www.zeek.org/download. Capstats's git repository is located at https://github.com/zeek/capstats This document describes capstats |version|. See the ``CHANGES`` file for version history. Output ------ Here's an example output with output in one-second intervals until ``CTRL-C`` is hit:: >capstats -i nve0 -I 1 1186620936.890567 pkts=12747 kpps=12.6 kbytes=10807 mbps=87.5 nic_pkts=12822 nic_drops=0 u=960 t=11705 i=58 o=24 nonip=0 1186620937.901490 pkts=13558 kpps=13.4 kbytes=11329 mbps=91.8 nic_pkts=13613 nic_drops=0 u=1795 t=24339 i=119 o=52 nonip=0 1186620938.912399 pkts=14771 kpps=14.6 kbytes=13659 mbps=110.7 nic_pkts=14781 nic_drops=0 u=2626 t=38154 i=185 o=111 nonip=0 1186620939.012446 pkts=1332 kpps=13.3 kbytes=1129 mbps=92.6 nic_pkts=1367 nic_drops=0 u=2715 t=39387 i=194 o=112 nonip=0 === Total 1186620939.012483 pkts=42408 kpps=13.5 kbytes=36925 mbps=96.5 nic_pkts=1 nic_drops=0 u=2715 t=39387 i=194 o=112 nonip=0 Each line starts with a timestamp and the other fields are: :pkts: Absolute number of packets seen by ``capstats`` during interval. :kpps: Number of thousands of packets per second. :kbytes: Absolute number of KBytes during interval. :mbps: Mbits/sec. :nic_pkts: Number of packets as reported by ``libpcap``'s ``pcap_stats()`` (may not match **pkts**) :nic_drops: Number of packet drops as reported by ``libpcap``'s ``pcap_stats()``. :u: Number of UDP packets. :t: Number of TCP packets. :i: Number of ICMP packets. :o: Number of IP packets with protocol other than TCP, UDP, and ICMP. :nonip: Number of non-IP packets. Options ------- A list of all options:: capstats [Options] -i interface -i| --interface Listen on interface -d| --dag Use native DAG API -f| --filter BPF filter -I| --interval Stats logging interval -l| --syslog Use syslog rather than print to stderr -n| --number Stop after outputting intervals -N| --select Use select() for live pcap (for testing only) -p| --payload Verifies that packets' payloads consist entirely of bytes of the given value. -q| --quiet Suppress output, exit code indicates >= count packets received. -S| --size Verify packets to have given -s| --snaplen Use pcap snaplen -v| --version Print version and exit -w| --write Write packets to file Installation ------------ ``capstats`` has been tested on Linux, FreeBSD, and MacOS. Please see the ``INSTALL`` file for installation instructions. capstats-0.31/COPYING000644 000765 000024 00000003457 14246446227 014272 0ustar00timstaff000000 000000 Copyright (c) 1995-2013, The Regents of the University of California through the Lawrence Berkeley National Laboratory and the International Computer Science Institute. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, U.S. Dept. of Energy, International Computer Science Institute, nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Note that some files in the distribution may carry their own copyright notices. capstats-0.31/VERSION000644 000765 000024 00000000005 14246446227 014271 0ustar00timstaff000000 000000 0.31 capstats-0.31/version.cc.in000644 000765 000024 00000000036 14246446227 015626 0ustar00timstaff000000 000000 char Version[] = "@VERSION@"; capstats-0.31/capstats.cc000644 000765 000024 00000035446 14246446227 015373 0ustar00timstaff000000 000000 // Counts captured packets. // // Robin Sommer #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__OpenBSD__) #include #elif defined(__NetBSD__) #include #else #include #endif #include #include #include #include #include #include #include #include "config.h" extern char Version[]; #ifdef USE_DAG # include // Length of ERF Header before Ethernet header. # define DAG_ETH_ERFLEN 18 # define EXTRA_WINDOW_SIZE (4 * 1024 * 1024) #endif bool CheckPayload = false; bool WritePackets = false; bool CheckSize = false; bool UseDag = false; bool UseSyslog = false; const char *Filter; const char *Interface = 0; const char *OutputFile = 0; int Interval = 0; int Payload = 0; int SnapLen = 8192; int NumberInts = 0; int UseSelect = false; unsigned int Size = 0; int Quiet = 0; pcap_dumper_t *Dumper; bool GotBreak = false; bool GotAlarm = false; double current_time(); struct Stats { unsigned long packets; unsigned long bytes; unsigned long size_mismatches; unsigned long payload_mismatches; unsigned long dag_drops; unsigned long dag_all; unsigned long proto[256]; unsigned long non_ip; double start; Stats() { clear(); } void clear() { memset(proto, 0, sizeof(proto)); packets = bytes = size_mismatches = payload_mismatches = non_ip = 0; dag_drops = dag_all = 0; start = current_time(); } }; Stats Total; Stats Current; unsigned long HdrSize = 14; // Ethernet pcap_t* Pcap = 0; struct bpf_program* Bpf = 0; int Dag = -1; const char* fmt_log(const char* prefix, const char* fmt, va_list ap) { const int SIZE = 32768; static char buffer[SIZE]; int n = 0; n += snprintf(buffer + n, SIZE - n, "%s: ", prefix); n += vsnprintf(buffer + n, SIZE - n, fmt, ap); strcat(buffer + n, "\n"); return buffer; } void logMsg(const char* msg) { if ( Quiet > 0 ) return; if (UseSyslog) syslog(LOG_NOTICE, "%s", msg); else fprintf(stderr, "%.6f %s\n", current_time(), msg); } void error(const char* fmt, ...) { va_list ap; va_start(ap, fmt); const char* msg = fmt_log("error", fmt, ap); va_end(ap); fputs(msg, stdout); exit(1); } double current_time() { struct timeval tv; if ( gettimeofday(&tv, 0) < 0 ) error("gettimeofday failed in current_time()"); return double(tv.tv_sec) + double(tv.tv_usec) / 1e6; } void setFilter() { Bpf = new bpf_program; if ( pcap_compile(Pcap, Bpf, (char*)Filter, 1, 0) < 0 ) error("can't compile %s: %s", Filter, pcap_geterr(Pcap)); if ( pcap_setfilter(Pcap, Bpf) < 0 ) error("can't set filter: %s", pcap_geterr(Pcap)); } void pcapOpen() { static char errbuf[PCAP_ERRBUF_SIZE]; Pcap = pcap_open_live((char *)Interface, SnapLen, 1, UseSelect ? 1 : 10, errbuf); if ( ! Pcap ) error("%s", errbuf); #ifdef HAVE_LINUX // Copied from Bro (we generally mimic how Bro is doing non-blocking i/o.) // We use the smallest time-out possible to return almost immediately if // no packets are available. (We can't use set_nonblocking() as it's // broken on FreeBSD: even when select() indicates that we can read // something, we may get nothing if the store buffer hasn't filled up // yet.) if ( pcap_setnonblock(Pcap, 1, errbuf) < 0 ) error("%s", errbuf); #endif int dl = pcap_datalink(Pcap); if ( dl != DLT_EN10MB ) error("unknown data link type 0x%x", dl); if ( Filter ) setFilter(); } bool pcapNext(const u_char **pkt, unsigned int *size) { struct pcap_pkthdr* hdr; const u_char* data; int result; if ( UseSelect ) { int fd = pcap_fileno(Pcap); struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0; fd_set fd_read; FD_ZERO(&fd_read); FD_SET(fd, &fd_read); if ( select(fd + 1, &fd_read, 0, 0, &timeout) <= 0 ) { // Wait a bit to allow packets to arrive for next time. // This might look a bit odd (i.e., we could use a larger timeout // right away) but we try to mimic the way Bro operates. struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 20; select(0, 0, 0, 0, &timeout); return false; } } result = pcap_next_ex(Pcap, &hdr, &data); if ( result < 0 ) error("no more input"); if ( result == 0 ) return false; *pkt = data; *size = hdr->caplen; if ( WritePackets ) pcap_dump((u_char*) Dumper, hdr, data); return true; } void pcapStats(unsigned int* pkts, unsigned int* drops) { static pcap_stat stats; if ( pcap_stats(Pcap, &stats) < 0 ) error("can't get pcap stats"); #ifdef HAVE_LINUX // Linux clears its counters each time. if ( pkts ) *pkts = stats.ps_recv; if ( drops ) *drops = stats.ps_drop; #else static pcap_stat *last_stats = 0; if ( ! last_stats ) { last_stats = new pcap_stat; last_stats->ps_recv = 0; last_stats->ps_drop = 0; } if ( pkts ) *pkts = stats.ps_recv - last_stats->ps_recv; if ( drops ) *drops = stats.ps_drop - last_stats->ps_drop; *last_stats = stats; #endif } void pcapClose() { pcap_close(Pcap); } void dagOpen() { #ifdef USE_DAG Dag = dag_open((char*)Interface); if ( Dag < 0 ) error("can't open dag interface %s", Interface); int dag_recordtype = dag_linktype(Dag); if ( dag_recordtype < TYPE_MIN || dag_recordtype > TYPE_MAX ) error("dag_linktype"); if ( dag_recordtype != TYPE_ETH ) error("unsupported DAG link type 0x%x", dag_recordtype); // long= is needed to prevent the DAG card from truncating jumbo frames. const char* dag_configure_string = "slen=1500 varlen long=1500"; if ( dag_configure(Dag, (char*)dag_configure_string) < 0 ) error("dag_configure"); if ( dag_attach_stream(Dag, 0, 0, EXTRA_WINDOW_SIZE) < 0 ) error("dag_attach_stream"); if ( dag_start_stream(Dag, 0) < 0 ) error("dag_start_stream"); // We open a dummy pcap file to get access to pcap data structures. Pcap = pcap_open_dead(DLT_EN10MB, 1500); if ( ! Pcap ) error("pcap_open_dead"); if ( Filter ) setFilter(); #endif } bool dagNext(const u_char **pkt, unsigned int *size) { #ifdef USE_DAG struct bpf_insn* fcode = 0; if ( Filter ) { fcode = Bpf->bf_insns; if ( ! fcode ) error("filter code not valid when extracting DAG packet"); } dag_record_t* r = (dag_record_t*) dag_rx_stream_next_record(Dag, 0); if ( ! r ) { if ( errno == EAGAIN ) // Dry. return false; error("dag_rx_stream_next_record: %s", strerror(errno)); } *size = ntohs(r->rlen) - DAG_ETH_ERFLEN; *pkt = (const u_char*) r->rec.eth.dst; Current.dag_drops += ntohs(r->lctr); Total.dag_drops += ntohs(r->lctr); if ( fcode && ! bpf_filter(fcode, (u_char*) *pkt, *size, *size) ) return false; return true; #else return false; #endif } void dagStats(unsigned int* pkts, unsigned int* drops, const Stats& s) { *pkts = s.dag_all; *drops = s.dag_drops; } void dagClose() { #ifdef USE_DAG dag_stop_stream(Dag, 0); dag_detach_stream(Dag, 0); dag_close(Dag); #endif } void reportStats(const Stats& s) { unsigned int pkts = 0, drops = 0; const int SIZE = 32768; static char buffer[SIZE]; int n = 0; int i; unsigned long proto_other = 0; if ( UseDag ) dagStats(&pkts, &drops, s); else pcapStats(&pkts, &drops); double dt = current_time() - s.start; double pps = s.packets / dt; double mbps = s.bytes / dt * 8 / 1000 / 1000; n += snprintf(buffer+n, SIZE-n, "pkts=%lu kpps=%.1f kbytes=%lu mbps=%.1f nic_pkts=%u nic_drops=%u", s.packets, pps / 1000, s.bytes / 1024, mbps, pkts, drops); for ( i=0; i<256; i++ ) if ( i != IPPROTO_UDP && i != IPPROTO_TCP && i != IPPROTO_ICMP ) proto_other += s.proto[i]; n += snprintf(buffer+n, SIZE-n, " u=%lu t=%lu i=%lu o=%lu nonip=%lu", s.proto[IPPROTO_UDP], s.proto[IPPROTO_TCP], s.proto[IPPROTO_ICMP], proto_other, s.non_ip); if ( CheckSize ) n += snprintf(buffer+n, SIZE-n, " size_mism=%lu", s.size_mismatches); if ( CheckPayload ) n += snprintf(buffer+n, SIZE-n, " payload_mism=%lu", s.size_mismatches); logMsg(buffer); Current.clear(); } void alarmHandler(int signo) { GotAlarm = true; } void scheduleAlarm() { GotAlarm = false; if ( Interval ) { signal(SIGALRM, alarmHandler); alarm(Interval); } } void mainLoop() { while ( ! GotBreak ) { if ( GotAlarm ) { reportStats(Current); scheduleAlarm(); if ( NumberInts == 1 ) { if ( Quiet > 0 ) exit(Total.packets >= (unsigned)Quiet ? 0 : 1); else exit(0); } if ( NumberInts ) NumberInts--; } bool result; unsigned int size; const u_char* pkt; const struct ip *ip; const struct ether_header *eh; if ( UseDag ) result = dagNext(&pkt, &size); else result = pcapNext(&pkt, &size); if ( ! result ) continue; eh = (struct ether_header*)pkt; if ( ntohs(eh->ether_type) == ETHERTYPE_IP ) { ip = (struct ip*)(pkt + HdrSize); ++Current.proto[ip->ip_p]; ++Total.proto[ip->ip_p]; } else { ++Current.non_ip; ++Total.non_ip; } size -= HdrSize; pkt += HdrSize; ++Current.packets; ++Total.packets; Current.bytes += size; Total.bytes += size; if ( CheckSize ) if ( size != Size ) { ++Current.size_mismatches; ++Total.size_mismatches; } if ( CheckPayload ) for ( unsigned int i = 0; i < size; i++ ) { if ( pkt[i] != Payload ) { ++Current.payload_mismatches; ++Total.payload_mismatches; break; } } } } void breakHandler(int signo) { GotBreak = true; } void usage() { printf("capstats [Options] -i interface\n" "\n" " -i| --interface Listen on interface\n" #ifdef USE_DAG " -d| --dag Use native DAG API\n" #endif " -f| --filter BPF filter\n" " -I| --interval Stats logging interval\n" " -l| --syslog Use syslog rather than print to stderr\n" " -n| --number Stop after outputting intervals\n" " -N| --select Use select() for live pcap (for testing only)\n" " -p| --payload Verifies that packets' payloads consist entirely of bytes of the given value.\n" " -q| --quiet Suppress output, exit code indicates >= count packets received.\n" " -S| --size Verify packets to have given \n" " -s| --snaplen Use pcap snaplen = \n" " -v| --version Print version and exit\n" " -w| --write Write packets to file\n" "\n"); exit(1); } static struct option long_options[] = { #ifdef USE_DAG {"dag", no_argument, 0, 'd'}, #endif {"filter", required_argument, 0, 'f'}, {"interface", required_argument, 0, 'i'}, {"interval", required_argument, 0, 'I'}, {"number", required_argument, 0, 'n'}, {"select", no_argument, 0, 'N'}, {"syslog", no_argument, 0, 'l'}, {"payload", required_argument, 0, 'p'}, {"quiet", required_argument, 0, 'q'}, {"size", required_argument, 0, 'S'}, {"snaplen", required_argument, 0, 's'}, {"version", no_argument, 0, 'v'}, {"write", required_argument, 0, 'w'}, {0, 0, 0, 0} }; int main(int argc, char **argv) { while (1) { #ifdef USE_DAG int c = getopt_long (argc, argv, "df:i:I:n:Np:q:s:lvw:S:", long_options, 0); #else int c = getopt_long (argc, argv, "f:i:I:n:Np:q:s:lvw:S:", long_options, 0); #endif if ( c == -1 ) break; switch ( c ) { case 'd': UseDag = true; break; case 'f': Filter = optarg; break; case 'i': Interface = optarg; break; case 'I': Interval = atoi(optarg); break; case 'l': UseSyslog = true; break; case 'n': NumberInts = atoi(optarg); break; case 'N': UseSelect = true; break; case 'p': CheckPayload = true; Payload = atoi(optarg); break; case 'q': Quiet = atoi(optarg); break; case 'S': CheckSize = true; Size = atoi(optarg); break; case 's': SnapLen = atoi(optarg); break; case 'w': OutputFile = optarg; WritePackets = true; break; case 'v': fprintf(stderr, "capstats %s\n", Version); exit(0); break; default: usage(); } } if ( optind != argc ) usage(); if ( ! Interface ) error("no interface given"); if ( UseSyslog ) { openlog("capstats", LOG_PID, LOG_NOTICE); syslog(LOG_NOTICE, "starting if=%s interval=%d filter=%s", Interface, Interval, Filter); } if ( UseDag ) dagOpen(); else pcapOpen(); if ( WritePackets ) { Dumper = pcap_dump_open(Pcap, OutputFile); if (not Dumper) error("can't open pcap dump file: %s", pcap_geterr(Pcap)); } signal(SIGINT, breakHandler); signal(SIGTERM, breakHandler); scheduleAlarm(); pcapStats(0, 0); mainLoop(); reportStats(Current); logMsg("\n=== Total\n"); reportStats(Total); if ( UseDag ) dagClose(); else pcapClose(); if ( Dumper ) pcap_dump_close(Dumper); if ( UseSyslog ) syslog(LOG_NOTICE, "exiting..."); if ( Quiet > 0 ) return Total.packets >= (unsigned)Quiet ? 0 : 1; return 0; } capstats-0.31/README.rst000755 000765 000024 00000000000 14246446227 015566 2READMEustar00timstaff000000 000000 capstats-0.31/cmake/InstallPackageConfigFile.cmake000644 000765 000024 00000005336 14246446227 022127 0ustar00timstaff000000 000000 include(InstallClobberImmune) # This macro can be used to install configuration files which # users are expected to modify after installation. It will: # # - If binary packaging is enabled: # Install the file in the typical CMake fashion, but append to the # INSTALLED_CONFIG_FILES cache variable for use with the Mac package's # pre/post install scripts # # - If binary packaging is not enabled: # Install the script in a way such that it will check at `make install` # time whether the file does not exist. See InstallClobberImmune.cmake # # - Always create a target "install-example-configs" which installs an # example version of the config file. # # _srcfile: the absolute path to the file to install # _dstdir: absolute path to the directory in which to install the file # _dstfilename: how to (re)name the file inside _dstdir macro(InstallPackageConfigFile _srcfile _dstdir _dstfilename) set(_dstfile ${_dstdir}/${_dstfilename}) if (BINARY_PACKAGING_MODE) # If packaging mode is enabled, always install the distribution's # version of the file. The Mac package's pre/post install scripts # or native functionality of RPMs will take care of not clobbering it. install(FILES ${_srcfile} DESTINATION ${_dstdir} RENAME ${_dstfilename}) # This cache variable is what the Mac package pre/post install scripts # use to avoid clobbering user-modified config files set(INSTALLED_CONFIG_FILES "${INSTALLED_CONFIG_FILES} ${_dstfile}" CACHE STRING "" FORCE) # Additionally, the Mac PackageMaker packages don't have any automatic # handling of configuration file conflicts so install an example file # that the post install script will cleanup in the case it's extraneous if (APPLE) install(FILES ${_srcfile} DESTINATION ${_dstdir} RENAME ${_dstfilename}.example) endif () else () # Have `make install` check at run time whether the file does not exist InstallClobberImmune(${_srcfile} ${_dstfile}) endif () if (NOT TARGET install-example-configs) add_custom_target(install-example-configs COMMENT "Installed example configuration files") endif () # Replace characters disallowed in target names (per CMP0037) with '.'. string(REGEX REPLACE "[^A-Za-z0-9_.+-]" "." _flatsrc ${_srcfile}) set(_example ${_dstfile}.example) add_custom_target(install-example-config-${_flatsrc} COMMAND "${CMAKE_COMMAND}" -E copy ${_srcfile} \${DESTDIR}${_example} COMMENT "Installing ${_example}") add_dependencies(install-example-configs install-example-config-${_flatsrc}) endmacro(InstallPackageConfigFile) capstats-0.31/cmake/MiscTests.cmake000644 000765 000024 00000002010 14246446227 017217 0ustar00timstaff000000 000000 include(CheckCXXSourceCompiles) include(CheckCSourceCompiles) # This autoconf variable is obsolete; it's portable to assume C89 and signal # handlers returning void set(RETSIGTYPE "void") set(RETSIGVAL "") check_c_source_compiles(" #include #include extern int socket(int, int, int); extern int connect(int, const struct sockaddr *, int); extern int send(int, const void *, int, int); extern int recvfrom(int, void *, int, int, struct sockaddr *, int *); int main() { return 0; } " DO_SOCK_DECL) if (DO_SOCK_DECL) message(STATUS "socket() and friends need explicit declaration") endif () check_cxx_source_compiles(" #include #include extern \"C\" { int openlog(const char* ident, int logopt, int facility); int syslog(int priority, const char* message_fmt, ...); int closelog(); } int main() { return 0; } " SYSLOG_INT) if (SYSLOG_INT) message(STATUS "syslog prototypes need declaration") endif () capstats-0.31/cmake/FindClangTidy.cmake000644 000765 000024 00000004311 14246446227 017766 0ustar00timstaff000000 000000 # Common functions to use clang-tidy. This requires you to have clang-tidy in your path. If you also # have run-clang-tidy.py in your path, it will attempt to use that to run clang-tidy in parallel. ######################################################################## # If this hasn't been initialized yet, find the program and then create a global property # to store the list of sources in. if (NOT CLANG_TIDY) find_program(CLANG_TIDY NAMES clang-tidy) find_program(RUN_CLANG_TIDY NAMES run-clang-tidy.py) if (CLANG_TIDY) define_property(GLOBAL PROPERTY TIDY_SRCS BRIEF_DOCS "Global list of sources for clang-tidy" FULL_DOCS "Global list of sources for clang-tidy") set_property(GLOBAL PROPERTY TIDY_SRCS "") endif() endif() ######################################################################## # Adds a list of files to the global list of files that will be checked. function(add_clang_tidy_files) if (CLANG_TIDY) foreach(f ${ARGV}) if (IS_ABSOLUTE ${f}) set_property(GLOBAL APPEND PROPERTY TIDY_SRCS "${f}") else() set_property(GLOBAL APPEND PROPERTY TIDY_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/${f}") endif() endforeach(f) endif() endfunction() ######################################################################## # Creates the final target using the global list of files. function(create_clang_tidy_target) if (CLANG_TIDY) get_property(final_tidy_srcs GLOBAL PROPERTY TIDY_SRCS) list(REMOVE_DUPLICATES final_tidy_srcs) if (RUN_CLANG_TIDY) add_custom_target(clang-tidy COMMAND ${RUN_CLANG_TIDY} -p ${PROJECT_BINARY_DIR} -clang-tidy-binary ${CLANG_TIDY} -j 4 -export-fixes ${PROJECT_BINARY_DIR}/clang-tidy.yaml ${final_tidy_srcs} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) else() add_custom_target(clang-tidy COMMAND ${CLANG_TIDY} -p ${PROJECT_BINARY_DIR} ${final_tidy_srcs} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) endif() endif() endfunction() capstats-0.31/cmake/FindBISON.cmake000644 000765 000024 00000022222 14246446227 016763 0ustar00timstaff000000 000000 # - Find bison executable and provides macros to generate custom build rules # The module defines the following variables: # # BISON_EXECUTABLE - path to the bison program # BISON_VERSION - version of bison # BISON_FOUND - true if the program was found # # If bison is found, the module defines the macros: # BISON_TARGET( [VERBOSE ] # [COMPILE_FLAGS ] [HEADER ]) # which will create a custom rule to generate a parser. is # the path to a yacc file. is the name of the source file # generated by bison. A header file containing the token list is also # generated according to bison's -d option by default or if the HEADER # option is used, the argument is passed to bison's --defines option to # specify output file. If COMPILE_FLAGS option is specified, the next # parameter is added in the bison command line. if VERBOSE option is # specified, is created and contains verbose descriptions of the # grammar and parser. The macro defines a set of variables: # BISON_${Name}_DEFINED - true is the macro ran successfully # BISON_${Name}_INPUT - The input source file, an alias for # BISON_${Name}_OUTPUT_SOURCE - The source file generated by bison # BISON_${Name}_OUTPUT_HEADER - The header file generated by bison # BISON_${Name}_OUTPUTS - The sources files generated by bison # BISON_${Name}_COMPILE_FLAGS - Options used in the bison command line # # ==================================================================== # Example: # # find_package(BISON) # BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp) # add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS}) # ==================================================================== #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2006 Tristan Carel # Modified 2010 by Jon Siwek, adding HEADER option # # Distributed under the OSI-approved BSD License (the "License"): # CMake - Cross Platform Makefile Generator # Copyright 2000-2009 Kitware, Inc., Insight Software Consortium # All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * Neither the names of Kitware, Inc., the Insight Software Consortium, # nor the names of their contributors may be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= FIND_PROGRAM(BISON_EXECUTABLE bison DOC "path to the bison executable") MARK_AS_ADVANCED(BISON_EXECUTABLE) IF(BISON_EXECUTABLE) EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version OUTPUT_VARIABLE BISON_version_output ERROR_VARIABLE BISON_version_error RESULT_VARIABLE BISON_version_result OUTPUT_STRIP_TRAILING_WHITESPACE) IF(NOT ${BISON_version_result} EQUAL 0) MESSAGE(SEND_ERROR "Command \"${BISON_EXECUTABLE} --version\" failed with output:\n${BISON_version_error}") ELSE() STRING(REGEX REPLACE "^bison \\(GNU [bB]ison\\) ([^\n]+)\n.*" "\\1" BISON_VERSION "${BISON_version_output}") ENDIF() # internal macro MACRO(BISON_TARGET_option_verbose Name BisonOutput filename) LIST(APPEND BISON_TARGET_cmdopt "--verbose") GET_FILENAME_COMPONENT(BISON_TARGET_output_path "${BisonOutput}" PATH) GET_FILENAME_COMPONENT(BISON_TARGET_output_name "${BisonOutput}" NAME_WE) ADD_CUSTOM_COMMAND(OUTPUT ${filename} COMMAND ${CMAKE_COMMAND} ARGS -E copy "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output" "${filename}" DEPENDS "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output" COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) SET(BISON_${Name}_VERBOSE_FILE ${filename}) LIST(APPEND BISON_TARGET_extraoutputs "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output") ENDMACRO(BISON_TARGET_option_verbose) # internal macro MACRO(BISON_TARGET_option_extraopts Options) SET(BISON_TARGET_extraopts "${Options}") SEPARATE_ARGUMENTS(BISON_TARGET_extraopts) LIST(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts}) ENDMACRO(BISON_TARGET_option_extraopts) #============================================================ # BISON_TARGET (public macro) #============================================================ # MACRO(BISON_TARGET Name BisonInput BisonOutput) SET(BISON_TARGET_output_header "") #SET(BISON_TARGET_command_opt "") SET(BISON_TARGET_cmdopt "") SET(BISON_TARGET_outputs "${BisonOutput}") IF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7 AND NOT ${ARGC} EQUAL 9) MESSAGE(SEND_ERROR "Usage") ELSE() # Parsing parameters IF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5) IF("${ARGV3}" STREQUAL "VERBOSE") BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV4}") ENDIF() IF("${ARGV3}" STREQUAL "COMPILE_FLAGS") BISON_TARGET_option_extraopts("${ARGV4}") ENDIF() IF("${ARGV3}" STREQUAL "HEADER") set(BISON_TARGET_output_header "${ARGV4}") ENDIF() ENDIF() IF(${ARGC} GREATER 7 OR ${ARGC} EQUAL 7) IF("${ARGV5}" STREQUAL "VERBOSE") BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV6}") ENDIF() IF("${ARGV5}" STREQUAL "COMPILE_FLAGS") BISON_TARGET_option_extraopts("${ARGV6}") ENDIF() IF("${ARGV5}" STREQUAL "HEADER") set(BISON_TARGET_output_header "${ARGV6}") ENDIF() ENDIF() IF(${ARGC} EQUAL 9) IF("${ARGV7}" STREQUAL "VERBOSE") BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV8}") ENDIF() IF("${ARGV7}" STREQUAL "COMPILE_FLAGS") BISON_TARGET_option_extraopts("${ARGV8}") ENDIF() IF("${ARGV7}" STREQUAL "HEADER") set(BISON_TARGET_output_header "${ARGV8}") ENDIF() ENDIF() IF(BISON_TARGET_output_header) # Header's name passed in as argument to be used in --defines option LIST(APPEND BISON_TARGET_cmdopt "--defines=${BISON_TARGET_output_header}") set(BISON_${Name}_OUTPUT_HEADER ${BISON_TARGET_output_header}) ELSE() # Header's name generated by bison (see option -d) LIST(APPEND BISON_TARGET_cmdopt "-d") STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}") STRING(REPLACE "c" "h" _fileext ${_fileext}) STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}" BISON_${Name}_OUTPUT_HEADER "${ARGV2}") ENDIF() LIST(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}") ADD_CUSTOM_COMMAND(OUTPUT ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs} COMMAND ${BISON_EXECUTABLE} ARGS ${BISON_TARGET_cmdopt} -o ${ARGV2} ${ARGV1} DEPENDS ${ARGV1} COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) # define target variables SET(BISON_${Name}_DEFINED TRUE) SET(BISON_${Name}_INPUT ${ARGV1}) SET(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs}) SET(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt}) SET(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}") ENDIF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7 AND NOT ${ARGC} EQUAL 9) ENDMACRO(BISON_TARGET) # #============================================================ ENDIF(BISON_EXECUTABLE) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(BISON DEFAULT_MSG BISON_EXECUTABLE) # FindBISON.cmake ends here capstats-0.31/cmake/OSSpecific.cmake000644 000765 000024 00000003401 14246446227 017275 0ustar00timstaff000000 000000 if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(HAVE_DARWIN true) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(HAVE_LINUX true) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Solaris") set(SOCKET_LIBS nsl socket) elseif (${CMAKE_SYSTEM_NAME} MATCHES "osf") # Workaround ip_hl vs. ip_vhl problem in netinet/ip.h add_definitions(-D__STDC__=2) elseif (${CMAKE_SYSTEM_NAME} MATCHES "irix") list(APPEND CMAKE_C_FLAGS -xansi -signed -g3) list(APPEND CMAKE_CXX_FLAGS -xansi -signed -g3) elseif (${CMAKE_SYSTEM_NAME} MATCHES "ultrix") list(APPEND CMAKE_C_FLAGS -std1 -g3) list(APPEND CMAKE_CXX_FLAGS -std1 -g3) include(CheckCSourceCompiles) check_c_source_compiles(" #include int main() { void c(const struct a *); return 0; } " have_ultrix_const) if (NOT have_ultrix_const) set(NEED_ULTRIX_CONST_HACK true) endif () elseif (${CMAKE_SYSTEM_NAME} MATCHES "hpux" OR ${CMAKE_SYSTEM_NAME} MATCHES "HP-UX") include(CheckCSourceCompiles) set(CMAKE_REQUIRED_FLAGS -Aa) set(CMAKE_REQUIRED_DEFINITIONS -D_HPUX_SOURCE) check_c_source_compiles(" #include int main() { int frob(int, char *); return 0; } " have_ansi_prototypes) set(CMAKE_REQUIRED_FLAGS) set(CMAKE_REQUIRED_DEFINITIONS) if (have_ansi_prototypes) add_definitions(-D_HPUX_SOURCE) list(APPEND CMAKE_C_FLAGS -Aa) list(APPEND CMAKE_CXX_FLAGS -Aa) endif () if (NOT have_ansi_prototypes) message(FATAL_ERROR "Can't get HPUX compiler to handle ANSI prototypes") endif () endif () capstats-0.31/cmake/BroPlugin.cmake000755 000765 000024 00000000000 14246446227 022261 2ZeekPlugin.cmakeustar00timstaff000000 000000 capstats-0.31/cmake/SetupRPATH.cmake000644 000765 000024 00000000566 14246446227 017216 0ustar00timstaff000000 000000 # Keep RPATH upon installing so that user doesn't have to ensure the linker # can find internal/private libraries or libraries external to the build # directory that were explicitly linked against if (NOT BINARY_PACKAGING_MODE) include(GNUInstallDirs) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") endif () capstats-0.31/cmake/FindBroker.cmake000644 000765 000024 00000003075 14246446227 017342 0ustar00timstaff000000 000000 # - Try to find Broker library and headers # # Usage of this module as follows: # # find_package(Broker) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # BROKER_ROOT_DIR Set this variable to the root installation of # Broker if the module has problems finding the # proper installation path. # # Variables defined by this module: # # BROKER_FOUND System has Broker library # BROKER_LIBRARY The broker library # BROKER_INCLUDE_DIR The broker headers if(NOT BROKER_ROOT_DIR) find_path(BROKER_ROOT_DIR NAMES include/broker/broker.hh ) set(header_hints "${BROKER_ROOT_DIR}/include" ) else() set(header_hints "${BROKER_ROOT_DIR}/include" "${BROKER_ROOT_DIR}/../include" "${BROKER_ROOT_DIR}/../../include" ) endif() find_library(BROKER_LIBRARY NAMES broker HINTS ${BROKER_ROOT_DIR}/lib ) find_path(broker_hh_dir NAMES broker/broker.hh HINTS ${header_hints} ) find_path(config_hh_dir NAMES broker/config.hh HINTS ${header_hints} ) if("${broker_hh_dir}" STREQUAL "${config_hh_dir}") set(BROKER_INCLUDE_DIR "${broker_hh_dir}") else() set(BROKER_INCLUDE_DIR "${broker_hh_dir}" "${config_hh_dir}") endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Broker DEFAULT_MSG BROKER_LIBRARY BROKER_INCLUDE_DIR ) mark_as_advanced( BROKER_ROOT_DIR BROKER_LIBRARY BROKER_INCLUDE_DIR ) capstats-0.31/cmake/CheckFunctions.cmake000644 000765 000024 00000000624 14246446227 020220 0ustar00timstaff000000 000000 include(CheckFunctionExists) check_function_exists(getopt_long HAVE_GETOPT_LONG) check_function_exists(mallinfo HAVE_MALLINFO) check_function_exists(mallinfo2 HAVE_MALLINFO2) check_function_exists(strcasestr HAVE_STRCASESTR) check_function_exists(strerror HAVE_STRERROR) check_function_exists(strsep HAVE_STRSEP) check_function_exists(sigset HAVE_SIGSET) check_function_exists(sigaction HAVE_SIGACTION) capstats-0.31/cmake/FindFTS.cmake000644 000765 000024 00000001742 14246446227 016551 0ustar00timstaff000000 000000 # - Try to find FTS library and headers # # Usage of this module as follows: # # find_package(FTS) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # FTS_ROOT_DIR Set this variable to the root installation of # FTS if the module has problems finding the # proper installation path. # # Variables defined by this module: # # FTS_FOUND System has FTS library # FTS_LIBRARY The FTS library # FTS_INCLUDE_DIR The FTS headers find_path(FTS_ROOT_DIR NAMES include/fts.h ) find_library(FTS_LIBRARY NAMES fts HINTS ${FTS_ROOT_DIR}/lib ) find_path(FTS_INCLUDE_DIR NAMES fts.h HINTS ${FTS_ROOT_DIR}/include ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(FTS DEFAULT_MSG FTS_LIBRARY FTS_INCLUDE_DIR ) mark_as_advanced( FTS_ROOT_DIR FTS_LIBRARY FTS_INCLUDE_DIR ) capstats-0.31/cmake/FindOpenSSL.cmake000644 000765 000024 00000056212 14246446227 017402 0ustar00timstaff000000 000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: FindOpenSSL ----------- Find the OpenSSL encryption library. This module finds an installed OpenSSL library and determines its version. .. versionadded:: 3.19 When a version is requested, it can be specified as a simple value or as a range. For a detailed description of version range usage and capabilities, refer to the :command:`find_package` command. .. versionadded:: 3.18 Support for OpenSSL 3.0. Optional COMPONENTS ^^^^^^^^^^^^^^^^^^^ .. versionadded:: 3.12 This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both components have associated imported targets, as described below. Imported Targets ^^^^^^^^^^^^^^^^ .. versionadded:: 3.4 This module defines the following :prop_tgt:`IMPORTED` targets: ``OpenSSL::SSL`` The OpenSSL ``ssl`` library, if found. ``OpenSSL::Crypto`` The OpenSSL ``crypto`` library, if found. ``OpenSSL::applink`` .. versionadded:: 3.18 The OpenSSL ``applink`` components that might be need to be compiled into projects under MSVC. This target is available only if found OpenSSL version is not less than 0.9.8. By linking this target the above OpenSSL targets can be linked even if the project has different MSVC runtime configurations with the above OpenSSL targets. This target has no effect on platforms other than MSVC. NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target, unless you certainly know what you are doing, it is always preferred to link ``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is linked at most once for the whole dependency graph of any library or executable: .. code-block:: cmake target_link_libraries(myTarget PRIVATE OpenSSL::applink) Otherwise you would probably encounter unexpected random problems when building and linking, as both the ISO C and the ISO C++ standard claims almost nothing about what a link process should be. Result Variables ^^^^^^^^^^^^^^^^ This module will set the following variables in your project: ``OPENSSL_FOUND`` System has the OpenSSL library. If no components are requested it only requires the crypto library. ``OPENSSL_INCLUDE_DIR`` The OpenSSL include directory. ``OPENSSL_CRYPTO_LIBRARY`` The OpenSSL crypto library. ``OPENSSL_CRYPTO_LIBRARIES`` The OpenSSL crypto library and its dependencies. ``OPENSSL_SSL_LIBRARY`` The OpenSSL SSL library. ``OPENSSL_SSL_LIBRARIES`` The OpenSSL SSL library and its dependencies. ``OPENSSL_LIBRARIES`` All OpenSSL libraries and their dependencies. ``OPENSSL_VERSION`` This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``). ``OPENSSL_APPLINK_SOURCE`` The sources in the target ``OpenSSL::applink`` that is mentioned above. This variable shall always be undefined if found openssl version is less than 0.9.8 or if platform is not MSVC. Hints ^^^^^ Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation. .. versionadded:: 3.4 Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries. .. versionadded:: 3.5 Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib. #]=======================================================================] macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library) if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND (("${ssl_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") OR ("${crypto_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$"))) set(_OpenSSL_has_dependencies TRUE) find_package(Threads) else() set(_OpenSSL_has_dependencies FALSE) endif() endmacro() function(_OpenSSL_add_dependencies libraries_var) if(CMAKE_THREAD_LIBS_INIT) list(APPEND ${libraries_var} ${CMAKE_THREAD_LIBS_INIT}) endif() list(APPEND ${libraries_var} ${CMAKE_DL_LIBS}) set(${libraries_var} ${${libraries_var}} PARENT_SCOPE) endfunction() function(_OpenSSL_target_add_dependencies target) if(_OpenSSL_has_dependencies) set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads ) set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} ) endif() if(WIN32 AND OPENSSL_USE_STATIC_LIBS) set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2_32 ) set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32 ) endif() endfunction() if (UNIX) find_package(PkgConfig QUIET) pkg_check_modules(_OPENSSL QUIET openssl) endif () # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES if(OPENSSL_USE_STATIC_LIBS) set(_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) if(WIN32) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) else() set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) endif() endif() if (WIN32) # http://www.slproweb.com/products/Win32OpenSSL.html set(_OPENSSL_ROOT_HINTS ${OPENSSL_ROOT_DIR} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]" "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]" ENV OPENSSL_ROOT_DIR ) if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") set(_arch "Win64") file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) else() set(_arch "Win32") set(_progfiles_x86 "ProgramFiles(x86)") if(NOT "$ENV{${_progfiles_x86}}" STREQUAL "") # under windows 64 bit machine file(TO_CMAKE_PATH "$ENV{${_progfiles_x86}}" _programfiles) else() # under windows 32 bit machine file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _programfiles) endif() endif() set(_OPENSSL_ROOT_PATHS "${_programfiles}/OpenSSL" "${_programfiles}/OpenSSL-${_arch}" "C:/OpenSSL/" "C:/OpenSSL-${_arch}/" ) unset(_programfiles) unset(_arch) else () set(_OPENSSL_ROOT_HINTS ${OPENSSL_ROOT_DIR} ENV OPENSSL_ROOT_DIR ) endif () set(_OPENSSL_ROOT_HINTS_AND_PATHS HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} ) find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h ${_OPENSSL_ROOT_HINTS_AND_PATHS} HINTS ${_OPENSSL_INCLUDEDIR} ${_OPENSSL_INCLUDE_DIRS} PATH_SUFFIXES include ) if(WIN32 AND NOT CYGWIN) if(MSVC) # /MD and /MDd are the standard values - if someone wants to use # others, the libnames have to change here too # use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b # enable OPENSSL_MSVC_STATIC_RT to get the libs build /MT (Multithreaded no-DLL) # In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix: # * MD for dynamic-release # * MDd for dynamic-debug # * MT for static-release # * MTd for static-debug # Implementation details: # We are using the libraries located in the VC subdir instead of the parent directory even though : # libeay32MD.lib is identical to ../libeay32.lib, and # ssleay32MD.lib is identical to ../ssleay32.lib # enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static if (OPENSSL_MSVC_STATIC_RT) set(_OPENSSL_MSVC_RT_MODE "MT") else () set(_OPENSSL_MSVC_RT_MODE "MD") endif () # Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" ) set(_OPENSSL_MSVC_ARCH_SUFFIX "64") else() set(_OPENSSL_MSVC_ARCH_SUFFIX "32") endif() if(OPENSSL_USE_STATIC_LIBS) set(_OPENSSL_STATIC_SUFFIX "_static" ) set(_OPENSSL_PATH_SUFFIXES "lib/VC/static" "VC/static" "lib" ) else() set(_OPENSSL_STATIC_SUFFIX "" ) set(_OPENSSL_PATH_SUFFIXES "lib/VC" "VC" "lib" ) endif () find_library(LIB_EAY_DEBUG NAMES # When OpenSSL is built with default options, the static library name is suffixed with "_static". # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the # import library of "libcrypto.dll". libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libcrypto${_OPENSSL_STATIC_SUFFIX}d libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libeay32${_OPENSSL_STATIC_SUFFIX}d crypto${_OPENSSL_STATIC_SUFFIX}d # When OpenSSL is built with the "-static" option, only the static build is produced, # and it is not suffixed with "_static". libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libcrypto${_OPENSSL_MSVC_RT_MODE}d libcryptod libeay32${_OPENSSL_MSVC_RT_MODE}d libeay32d cryptod NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES ${_OPENSSL_PATH_SUFFIXES} ) find_library(LIB_EAY_RELEASE NAMES # When OpenSSL is built with default options, the static library name is suffixed with "_static". # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the # import library of "libcrypto.dll". libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libcrypto${_OPENSSL_STATIC_SUFFIX} libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libeay32${_OPENSSL_STATIC_SUFFIX} crypto${_OPENSSL_STATIC_SUFFIX} # When OpenSSL is built with the "-static" option, only the static build is produced, # and it is not suffixed with "_static". libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libcrypto${_OPENSSL_MSVC_RT_MODE} libcrypto libeay32${_OPENSSL_MSVC_RT_MODE} libeay32 crypto NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES ${_OPENSSL_PATH_SUFFIXES} ) find_library(SSL_EAY_DEBUG NAMES # When OpenSSL is built with default options, the static library name is suffixed with "_static". # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the # import library of "libssl.dll". libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libssl${_OPENSSL_STATIC_SUFFIX}d ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d ssleay32${_OPENSSL_STATIC_SUFFIX}d ssl${_OPENSSL_STATIC_SUFFIX}d # When OpenSSL is built with the "-static" option, only the static build is produced, # and it is not suffixed with "_static". libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libssl${_OPENSSL_MSVC_RT_MODE}d libssld ssleay32${_OPENSSL_MSVC_RT_MODE}d ssleay32d ssld NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES ${_OPENSSL_PATH_SUFFIXES} ) find_library(SSL_EAY_RELEASE NAMES # When OpenSSL is built with default options, the static library name is suffixed with "_static". # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the # import library of "libssl.dll". libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libssl${_OPENSSL_STATIC_SUFFIX} ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} ssleay32${_OPENSSL_STATIC_SUFFIX} ssl${_OPENSSL_STATIC_SUFFIX} # When OpenSSL is built with the "-static" option, only the static build is produced, # and it is not suffixed with "_static". libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libssl${_OPENSSL_MSVC_RT_MODE} libssl ssleay32${_OPENSSL_MSVC_RT_MODE} ssleay32 ssl NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES ${_OPENSSL_PATH_SUFFIXES} ) set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}") set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}") set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}") set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}") include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(LIB_EAY) select_library_configurations(SSL_EAY) mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE) set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} ) set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} ) elseif(MINGW) # same player, for MinGW set(LIB_EAY_NAMES crypto libeay32) set(SSL_EAY_NAMES ssl ssleay32) find_library(LIB_EAY NAMES ${LIB_EAY_NAMES} NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES "lib/MinGW" "lib" ) find_library(SSL_EAY NAMES ${SSL_EAY_NAMES} NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES "lib/MinGW" "lib" ) mark_as_advanced(SSL_EAY LIB_EAY) set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) unset(LIB_EAY_NAMES) unset(SSL_EAY_NAMES) else() # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues: find_library(LIB_EAY NAMES libcrypto libeay32 NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} HINTS ${_OPENSSL_LIBDIR} PATH_SUFFIXES lib ) find_library(SSL_EAY NAMES libssl ssleay32 NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} HINTS ${_OPENSSL_LIBDIR} PATH_SUFFIXES lib ) mark_as_advanced(SSL_EAY LIB_EAY) set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) endif() else() find_library(OPENSSL_SSL_LIBRARY NAMES ssl ssleay32 ssleay32MD NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} HINTS ${_OPENSSL_LIBDIR} ${_OPENSSL_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto NAMES_PER_DIR ${_OPENSSL_ROOT_HINTS_AND_PATHS} HINTS ${_OPENSSL_LIBDIR} ${_OPENSSL_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY) endif() set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY}) set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} ) _OpenSSL_test_and_find_dependencies("${OPENSSL_SSL_LIBRARY}" "${OPENSSL_CRYPTO_LIBRARY}") if(_OpenSSL_has_dependencies) _OpenSSL_add_dependencies( OPENSSL_SSL_LIBRARIES ) _OpenSSL_add_dependencies( OPENSSL_CRYPTO_LIBRARIES ) _OpenSSL_add_dependencies( OPENSSL_LIBRARIES ) endif() function(from_hex HEX DEC) string(TOUPPER "${HEX}" HEX) set(_res 0) string(LENGTH "${HEX}" _strlen) while (_strlen GREATER 0) math(EXPR _res "${_res} * 16") string(SUBSTRING "${HEX}" 0 1 NIBBLE) string(SUBSTRING "${HEX}" 1 -1 HEX) if (NIBBLE STREQUAL "A") math(EXPR _res "${_res} + 10") elseif (NIBBLE STREQUAL "B") math(EXPR _res "${_res} + 11") elseif (NIBBLE STREQUAL "C") math(EXPR _res "${_res} + 12") elseif (NIBBLE STREQUAL "D") math(EXPR _res "${_res} + 13") elseif (NIBBLE STREQUAL "E") math(EXPR _res "${_res} + 14") elseif (NIBBLE STREQUAL "F") math(EXPR _res "${_res} + 15") else() math(EXPR _res "${_res} + ${NIBBLE}") endif() string(LENGTH "${HEX}" _strlen) endwhile() set(${DEC} ${_res} PARENT_SCOPE) endfunction() if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") if(openssl_version_str) # The version number is encoded as 0xMNNFFPPS: major minor fix patch status # The status gives if this is a developer or prerelease and is ignored here. # Major, minor, and fix directly translate into the version numbers shown in # the string. The patch field translates to the single character suffix that # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so # on. string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$" "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}") list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR) list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR) from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR) list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX) from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX) list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH) if (NOT OPENSSL_VERSION_PATCH STREQUAL "00") from_hex("${OPENSSL_VERSION_PATCH}" _tmp) # 96 is the ASCII code of 'a' minus 1 math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96") unset(_tmp) # Once anyone knows how OpenSSL would call the patch versions beyond 'z' # this should be updated to handle that, too. This has not happened yet # so it is simply ignored here for now. string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING) endif () set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}") else () # Since OpenSSL 3.0.0, the new version format is MAJOR.MINOR.PATCH and # a new OPENSSL_VERSION_STR macro contains exactly that file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSL_VERSION_STR REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_STR[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+\".*") string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$" "\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}") set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}") unset(OPENSSL_VERSION_STR) endif () endif () foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS) if(_comp STREQUAL "Crypto") if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR EXISTS "${LIB_EAY_LIBRARY_RELEASE}") ) set(OpenSSL_${_comp}_FOUND TRUE) else() set(OpenSSL_${_comp}_FOUND FALSE) endif() elseif(_comp STREQUAL "SSL") if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND (EXISTS "${OPENSSL_SSL_LIBRARY}" OR EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR EXISTS "${SSL_EAY_LIBRARY_RELEASE}") ) set(OpenSSL_${_comp}_FOUND TRUE) else() set(OpenSSL_${_comp}_FOUND FALSE) endif() else() message(WARNING "${_comp} is not a valid OpenSSL component") set(OpenSSL_${_comp}_FOUND FALSE) endif() endforeach() unset(_comp) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(OpenSSL REQUIRED_VARS OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR VERSION_VAR OPENSSL_VERSION HANDLE_VERSION_RANGE HANDLE_COMPONENTS FAIL_MESSAGE "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR" ) mark_as_advanced(OPENSSL_INCLUDE_DIR) if(OPENSSL_FOUND) if(NOT TARGET OpenSSL::Crypto AND (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR EXISTS "${LIB_EAY_LIBRARY_RELEASE}") ) add_library(OpenSSL::Crypto UNKNOWN IMPORTED) set_target_properties(OpenSSL::Crypto PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}") set_target_properties(OpenSSL::Crypto PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}") endif() if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}") set_property(TARGET OpenSSL::Crypto APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(OpenSSL::Crypto PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}") endif() if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}") set_property(TARGET OpenSSL::Crypto APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(OpenSSL::Crypto PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}") endif() _OpenSSL_target_add_dependencies(OpenSSL::Crypto) endif() if(NOT TARGET OpenSSL::SSL AND (EXISTS "${OPENSSL_SSL_LIBRARY}" OR EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR EXISTS "${SSL_EAY_LIBRARY_RELEASE}") ) add_library(OpenSSL::SSL UNKNOWN IMPORTED) set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") if(EXISTS "${OPENSSL_SSL_LIBRARY}") set_target_properties(OpenSSL::SSL PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}") endif() if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}") set_property(TARGET OpenSSL::SSL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(OpenSSL::SSL PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}") endif() if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}") set_property(TARGET OpenSSL::SSL APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(OpenSSL::SSL PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}") endif() if(TARGET OpenSSL::Crypto) set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) endif() _OpenSSL_target_add_dependencies(OpenSSL::SSL) endif() if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8") if(MSVC) if(EXISTS "${OPENSSL_INCLUDE_DIR}") set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR}) endif() find_file(OPENSSL_APPLINK_SOURCE NAMES openssl/applink.c ${_OPENSSL_applink_paths} NO_DEFAULT_PATH) if(OPENSSL_APPLINK_SOURCE) set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE}) endif() endif() if(NOT TARGET OpenSSL::applink) add_library(OpenSSL::applink INTERFACE IMPORTED) set_property(TARGET OpenSSL::applink APPEND PROPERTY INTERFACE_SOURCES ${_OPENSSL_applink_interface_srcs}) endif() endif() endif() # Restore the original find library ordering if(OPENSSL_USE_STATIC_LIBS) set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) endif() capstats-0.31/cmake/cmake_uninstall.cmake.in000644 000765 000024 00000002211 14246446227 021062 0ustar00timstaff000000 000000 function(uninstall_manifest manifestPath) file(READ "${manifestPath}" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach (file ${files}) set(fileName $ENV{DESTDIR}${file}) if (EXISTS "${fileName}" OR IS_SYMLINK "${fileName}") message(STATUS "Uninstalling: ${fileName}") execute_process( COMMAND "@CMAKE_COMMAND@" -E remove "${fileName}" OUTPUT_VARIABLE rm_out RESULT_VARIABLE rm_retval ) if (NOT ${rm_retval} EQUAL 0) message(FATAL_ERROR "Problem when removing: ${fileName}") endif () else () message(STATUS "Does not exist: ${fileName}") endif () endforeach () endfunction(uninstall_manifest) file(GLOB install_manifests @CMAKE_CURRENT_BINARY_DIR@/install_manifest*.txt) if (install_manifests) foreach (manifest ${install_manifests}) uninstall_manifest(${manifest}) endforeach () else () message(FATAL_ERROR "Cannot find any install manifests in: " "\"@CMAKE_CURRENT_BINARY_DIR@/install_manifest*.txt\"") endif () capstats-0.31/cmake/CheckCompilers.cmake000644 000765 000024 00000000670 14246446227 020206 0ustar00timstaff000000 000000 # Aborts the configuration if no C or C++ compiler is found, depending # on whether a previous call to the project() macro was supplied either # language as a requirement. if (NOT CMAKE_C_COMPILER AND DEFINED CMAKE_C_COMPILER) message(FATAL_ERROR "Could not find prerequisite C compiler") endif () if (NOT CMAKE_CXX_COMPILER AND DEFINED CMAKE_CXX_COMPILER) message(FATAL_ERROR "Could not find prerequisite C++ compiler") endif () capstats-0.31/cmake/FindZeek.cmake000644 000765 000024 00000002122 14246446227 017004 0ustar00timstaff000000 000000 # - Try to find Zeek installation # # Usage of this module as follows: # # find_package(Zeek) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # ZEEK_ROOT_DIR Set this variable to the root installation of # Zeek if the module has problems finding the # proper installation path. # # Variables defined by this module: # # BRO_FOUND Zeek is installed # ZEEK_EXE path to the 'zeek' binary if (ZEEK_EXE AND ZEEK_ROOT_DIR) # this implies that we're building from the Zeek source tree set(BRO_FOUND true) return() endif () find_program(ZEEK_EXE zeek HINTS ${ZEEK_ROOT_DIR}/bin /usr/local/zeek/bin /usr/local/bro/bin) if (ZEEK_EXE) get_filename_component(ZEEK_ROOT_DIR ${ZEEK_EXE} PATH) get_filename_component(ZEEK_ROOT_DIR ${ZEEK_ROOT_DIR} PATH) endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Zeek DEFAULT_MSG ZEEK_EXE) mark_as_advanced(ZEEK_ROOT_DIR) capstats-0.31/cmake/ConfigurePackaging.cmake000644 000765 000024 00000025772 14246446227 021053 0ustar00timstaff000000 000000 # A collection of macros to assist in configuring CMake/Cpack # source and binary packaging # Sets CPack version variables by splitting the first macro argument # using "." or "-" as a delimiter. If the length of the split list is # greater than 2, all remaining elements are tacked on to the patch # level version. Not that the version set by the macro is internal # to binary packaging, the file name of our package will reflect the # exact version number. macro(SetPackageVersion _version) string(REGEX REPLACE "[.-]" " " version_numbers ${_version}) separate_arguments(version_numbers) list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MAJOR) list(REMOVE_AT version_numbers 0) list(GET version_numbers 0 CPACK_PACKAGE_VERSION_MINOR) list(REMOVE_AT version_numbers 0) list(LENGTH version_numbers version_length) while (version_length GREATER 0) list(GET version_numbers 0 patch_level) if (CPACK_PACKAGE_VERSION_PATCH) set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}.${patch_level}") else () set(CPACK_PACKAGE_VERSION_PATCH ${patch_level}) endif () list(REMOVE_AT version_numbers 0) list(LENGTH version_numbers version_length) endwhile () if (APPLE) # Mac PackageMaker package requires only numbers in the versioning string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) if (CPACK_PACKAGE_VERSION_PATCH) string(REGEX REPLACE "[_a-zA-Z-]" "" CPACK_PACKAGE_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}) endif () endif () if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") # RPM version accepts letters, but not dashes. string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) if (CPACK_PACKAGE_VERSION_PATCH) string(REGEX REPLACE "[-]" "." CPACK_PACKAGE_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}) endif () endif () # Minimum supported OS X version set(CPACK_OSX_PACKAGE_VERSION 10.5) endmacro(SetPackageVersion) # Sets the list of desired package types to be created by the make # package target. A .tar.gz is only made for source packages, and # binary pacakage format depends on the operating system: # # Darwin - PackageMaker # Linux - RPM if the platform has rpmbuild installed # DEB if the platform has dpkg-shlibdeps installed # # CPACK_GENERATOR is set by this macro # CPACK_SOURCE_GENERATOR is set by this macro macro(SetPackageGenerators) set(CPACK_SOURCE_GENERATOR TGZ) #set(CPACK_GENERATOR TGZ) if (APPLE) list(APPEND CPACK_GENERATOR PackageMaker) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") find_program(RPMBUILD_EXE rpmbuild) find_program(DPKGSHLIB_EXE dpkg-shlibdeps) if (RPMBUILD_EXE) set(CPACK_GENERATOR ${CPACK_GENERATOR} RPM) endif () if (DPKGSHLIB_EXE) set(CPACK_GENERATOR ${CPACK_GENERATOR} DEB) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS true) endif () endif () endmacro(SetPackageGenerators) # Sets CPACK_PACKAGE_FILE_NAME in the following format: # # --- # # and CPACK_SOURCE_PACKAGE_FILE_NAME as: # # - macro(SetPackageFileName _version) if (PACKAGE_NAME_PREFIX) set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_NAME_PREFIX}-${_version}") else () set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${_version}") endif () set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_NAME}") if (APPLE) # Only Intel-based Macs are supported. CMAKE_SYSTEM_PROCESSOR may # return the confusing 'i386' if running a 32-bit kernel, but chances # are the binary is x86_64 (or more generally 'Intel') compatible. set(arch "Intel") else () set (arch ${CMAKE_SYSTEM_PROCESSOR}) endif () set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${arch}") endmacro(SetPackageFileName) # Sets up binary package metadata macro(SetPackageMetadata) if ( NOT CPACK_PACKAGE_VENDOR ) set(CPACK_PACKAGE_VENDOR "International Computer Science Institute") endif () if ( NOT CPACK_PACKAGE_CONTACT ) set(CPACK_PACKAGE_CONTACT "info@zeek.org") endif () if ( NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY ) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Zeek Network Security Monitor") endif () # CPack may enforce file name extensions for certain package generators configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/README.txt COPYONLY) if ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/COPYING ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt COPYONLY) elseif ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me ) # Zeek plugin skeletons have a placeholder file. Just use # it even if it hasn't actually been changed. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt COPYONLY) endif () if ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/MAC_PACKAGE_INTRO ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MAC_PACKAGE_INTRO ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) else () configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) endif () set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_BINARY_DIR}/README.txt) set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt) set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.txt) set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/MAC_PACKAGE_INTRO.txt) if ( NOT CPACK_RPM_PACKAGE_LICENSE ) set(CPACK_RPM_PACKAGE_LICENSE "BSD") endif () if ( NOT CPACK_RPM_PACKAGE_GROUP ) set(CPACK_RPM_PACKAGE_GROUP "Applications/System") endif () # If we're building a dynamic Zeek plugin, exclude various additional paths # already provided by our Zeek packages. if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /opt /var /var/opt ${CMAKE_INSTALL_PREFIX} ${BRO_CONFIG_PREFIX} ${BRO_CONFIG_PREFIX}/lib ${BRO_CONFIG_PREFIX}/lib/zeek ${BRO_CONFIG_PLUGIN_DIR} ) else () set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /opt /var /var/opt) endif () endmacro(SetPackageMetadata) # Sets pre and post install scripts for PackageMaker packages. # The main functionality that such scripts offer is a way to make backups # of "configuration" files that a user may have modified. # Note that RPMs already have a robust mechanism for dealing with # user-modified files, so we do not need this additional functionality macro(SetPackageInstallScripts VERSION) if (INSTALLED_CONFIG_FILES) # Remove duplicates from the list of installed config files separate_arguments(INSTALLED_CONFIG_FILES) list(REMOVE_DUPLICATES INSTALLED_CONFIG_FILES) # Space delimit the list again foreach (_file ${INSTALLED_CONFIG_FILES}) set(_tmp "${_tmp} ${_file}") endforeach () set(INSTALLED_CONFIG_FILES "${_tmp}" CACHE STRING "" FORCE) endif () if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") # DEB packages can automatically handle configuration files # if provided in a "conffiles" file in the packaging set(conffiles_file ${CMAKE_CURRENT_BINARY_DIR}/conffiles) if (INSTALLED_CONFIG_FILES) string(REPLACE " " ";" conffiles ${INSTALLED_CONFIG_FILES}) endif () file(WRITE ${conffiles_file} "") foreach (_file ${conffiles}) file(APPEND ${conffiles_file} "${_file}\n") endforeach () list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/conffiles) # RPMs don't need any explicit direction regarding config files. # Leaving the set of installed config files empty will just # bypass the logic in the default pre/post install scripts and let # the RPMs/DEBs do their own thing (regarding backups, etc.) # when upgrading packages. set(INSTALLED_CONFIG_FILES "") endif () if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh @ONLY) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in ${CMAKE_CURRENT_BINARY_DIR}/preinst @ONLY) set(CPACK_PREFLIGHT_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/preinst) endif () if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh @ONLY) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in ${CMAKE_CURRENT_BINARY_DIR}/postinst @ONLY) set(CPACK_POSTUPGRADE_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/postinst) endif () endmacro(SetPackageInstallScripts) # Main macro to configure all the packaging options macro(ConfigurePackaging _version) SetPackageVersion(${_version}) SetPackageGenerators() SetPackageFileName(${_version}) SetPackageMetadata() SetPackageInstallScripts(${_version}) set(CPACK_SET_DESTDIR true) set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) # add default files/directories to ignore for source package # user may specify others via configure script list(APPEND CPACK_SOURCE_IGNORE_FILES ${PROJECT_BINARY_DIR} ".git") include(CPack) endmacro(ConfigurePackaging) capstats-0.31/cmake/PCAPTests.cmake000644 000765 000024 00000004206 14246446227 017060 0ustar00timstaff000000 000000 include(CheckFunctionExists) include(CheckSymbolExists) include(CheckCSourceCompiles) include(CheckIncludeFiles) set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) cmake_policy(PUSH) if ( POLICY CMP0075 ) # It's fine that check_include_files links against CMAKE_REQUIRED_LIBRARIES cmake_policy(SET CMP0075 NEW) endif () check_include_files(pcap-int.h HAVE_PCAP_INT_H) cmake_policy(POP) check_function_exists(pcap_freecode HAVE_LIBPCAP_PCAP_FREECODE) if (NOT HAVE_LIBPCAP_PCAP_FREECODE) set(DONT_HAVE_LIBPCAP_PCAP_FREECODE true) message(STATUS "No implementation for pcap_freecode()") endif () check_c_source_compiles(" #include int main () { int snaplen; int linktype; struct bpf_program fp; int optimize; bpf_u_int32 netmask; char str[10]; char error[1024]; snaplen = 50; linktype = DLT_EN10MB; optimize = 1; netmask = 0L; str[0] = 'i'; str[1] = 'p'; str[2] = '\\\\0'; (void)pcap_compile_nopcap( snaplen, linktype, &fp, str, optimize, netmask, &error); return 0; } " LIBPCAP_PCAP_COMPILE_NOPCAP_HAS_ERROR_PARAMETER) if (NOT LIBPCAP_PCAP_COMPILE_NOPCAP_HAS_ERROR_PARAMETER) # double check check_c_source_compiles(" #include int main () { int snaplen; int linktype; struct bpf_program fp; int optimize; bpf_u_int32 netmask; char str[10]; snaplen = 50; linktype = DLT_EN10MB; optimize = 1; netmask = 0L; str[0] = 'i'; str[1] = 'p'; str[2] = '\\\\0'; (void)pcap_compile_nopcap(snaplen, linktype, &fp, str, optimize, netmask); return 0; } " LIBPCAP_PCAP_COMPILE_NOPCAP_NO_ERROR_PARAMETER) if (NOT LIBPCAP_PCAP_COMPILE_NOPCAP_NO_ERROR_PARAMETER) message(FATAL_ERROR "Can't determine if pcap_compile_nopcap takes an error parameter") endif () endif () check_symbol_exists(DLT_PPP_SERIAL pcap.h HAVE_DLT_PPP_SERIAL) if (NOT HAVE_DLT_PPP_SERIAL) set(DLT_PPP_SERIAL 50) endif () check_symbol_exists(DLT_NFLOG pcap.h HAVE_DLT_NFLOG) if (NOT HAVE_DLT_NFLOG) set(DLT_NFLOG 239) endif () set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_LIBRARIES) capstats-0.31/cmake/FindTraceSummary.cmake000644 000765 000024 00000000704 14246446227 020526 0ustar00timstaff000000 000000 # - Try to find the trace-summary Python program # # Usage of this module as follows: # # find_package(TraceSummary) # # Variables defined by this module: # # TRACESUMMARY_FOUND capstats binary found # TraceSummary_EXE path to the capstats executable binary find_program(TRACE_SUMMARY_EXE trace-summary) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(TraceSummary DEFAULT_MSG TRACE_SUMMARY_EXE) capstats-0.31/cmake/Gen-ZAM.cmake000644 000765 000024 00000004717 14246446227 016457 0ustar00timstaff000000 000000 # A macro to define a command that uses the gen-zam templator to produce # C++ headers from an input template file. The outputs are returned in # GEN_ZAM_OUTPUT_H. # # The macro also creates a target that can be used to define depencencies on the # generated files. The name of the target includes the input template filename # to make it unique, and is added automatically to bro_ALL_GENERATED_OUTPUTS. macro(gen_zam_target gzInput) get_filename_component(gzInputBasename "${gzInput}" NAME) set(target "gen-zam-${gzInputBasename}") string(REGEX REPLACE "/" "-" target "${target}") set(GEN_ZAM_OUTPUT_H ${CMAKE_CURRENT_BINARY_DIR}/ZAM-AssignFlavorsDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Conds.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-DirectDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-EvalDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-EvalMacros.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC1.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC2.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsC3.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenExprsDefsV.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsC1.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsC2.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-GenFieldsDefsV.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-MethodDecls.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-MethodDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Op1FlavorsDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpSideEffects.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpsDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-OpsNamesDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Vec1EvalDefs.h ${CMAKE_CURRENT_BINARY_DIR}/ZAM-Vec2EvalDefs.h) if ( GEN_ZAM_EXE_PATH ) set(GEN_ZAM_EXE ${GEN_ZAM_EXE_PATH}) else () set(GEN_ZAM_EXE "gen-zam") endif () add_custom_command(OUTPUT ${GEN_ZAM_OUTPUT_H} COMMAND ${GEN_ZAM_EXE} ARGS ${gzInput} DEPENDS ${gzInput} ${GEN_ZAM_EXE} COMMENT "[gen-zam] Generating ZAM operations" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(${target} DEPENDS ${GEN_ZAM_OUTPUT_H}) set_source_files_properties(${gzOutputs} PROPERTIES GENERATED 1) set(bro_ALL_GENERATED_OUTPUTS ${bro_ALL_GENERATED_OUTPUTS} ${target} CACHE INTERNAL "automatically generated files" FORCE) # Propagate to top-level. endmacro(gen_zam_target) capstats-0.31/cmake/CheckCompilerArch.cmake000644 000765 000024 00000002215 14246446227 020616 0ustar00timstaff000000 000000 # Findm the name of the architecture that we compile to. Currently # this is used for highwayhash - but may be generally useful. include(CheckCSourceCompiles) check_c_source_compiles(" #if defined(__x86_64__) || defined(_M_X64) int main() { return 0; } #else #error wrongarch #endif " test_arch_x64) check_c_source_compiles(" #if defined(__aarch64__) || defined(__arm64__) int main() { return 0; } #else #error wrongarch #endif " test_arch_aarch64) check_c_source_compiles(" #if defined(__arm__) || defined(__ARM_NEON__) || defined(__ARM_NEON) int main() { return 0; } #else #error wrongarch #endif " test_arch_arm) check_c_source_compiles(" #if defined(__powerpc64__) || defined(_M_PPC) int main() { return 0; } #else #error wrongarch #endif " test_arch_power) if (test_arch_x64) set(COMPILER_ARCHITECTURE "x86_64") elseif(test_arch_aarch64) set(COMPILER_ARCHITECTURE "aarch64") elseif(test_arch_arm) set(COMPILER_ARCHITECTURE "arm") elseif(test_arch_power) set(COMPILER_ARCHITECTURE "power") else() set(COMPILER_ARCHITECTURE "portable") endif() message(STATUS "Determined target architecture (for hashing): ${COMPILER_ARCHITECTURE}") capstats-0.31/cmake/SetDefaultCompileFlags.cmake000644 000765 000024 00000002421 14246446227 021635 0ustar00timstaff000000 000000 # Set up the default flags and CMake build type once during the configuration # of the top-level CMake project. if ( MSVC ) return() endif () if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") set(EXTRA_COMPILE_FLAGS "-Wall -Wno-unused") set(EXTRA_COMPILE_FLAGS_CXX "-Wno-register -Werror=vla") if ( NOT CMAKE_BUILD_TYPE ) if ( ENABLE_DEBUG ) set(CMAKE_BUILD_TYPE Debug) else () set(CMAKE_BUILD_TYPE RelWithDebInfo) endif () endif () string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type_upper) if ( "${_build_type_upper}" STREQUAL "DEBUG" ) if ( ENABLE_COVERAGE ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") endif() # manual add of -g works around its omission in FreeBSD's CMake port set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -g -DDEBUG -DBRO_DEBUG") endif () # Compiler flags may already exist in CMake cache (e.g. when specifying # CFLAGS environment variable before running cmake for the the first time) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_COMPILE_FLAGS} ${EXTRA_COMPILE_FLAGS_CXX}") endif () capstats-0.31/cmake/GetArchitecture.cmake000644 000765 000024 00000000527 14246446227 020376 0ustar00timstaff000000 000000 # Determine a tag for the host architecture (e.g., "linux-x86_64"). # We run uname ourselves here as CMAKE by default uses -p rather than # -m. execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE) set(HOST_ARCHITECTURE "${CMAKE_SYSTEM_NAME}-${arch}") string(TOLOWER ${HOST_ARCHITECTURE} HOST_ARCHITECTURE) capstats-0.31/cmake/FindPackageHandleStandardArgs.cmake000644 000765 000024 00000054642 14246446227 023071 0ustar00timstaff000000 000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: FindPackageHandleStandardArgs ----------------------------- This module provides functions intended to be used in :ref:`Find Modules` implementing :command:`find_package()` calls. .. command:: find_package_handle_standard_args This command handles the ``REQUIRED``, ``QUIET`` and version-related arguments of :command:`find_package`. It also sets the ``_FOUND`` variable. The package is considered found if all variables listed contain valid results, e.g. valid filepaths. There are two signatures: .. code-block:: cmake find_package_handle_standard_args( (DEFAULT_MSG|) ... ) find_package_handle_standard_args( [FOUND_VAR ] [REQUIRED_VARS ...] [VERSION_VAR ] [HANDLE_VERSION_RANGE] [HANDLE_COMPONENTS] [CONFIG_MODE] [NAME_MISMATCHED] [REASON_FAILURE_MESSAGE ] [FAIL_MESSAGE ] ) The ``_FOUND`` variable will be set to ``TRUE`` if all the variables ``...`` are valid and any optional constraints are satisfied, and ``FALSE`` otherwise. A success or failure message may be displayed based on the results and on whether the ``REQUIRED`` and/or ``QUIET`` option was given to the :command:`find_package` call. The options are: ``(DEFAULT_MSG|)`` In the simple signature this specifies the failure message. Use ``DEFAULT_MSG`` to ask for a default message to be computed (recommended). Not valid in the full signature. ``FOUND_VAR `` .. deprecated:: 3.3 Specifies either ``_FOUND`` or ``_FOUND`` as the result variable. This exists only for compatibility with older versions of CMake and is now ignored. Result variables of both names are always set for compatibility. ``REQUIRED_VARS ...`` Specify the variables which are required for this package. These may be named in the generated failure message asking the user to set the missing variable values. Therefore these should typically be cache entries such as ``FOO_LIBRARY`` and not output variables like ``FOO_LIBRARIES``. .. versionchanged:: 3.18 If ``HANDLE_COMPONENTS`` is specified, this option can be omitted. ``VERSION_VAR `` Specify the name of a variable that holds the version of the package that has been found. This version will be checked against the (potentially) specified required version given to the :command:`find_package` call, including its ``EXACT`` option. The default messages include information about the required version and the version which has been actually found, both if the version is ok or not. ``HANDLE_VERSION_RANGE`` .. versionadded:: 3.19 Enable handling of a version range, if one is specified. Without this option, a developer warning will be displayed if a version range is specified. ``HANDLE_COMPONENTS`` Enable handling of package components. In this case, the command will report which components have been found and which are missing, and the ``_FOUND`` variable will be set to ``FALSE`` if any of the required components (i.e. not the ones listed after the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are missing. ``CONFIG_MODE`` Specify that the calling find module is a wrapper around a call to ``find_package( NO_MODULE)``. This implies a ``VERSION_VAR`` value of ``_VERSION``. The command will automatically check whether the package configuration file was found. ``REASON_FAILURE_MESSAGE `` .. versionadded:: 3.16 Specify a custom message of the reason for the failure which will be appended to the default generated message. ``FAIL_MESSAGE `` Specify a custom failure message instead of using the default generated message. Not recommended. ``NAME_MISMATCHED`` .. versionadded:: 3.17 Indicate that the ```` does not match ``${CMAKE_FIND_PACKAGE_NAME}``. This is usually a mistake and raises a warning, but it may be intentional for usage of the command for components of a larger package. Example for the simple signature: .. code-block:: cmake find_package_handle_standard_args(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) The ``LibXml2`` package is considered to be found if both ``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid. Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found and ``REQUIRED`` was used, it fails with a :command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was used or not. If it is found, success will be reported, including the content of the first ````. On repeated CMake runs, the same message will not be printed again. .. note:: If ```` does not match ``CMAKE_FIND_PACKAGE_NAME`` for the calling module, a warning that there is a mismatch is given. The ``FPHSA_NAME_MISMATCHED`` variable may be set to bypass the warning if using the old signature and the ``NAME_MISMATCHED`` argument using the new signature. To avoid forcing the caller to require newer versions of CMake for usage, the variable's value will be used if defined when the ``NAME_MISMATCHED`` argument is not passed for the new signature (but using both is an error).. Example for the full signature: .. code-block:: cmake find_package_handle_standard_args(LibArchive REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR VERSION_VAR LibArchive_VERSION) In this case, the ``LibArchive`` package is considered to be found if both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid. Also the version of ``LibArchive`` will be checked by using the version contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given, the default messages will be printed. Another example for the full signature: .. code-block:: cmake find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) find_package_handle_standard_args(Automoc4 CONFIG_MODE) In this case, a ``FindAutmoc4.cmake`` module wraps a call to ``find_package(Automoc4 NO_MODULE)`` and adds an additional search directory for ``automoc4``. Then the call to ``find_package_handle_standard_args`` produces a proper success/failure message. .. command:: find_package_check_version .. versionadded:: 3.19 Helper function which can be used to check if a ```` is valid against version-related arguments of :command:`find_package`. .. code-block:: cmake find_package_check_version( [HANDLE_VERSION_RANGE] [RESULT_MESSAGE_VARIABLE ] ) The ```` will hold a boolean value giving the result of the check. The options are: ``HANDLE_VERSION_RANGE`` Enable handling of a version range, if one is specified. Without this option, a developer warning will be displayed if a version range is specified. ``RESULT_MESSAGE_VARIABLE `` Specify a variable to get back a message describing the result of the check. Example for the usage: .. code-block:: cmake find_package_check_version(1.2.3 result HANDLE_VERSION_RANGE RESULT_MESSAGE_VARIABLE reason) if (result) message (STATUS "${reason}") else() message (FATAL_ERROR "${reason}") endif() #]=======================================================================] include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) cmake_policy(PUSH) # numbers and boolean constants cmake_policy (SET CMP0012 NEW) # IN_LIST operator cmake_policy (SET CMP0057 NEW) # internal helper macro macro(_FPHSA_FAILURE_MESSAGE _msg) set (__msg "${_msg}") if (FPHSA_REASON_FAILURE_MESSAGE) string(APPEND __msg "\n Reason given by package: ${FPHSA_REASON_FAILURE_MESSAGE}\n") endif() if (${_NAME}_FIND_REQUIRED) message(FATAL_ERROR "${__msg}") else () if (NOT ${_NAME}_FIND_QUIETLY) message(STATUS "${__msg}") endif () endif () endmacro() # internal helper macro to generate the failure message when used in CONFIG_MODE: macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: if(${_NAME}_CONFIG) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing:${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") else() # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. # List them all in the error message: if(${_NAME}_CONSIDERED_CONFIGS) set(configsText "") list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) math(EXPR configsCount "${configsCount} - 1") foreach(currentConfigIndex RANGE ${configsCount}) list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) string(APPEND configsText "\n ${filename} (version ${version})") endforeach() if (${_NAME}_NOT_FOUND_MESSAGE) if (FPHSA_REASON_FAILURE_MESSAGE) string(PREPEND FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}\n ") else() set(FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}") endif() else() string(APPEND configsText "\n") endif() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:${configsText}") else() # Simple case: No Config-file was found at all: _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") endif() endif() endmacro() function(FIND_PACKAGE_CHECK_VERSION version result) cmake_parse_arguments (PARSE_ARGV 2 FPCV "HANDLE_VERSION_RANGE;NO_AUTHOR_WARNING_VERSION_RANGE" "RESULT_MESSAGE_VARIABLE" "") if (FPCV_UNPARSED_ARGUMENTS) message (FATAL_ERROR "find_package_check_version(): ${FPCV_UNPARSED_ARGUMENTS}: unexpected arguments") endif() if ("RESULT_MESSAGE_VARIABLE" IN_LIST FPCV_KEYWORDS_MISSING_VALUES) message (FATAL_ERROR "find_package_check_version(): RESULT_MESSAGE_VARIABLE expects an argument") endif() set (${result} FALSE PARENT_SCOPE) if (FPCV_RESULT_MESSAGE_VARIABLE) unset (${FPCV_RESULT_MESSAGE_VARIABLE} PARENT_SCOPE) endif() if (_CMAKE_FPHSA_PACKAGE_NAME) set (package "${_CMAKE_FPHSA_PACKAGE_NAME}") elseif (CMAKE_FIND_PACKAGE_NAME) set (package "${CMAKE_FIND_PACKAGE_NAME}") else() message (FATAL_ERROR "find_package_check_version(): Cannot be used outside a 'Find Module'") endif() if (NOT FPCV_NO_AUTHOR_WARNING_VERSION_RANGE AND ${package}_FIND_VERSION_RANGE AND NOT FPCV_HANDLE_VERSION_RANGE) message(AUTHOR_WARNING "`find_package()` specify a version range but the option " "HANDLE_VERSION_RANGE` is not passed to `find_package_check_version()`. " "Only the lower endpoint of the range will be used.") endif() set (version_ok FALSE) unset (version_msg) if (FPCV_HANDLE_VERSION_RANGE AND ${package}_FIND_VERSION_RANGE) if ((${package}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND version VERSION_GREATER_EQUAL ${package}_FIND_VERSION_MIN) AND ((${package}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND version VERSION_LESS_EQUAL ${package}_FIND_VERSION_MAX) OR (${package}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND version VERSION_LESS ${package}_FIND_VERSION_MAX))) set (version_ok TRUE) set(version_msg "(found suitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\")") else() set(version_msg "Found unsuitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\"") endif() elseif (DEFINED ${package}_FIND_VERSION) if(${package}_FIND_VERSION_EXACT) # exact version required # count the dots in the version string string(REGEX REPLACE "[^.]" "" version_dots "${version}") # add one dot because there is one dot more than there are components string(LENGTH "${version_dots}." version_dots) if (version_dots GREATER ${package}_FIND_VERSION_COUNT) # Because of the C++ implementation of find_package() ${package}_FIND_VERSION_COUNT # is at most 4 here. Therefore a simple lookup table is used. if (${package}_FIND_VERSION_COUNT EQUAL 1) set(version_regex "[^.]*") elseif (${package}_FIND_VERSION_COUNT EQUAL 2) set(version_regex "[^.]*\\.[^.]*") elseif (${package}_FIND_VERSION_COUNT EQUAL 3) set(version_regex "[^.]*\\.[^.]*\\.[^.]*") else() set(version_regex "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") endif() string(REGEX REPLACE "^(${version_regex})\\..*" "\\1" version_head "${version}") if (NOT ${package}_FIND_VERSION VERSION_EQUAL version_head) set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"") else () set(version_ok TRUE) set(version_msg "(found suitable exact version \"${_FOUND_VERSION}\")") endif () else () if (NOT ${package}_FIND_VERSION VERSION_EQUAL version) set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"") else () set(version_ok TRUE) set(version_msg "(found suitable exact version \"${version}\")") endif () endif () else() # minimum version if (${package}_FIND_VERSION VERSION_GREATER version) set(version_msg "Found unsuitable version \"${version}\", but required is at least \"${${package}_FIND_VERSION}\"") else() set(version_ok TRUE) set(version_msg "(found suitable version \"${version}\", minimum required is \"${${package}_FIND_VERSION}\")") endif() endif() else () set(version_ok TRUE) set(version_msg "(found version \"${version}\")") endif() set (${result} ${version_ok} PARENT_SCOPE) if (FPCV_RESULT_MESSAGE_VARIABLE) set (${FPCV_RESULT_MESSAGE_VARIABLE} "${version_msg}" PARENT_SCOPE) endif() endfunction() function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # Set up the arguments for `cmake_parse_arguments`. set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED HANDLE_VERSION_RANGE) set(oneValueArgs FAIL_MESSAGE REASON_FAILURE_MESSAGE VERSION_VAR FOUND_VAR) set(multiValueArgs REQUIRED_VARS) # Check whether we are in 'simple' or 'extended' mode: set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) unset(FPHSA_NAME_MISMATCHED_override) if (DEFINED FPHSA_NAME_MISMATCHED) # If the variable NAME_MISMATCHED variable is set, error if it is passed as # an argument. The former is for old signatures, the latter is for new # signatures. list(FIND ARGN "NAME_MISMATCHED" name_mismatched_idx) if (NOT name_mismatched_idx EQUAL "-1") message(FATAL_ERROR "The `NAME_MISMATCHED` argument may only be specified by the argument or " "the variable, not both.") endif () # But use the variable if it is not an argument to avoid forcing minimum # CMake version bumps for calling modules. set(FPHSA_NAME_MISMATCHED_override "${FPHSA_NAME_MISMATCHED}") endif () if(${INDEX} EQUAL -1) set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) set(FPHSA_REQUIRED_VARS ${ARGN}) set(FPHSA_VERSION_VAR) else() cmake_parse_arguments(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) if(FPHSA_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") endif() if(NOT FPHSA_FAIL_MESSAGE) set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") endif() # In config-mode, we rely on the variable _CONFIG, which is set by find_package() # when it successfully found the config-file, including version checking: if(FPHSA_CONFIG_MODE) list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) set(FPHSA_VERSION_VAR ${_NAME}_VERSION) endif() if(NOT FPHSA_REQUIRED_VARS AND NOT FPHSA_HANDLE_COMPONENTS) message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") endif() endif() if (DEFINED FPHSA_NAME_MISMATCHED_override) set(FPHSA_NAME_MISMATCHED "${FPHSA_NAME_MISMATCHED_override}") endif () if (DEFINED CMAKE_FIND_PACKAGE_NAME AND NOT FPHSA_NAME_MISMATCHED AND NOT _NAME STREQUAL CMAKE_FIND_PACKAGE_NAME) message(AUTHOR_WARNING "The package name passed to `find_package_handle_standard_args` " "(${_NAME}) does not match the name of the calling package " "(${CMAKE_FIND_PACKAGE_NAME}). This can lead to problems in calling " "code that expects `find_package` result variables (e.g., `_FOUND`) " "to follow a certain pattern.") endif () if (${_NAME}_FIND_VERSION_RANGE AND NOT FPHSA_HANDLE_VERSION_RANGE) message(AUTHOR_WARNING "`find_package()` specify a version range but the module ${_NAME} does " "not support this capability. Only the lower endpoint of the range " "will be used.") endif() # to propagate package name to FIND_PACKAGE_CHECK_VERSION set(_CMAKE_FPHSA_PACKAGE_NAME "${_NAME}") # now that we collected all arguments, process them if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG") set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") endif() if (FPHSA_REQUIRED_VARS) list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) endif() string(TOUPPER ${_NAME} _NAME_UPPER) string(TOLOWER ${_NAME} _NAME_LOWER) if(FPHSA_FOUND_VAR) set(_FOUND_VAR_UPPER ${_NAME_UPPER}_FOUND) set(_FOUND_VAR_MIXED ${_NAME}_FOUND) if(FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_MIXED OR FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_UPPER) set(_FOUND_VAR ${FPHSA_FOUND_VAR}) else() message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_FOUND_VAR_MIXED}\" and \"${_FOUND_VAR_UPPER}\" are valid names.") endif() else() set(_FOUND_VAR ${_NAME_UPPER}_FOUND) endif() # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) set(MISSING_VARS "") set(DETAILS "") # check if all passed variables are valid set(FPHSA_FOUND_${_NAME} TRUE) foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) if(NOT ${_CURRENT_VAR}) set(FPHSA_FOUND_${_NAME} FALSE) string(APPEND MISSING_VARS " ${_CURRENT_VAR}") else() string(APPEND DETAILS "[${${_CURRENT_VAR}}]") endif() endforeach() if(FPHSA_FOUND_${_NAME}) set(${_NAME}_FOUND TRUE) set(${_NAME_UPPER}_FOUND TRUE) else() set(${_NAME}_FOUND FALSE) set(${_NAME_UPPER}_FOUND FALSE) endif() # component handling unset(FOUND_COMPONENTS_MSG) unset(MISSING_COMPONENTS_MSG) if(FPHSA_HANDLE_COMPONENTS) foreach(comp ${${_NAME}_FIND_COMPONENTS}) if(${_NAME}_${comp}_FOUND) if(NOT DEFINED FOUND_COMPONENTS_MSG) set(FOUND_COMPONENTS_MSG "found components:") endif() string(APPEND FOUND_COMPONENTS_MSG " ${comp}") else() if(NOT DEFINED MISSING_COMPONENTS_MSG) set(MISSING_COMPONENTS_MSG "missing components:") endif() string(APPEND MISSING_COMPONENTS_MSG " ${comp}") if(${_NAME}_FIND_REQUIRED_${comp}) set(${_NAME}_FOUND FALSE) string(APPEND MISSING_VARS " ${comp}") endif() endif() endforeach() set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") string(APPEND DETAILS "[c${COMPONENT_MSG}]") endif() # version handling: set(VERSION_MSG "") set(VERSION_OK TRUE) # check with DEFINED here as the requested or found version may be "0" if (DEFINED ${_NAME}_FIND_VERSION) if(DEFINED ${FPHSA_VERSION_VAR}) set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}}) if (FPHSA_HANDLE_VERSION_RANGE) set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE) else() set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE) endif() find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG ${FPCV_HANDLE_VERSION_RANGE}) else() # if the package was not found, but a version was given, add that to the output: if(${_NAME}_FIND_VERSION_EXACT) set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") elseif (FPHSA_HANDLE_VERSION_RANGE AND ${_NAME}_FIND_VERSION_RANGE) set(VERSION_MSG "(Required is version range \"${${_NAME}_FIND_VERSION_RANGE}\")") else() set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") endif() endif() else () # Check with DEFINED as the found version may be 0. if(DEFINED ${FPHSA_VERSION_VAR}) set(VERSION_MSG "(found version \"${${FPHSA_VERSION_VAR}}\")") endif() endif () if(VERSION_OK) string(APPEND DETAILS "[v${${FPHSA_VERSION_VAR}}(${${_NAME}_FIND_VERSION})]") else() set(${_NAME}_FOUND FALSE) endif() # print the result: if (${_NAME}_FOUND) FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") else () if(FPHSA_CONFIG_MODE) _FPHSA_HANDLE_FAILURE_CONFIG_MODE() else() if(NOT VERSION_OK) set(RESULT_MSG) if (_FIRST_REQUIRED_VAR) string (APPEND RESULT_MSG "found ${${_FIRST_REQUIRED_VAR}}") endif() if (COMPONENT_MSG) if (RESULT_MSG) string (APPEND RESULT_MSG ", ") endif() string (APPEND RESULT_MSG "${FOUND_COMPONENTS_MSG}") endif() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (${RESULT_MSG})") else() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing:${MISSING_VARS}) ${VERSION_MSG}") endif() endif() endif () set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) endfunction() cmake_policy(POP) capstats-0.31/cmake/FindLibKrb5.cmake000644 000765 000024 00000002137 14246446227 017346 0ustar00timstaff000000 000000 # - Try to find Krb5 headers and libraries # # Usage of this module as follows: # # find_package(LibKrb5) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # LibKrb5_ROOT_DIR Set this variable to the root installation of # libKrb5 if the module has problems finding the # proper installation path. # # Variables defined by this module: # # LibKrb5_FOUND System has Krb5 libraries and headers # LibKrb5_LIBRARY The Krb5 library # LibKrb5_INCLUDE_DIR The location of Krb5 headers find_path(LibKrb5_ROOT_DIR NAMES include/krb5.h ) find_library(LibKrb5_LIBRARY NAMES krb5 HINTS ${LibKrb5_ROOT_DIR}/lib ) find_path(LibKrb5_INCLUDE_DIR NAMES krb5.h HINTS ${LibKrb5_ROOT_DIR}/include ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibKrb5 DEFAULT_MSG LibKrb5_LIBRARY LibKrb5_INCLUDE_DIR ) mark_as_advanced( LibKrb5_ROOT_DIR LibKrb5_LIBRARY LibKrb5_INCLUDE_DIR ) capstats-0.31/cmake/package_postupgrade.sh.in000755 000765 000024 00000004361 14246446227 021266 0ustar00timstaff000000 000000 #!/bin/sh # This script is meant to be used by binary packages post-installation. # Variables between @ symbols are replaced by CMake at configure time. backupNamesFile=/tmp/zeek_install_backups version=@VERSION@ sampleFiles="" # check whether it's safe to remove backup configuration files that # the most recent package install created if [ -e ${backupNamesFile} ]; then backupFileList=`cat ${backupNamesFile}` for backupFile in ${backupFileList}; do origFileName=`echo ${backupFile} | sed 's/\(.*\)\..*/\1/'` diff ${origFileName} ${backupFile} > /dev/null 2>&1 if [ $? -eq 0 ]; then # if the installed version and the backup version don't differ # then we can remove the backup version and the example file rm ${backupFile} rm ${origFileName}.example else # The backup file differs from the newly installed version, # since we can't tell if the backup version has been modified # by the user, we should restore it to its original location # and rename the new version appropriately. sampleFiles="${sampleFiles}\n${origFileName}.example" mv ${backupFile} ${origFileName} fi done rm ${backupNamesFile} fi if [ -n "${sampleFiles}" ]; then # Use some apple script to display a message to user /usr/bin/osascript << EOF tell application "System Events" activate display alert "Existing configuration files differ from the ones that would be installed by this package. To avoid overwriting configuration which you may have modified, the following new config files have been installed:\n${sampleFiles}\n\nIf you have previously modified configuration files, please make sure that they are still compatible, else you should update your config files to the new versions." end tell EOF fi # Set up world writeable spool and logs directory for zeekctl, making sure # to set the sticky bit so that unprivileged users can't rename/remove files. # (CMake/CPack is supposed to install them, but has problems with empty dirs) if [ -n "@EMPTY_WORLD_DIRS@" ]; then for dir in "@EMPTY_WORLD_DIRS@"; do mkdir -p ${dir} chmod 777 ${dir} chmod +t ${dir} done fi capstats-0.31/cmake/CheckOptionalBuildSources.cmake000644 000765 000024 00000001650 14246446227 022361 0ustar00timstaff000000 000000 # A macro that checks whether optional sources exist and if they do, they # are added to the build/install process, else a warning is issued # # _dir: the subdir of the current source dir in which the optional # sources are located # _packageName: a string that identifies the package # _varName: name of the variable indicating whether package is scheduled # to be installed macro(CheckOptionalBuildSources _dir _packageName _varName) if (${_varName}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeLists.txt) add_subdirectory(${_dir}) else () message(WARNING "${_packageName} source code does not exist in " "${CMAKE_CURRENT_SOURCE_DIR}/${_dir} " "so it will not be built or installed") set(${_varName} false) endif () endif () endmacro(CheckOptionalBuildSources) capstats-0.31/cmake/BifCl.cmake000644 000765 000024 00000023506 14246446227 016275 0ustar00timstaff000000 000000 # A macro to define a command that uses the BIF compiler to produce C++ # segments and Zeek language declarations from a .bif file. The outputs # are returned in BIF_OUTPUT_{CC,H,BRO}. By default, it runs bifcl in # alternative mode (-a; suitable for standalone compilation). If # an additional parameter "standard" is given, it runs it in standard mode # for inclusion in NetVar.*. If an additional parameter "plugin" is given, # it runs it in plugin mode (-p). In the latter case, one more argument # is required with the plugin's name. # # The macro also creates a target that can be used to define depencencies on # the generated files. The name of the target depends on the mode and includes # a normalized path to the input bif to make it unique. The target is added # automatically to bro_ALL_GENERATED_OUTPUTS. macro(bif_target bifInput) set(target "") get_filename_component(bifInputBasename "${bifInput}" NAME) if ( "${ARGV1}" STREQUAL "standard" ) set(bifcl_args "") set(target "bif-std-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}") set(bifOutputs ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_def ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_h ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_init ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_def ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_h ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_init) set(BIF_OUTPUT_CC ${bifInputBasename}.func_def ${bifInputBasename}.func_init ${bifInputBasename}.netvar_def ${bifInputBasename}.netvar_init) set(BIF_OUTPUT_H ${bifInputBasename}.func_h ${bifInputBasename}.netvar_h) set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_def) elseif ( "${ARGV1}" STREQUAL "plugin" ) set(plugin_name ${ARGV2}) set(plugin_name_canon ${ARGV3}) set(plugin_is_static ${ARGV4}) set(target "bif-plugin-${plugin_name_canon}-${bifInputBasename}") set(bifcl_args "-p;${plugin_name}") set(bifOutputs ${bifInputBasename}.h ${bifInputBasename}.cc ${bifInputBasename}.init.cc ${bifInputBasename}.register.cc) if ( plugin_is_static ) set(BIF_OUTPUT_CC ${bifInputBasename}.cc ${bifInputBasename}.init.cc) set(bro_REGISTER_BIFS ${bro_REGISTER_BIFS} ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename} CACHE INTERNAL "BIFs for automatic registering" FORCE) # Propagate to top-level. else () set(BIF_OUTPUT_CC ${bifInputBasename}.cc ${bifInputBasename}.init.cc ${bifInputBasename}.register.cc) endif() # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy foreach (bif_cc_file ${BIF_OUTPUT_CC}) add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bif_cc_file}) endforeach(bif_cc_file) set(BIF_OUTPUT_H ${bifInputBasename}.h) if ( NOT ZEEK_PLUGIN_BUILD_DYNAMIC ) set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/plugins/${plugin_name_canon}.${bifInputBasename}.zeek) else () set(BIF_OUTPUT_BRO ${BRO_PLUGIN_BIF}/${bifInputBasename}.zeek) endif() set(bro_PLUGIN_BIF_SCRIPTS ${bro_PLUGIN_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) # Propogate to top-level else () # Alternative mode. These will get compiled in automatically. set(bifcl_args "-s") set(target "bif-alt-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}") set(bifOutputs ${bifInputBasename}.h ${bifInputBasename}.cc ${bifInputBasename}.init.cc) set(BIF_OUTPUT_CC ${bifInputBasename}.cc) set(BIF_OUTPUT_H ${bifInputBasename}.h) # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy foreach (bif_cc_file ${BIF_OUTPUT_CC}) add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bif_cc_file}) endforeach(bif_cc_file) # In order be able to run Zeek from the build directory, the # generated Zeek script needs to be inside a directory tree # named the same way it will be referenced from an @load. set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) set(bro_AUTO_BIFS ${bro_AUTO_BIFS} ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename} CACHE INTERNAL "BIFs for automatic inclusion" FORCE) # Propagate to top-level. set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level endif () if ( ZEEK_PLUGIN_INTERNAL_BUILD ) if ( BIFCL_EXE_PATH ) set(BifCl_EXE ${BIFCL_EXE_PATH}) else () set(BifCl_EXE "bifcl") endif () else () if ( NOT BifCl_EXE ) if ( BRO_PLUGIN_BRO_BUILD ) # Zeek 3.2+ has auxil/ instead of aux/ if ( EXISTS "${BRO_PLUGIN_BRO_BUILD}/auxil" ) set(BifCl_EXE "${BRO_PLUGIN_BRO_BUILD}/auxil/bifcl/bifcl") else () set(BifCl_EXE "${BRO_PLUGIN_BRO_BUILD}/aux/bifcl/bifcl") endif () else () find_program(BifCl_EXE bifcl) if ( NOT BifCl_EXE ) message(FATAL_ERROR "Failed to find 'bifcl' program") endif () endif () endif () endif () set(bifclDep ${BifCl_EXE}) add_custom_command(OUTPUT ${bifOutputs} ${BIF_OUTPUT_BRO} COMMAND ${BifCl_EXE} ARGS ${bifcl_args} ${CMAKE_CURRENT_SOURCE_DIR}/${bifInput} || (rm -f ${bifOutputs} && exit 1) COMMAND "${CMAKE_COMMAND}" ARGS -E copy ${bifInputBasename}.zeek ${BIF_OUTPUT_BRO} COMMAND "${CMAKE_COMMAND}" ARGS -E remove -f ${bifInputBasename}.zeek DEPENDS ${bifInput} DEPENDS ${bifclDep} COMMENT "[BIFCL] Processing ${bifInput}" ) # Make sure to escape a bunch of special characters in the path before trying to use it as a # regular expression below. string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_path "${Zeek_BINARY_DIR}/src/") string(REGEX REPLACE "${escaped_path}" "" target "${target}") string(REGEX REPLACE "/" "-" target "${target}") add_custom_target(${target} DEPENDS ${BIF_OUTPUT_H} ${BIF_OUTPUT_CC}) set_source_files_properties(${bifOutputs} PROPERTIES GENERATED 1) set(BIF_BUILD_TARGET ${target}) set(bro_ALL_GENERATED_OUTPUTS ${bro_ALL_GENERATED_OUTPUTS} ${target} CACHE INTERNAL "automatically generated files" FORCE) # Propagate to top-level. endmacro(bif_target) # A macro to create a __load__.zeek file for all *.bif.zeek files in # a given collection (which should all be in the same directory). # It creates a corresponding target to trigger the generation. function(bro_bif_create_loader target bifinputs) set(_bif_loader_dir "") foreach ( _bro_file ${bifinputs} ) get_filename_component(_bif_loader_dir_tmp ${_bro_file} PATH) get_filename_component(_bro_file_name ${_bro_file} NAME) if ( _bif_loader_dir ) if ( NOT _bif_loader_dir_tmp STREQUAL _bif_loader_dir ) message(FATAL_ERROR "Directory of Zeek script BIF stub ${_bro_file} differs from expected: ${_bif_loader_dir}") endif () else () set(_bif_loader_dir ${_bif_loader_dir_tmp}) endif () set(_bif_loader_content "${_bif_loader_content} ${_bro_file_name}") endforeach () if ( NOT _bif_loader_dir ) return () endif () file(MAKE_DIRECTORY ${_bif_loader_dir}) set(_bif_loader_file ${_bif_loader_dir}/__load__.zeek) add_custom_target(${target} COMMAND "sh" "-c" "rm -f ${_bif_loader_file}" COMMAND "sh" "-c" "for i in ${_bif_loader_content}; do echo @load ./$i >> ${_bif_loader_file}; done" WORKING_DIRECTORY ${_bif_loader_dir} VERBATIM ) add_dependencies(${target} generate_outputs) endfunction() # A macro to create joint include files for compiling in all the # autogenerated bif code. Adds an empty target named ${target} (for # compatibility) and creates ${dstdir}/__all__.bif.cc and # ${dstdir}/__all__.bif.init.cc. function(bro_bif_create_includes target dstdir bifinputs) add_custom_target(${target}) bif_create_include(${dstdir} "" "${bifinputs}") bif_create_include(${dstdir} .init "${bifinputs}") endfunction() # Adds and empty target (for compatibility) and creates # ${dstdir}/__all__.bif.register.cc. function(bro_bif_create_register target dstdir bifinputs) add_custom_target(${target}) bif_create_include(${dstdir} .register "${bifinputs}") endfunction() # Creates ${dstdir}/__all__.bif${suffix}.cc. function(bif_create_include dstdir suffix bifinputs) set(dst ${dstdir}/__all__.bif${suffix}.cc) file(REMOVE ${dst}.tmp) foreach (b ${bifinputs}) file(APPEND ${dst}.tmp "#include \"${b}${suffix}.cc\"\n") endforeach () configure_file(${dst}.tmp ${dst} COPYONLY) file(REMOVE ${dst}.tmp) endfunction() capstats-0.31/cmake/AddUninstallTarget.cmake000644 000765 000024 00000000674 14246446227 021050 0ustar00timstaff000000 000000 if (NOT TARGET uninstall) if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif () endif () capstats-0.31/cmake/CommonCMakeConfig.cmake000644 000765 000024 00000000430 14246446227 020564 0ustar00timstaff000000 000000 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(CheckCompilers) include(ProhibitInSourceBuild) include(AddUninstallTarget) include(SetupRPATH) include(SetDefaultCompileFlags) include(MacDependencyPaths) capstats-0.31/cmake/CheckNameserCompat.cmake000644 000765 000024 00000001360 14246446227 021004 0ustar00timstaff000000 000000 include(CheckCSourceCompiles) # Check whether the namser compatibility header is required # This can be the case on the Darwin platform set(CMAKE_REQUIRED_INCLUDES ${BIND_INCLUDE_DIR}) check_c_source_compiles(" #include int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }" have_nameser_header) if (NOT have_nameser_header) check_c_source_compiles(" #include #include int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }" NEED_NAMESER_COMPAT_H) if (NOT NEED_NAMESER_COMPAT_H) message(FATAL_ERROR "Asynchronous DNS support compatibility check failed.") endif () endif () set(CMAKE_REQUIRED_INCLUDES) capstats-0.31/cmake/BinPAC.cmake000644 000765 000024 00000006105 14246446227 016346 0ustar00timstaff000000 000000 # A macro to define a command that uses the BinPac compiler to # produce C++ code that implements a protocol parser/analyzer. # The outputs are returned in BINPAC_OUTPUT_{CC,H}. # Additional dependencies are pulled from BINPAC_AUXSRC. # # The macro also creates a target that can be used to define depencencies on # the generated files. The name of the target includes a normalized path to # the input pac to make it unique. The target is added automatically to # bro_ALL_GENERATED_OUTPUTS. macro(BINPAC_TARGET pacFile) if ( ZEEK_PLUGIN_INTERNAL_BUILD ) if ( BINPAC_EXE_PATH ) set(BinPAC_EXE ${BINPAC_EXE_PATH}) endif () set(binpacDep "${BinPAC_EXE}") else () if ( BRO_PLUGIN_BRO_BUILD ) # Zeek 3.2+ has auxil/ instead of aux/ if ( EXISTS "${BRO_PLUGIN_BRO_BUILD}/auxil" ) set(BinPAC_EXE "${BRO_PLUGIN_BRO_BUILD}/auxil/binpac/src/binpac") else () set(BinPAC_EXE "${BRO_PLUGIN_BRO_BUILD}/aux/binpac/src/binpac") endif () set(BinPAC_addl_args "-I;${BRO_PLUGIN_BRO_SRC}/src") else () find_package(BinPAC REQUIRED) set(BinPAC_addl_args "-I;${BRO_PLUGIN_BRO_CONFIG_INCLUDE_DIR}") endif () endif () get_filename_component(basename ${pacFile} NAME_WE) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.h ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.cc COMMAND ${BinPAC_EXE} ARGS -q -d ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR}/src -I ${PROJECT_SOURCE_DIR}/src ${BinPAC_addl_args} ${CMAKE_CURRENT_SOURCE_DIR}/${pacFile} DEPENDS ${binpacDep} ${pacFile} ${BINPAC_AUXSRC} ${ARGN} COMMENT "[BINPAC] Processing ${pacFile}" ) set(BINPAC_OUTPUT_H ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.h) set(BINPAC_OUTPUT_CC ${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.cc) set(pacOutputs ${BINPAC_OUTPUT_H} ${BINPAC_OUTPUT_CC}) set_property(SOURCE ${BINPAC_OUTPUT_CC} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-tautological-compare") add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${basename}_pac.cc) set(target "pac-${CMAKE_CURRENT_BINARY_DIR}/${pacFile}") # Make sure to escape a bunch of special characters in the path before trying to use it as a # regular expression below. string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_path "${PROJECT_BINARY_DIR}/src/") string(REGEX REPLACE "${escaped_path}" "" target "${target}") string(REGEX REPLACE "/" "-" target "${target}") add_custom_target(${target} DEPENDS ${pacOutputs}) set(BINPAC_BUILD_TARGET ${target}) set(bro_ALL_GENERATED_OUTPUTS ${bro_ALL_GENERATED_OUTPUTS} ${target} CACHE INTERNAL "automatically generated files" FORCE) # Propagate to top-level. endmacro(BINPAC_TARGET) capstats-0.31/cmake/README000644 000765 000024 00000000207 14246446227 015165 0ustar00timstaff000000 000000 This is a collection of CMake scripts intended to be included as a git submodule in other repositories related to Zeek (www.zeek.org). capstats-0.31/cmake/InstallSymlink.cmake000644 000765 000024 00000004664 14246446227 020277 0ustar00timstaff000000 000000 # This macro can be used to install symlinks, which turns out to be # non-trivial due to CMake version differences and limitations on how # files can be installed when building binary packages. # # The rule for binary packaging is that files (including symlinks) must # be installed with the standard CMake install() macro. We do so via # a detour through CMAKE_CURRENT_BINARY_DIR: at install time we create # the symlink there (using a tweaked name, to avoid collisions), then # install that, and then clean it up to avoid leaving potential dangling # symlinks in the build tree. # # The rule for non-binary packaging is that CMake 2.6 cannot install() # symlinks, but can create the symlink at install-time via scripting. # Though, we assume that CMake 2.6 isn't going to be used to generate # packages because versions later than 2.8.3 are superior for that purpose. # # _filepath: the absolute path to the file to symlink # _sympath: absolute path of the installed symlink macro(InstallSymlink _filepath _sympath) get_filename_component(_symname ${_sympath} NAME) get_filename_component(_installdir ${_sympath} PATH) if (BINARY_PACKAGING_MODE) # We need install(CODE ...) here to run this at installation time. # execute_process would run at the configuration stage, making the # symlink potentially conflict with other actions by the caller. install(CODE " execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${_filepath} ${CMAKE_CURRENT_BINARY_DIR}/${_symname}.link) ") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_symname}.link DESTINATION ${_installdir} RENAME ${_symname}) install(CODE "file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_symname}.link)") else () # scripting the symlink installation at install time should work # for CMake 2.6.x and 2.8.x install(CODE " if (\"\$ENV{DESTDIR}\" STREQUAL \"\") execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${_filepath} ${_installdir}/${_symname}) else () execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${_filepath} \$ENV{DESTDIR}/${_installdir}/${_symname}) endif () ") endif () endmacro(InstallSymlink) capstats-0.31/cmake/zeek-plugin-install-package.sh000755 000765 000024 00000000772 14246446227 022142 0ustar00timstaff000000 000000 #! /bin/sh # # Helper script to install the tarball with a plugin's binary distribution. # # Called from ZeekPluginDynamic.cmake. Current directory is the plugin # build directory. if [ $# != 2 ]; then echo "usage: `basename $0` " exit 1 fi dst=$2 if [ ! -d "${dst}" ]; then echo "Warning: ${dst} does not exist; has Zeek been installed?" mkdir -p ${dst} fi name=$1 tgz=`pwd`/$name.tgz ( cd ${dst} && rm -rf "${name}" && tar xzf ${tgz} ) capstats-0.31/cmake/FindKqueue.cmake000644 000765 000024 00000011045 14246446227 017351 0ustar00timstaff000000 000000 include(CheckFunctionExists) # First check whether the system has kqueue built-in. Prefer that over everything else. check_function_exists(kqueue HAVE_KQUEUE) if ( NOT HAVE_KQUEUE ) # If the user passed in a path for libkqueue, see if we can find a copy of it there. # If they didn't pass one, build our local copy of it. if ( LIBKQUEUE_ROOT_DIR ) find_path(LIBKQUEUE_ROOT_DIR NAMES "include/sys/event.h") # Prefer linking statically but look for a shared library version too. find_library(LIBKQUEUE_LIBRARIES NAMES libkqueue.a libkqueue.so HINTS ${LIBKQUEUE_ROOT_DIR}/lib) find_path(LIBKQUEUE_INCLUDE_DIRS NAMES "sys/event.h" HINTS ${LIBKQUEUE_ROOT_DIR}/include/kqueue) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LIBKQUEUE DEFAULT_MSG LIBKQUEUE_LIBRARIES LIBKQUEUE_INCLUDE_DIRS ) mark_as_advanced( LIBKQUEUE_ROOT_DIR LIBKQUEUE_LIBRARIES LIBKQUEUE_INCLUDE_DIRS ) set(HAVE_KQUEUE true) set(zeekdeps ${zeekdeps} ${LIBKQUEUE_LIBRARIES}) include_directories(BEFORE ${LIBKQUEUE_INCLUDE_DIRS}) else() include(ExternalProject) set(kqueue_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/libkqueue") set(kqueue_ep "${CMAKE_CURRENT_BINARY_DIR}/libkqueue-ep") set(kqueue_build "${CMAKE_CURRENT_BINARY_DIR}/libkqueue-build") set(kqueue_static "${kqueue_build}/libkqueue${CMAKE_STATIC_LIBRARY_SUFFIX}") if ( ${CMAKE_VERSION} VERSION_LESS "3.2.0" ) # Build byproducts is just required by the Ninja generator # though it's not available before CMake 3.2 ... if ( ${CMAKE_GENERATOR} STREQUAL Ninja ) message(FATAL_ERROR "Ninja generator requires CMake >= 3.2") endif () set(build_byproducts_arg) else () set(build_byproducts_arg BUILD_BYPRODUCTS ${kqueue_static}) endif () ExternalProject_Add(project_kqueue PREFIX "${kqueue_ep}" BINARY_DIR "${kqueue_build}" DOWNLOAD_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ${build_byproducts_arg} ) if ( ${CMAKE_VERSION} VERSION_LESS "3.4.0" ) set(use_terminal_arg) else () set(use_terminal_arg USES_TERMINAL 1) endif () ExternalProject_Add_Step(project_kqueue project_kqueue_build_step COMMAND ${CMAKE_MAKE_PROGRAM} COMMENT "Building libkqueue" WORKING_DIRECTORY ${kqueue_build} ALWAYS 1 ${use_terminal_arg} ) if ( CMAKE_TOOLCHAIN_FILE ) set(toolchain_arg -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) else () set(toolchain_arg) endif () if ( CMAKE_C_COMPILER_LAUNCHER ) set(cmake_c_compiler_launcher_arg -DCMAKE_C_COMPILER_LAUNCHER:path=${CMAKE_C_COMPILER_LAUNCHER}) else () set(cmake_c_compiler_launcher_arg) endif () if ( CMAKE_CXX_COMPILER_LAUNCHER ) set(cmake_cxx_compiler_launcher_arg -DCMAKE_CXX_COMPILER_LAUNCHER:path=${CMAKE_CXX_COMPILER_LAUNCHER}) else () set(cmake_cxx_compiler_launcher_arg) endif () execute_process( COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${toolchain_arg} ${cmake_c_compiler_launcher_arg} ${cmake_cxx_compiler_launcher_arg} -DCMAKE_BUILD_TYPE:string=${CMAKE_BUILD_TYPE} -DSTATIC_KQUEUE=yes ${kqueue_src} WORKING_DIRECTORY ${kqueue_build} RESULT_VARIABLE kqueue_cmake_result ERROR_VARIABLE KQUEUE_CMAKE_OUTPUT OUTPUT_VARIABLE KQUEUE_CMAKE_OUTPUT ERROR_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE ) message("\n********** Begin libkqueue External Project CMake Output ************") message("\n${KQUEUE_CMAKE_OUTPUT}") message("\n*********** End libkqueue External Project CMake Output *************") message("\n") if (kqueue_cmake_result) message(FATAL_ERROR "libkqueue CMake configuration failed") endif () add_library(libkqueue_a STATIC IMPORTED) set_property(TARGET libkqueue_a PROPERTY IMPORTED_LOCATION ${kqueue_static}) add_dependencies(libkqueue_a project_kqueue) set(HAVE_KQUEUE true) set(LIBKQUEUE_LIBRARIES libkqueue_a CACHE STRING "libkqueue libs" FORCE) set(LIBKQUEUE_INCLUDE_DIRS "${kqueue_src}/include;${kqueue_build}/include" CACHE INTERNAL "libkqueue includes" FORCE) include_directories(BEFORE ${LIBKQUEUE_INCLUDE_DIRS}) set(zeekdeps ${zeekdeps} ${LIBKQUEUE_LIBRARIES}) endif() endif() if ( NOT HAVE_KQUEUE ) message(FATAL_ERROR "Failed to find a working version of kqueue.") endif() capstats-0.31/cmake/MAC_PACKAGE_INTRO000644 000765 000024 00000001247 14246446227 016723 0ustar00timstaff000000 000000 This package will install @CMAKE_PROJECT_NAME@ into the following location: @CMAKE_INSTALL_PREFIX@ You may choose to update your PATH environment variable: # For Bash export PATH=@CMAKE_INSTALL_PREFIX@/bin:$PATH # For CSH setenv PATH @CMAKE_INSTALL_PREFIX@/bin:$PATH If you have more than one volume, please choose the install destination as the one that contains the root filesystem. If you have existing configuration files that are modified or otherwise different from the version included in the package, this installer will attempt to prevent overwirting them, but its also advisable to make your own backups of important files before proceeding. capstats-0.31/cmake/ZeekPluginStatic.cmake000644 000765 000024 00000005131 14246446227 020535 0ustar00timstaff000000 000000 ## A set of functions for defining Zeek plugins. ## ## This set is for plugins compiled in statically. ## See ZeekPluginDynamic.cmake for the dynamic version. function(bro_plugin_bif_static) foreach ( bif ${ARGV} ) bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} TRUE) list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) endforeach () endfunction() function(bro_plugin_link_library_static) foreach ( lib ${ARGV} ) set(bro_SUBDIR_LIBS ${bro_SUBDIR_LIBS} "${lib}" CACHE INTERNAL "plugin libraries") endforeach () endfunction() function(bro_plugin_end_static) add_library(${_plugin_lib} OBJECT ${_plugin_objs}) if ( NOT "${_plugin_deps}" STREQUAL "" ) add_dependencies(${_plugin_lib} ${_plugin_deps}) endif () add_dependencies(${_plugin_lib} generate_outputs) set(preload_script ${_plugin_name_canon}/__preload__.zeek) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/__preload__.zeek) file(APPEND ${Zeek_BINARY_DIR}/scripts/builtin-plugins/__preload__.zeek "\n@load ${preload_script}") endif() set(load_script ${_plugin_name_canon}/__load__.zeek) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/__load__.zeek) file(APPEND ${Zeek_BINARY_DIR}/scripts/builtin-plugins/__load__.zeek "\n@load ${load_script}") endif() get_filename_component(plugin_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/scripts" ) install(DIRECTORY ./scripts/ DESTINATION "${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins/${_plugin_name_canon}" FILES_MATCHING PATTERN "*.zeek" PATTERN "*.sig" PATTERN "*.fp") # Make a plugin directory and symlink the scripts directory into it # so that the development ZEEKPATH will work too. file(MAKE_DIRECTORY ${Zeek_BINARY_DIR}/scripts/builtin-plugins) execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/scripts" "${Zeek_BINARY_DIR}/scripts/builtin-plugins/${_plugin_name_canon}") endif () set(bro_PLUGIN_LIBS ${bro_PLUGIN_LIBS} "$" CACHE INTERNAL "plugin libraries") set(bro_PLUGIN_DEPS ${bro_PLUGIN_DEPS} "${_plugin_lib}" CACHE INTERNAL "plugin dependencies") endfunction() macro(_plugin_target_name_static target ns name) set(${target} "plugin-${ns}-${name}") endmacro() capstats-0.31/cmake/FindSubnetTree.cmake000644 000765 000024 00000001446 14246446227 020176 0ustar00timstaff000000 000000 # - Determine if the SubnetTree Python module is available # # Usage of this module as follows: # # find_package(PythonInterp REQUIRED) # find_package(SubnetTree) # # Variables defined by this module: # # SUBNETTREE_FOUND Python successfully imports SubnetTree module if (NOT SUBNETTREE_FOUND) execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import SubnetTree" RESULT_VARIABLE SUBNETTREE_IMPORT_RESULT) if (SUBNETTREE_IMPORT_RESULT) # python returned non-zero exit status set(SUBNETTREE_PYTHON_MODULE false) else () set(SUBNETTREE_PYTHON_MODULE true) endif () endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(SubnetTree DEFAULT_MSG SUBNETTREE_PYTHON_MODULE) capstats-0.31/cmake/CheckHeaders.cmake000644 000765 000024 00000003163 14246446227 017624 0ustar00timstaff000000 000000 include(CheckIncludeFiles) include(CheckStructHasMember) include(CheckSymbolExists) check_include_files(getopt.h HAVE_GETOPT_H) check_include_files(memory.h HAVE_MEMORY_H) check_include_files("netinet/ether.h" HAVE_NETINET_ETHER_H) check_include_files("sys/socket.h;netinet/in.h;net/if.h;netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H) check_include_files("sys/socket.h;netinet/in.h;net/if.h;netinet/ip6.h" HAVE_NETINET_IP6_H) check_include_files("sys/socket.h;net/if.h;net/ethernet.h" HAVE_NET_ETHERNET_H) check_include_files(sys/ethernet.h HAVE_SYS_ETHERNET_H) check_include_files(net/ethertypes.h HAVE_NET_ETHERTYPES_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files("time.h;sys/time.h" TIME_WITH_SYS_TIME) check_include_files(os-proto.h HAVE_OS_PROTO_H) check_struct_has_member(HISTORY_STATE entries "stdio.h;readline/readline.h" HAVE_READLINE_HISTORY_ENTRIES) check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H) check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H) if (HAVE_READLINE_READLINE_H AND HAVE_READLINE_HISTORY_H AND HAVE_READLINE_HISTORY_ENTRIES) set(HAVE_READLINE true) endif () check_struct_has_member("struct sockaddr_in" sin_len "netinet/in.h" SIN_LEN) macro(CheckIPProto _proto) check_symbol_exists(IPPROTO_${_proto} netinet/in.h HAVE_IPPROTO_${_proto}) endmacro(CheckIPProto _proto) CheckIPProto(HOPOPTS) CheckIPProto(IPV6) CheckIPProto(IPV4) CheckIPProto(ROUTING) CheckIPProto(FRAGMENT) CheckIPProto(ESP) CheckIPProto(AH) CheckIPProto(ICMPV6) CheckIPProto(NONE) CheckIPProto(DSTOPTS) capstats-0.31/cmake/FindBIND.cmake000644 000765 000024 00000005531 14246446227 016631 0ustar00timstaff000000 000000 # - Try to find BIND include dirs and libraries # # Usage of this module as follows: # # find_package(BIND) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # BIND_ROOT_DIR Set this variable to the root installation of BIND # if the module has problems finding the proper # installation path. # # Variables defined by this module: # # BIND_FOUND System has BIND, include and library dirs found # BIND_INCLUDE_DIR The BIND include directories. # BIND_LIBRARY The BIND library (if any) required for # ns_inittab and res_mkquery symbols find_path(BIND_ROOT_DIR NAMES include/bind/resolv.h include/resolv.h ) find_path(BIND_INCLUDE_DIR NAMES resolv.h HINTS ${BIND_ROOT_DIR}/include/bind ${BIND_ROOT_DIR}/include ) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") # the static resolv library is preferred because # on some systems, the ns_initparse symbol is not # exported in the shared library (strangely) # see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=291609 set(bind_libs none libresolv.a resolv bind) else () set(bind_libs none resolv bind) endif () include(CheckCSourceCompiles) # Find which library has the res_mkquery and ns_initparse symbols set(CMAKE_REQUIRED_INCLUDES ${BIND_INCLUDE_DIR}) foreach (bindlib ${bind_libs}) if (NOT ${bindlib} MATCHES "none") find_library(BIND_LIBRARY NAMES ${bindlib} HINTS ${BIND_ROOT_DIR}/lib ${BIND_ROOT_DIR}/lib/libbind ) endif () set(CMAKE_REQUIRED_LIBRARIES ${BIND_LIBRARY}) check_c_source_compiles(" #include int main() { ns_initparse(0, 0, 0); return 0; } " ns_initparse_works_${bindlib}) check_c_source_compiles(" #include #include #include #include #include int main() { int (*p)() = res_mkquery; return 0; } " res_mkquery_works_${bindlib}) set(CMAKE_REQUIRED_LIBRARIES) if (ns_initparse_works_${bindlib} AND res_mkquery_works_${bindlib}) break () else () set(BIND_LIBRARY BIND_LIBRARY-NOTFOUND) endif () endforeach () set(CMAKE_REQUIRED_INCLUDES) include(FindPackageHandleStandardArgs) if (ns_initparse_works_none AND res_mkquery_works_none) # system does not require linking to a BIND library find_package_handle_standard_args(BIND DEFAULT_MSG BIND_INCLUDE_DIR ) else () find_package_handle_standard_args(BIND DEFAULT_MSG BIND_LIBRARY BIND_INCLUDE_DIR ) endif () mark_as_advanced( BIND_ROOT_DIR BIND_LIBRARY BIND_INCLUDE_DIR ) capstats-0.31/cmake/InstallShellScript.cmake000644 000765 000024 00000004550 14246446227 021077 0ustar00timstaff000000 000000 # Schedules a file to be installed by the 'install' target, but first # transformed by configure_file(... @ONLY) as well as by changing the # shell script's hashbang (#!) line to use the absolute path to the # interpreter in the path of the user running ./configure (or CMake equiv.). # # Hashbangs are not transformed when in binary packaging or cross-compiling # mode because that can result in inserting paths on the build system # that are not valid on the target system. # # _dstdir: absolute path to the directory in which to install the transformed # source file # _srcfile: path relevant to CMAKE_CURRENT_SOURCE_DIR pointing to the shell # script to install # [_dstfilename]: an optional argument for how to (re)name the file as # it's installed inside _dstdir macro(InstallShellScript _dstdir _srcfile) if (NOT "${ARGN}" STREQUAL "") set(_dstfilename ${ARGN}) else () get_filename_component(_dstfilename ${_srcfile} NAME) endif () set(orig_file ${CMAKE_CURRENT_SOURCE_DIR}/${_srcfile}) set(configed_file ${CMAKE_CURRENT_BINARY_DIR}/${_srcfile}) set(dehashbanged_file ${CMAKE_CURRENT_BINARY_DIR}/${_srcfile}.dehashbanged) configure_file(${orig_file} ${configed_file} @ONLY) file(READ ${configed_file} _srclines) file(WRITE ${dehashbanged_file} "") if (NOT BINARY_PACKAGING_MODE AND NOT CMAKE_CROSSCOMPILING) set(_regex "^#![ ]*/usr/bin/env[ ]+([^\n ]*)") string(REGEX MATCH ${_regex} _match ${_srclines}) if (_match) set(_shell ${CMAKE_MATCH_1}) if ( (${_shell} STREQUAL "python" OR ${_shell} STREQUAL "python3") AND PYTHON_EXECUTABLE ) set(${_shell}_interp ${PYTHON_EXECUTABLE}) else () find_program(${_shell}_interp ${_shell}) endif () if (NOT ${_shell}_interp) message(FATAL_ERROR "Absolute path to interpreter '${_shell}' not found, " "failed to configure shell script: ${orig_file}") endif () string(REGEX REPLACE ${_regex} "#!${${_shell}_interp}" _srclines "${_srclines}") endif () endif () file(WRITE ${dehashbanged_file} "${_srclines}") install(PROGRAMS ${dehashbanged_file} DESTINATION ${_dstdir} RENAME ${_dstfilename}) endmacro(InstallShellScript) capstats-0.31/cmake/COPYING000644 000765 000024 00000003457 14246446227 015352 0ustar00timstaff000000 000000 Copyright (c) 1995-2017, The Regents of the University of California through the Lawrence Berkeley National Laboratory and the International Computer Science Institute. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, U.S. Dept. of Energy, International Computer Science Institute, nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Note that some files in the distribution may carry their own copyright notices. capstats-0.31/cmake/ZeekPlugin.cmake000644 000765 000024 00000000744 14246446227 017372 0ustar00timstaff000000 000000 # Wrapper include file that loads the macros for building a Zeek # plugin either statically or dynamically, depending on whether # we're building as part of the main Zeek source tree, or externally. if ( ZEEK_PLUGIN_INTERNAL_BUILD ) if ( "${ZEEK_PLUGIN_BUILD_DYNAMIC}" STREQUAL "" ) set(ZEEK_PLUGIN_BUILD_DYNAMIC FALSE) endif() else () set(ZEEK_PLUGIN_BUILD_DYNAMIC TRUE) endif () include(ZeekPluginCommon) include(ZeekPluginStatic) include(ZeekPluginDynamic) capstats-0.31/cmake/ZeekPluginDynamic.cmake000644 000765 000024 00000036463 14246446227 020706 0ustar00timstaff000000 000000 ## A set of functions for defining Zeek plugins. ## ## This set is for plugins compiled dynamically for loading at run-time. ## See ZeekPluginStatic.cmake for the static version. ## ## Note: This is meant to run as a standalone CMakeLists.txt. It sets ## up all the basic infrastructure to compile a dynamic Zeek plugin when ## included from its top-level CMake file. if ( NOT ZEEK_PLUGIN_INTERNAL_BUILD ) set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH "${BRO_PLUGIN_INSTALL_ROOT}" CACHE INTERNAL "" FORCE) if ( BRO_DIST ) include(${BRO_DIST}/cmake/CommonCMakeConfig.cmake) if ( NOT EXISTS "${BRO_DIST}/build/CMakeCache.txt" ) message(FATAL_ERROR "${BRO_DIST}/build/CMakeCache.txt; has Zeek been built?") endif () load_cache("${BRO_DIST}/build" READ_WITH_PREFIX bro_cache_ CMAKE_INSTALL_PREFIX Zeek_BINARY_DIR Zeek_SOURCE_DIR ENABLE_DEBUG BRO_PLUGIN_INSTALL_PATH BRO_EXE_PATH CMAKE_CXX_FLAGS CMAKE_C_FLAGS PCAP_INCLUDE_DIR ZLIB_INCLUDE_DIR OPENSSL_INCLUDE_DIR LibKrb5_INCLUDE_DIR GooglePerftools_INCLUDE_DIR) if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH "${bro_cache_BRO_PLUGIN_INSTALL_PATH}" CACHE INTERNAL "" FORCE) endif () set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${bro_cache_CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_ENABLE_DEBUG "${bro_cache_ENABLE_DEBUG}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_SRC "${bro_cache_Zeek_SOURCE_DIR}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_BUILD "${bro_cache_Zeek_BINARY_DIR}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_EXE_PATH "${bro_cache_BRO_EXE_PATH}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_CMAKE ${BRO_PLUGIN_BRO_SRC}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${bro_cache_CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${bro_cache_CMAKE_CXX_FLAGS}") if ( bro_cache_PCAP_INCLUDE_DIR ) include_directories(BEFORE ${bro_cache_PCAP_INCLUDE_DIR}) endif () if ( bro_cache_ZLIB_INCLUDE_DIR ) include_directories(BEFORE ${bro_cache_ZLIB_INCLUDE_DIR}) endif () if ( bro_cache_OPENSSL_INCLUDE_DIR ) include_directories(BEFORE ${bro_cache_OPENSSL_INCLUDE_DIR}) endif () if ( bro_cache_LibKrb5_INCLUDE_DIR ) include_directories(BEFORE ${bro_cache_LibKrb5_INCLUDE_DIR}) endif () if ( bro_cache_GooglePerftools_INCLUDE_DIR ) include_directories(BEFORE ${bro_cache_GooglePerftools_INCLUDE_DIR}) endif () # Zeek 3.2+ has auxil/ instead of aux/ include_directories(BEFORE ${BRO_PLUGIN_BRO_SRC}/src ${BRO_PLUGIN_BRO_SRC}/aux/binpac/lib ${BRO_PLUGIN_BRO_SRC}/auxil/binpac/lib ${BRO_PLUGIN_BRO_SRC}/aux/broker/include ${BRO_PLUGIN_BRO_SRC}/auxil/broker/include ${BRO_PLUGIN_BRO_SRC}/aux/paraglob/include ${BRO_PLUGIN_BRO_SRC}/auxil/paraglob/include ${BRO_PLUGIN_BRO_SRC}/aux/rapidjson/include ${BRO_PLUGIN_BRO_SRC}/auxil/rapidjson/include ${BRO_PLUGIN_BRO_BUILD} ${BRO_PLUGIN_BRO_BUILD}/src ${BRO_PLUGIN_BRO_BUILD}/src/include ${BRO_PLUGIN_BRO_BUILD}/aux/binpac/lib ${BRO_PLUGIN_BRO_BUILD}/auxil/binpac/lib ${BRO_PLUGIN_BRO_BUILD}/aux/broker/include ${BRO_PLUGIN_BRO_BUILD}/auxil/broker/include ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src ) set(ENV{PATH} "${BRO_PLUGIN_BRO_BUILD}/build/src:$ENV{PATH}") else () # Independent from BRO_DIST source tree if ( NOT BRO_CONFIG_CMAKE_DIR ) message(FATAL_ERROR "CMake var. BRO_CONFIG_CMAKE_DIR must be set" " to the path where Zeek installed its cmake modules") endif () include(${BRO_CONFIG_CMAKE_DIR}/CommonCMakeConfig.cmake) if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) if ( NOT BRO_CONFIG_PLUGIN_DIR ) message(FATAL_ERROR "CMake var. BRO_CONFIG_PLUGIN_DIR must be" " set to the path where Zeek installs its plugins") endif () set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH "${BRO_CONFIG_PLUGIN_DIR}" CACHE INTERNAL "" FORCE) endif () if ( NOT BRO_CONFIG_PREFIX ) message(FATAL_ERROR "CMake var. BRO_CONFIG_PREFIX must be set" " to the root installation path of Zeek") endif () if ( NOT BRO_CONFIG_INCLUDE_DIR ) message(FATAL_ERROR "CMake var. BRO_CONFIG_INCLUDE_DIR must be set" " to the installation path of Zeek headers") endif () # Add potential custom library paths to our search path. This # works transparently across future find_library() calls. # # The zeek-config call is currently an outlier ... we need it # because existing plugin configure scripts need to keep # working with possible alternative libdirs, but do not # determine the libdir themselves. zeek-config is the only way # to determine it post-installation in those cases. # # XXX In the future the FindZeek module should make # zeek-config calls to establish the various settings # consistently within cmake. This would simplify configure # scripts and make cmake use with Zeek more standard. if ( NOT BRO_CONFIG_LIB_DIR ) execute_process( COMMAND ${BRO_CONFIG_PREFIX}/bin/zeek-config --lib_dir OUTPUT_VARIABLE BRO_CONFIG_LIB_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) endif () if ( BRO_CONFIG_LIB_DIR ) set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${BRO_CONFIG_LIB_DIR}) endif () set(BRO_PLUGIN_BRO_CONFIG_INCLUDE_DIR "${BRO_CONFIG_INCLUDE_DIR}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${BRO_CONFIG_PREFIX}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_EXE_PATH "${BRO_CONFIG_PREFIX}/bin/zeek" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BRO_CMAKE ${BRO_CONFIG_CMAKE_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) find_package(BinPAC REQUIRED) find_package(Broker REQUIRED) string(REPLACE ":" ";" ZEEK_CONFIG_INCLUDE_DIRS "${BRO_CONFIG_INCLUDE_DIR}") list(GET ZEEK_CONFIG_INCLUDE_DIRS 0 ZEEK_CONFIG_BASE_INCLUDE_DIR) list(APPEND ZEEK_CONFIG_INCLUDE_DIRS "${ZEEK_CONFIG_BASE_INCLUDE_DIR}/zeek/3rdparty/rapidjson/include") include_directories(BEFORE ${ZEEK_CONFIG_INCLUDE_DIRS} ${BinPAC_INCLUDE_DIR} ${BROKER_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src ) endif () if ( NOT BRO_PLUGIN_BASE ) set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "" FORCE) endif () set(BRO_PLUGIN_SCRIPTS "${CMAKE_CURRENT_BINARY_DIR}/scripts" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_SCRIPTS_SRC "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BUILD "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_LIB "${BRO_PLUGIN_BUILD}/lib" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BUILD}/__bro_plugin__" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) set(ZEEK_PLUGIN_INTERNAL_BUILD false CACHE INTERNAL "" FORCE) set(ZEEK_PLUGIN_BUILD_DYNAMIC true CACHE INTERNAL "" FORCE) message(STATUS "Zeek executable : ${BRO_PLUGIN_BRO_EXE_PATH}") message(STATUS "Zeek source : ${BRO_PLUGIN_BRO_SRC}") message(STATUS "Zeek build : ${BRO_PLUGIN_BRO_BUILD}") message(STATUS "Zeek install prefix : ${BRO_PLUGIN_BRO_INSTALL_PREFIX}") message(STATUS "Zeek plugin directory: ${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}") message(STATUS "Zeek debug mode : ${BRO_PLUGIN_ENABLE_DEBUG}") # Determine whether Zeek has unit-test support. This would be better via an # improved FindZeek, or at least an explicit feature list via zeek-config. # It's unavailable if Zeek is pre-4.2 or the build got configured with # --disable-cpp-tests. execute_process( COMMAND ${BRO_PLUGIN_BRO_EXE_PATH} --test -v RESULT_VARIABLE _zeek_retcode OUTPUT_QUIET ERROR_QUIET) if ( _zeek_retcode EQUAL 0 ) message(STATUS "Zeek unittest support: yes") set(ZEEK_HAS_CPP_TESTS true) else () message(STATUS "Zeek unittest support: no") set(ZEEK_HAS_CPP_TESTS false) endif () if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # By default Darwin's linker requires all symbols to be present at link time. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -undefined dynamic_lookup -Wl,-bind_at_load") endif () set(bro_PLUGIN_LIBS CACHE INTERNAL "plugin libraries" FORCE) set(bro_PLUGIN_BIF_SCRIPTS CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) add_definitions(-DZEEK_PLUGIN_INTERNAL_BUILD=false) add_custom_target(generate_outputs) if ( BRO_PLUGIN_ENABLE_DEBUG ) set(ENABLE_DEBUG true) set(CMAKE_BUILD_TYPE Debug) endif () include(SetDefaultCompileFlags) else () set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BASE}/__bro_plugin__" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_SCRIPTS "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) set(BRO_PLUGIN_SCRIPTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/scripts" CACHE INTERNAL "" FORCE) endif () include(GetArchitecture) function(bro_plugin_bif_dynamic) foreach ( bif ${ARGV} ) bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} FALSE) list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) endforeach () endfunction() function(bro_plugin_link_library_dynamic) foreach ( lib ${ARGV} ) set(_plugin_libs ${_plugin_libs} ${lib} CACHE INTERNAL "dynamic plugin libraries") endforeach () endfunction() function(bro_plugin_end_dynamic) # Create the dynamic library/bundle. add_library(${_plugin_lib} MODULE ${_plugin_objs}) set_target_properties(${_plugin_lib} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${BRO_PLUGIN_LIB}") set_target_properties(${_plugin_lib} PROPERTIES PREFIX "") # set_target_properties(${_plugin_lib} PROPERTIES ENABLE_EXPORTS TRUE) add_dependencies(${_plugin_lib} generate_outputs) if ( _plugin_deps ) add_dependencies(${_plugin_lib} ${_plugin_deps}) endif() target_link_libraries(${_plugin_lib} ${_plugin_libs}) # Create bif/__load__.zeek. bro_bif_create_loader(bif-init-${_plugin_name_canon} "${bro_PLUGIN_BIF_SCRIPTS}") # Copy scripts/ if it's not already at the right place inside the # plugin directory. (Actually, we create a symbolic link rather # than copy so that edits to the scripts show up immediately.) if ( NOT "${BRO_PLUGIN_SCRIPTS_SRC}" STREQUAL "${BRO_PLUGIN_SCRIPTS}" ) add_custom_target(copy-scripts-${_plugin_name_canon} # COMMAND "${CMAKE_COMMAND}" -E remove_directory ${BRO_PLUGIN_SCRIPTS} # COMMAND "${CMAKE_COMMAND}" -E copy_directory ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS}) COMMAND test -d ${BRO_PLUGIN_SCRIPTS_SRC} && rm -f ${BRO_PLUGIN_SCRIPTS} && ln -s ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS} || true) add_dependencies(${_plugin_lib} copy-scripts-${_plugin_name_canon}) endif() if ( _plugin_deps ) add_dependencies(bif-init-${_plugin_name_canon} ${_plugin_deps}) add_dependencies(${_plugin_lib} bif-init-${_plugin_name_canon}) endif() # Create __bro_plugin__ # string(REPLACE "${BRO_PLUGIN_BASE}/" "" msg "Creating ${BRO_PLUGIN_MAGIC} for ${_plugin_name}") get_filename_component(_magic_basename ${BRO_PLUGIN_MAGIC} NAME) add_custom_target(bro-plugin-${_plugin_name_canon} COMMAND echo "${_plugin_name}" ">${BRO_PLUGIN_MAGIC}" COMMENT "Creating ${_magic_basename} for ${_plugin_name}") if ( _plugin_deps ) add_dependencies(bro-plugin-${_plugin_name_canon} ${_plugin_deps}) endif() add_dependencies(${_plugin_lib} bro-plugin-${_plugin_name_canon}) set(_dist_tarball_name ${_plugin_name_canon}.tgz) set(_dist_output ${CMAKE_CURRENT_BINARY_DIR}/${_dist_tarball_name}) # Create binary install package. add_custom_command(OUTPUT ${_dist_output} COMMAND ${BRO_PLUGIN_BRO_CMAKE}/zeek-plugin-create-package.sh ${_plugin_name_canon} ${_plugin_dist} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${_plugin_lib} ${_plugin_scripts} COMMENT "Building binary plugin package: ${_dist_tarball_name}") add_custom_target(dist ALL DEPENDS ${_dist_output}) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_BIF}) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_LIB}) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_MAGIC}) ### Plugin installation. set(plugin_install "${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}/${_plugin_name_canon}") INSTALL(CODE "execute_process( COMMAND ${BRO_PLUGIN_BRO_CMAKE}/zeek-plugin-install-package.sh ${_plugin_name_canon} \$ENV{DESTDIR}/${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )") endfunction() macro(_plugin_target_name_dynamic target ns name) set(${target} "${ns}-${name}.${HOST_ARCHITECTURE}") endmacro() capstats-0.31/cmake/ZeekSubdir.cmake000644 000765 000024 00000000700 14246446227 017354 0ustar00timstaff000000 000000 # Creates a target for a library of objects file in a subdirectory, # and adds to the global bro_SUBDIR_LIBS. function(bro_add_subdir_library name) add_library("bro_${name}" OBJECT ${ARGN}) set(bro_SUBDIR_LIBS "$" ${bro_SUBDIR_LIBS} CACHE INTERNAL "subdir libraries") set(bro_SUBDIR_DEPS "bro_${name}" ${bro_SUBDIR_DEPS} CACHE INTERNAL "subdir dependencies") add_clang_tidy_files(${ARGN}) endfunction() capstats-0.31/cmake/FindPCAP.cmake000644 000765 000024 00000004546 14246446227 016645 0ustar00timstaff000000 000000 # - Try to find libpcap include dirs and libraries # # Usage of this module as follows: # # find_package(PCAP) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # PCAP_ROOT_DIR Set this variable to the root installation of # libpcap if the module has problems finding the # proper installation path. # # Variables defined by this module: # # PCAP_FOUND System has libpcap, include and library dirs found # PCAP_INCLUDE_DIR The libpcap include directories. # PCAP_LIBRARY The libpcap library (possibly includes a thread # library e.g. required by pf_ring's libpcap) # HAVE_PF_RING If a found version of libpcap supports PF_RING find_path(PCAP_ROOT_DIR NAMES include/pcap.h ) find_path(PCAP_INCLUDE_DIR NAMES pcap.h HINTS ${PCAP_ROOT_DIR}/include ) find_library(PCAP_LIBRARY NAMES pcap HINTS ${PCAP_ROOT_DIR}/lib ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(PCAP DEFAULT_MSG PCAP_LIBRARY PCAP_INCLUDE_DIR ) include(CheckCSourceCompiles) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) set(CMAKE_REQUIRED_LIBRARIES) # check if linking against libpcap also needs to link against a thread library if (NOT PCAP_LINKS_SOLO) find_package(Threads) if (THREADS_FOUND) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) set(CMAKE_REQUIRED_LIBRARIES) endif () if (THREADS_FOUND AND PCAP_NEEDS_THREADS) set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) list(REMOVE_DUPLICATES _tmp) set(PCAP_LIBRARY ${_tmp} CACHE STRING "Libraries needed to link against libpcap" FORCE) else () message(FATAL_ERROR "Couldn't determine how to link against libpcap") endif () endif () include(CheckFunctionExists) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) check_function_exists(pcap_get_pfring_id HAVE_PF_RING) check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND) set(CMAKE_REQUIRED_LIBRARIES) mark_as_advanced( PCAP_ROOT_DIR PCAP_INCLUDE_DIR PCAP_LIBRARY ) capstats-0.31/cmake/InstallClobberImmune.cmake000644 000765 000024 00000002556 14246446227 021372 0ustar00timstaff000000 000000 # Determines at `make install` time if a file, typically a configuration # file placed in $PREFIX/etc, shouldn't be installed to prevent overwrite # of an existing file. # # _srcfile: the file to install # _dstfile: the absolute file name after installation macro(InstallClobberImmune _srcfile _dstfile) install(CODE " set(_destfile \"${_dstfile}\") if (NOT \"\$ENV{DESTDIR}\" STREQUAL \"\") # prepend install root prefix with install-time DESTDIR set(_destfile \"\$ENV{DESTDIR}/${_dstfile}\") endif () if (EXISTS \${_destfile}) message(STATUS \"Skipping: \${_destfile} (already exists)\") execute_process(COMMAND \"${CMAKE_COMMAND}\" -E compare_files ${_srcfile} \${_destfile} RESULT_VARIABLE _diff) if (NOT \"\${_diff}\" STREQUAL \"0\") message(STATUS \"Installing: \${_destfile}.example\") configure_file(${_srcfile} \${_destfile}.example COPYONLY) endif () else () message(STATUS \"Installing: \${_destfile}\") # install() is not scriptable within install(), and # configure_file() is the next best thing configure_file(${_srcfile} \${_destfile} COPYONLY) # TODO: create additional install_manifest files? endif () ") endmacro(InstallClobberImmune) capstats-0.31/cmake/FindRequiredPackage.cmake000644 000765 000024 00000003557 14246446227 021157 0ustar00timstaff000000 000000 # A wrapper macro around the standard CMake find_package macro that # facilitates displaying better error messages by default, or even # accepting custom error messages on a per package basis. # # If a package is not found, then the MISSING_PREREQS variable gets # set to true and either a default or custom error message appended # to MISSING_PREREQ_DESCS. # # The caller can use these variables to display a list of any missing # packages and abort the build/configuration if there were any. # # Use as follows: # # include(FindRequiredPackage) # FindRequiredPackage(Perl) # FindRequiredPackage(FLEX "You need to install flex (Fast Lexical Analyzer)") # # if (MISSING_PREREQS) # foreach (prereq ${MISSING_PREREQ_DESCS}) # message(SEND_ERROR ${prereq}) # endforeach () # message(FATAL_ERROR "Configuration aborted due to missing prerequisites") # endif () macro(FindRequiredPackage packageName) string(TOUPPER ${packageName} upperPackageName) if ( (DEFINED ${upperPackageName}_ROOT_DIR) AND (DEFINED CMAKE_PREFIX_PATH) ) set(CMAKE_PREFIX_SAVE ${CMAKE_PREFIX_PATH}) unset(CMAKE_PREFIX_PATH) find_package(${packageName}) set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_SAVE}) else() find_package(${packageName}) endif () string(TOUPPER ${packageName} canonPackageName) if (NOT ${canonPackageName}_FOUND) set(MISSING_PREREQS true) set(customDesc) foreach (descArg ${ARGN}) set(customDesc "${customDesc} ${descArg}") endforeach () if (customDesc) # append the custom error message that was provided as an argument list(APPEND MISSING_PREREQ_DESCS ${customDesc}) else () list(APPEND MISSING_PREREQ_DESCS " Could not find prerequisite package '${packageName}'") endif () endif () endmacro(FindRequiredPackage) capstats-0.31/cmake/package_preinstall.sh.in000755 000765 000024 00000001673 14246446227 021111 0ustar00timstaff000000 000000 #!/bin/sh # This script is meant to be used by binary packages pre-installation. # Variables between @ symbols are replaced by CMake at configure time. configFiles="@INSTALLED_CONFIG_FILES@" backupNamesFile=/tmp/zeek_install_backups # Checks if a config file exists in a default location and makes a backup # so that a modified version is not clobbered backupFile () { origFile="$1" if [ -e ${origFile} ]; then # choose a file suffix that doesn't already exist ver=1 while [ -e ${origFile}.${ver} ]; do ver=$(( ver + 1 )) done backupFile=${origFile}.${ver} cp -p ${origFile} ${backupFile} # the post upgrade script will check whether the installed # config file actually differs from existing version # and delete unnecessary backups echo "${backupFile}" >> ${backupNamesFile} fi } for file in ${configFiles}; do backupFile "${file}" done capstats-0.31/cmake/ChangeMacInstallNames.cmake000644 000765 000024 00000006576 14246446227 021447 0ustar00timstaff000000 000000 # Calling this macro with the name of a list variable will modify that # list such that any third party libraries that do not come with a # vanilla Mac OS X system will be replaced by an adjusted library that # has an install_name relative to the location of any executable that # links to it. # # Also, it will schedule the modified libraries for installation in a # 'support_libs' subdirectory of the CMAKE_INSTALL_PREFIX. # # The case of third party libraries depending on other third party # libraries is currently not handled by this macro. # # Ex. # # set(libs /usr/lib/libz.dylib # /usr/lib/libssl.dylib # /usr/local/lib/libmagic.dylib # /usr/local/lib/libGeoIP.dylib # /usr/local/lib/somestaticlib.a) # # include(ChangeMacInstallNames) # ChangeMacInstallNames(libs) # # Should result in ${libs} containing: # /usr/lib/libz.dylib # /usr/lib/libssl.dylib # ${Zeek_BINARY_DIR}/darwin_support_libs/libmagic.dylib # ${Zeek_BINARY_DIR}/darwin_support_libs/libGeoIP.dylib # /usr/local/lib/somestaticlib.a # # such that we can now do: # # add_executable(some_exe ${srcs}) # target_link_libraries(some_exe ${libs}) # # Any binary packages created from such a build should be self-contained # and provide working installs on vanilla OS X systems. macro(ChangeMacInstallNames libListVar) if (APPLE) find_program(INSTALL_NAME_TOOL install_name_tool) set(MAC_INSTALL_NAME_DEPS) set(SUPPORT_BIN_DIR ${Zeek_BINARY_DIR}/darwin_support_libs) set(SUPPORT_INSTALL_DIR support_libs) file(MAKE_DIRECTORY ${SUPPORT_BIN_DIR}) foreach (_lib ${${libListVar}}) # only care about install_name for shared libraries that are # not shipped in Apple's vanilla OS X installs string(REGEX MATCH ^/usr/lib/* apple_provided_lib ${_lib}) string(REGEX MATCH dylib$ is_shared_lib ${_lib}) if (NOT apple_provided_lib AND is_shared_lib) get_filename_component(_libname ${_lib} NAME) set(_adjustedLib ${SUPPORT_BIN_DIR}/${_libname}) set(_tmpLib ${Zeek_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}) # make a tempory copy so we can adjust permissions configure_file(${_lib} ${_tmpLib} COPYONLY) # copy to build directory with correct write permissions file(COPY ${_tmpLib} DESTINATION ${SUPPORT_BIN_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) # remove the old library from the list provided as macro # argument and add the new library with modified install_name list(REMOVE_ITEM ${libListVar} ${_lib}) list(APPEND ${libListVar} ${_adjustedLib}) # update the install target to install the third party libs # with modified install_name install(FILES ${_adjustedLib} DESTINATION ${SUPPORT_INSTALL_DIR}) # perform the install_name change execute_process(COMMAND install_name_tool -id @executable_path/../${SUPPORT_INSTALL_DIR}/${_libname} ${_adjustedLib}) endif () endforeach () endif () endmacro() capstats-0.31/cmake/FindCapstats.cmake000644 000765 000024 00000000625 14246446227 017676 0ustar00timstaff000000 000000 # - Try to find capstats program # # Usage of this module as follows: # # find_package(Capstats) # # Variables defined by this module: # # CAPSTATS_FOUND capstats binary found # Capstats_EXE path to the capstats executable binary find_program(CAPSTATS_EXE capstats) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Capstats DEFAULT_MSG CAPSTATS_EXE) capstats-0.31/cmake/FindJeMalloc.cmake000644 000765 000024 00000002174 14246446227 017603 0ustar00timstaff000000 000000 # - Try to find jemalloc headers and libraries. # # Usage of this module as follows: # # find_package(JeMalloc) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # JEMALLOC_ROOT_DIR Set this variable to the root installation of # jemalloc if the module has problems finding # the proper installation path. # # Variables defined by this module: # # JEMALLOC_FOUND System has jemalloc libs/headers # JEMALLOC_LIBRARIES The jemalloc library/libraries # JEMALLOC_INCLUDE_DIR The location of jemalloc headers find_path(JEMALLOC_ROOT_DIR NAMES include/jemalloc/jemalloc.h ) find_library(JEMALLOC_LIBRARIES NAMES jemalloc HINTS ${JEMALLOC_ROOT_DIR}/lib ) find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h HINTS ${JEMALLOC_ROOT_DIR}/include ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(JeMalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR ) mark_as_advanced( JEMALLOC_ROOT_DIR JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR ) capstats-0.31/cmake/FindCAres.cmake000644 000765 000024 00000004505 14246446227 017112 0ustar00timstaff000000 000000 include(CheckFunctionExists) # First check whether the system has cares built-in. Prefer that over everything else. check_function_exists(ares_init HAVE_CARES) if ( NOT HAVE_CARES ) # If the user passed in a path for cares, see if we can find a copy of it there. # If they didn't pass one, build our local copy of it. if ( CARES_ROOT_DIR ) find_path(CARES_ROOT_DIR NAMES "include/ares.h") # Prefer linking statically but look for a shared library version too. find_library(CARES_LIBRARIES NAMES libcares_static.a libcares.so HINTS ${CARES_ROOT_DIR}/lib) find_path(CARES_INCLUDE_DIRS NAMES "ares.h" HINTS ${CARES_ROOT_DIR}/include) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(CARES DEFAULT_MSG CARES_LIBRARIES CARES_INCLUDE_DIRS ) mark_as_advanced( CARES_ROOT_DIR CARES_LIBRARIES CARES_INCLUDE_DIRS ) set(HAVE_CARES true) set(zeekdeps ${zeekdeps} ${CARES_LIBRARIES}) include_directories(BEFORE ${CARES_INCLUDE_DIRS}) else() OPTION (CARES_STATIC "" ON) OPTION (CARES_SHARED "" OFF) OPTION (CARES_INSTALL "" OFF) OPTION (CARES_STATIC_PIC "" ON) OPTION (CARES_BUILD_TESTS "" OFF) OPTION (CARES_BUILD_CONTAINER_TESTS "" OFF) OPTION (CARES_BUILD_TOOLS "" OFF) set(cares_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/c-ares") set(cares_build "${CMAKE_CURRENT_BINARY_DIR}/auxil/c-ares") set(cares_lib "${cares_build}/${CMAKE_INSTALL_LIBDIR}/libcares.a") # For reasons we haven't been able to determine, systems with c-ares already # installed will sometimes add /usr/local/include to the include path with # the call to add_subdirectory() below, which breaks things since it tries # use those versions of the c-ares headers before the local ones. I think # this is tied to a bug in c-ares 1.17.1 but we never nailed it down to that. # Instead, ensure that the local paths end up in the include path before # anything c-ares adds. include_directories(BEFORE ${cares_src}/include) include_directories(BEFORE ${cares_build}) add_subdirectory(auxil/c-ares) set(HAVE_CARES true) set(zeekdeps ${zeekdeps} ${cares_lib}) endif() endif() if ( NOT HAVE_CARES ) message(FATAL_ERROR "Failed to find a working version of c-ares.") endif() capstats-0.31/cmake/FindGooglePerftools.cmake000644 000765 000024 00000003364 14246446227 021231 0ustar00timstaff000000 000000 # - Try to find GooglePerftools headers and libraries # # Usage of this module as follows: # # find_package(GooglePerftools) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # GooglePerftools_ROOT_DIR Set this variable to the root installation of # GooglePerftools if the module has problems finding # the proper installation path. # # Variables defined by this module: # # GOOGLEPERFTOOLS_FOUND System has GooglePerftools libs/headers # TCMALLOC_FOUND System has GooglePerftools tcmalloc library # GooglePerftools_LIBRARIES The GooglePerftools libraries # GooglePerftools_LIBRARIES_DEBUG The GooglePerftools libraries for heap checking. # GooglePerftools_INCLUDE_DIR The location of GooglePerftools headers find_path(GooglePerftools_ROOT_DIR NAMES include/google/heap-profiler.h ) find_library(GooglePerftools_LIBRARIES_DEBUG NAMES tcmalloc_and_profiler HINTS ${GooglePerftools_ROOT_DIR}/lib ) find_library(GooglePerftools_LIBRARIES NAMES tcmalloc tcmalloc_minimal HINTS ${GooglePerftools_ROOT_DIR}/lib ) find_path(GooglePerftools_INCLUDE_DIR NAMES google/heap-profiler.h HINTS ${GooglePerftools_ROOT_DIR}/include ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GooglePerftools DEFAULT_MSG GooglePerftools_LIBRARIES GooglePerftools_LIBRARIES_DEBUG GooglePerftools_INCLUDE_DIR ) find_package_handle_standard_args(tcmalloc DEFAULT_MSG GooglePerftools_LIBRARIES ) mark_as_advanced( GooglePerftools_ROOT_DIR GooglePerftools_LIBRARIES GooglePerftools_LIBRARIES_DEBUG GooglePerftools_INCLUDE_DIR ) capstats-0.31/cmake/MacDependencyPaths.cmake000644 000765 000024 00000002720 14246446227 021010 0ustar00timstaff000000 000000 # As of CMake 2.8.3, Fink and MacPorts search paths are appended to the # default search prefix paths, but the nicer thing would be if they are # prepended to the default, so that is fixed here. # Prepend the default search path locations, in case for some reason the # ports/brew/fink executables are not found. # If they are found, the actual paths will be pre-pended again below. list(PREPEND CMAKE_PREFIX_PATH /usr/local) list(PREPEND CMAKE_PREFIX_PATH /opt/local) list(PREPEND CMAKE_PREFIX_PATH /sw) if (APPLE AND "${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") find_program(MAC_PORTS_BIN ports) find_program(MAC_HBREW_BIN brew) find_program(MAC_FINK_BIN fink) if (MAC_PORTS_BIN) list(PREPEND CMAKE_PREFIX_PATH ${MAC_PORTS_BIN}) # MacPorts endif () if (MAC_HBREW_BIN) execute_process(COMMAND ${MAC_HBREW_BIN} "--prefix" OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE) list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}) # Homebrew, if linked list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/openssl) # Homebrew OpenSSL list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/bison/bin) # Homebrew Bison list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/flex/bin) # Homebrew Flex list(PREPEND CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/actor-framework) # Homebrew actor-framework endif () if (MAC_FINK_BIN) list(PREPEND CMAKE_PREFIX_PATH /sw) # Fink endif () endif () capstats-0.31/cmake/zeek-plugin-create-package.sh000755 000765 000024 00000002010 14246446227 021722 0ustar00timstaff000000 000000 #! /bin/sh # # Helper script creating a tarball with a plugin's binary distribution. We'll # also leave a MANIFEST in place with all files part of the tar ball. # # Called from ZeekPluginDynamic.cmake. Current directory is the plugin # build directory. if [ $# = 0 ]; then echo "usage: `basename $0` []" exit 1 fi name=$1 shift addl=$@ # Copy additional distribution files into build directory. for i in ${addl}; do if [ -e ../$i ]; then dir=`dirname $i` mkdir -p ${dir} cp -p ../$i ${dir} fi done tgz=${name}-`(test -e ../VERSION && cat ../VERSION | head -1) || echo 0.0`.tar.gz rm -f MANIFEST ${name} ${name}.tgz ${tgz} for i in __bro_plugin__ lib scripts ${addl}; do test -e $i && find -L $i -type f | sed "s%^%${name}/%g" >>MANIFEST done ln -s . ${name} mkdir -p dist flag="-T" test `uname` = "OpenBSD" && flag="-I" tar czf dist/${tgz} ${flag} MANIFEST ln -s dist/${tgz} ${name}.tgz rm -f ${name} capstats-0.31/cmake/ZeekPluginCommon.cmake000644 000765 000024 00000014575 14246446227 020552 0ustar00timstaff000000 000000 ## A set of functions for defining Zeek plugins. ## ## This set is used by both static and dynamic plugins via ## ZeekPluginStatic and ZeekPluginDynamic, respectively. include(RequireCXX17) include(FindClangTidy) include(BifCl) include(BinPAC) # CTest support: the following does not work when called from a function. We # enable it always, but add tests only when zeek_plugin_begin() doesn't disable # testing and Zeek has unit-test support. enable_testing() # Begins a plugin definition, giving its namespace and name as the arguments. # The DISABLE_CPP_TESTS option disables unit test support. When not provided, # unit-testing is enabled when Zeek supports it, and disabled otherwise. function(zeek_plugin_begin ns name) _plugin_target_name(target "${ns}" "${name}") set(_plugin_lib "${target}" PARENT_SCOPE) set(_plugin_name "${ns}::${name}" PARENT_SCOPE) set(_plugin_name_canon "${ns}_${name}" PARENT_SCOPE) set(_plugin_ns "${ns}" PARENT_SCOPE) set(_plugin_objs "" PARENT_SCOPE) set(_plugin_deps "" PARENT_SCOPE) set(_plugin_dist "" PARENT_SCOPE) set(_plugin_scripts "" PARENT_SCOPE) cmake_parse_arguments(PARSE_ARGV 2 ZEEK_PLUGIN "DISABLE_CPP_TESTS" "" "") # Whether to build the plugin with unit-test support set(_plugin_cpp_tests true PARENT_SCOPE) # The set of files to check for unit tests set(_plugin_cpp_test_sources "" PARENT_SCOPE) # Cover the dynamic case (ZEEK_HAS_CPP_TESTS, based on zeek --test return # code), the static one (ENABLE_ZEEK_UNIT_TESTS, provided by the build # system), and a possible override if the caller opted to DISABLE_CPP_TESTS. if ( (ZEEK_HAS_CPP_TESTS OR ENABLE_ZEEK_UNIT_TESTS) AND NOT ZEEK_PLUGIN_DISABLE_CPP_TESTS ) add_definitions(-DDOCTEST_CONFIG_SUPER_FAST_ASSERTS) else () set(_plugin_cpp_tests false PARENT_SCOPE) add_definitions(-DDOCTEST_CONFIG_DISABLE) endif() endfunction() # This is needed to support legacy Bro plugins. macro(bro_plugin_begin) zeek_plugin_begin(${ARGV}) endmacro() # Adds specified .zeek scripts to a plugin # scripts will be added to the distribution regardless of this # but adding them explicitly allows tracking changes in scripts # when building dist function(zeek_plugin_scripts) list(APPEND _plugin_scripts ${ARGV}) set(_plugin_scripts "${_plugin_scripts}" PARENT_SCOPE) endfunction() # Adds *.cc files to a plugin. function(zeek_plugin_cc) list(APPEND _plugin_objs ${ARGV}) list(APPEND _plugin_cpp_test_sources ${ARGV}) set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) set(_plugin_cpp_test_sources "${_plugin_cpp_test_sources}" PARENT_SCOPE) add_clang_tidy_files(${ARGV}) endfunction() # This is needed to support legacy Bro plugins. macro(bro_plugin_cc) zeek_plugin_cc(${ARGV}) endmacro() # Adds a *.pac file to a plugin. Further *.pac files may given that # it depends on. function(zeek_plugin_pac) binpac_target(${ARGV}) list(APPEND _plugin_objs ${BINPAC_OUTPUT_CC}) list(APPEND _plugin_deps ${BINPAC_BUILD_TARGET}) set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) endfunction() # This is needed to support legacy Bro plugins. macro(bro_plugin_pac) zeek_plugin_pac(${ARGV}) endmacro() # Add an additional object file to the plugin's library. function(zeek_plugin_obj) foreach ( bif ${ARGV} ) list(APPEND _plugin_objs ${bif}) set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) endforeach () endfunction() # This is needed to support legacy Bro plugins. macro(bro_plugin_obj) zeek_plugin_obj(${ARGV}) endmacro() # Add additional files that should be included into the binary plugin distribution. # Ignored for static plugins. macro(zeek_plugin_dist_files) foreach ( file ${ARGV} ) list(APPEND _plugin_dist ${file}) # Don't need this here, and generates an error that # there is not parent scope. Not sure why it does that # here but not for other macros doing something similar. # set(_plugin_dist "${_plugin_dist}" PARENT_SCOPE) endforeach () endmacro() # This is needed to support legacy Bro plugins. macro(bro_plugin_dist_files) zeek_plugin_dist_files(${ARGV}) endmacro() # Link an additional library to the plugin's library. function(zeek_plugin_link_library) if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) bro_plugin_link_library_dynamic(${ARGV}) else () bro_plugin_link_library_static(${ARGV}) endif () endfunction() # This is needed to support legacy Bro plugins. macro(bro_plugin_link_library) zeek_plugin_link_library(${ARGV}) endmacro() # Adds *.bif files to a plugin. macro(zeek_plugin_bif) list(APPEND _plugin_cpp_test_sources ${ARGV}) if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) bro_plugin_bif_dynamic(${ARGV}) else () bro_plugin_bif_static(${ARGV}) endif () endmacro() # This is needed to support legacy Bro plugins. macro(bro_plugin_bif) zeek_plugin_bif(${ARGV}) endmacro() # Ends a plugin definition. macro(zeek_plugin_end) if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) bro_plugin_end_dynamic(${ARGV}) else () bro_plugin_end_static(${ARGV}) endif () # Scan relevant files for TEST_CASE macros and generate CTest targets. # This is similar to the logic in Zeek's src/CMakeLists.txt. if (_plugin_cpp_tests) set(test_cases "") foreach (cc_file ${_plugin_cpp_test_sources}) file (STRINGS ${cc_file} test_case_lines REGEX "TEST_CASE") foreach (line ${test_case_lines}) string(REGEX REPLACE "TEST_CASE\\(\"(.+)\"\\)" "\\1" test_case "${line}") list(APPEND test_cases "${test_case}") endforeach () endforeach () list(LENGTH test_cases num_test_cases) if (${num_test_cases} GREATER 0) foreach (test_case ${test_cases}) add_test(NAME "${test_case}" COMMAND zeek --test "--test-case=${test_case}") endforeach() endif () endif () endmacro() # This is needed to support legacy Bro plugins. macro(bro_plugin_end) zeek_plugin_end(${ARGV}) endmacro() # Internal macro to create a unique target name for a plugin. macro(_plugin_target_name target ns name) if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) _plugin_target_name_dynamic(${ARGV}) else () _plugin_target_name_static(${ARGV}) endif () endmacro() capstats-0.31/cmake/FindLibMMDB.cmake000644 000765 000024 00000002664 14246446227 017267 0ustar00timstaff000000 000000 # - Try to find libmaxminddb headers and libraries # # Usage of this module as follows: # # find_package(LibMMDB) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # LibMMDB_ROOT_DIR Set this variable to the root installation of # libmaxminddb if the module has problems finding the # proper installation path. # # Variables defined by this module: # # LibMMDB_FOUND System has libmaxminddb libraries and headers # LibMMDB_LIBRARY The libmaxminddb library # LibMMDB_INCLUDE_DIR The location of libmaxminddb headers find_path(LibMMDB_ROOT_DIR NAMES include/maxminddb.h ) if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # the static version of the library is preferred on OS X for the # purposes of making packages (libmaxminddb doesn't ship w/ OS X) set(libmmdb_names libmaxminddb.a maxminddb) else () set(libmmdb_names maxminddb) endif () find_library(LibMMDB_LIBRARY NAMES ${libmmdb_names} HINTS ${LibMMDB_ROOT_DIR}/lib ) find_path(LibMMDB_INCLUDE_DIR NAMES maxminddb.h HINTS ${LibMMDB_ROOT_DIR}/include ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibMMDB DEFAULT_MSG LibMMDB_LIBRARY LibMMDB_INCLUDE_DIR ) mark_as_advanced( LibMMDB_ROOT_DIR LibMMDB_LIBRARY LibMMDB_INCLUDE_DIR ) capstats-0.31/cmake/FindBinPAC.cmake000644 000765 000024 00000002541 14246446227 017147 0ustar00timstaff000000 000000 # - Try to find BinPAC binary and library # # Usage of this module as follows: # # find_package(BinPAC) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # BinPAC_ROOT_DIR Set this variable to the root installation of # BinPAC if the module has problems finding the # proper installation path. # # Variables defined by this module: # # BINPAC_FOUND System has BinPAC binary and library # BinPAC_EXE The binpac executable # BinPAC_LIBRARY The libbinpac.a library # BinPAC_INCLUDE_DIR The binpac headers # look for BinPAC in standard locations or user-provided root find_path(BinPAC_ROOT_DIR NAMES include/binpac.h include/binpac/binpac.h ) find_file(BinPAC_EXE NAMES binpac HINTS ${BinPAC_ROOT_DIR}/bin ) find_library(BinPAC_LIBRARY NAMES binpac libbinpac.a HINTS ${BinPAC_ROOT_DIR}/lib ) find_path(BinPAC_INCLUDE_DIR NAMES binpac.h HINTS ${BinPAC_ROOT_DIR}/include ${BinPAC_ROOT_DIR}/include/binpac ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(BinPAC DEFAULT_MSG BinPAC_EXE BinPAC_LIBRARY BinPAC_INCLUDE_DIR ) mark_as_advanced( BinPAC_ROOT_DIR BinPAC_EXE BinPAC_LIBRARY BinPAC_INCLUDE_DIR ) capstats-0.31/cmake/ProhibitInSourceBuild.cmake000644 000765 000024 00000000462 14246446227 021522 0ustar00timstaff000000 000000 # Prohibit in-source builds. if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") message(FATAL_ERROR "In-source builds are not allowed. Please use " "./configure to choose a build directory and " "initialize the build configuration.") endif () capstats-0.31/cmake/FindPackageMessage.cmake000644 000765 000024 00000003257 14246446227 020760 0ustar00timstaff000000 000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: FindPackageMessage ------------------ .. code-block:: cmake find_package_message( "message for user" "find result details") This function is intended to be used in FindXXX.cmake modules files. It will print a message once for each unique find result. This is useful for telling the user where a package was found. The first argument specifies the name (XXX) of the package. The second argument specifies the message to display. The third argument lists details about the find result so that if they change the message will be displayed again. The macro also obeys the QUIET argument to the find_package command. Example: .. code-block:: cmake if(X11_FOUND) find_package_message(X11 "Found X11: ${X11_X11_LIB}" "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") else() ... endif() #]=======================================================================] function(find_package_message pkg msg details) # Avoid printing a message repeatedly for the same find result. if(NOT ${pkg}_FIND_QUIETLY) string(REPLACE "\n" "" details "${details}") set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") # The message has not yet been printed. message(STATUS "${msg}") # Save the find details in the cache to avoid printing the same # message again. set("${DETAILS_VAR}" "${details}" CACHE INTERNAL "Details about finding ${pkg}") endif() endif() endfunction() capstats-0.31/cmake/UserChangedWarning.cmake000644 000765 000024 00000001370 14246446227 021027 0ustar00timstaff000000 000000 # Show warning when installing user is different from the one that configured, # except when the install is root. if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") install(CODE " if (NOT \"$ENV{USER}\" STREQUAL \"\$ENV{USER}\" AND NOT \"\$ENV{USER}\" STREQUAL root) message(STATUS \"WARNING: Install is being performed by user \" \"'\$ENV{USER}', but the build directory was configured by \" \"user '$ENV{USER}'. This may result in a permissions error \" \"when writing the install manifest, but you can ignore it \" \"and consider the installation as successful if you don't \" \"care about the install manifest.\") endif () ") endif () capstats-0.31/cmake/RequireCXX17.cmake000644 000765 000024 00000005561 14246446227 017466 0ustar00timstaff000000 000000 # Detect if compiler version is sufficient for supporting C++17. # If it is, CMAKE_CXX_FLAGS are modified appropriately and HAVE_CXX17 # is set to a true value. Else, CMake exits with a fatal error message. # This currently only works for GCC and Clang compilers. # In Cmake 3.8+, CMAKE_CXX_STANDARD_REQUIRED should be able to replace # all the logic below. if ( DEFINED HAVE_CXX17 ) return() endif () set(required_gcc_version 7.0) set(required_clang_version 4.0) set(required_msvc_version 19.14) set(required_apple_clang_version 6.0) if ( MSVC ) if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${required_msvc_version} ) message(FATAL_ERROR "MSVC version must be at least " "${required_gcc_version} for C++17 support, detected: " "${CMAKE_CXX_COMPILER_VERSION}") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") set(HAVE_CXX17 true) return() endif () include(CheckCXXSourceCompiles) set(cxx17_testcode "#include int main() { std::optional a; }") check_cxx_source_compiles("${cxx17_testcode}" cxx17_already_works) if ( cxx17_already_works ) # Nothing to do. Flags already select a suitable C++ version. set(HAVE_CXX17 true) return() endif () set(cxx17_flag "-std=c++17") if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ) if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${required_gcc_version} ) message(FATAL_ERROR "GCC version must be at least " "${required_gcc_version} for C++17 support, detected: " "${CMAKE_CXX_COMPILER_VERSION}") endif () elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ) if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${required_clang_version} ) message(FATAL_ERROR "Clang version must be at least " "${required_clang_version} for C++17 support, detected: " "${CMAKE_CXX_COMPILER_VERSION}") endif () if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5 ) set(cxx17_flag "-std=c++1z") endif () elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" ) if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${required_apple_clang_version} ) message(FATAL_ERROR "Apple Clang version must be at least " "${required_apple_clang_version} for C++17 support, detected: " "${CMAKE_CXX_COMPILER_VERSION}") endif () else() # Unrecognized compiler: fine to be permissive of other compilers as long # as they are able to support C++17 and can compile the test program, but # we just won't be able to give specific advice on what compiler version a # user needs in the case it actually doesn't support C++17. endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx17_flag}") check_cxx_source_compiles("${cxx17_testcode}" cxx17_works) if ( NOT cxx17_works ) message(FATAL_ERROR "failed using C++17 for compilation") endif () set(HAVE_CXX17 true) capstats-0.31/cmake/CheckTypes.cmake000644 000765 000024 00000002230 14246446227 017347 0ustar00timstaff000000 000000 include(CheckTypeSize) check_type_size("long int" SIZEOF_LONG_INT) check_type_size("long long" SIZEOF_LONG_LONG) check_type_size("void *" SIZEOF_VOID_P) # checks existence of ${_type}, and if it does not, sets CMake variable ${_var} # to alternative type, ${_alt_type} macro(CheckType _type _alt_type _var) # don't perform check if we have a result from a previous CMake run if (NOT HAVE_${_var}) check_type_size(${_type} ${_var}) if (NOT ${_var}) set(${_var} ${_alt_type}) else () unset(${_var}) unset(${_var} CACHE) endif () endif () endmacro(CheckType _type _alt_type _var) set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h) CheckType(int32_t int int32_t) CheckType(u_int32_t u_int u_int32_t) CheckType(u_int16_t u_short u_int16_t) CheckType(u_int8_t u_char u_int8_t) set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) CheckType(socklen_t int socklen_t) set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES netinet/in.h netinet/ip6.h) check_type_size("struct ip6_opt" IP6_OPT) check_type_size("struct ip6_ext" IP6_EXT) set(CMAKE_EXTRA_INCLUDE_FILES) capstats-0.31/cmake/SelectLibraryConfigurations.cmake000644 000765 000024 00000006332 14246446227 022773 0ustar00timstaff000000 000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: SelectLibraryConfigurations --------------------------- .. code-block:: cmake select_library_configurations(basename) This macro takes a library base name as an argument, and will choose good values for the variables :: basename_LIBRARY basename_LIBRARIES basename_LIBRARY_DEBUG basename_LIBRARY_RELEASE depending on what has been found and set. If only ``basename_LIBRARY_RELEASE`` is defined, ``basename_LIBRARY`` will be set to the release value, and ``basename_LIBRARY_DEBUG`` will be set to ``basename_LIBRARY_DEBUG-NOTFOUND``. If only ``basename_LIBRARY_DEBUG`` is defined, then ``basename_LIBRARY`` will take the debug value, and ``basename_LIBRARY_RELEASE`` will be set to ``basename_LIBRARY_RELEASE-NOTFOUND``. If the generator supports configuration types, then ``basename_LIBRARY`` and ``basename_LIBRARIES`` will be set with debug and optimized flags specifying the library to be used for the given configuration. If no build type has been set or the generator in use does not support configuration types, then ``basename_LIBRARY`` and ``basename_LIBRARIES`` will take only the release value, or the debug value if the release one is not set. #]=======================================================================] # This macro was adapted from the FindQt4 CMake module and is maintained by Will # Dicharry . macro(select_library_configurations basename) if(NOT ${basename}_LIBRARY_RELEASE) set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") endif() if(NOT ${basename}_LIBRARY_DEBUG) set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") endif() get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for # single-config generators, set optimized and debug libraries set( ${basename}_LIBRARY "" ) foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) endforeach() foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) list( APPEND ${basename}_LIBRARY debug "${_libname}" ) endforeach() elseif( ${basename}_LIBRARY_RELEASE ) set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) elseif( ${basename}_LIBRARY_DEBUG ) set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) else() set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") endif() set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) if( ${basename}_LIBRARY ) set( ${basename}_FOUND TRUE ) endif() mark_as_advanced( ${basename}_LIBRARY_RELEASE ${basename}_LIBRARY_DEBUG ) endmacro() capstats-0.31/cmake/FindPythonDev.cmake000644 000765 000024 00000013235 14246446227 020035 0ustar00timstaff000000 000000 # - Try to find Python include dirs and libraries # # Usage of this module as follows: # # find_package(PythonDev) # # Variables used by this module, they can change the default behaviour and need # to be set before calling find_package: # # PYTHON_EXECUTABLE If this is set to a path to a Python interpreter # then this module attempts to infer the path to # python-config from it # PYTHON_CONFIG Set this variable to the location of python-config # if the module has problems finding the proper # installation path. # # Variables defined by this module: # # PYTHONDEV_FOUND System has Python dev headers/libraries # PYTHON_INCLUDE_DIR The Python include directories. # PYTHON_LIBRARIES The Python libraries and linker flags. include(FindPackageHandleStandardArgs) if ( CMAKE_CROSSCOMPILING ) find_package(PythonLibs) if (PYTHON_INCLUDE_PATH AND NOT PYTHON_INCLUDE_DIR) set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}") endif () find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_INCLUDE_DIR PYTHON_LIBRARIES ) return() endif () if (PYTHON_EXECUTABLE) # Get the real path so that we can reliably find the correct python-config # (e.g. some systems may have a "python" symlink, but not a "python-config" # symlink). get_filename_component(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}" REALPATH) get_filename_component(PYTHON_EXECUTABLE_DIR "${PYTHON_EXECUTABLE}" DIRECTORY) get_filename_component(PYTHON_EXECUTABLE_NAME "${PYTHON_EXECUTABLE}" NAME) if ( EXISTS ${PYTHON_EXECUTABLE}-config ) set(PYTHON_CONFIG ${PYTHON_EXECUTABLE}-config CACHE PATH "" FORCE) # Avoid assumption that python-config is associated with python3 if # python3 co-exists in a directory that also contains python2 stuff elseif ( EXISTS ${PYTHON_EXECUTABLE_DIR}/python-config AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2 AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2.7 AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2-config AND NOT EXISTS ${PYTHON_EXECUTABLE_DIR}/python2.7-config ) set(PYTHON_CONFIG ${PYTHON_EXECUTABLE_DIR}/python-config CACHE PATH "" FORCE) endif () else () find_program(PYTHON_CONFIG NAMES python3-config python3.9-config python3.8-config python3.7-config python3.6-config python3.5-config python-config ) endif () # The OpenBSD python packages have python-config's that don't reliably # report linking flags that will work. if (PYTHON_CONFIG AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") # Try `--ldflags --embed` first and fallback to `--ldflags` if it fails. # Python 3.8+ introduced the `--embed` flag in relation to this: # https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build # Note that even if this FindPythonDev script could technically apply to # either embedded or extension use cases, the `--embed` flag only adds # a `-lpython` and it's generally safe to link libpython in both cases. # The only downside to doing that against an extension when it's not # strictly necessary is losing the ability to mix-and-match debug/release # modes between Python and extensions and that's not a feature to typically # care about. execute_process(COMMAND "${PYTHON_CONFIG}" --ldflags --embed RESULT_VARIABLE _python_config_result OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) if ( NOT ${_python_config_result} EQUAL 0 ) execute_process(COMMAND "${PYTHON_CONFIG}" --ldflags RESULT_VARIABLE _python_config_result OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) endif () string(STRIP "${PYTHON_LIBRARIES}" PYTHON_LIBRARIES) execute_process(COMMAND "${PYTHON_CONFIG}" --includes OUTPUT_VARIABLE PYTHON_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) string(REGEX REPLACE "^[-I]" "" PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}") string(REGEX REPLACE "[ ]-I" " " PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}") separate_arguments(PYTHON_INCLUDE_DIR) find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_CONFIG PYTHON_INCLUDE_DIR PYTHON_LIBRARIES ) else () if ( ${CMAKE_VERSION} VERSION_LESS "3.12.0" ) find_package(PythonLibs) if ( PYTHON_INCLUDE_PATH AND NOT PYTHON_INCLUDE_DIR ) set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}") endif () else () # Expect this branch to be used mostly in macOS where the system # default Python 3 installation is not easily/consistently detected # by CMake. CMake 3.12+ is required, but it's expected that macOS # users are getting a recent version from homebrew/etc anyway. find_package(Python3 COMPONENTS Development) if ( Python3_INCLUDE_DIRS AND NOT PYTHON_INCLUDE_DIR ) set(PYTHON_INCLUDE_DIR "${Python3_INCLUDE_DIRS}") endif () if ( Python3_LIBRARIES AND NOT PYTHON_LIBRARIES ) set(PYTHON_LIBRARIES "${Python3_LIBRARIES}") endif () endif () find_package_handle_standard_args(PythonDev DEFAULT_MSG PYTHON_INCLUDE_DIR PYTHON_LIBRARIES ) endif () capstats-0.31/cmake/OpenSSLTests.cmake000644 000765 000024 00000005225 14246446227 017622 0ustar00timstaff000000 000000 include(CheckCSourceCompiles) include(CheckCXXSourceCompiles) include(CheckCSourceRuns) include(CheckIncludeFiles) set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES} ${CMAKE_DL_LIBS}) # Use all includes, not just OpenSSL includes to see if there are # include files of different versions that do not match GET_DIRECTORY_PROPERTY(includes INCLUDE_DIRECTORIES) set(CMAKE_REQUIRED_INCLUDES ${includes}) check_c_source_compiles(" #include int main() { return 0; } " including_ssl_h_works) if (NOT including_ssl_h_works) # On Red Hat we may need to include Kerberos header. set(CMAKE_REQUIRED_INCLUDES ${includes} /usr/kerberos/include) check_c_source_compiles(" #include #include int main() { return 0; } " NEED_KRB5_H) if (NOT NEED_KRB5_H) message(FATAL_ERROR "OpenSSL test failure. See CmakeError.log for details.") else () message(STATUS "OpenSSL requires Kerberos header") include_directories("/usr/kerberos/include") endif () endif () if (OPENSSL_VERSION VERSION_LESS "0.9.7") message(FATAL_ERROR "OpenSSL >= v0.9.7 required") endif() check_include_files(openssl/kdf.h OPENSSL_HAVE_KDF_H) check_cxx_source_compiles(" #include int main() { const unsigned char** cpp = 0; X509** x =0; d2i_X509(x, cpp, 0); return 0; } " OPENSSL_D2I_X509_USES_CONST_CHAR) if (NOT OPENSSL_D2I_X509_USES_CONST_CHAR) # double check that it compiles without const check_cxx_source_compiles(" #include int main() { unsigned char** cpp = 0; X509** x =0; d2i_X509(x, cpp, 0); return 0; } " OPENSSL_D2I_X509_USES_CHAR) if (NOT OPENSSL_D2I_X509_USES_CHAR) message(FATAL_ERROR "Can't determine if openssl_d2i_x509() takes const char parameter") endif () endif () if (NOT CMAKE_CROSSCOMPILING) check_c_source_runs(" #include #include #include int main() { printf(\"-- OpenSSL Library version: %s\\\\n\", SSLeay_version(SSLEAY_VERSION)); printf(\"-- OpenSSL Header version: %s\\\\n\", OPENSSL_VERSION_TEXT); if (SSLeay() == OPENSSL_VERSION_NUMBER) { return 0; } return -1; } " OPENSSL_CORRECT_VERSION_NUMBER ) if (NOT OPENSSL_CORRECT_VERSION_NUMBER) message(FATAL_ERROR "OpenSSL library version does not match headers") endif () endif () set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_LIBRARIES)