2023-04-04 21:33:46 +02:00
# We upgraded it to support https://cmake.org/cmake/help/latest/policy/CMP0077.html
cmake_minimum_required ( VERSION 3.13 )
2022-06-11 19:53:03 +02:00
2022-05-29 23:02:49 +02:00
set ( FASTNETMON_LIBRARIES_GLOBAL_PATH "/opt/fastnetmon-community/libraries" )
2022-02-09 15:27:32 +01:00
2023-04-05 13:02:55 +02:00
# We need this options for generating compile_commands.json file
# It's required for clang static analyzer and autocompletion tools based on clang
# PVS uses it too
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2014-11-28 15:22:27 +01:00
project ( FastNetMon )
2022-06-17 13:50:22 +02:00
include ( GNUInstallDirs )
2015-06-04 15:13:22 +02:00
2018-02-05 23:21:12 +01:00
include ( CheckCXXCompilerFlag )
include ( CheckLibraryExists )
2022-06-11 19:53:03 +02:00
# Enable it and fix all warnings
2015-03-22 22:30:51 +01:00
# add_definitions ("-Wall")
2015-08-12 17:24:13 +02:00
set ( FASTNETMON_VERSION_MAJOR 1 )
2022-05-08 14:19:46 +02:00
set ( FASTNETMON_VERSION_MINOR 2 )
2023-10-15 23:19:31 +02:00
set ( FASTNETMON_VERSION_PATCH 7 )
2022-03-13 16:18:21 +01:00
2023-01-13 15:03:58 +01:00
set ( HIREDIS_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/hiredis_0_14" )
2023-04-10 23:36:58 +02:00
set ( LOG4CPP_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/log4cpp_1_1_4" )
2023-08-22 14:17:26 +02:00
set ( LIBPCAP_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/pcap_1_10_4" )
2022-12-02 14:34:29 +01:00
set ( MONGO_C_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/mongo_c_driver_1_23_0" )
2022-03-13 16:18:21 +01:00
set ( CAPNP_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/capnproto_0_8_0" )
2022-10-12 18:34:32 +02:00
set ( OPENSSL_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/openssl_1_1_1q" )
2023-01-04 21:39:54 +01:00
set ( GRPC_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/grpc_1_49_2" )
2023-01-13 15:03:58 +01:00
set ( LIBBPF_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/bpf_1_0_1" )
2022-10-03 00:13:16 +02:00
set ( LIBELF_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/elfutils_0_186" )
2023-01-04 21:06:59 +01:00
set ( PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/protobuf_21_12" )
2023-01-12 21:11:47 +01:00
set ( ABSL_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/abseil_2022_06_23" )
2023-01-14 19:33:40 +01:00
set ( BOOST_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/boost_1_81_0" )
2023-01-13 17:24:54 +01:00
set ( GCC_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/gcc_12_1_0" )
2023-02-05 18:28:36 +01:00
set ( LIB_CPP_KAFKA_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/cppkafka_0_3_1" )
set ( LIB_RDKAFKA_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/rdkafka_1_7_0" )
2023-02-27 22:05:58 +01:00
set ( GTEST_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/gtest_1_13_0" )
2022-03-13 16:18:21 +01:00
2023-08-05 13:45:46 +02:00
# Enable time profiling for compilation phase
# https://stackoverflow.com/questions/5962285/cmake-compilation-statistics-per-transation-unit
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
2023-07-31 11:09:09 +02:00
# -Wunused includes more warnings than -Wall
# In order to get a warning about an unused function parameter, you must either specify -Wextra -Wunused (note that -Wall implies -Wunused), or separately specify -Wunused-parameter.
# TODO: return -Wunused-parameter and address all warning later, I started it but did not finish as we have too many of them
# catch-value is documented here: https://patchwork.ozlabs.org/project/gcc/patch/tkrat.8c7b4260a533be2f@netcologne.de/#1680619
add_definitions ( "-Wreorder -Wunused -Wparentheses -Wimplicit-fallthrough -Wreturn-type -Wuninitialized -Winit-self -Wmaybe-uninitialized -Wcatch-value=3 -Wclass-memaccess" )
2023-04-03 22:20:04 +02:00
# On Windows we need to build libgcc and libstdc++ statically to avoid need to carry dlls with us
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
set ( CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ ${CMAKE_CXX_STANDARD_LIBRARIES}" )
endif ( )
# We need this to avoid dependency on libwinpthread-1.dll
# Details: https://cmake.org/pipermail/cmake/2019-June/069611.html
if ( MINGW )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive" )
endif ( )
2023-07-11 21:22:15 +02:00
# We use this approach instead of following:
2023-07-11 21:10:29 +02:00
# set (CMAKE_CXX_STANDARD 20)
2023-07-11 21:22:15 +02:00
# Because it allows us to specify intermediate releases and releases not yet supported by cmake
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++20" )
2023-07-11 20:49:31 +02:00
2022-02-09 15:27:32 +01:00
# With this flag we can enable GoBGP build via console: cmake .. -DENABLE_GOBGP_SUPPORT=ON
2022-03-13 16:18:21 +01:00
option ( ENABLE_GOBGP_SUPPORT "Enable GoBGP support build" ON )
2022-02-09 15:27:32 +01:00
2023-04-02 20:57:29 +02:00
# It can be disabled this way: cmake .. -DENABLE_PCAP_SUPPORT=OFF
option ( ENABLE_PCAP_SUPPORT "Enable PCAP support" ON )
2022-05-23 18:47:57 +02:00
# On some platforms like Fedora we need to explicitly link with libabseil / libabsl.
# We do not use it directly but gRPC uses it for libgpr and we need to link with absl explicitly to avoid linker errors like this:
# libgpr.so: undefined reference to symbol '_ZN4absl12lts_202103245Mutex4LockEv'
# /usr/lib64/libabsl_synchronization.so.2103.0.1: error adding symbols: DSO missing from command line
option ( LINK_WITH_ABSL "Enable optonal linking with ABSL" OFF )
2023-02-05 18:28:36 +01:00
# Kafka support is optional and we do not enable it for build by default
option ( KAFKA_SUPPORT "Enables Kafka support" OFF )
2023-01-12 21:11:47 +01:00
# We need to add it into include path as gRPC uses it include path
include_directories ( "${ABSL_INSTALL_PATH}/include" )
2023-01-16 14:10:27 +01:00
option ( DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD "Disables use of libraries from system path" OFF )
2022-05-01 15:51:54 +02:00
if ( DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD )
# We need to avoid using system path for libraries and includes search because we ship specific versions of our own libraries in package
2023-01-16 14:30:10 +01:00
# And we need to avoid implicit fallbacks to system libraries as it will break dependencies
2022-05-01 15:51:54 +02:00
set ( DISABLE_DEFAULT_PATH_SEARCH_VAR "NO_DEFAULT_PATH" )
else ( )
# Disable this logic and allow any paths
set ( DISABLE_DEFAULT_PATH_SEARCH_VAR "" )
endif ( )
2023-01-16 14:30:10 +01:00
if ( DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD )
2022-02-09 15:27:32 +01:00
message ( STATUS "Build with custom Boost" )
2022-02-09 15:27:32 +01:00
set ( Boost_NO_SYSTEM_PATHS ON )
2023-01-13 15:41:24 +01:00
set ( BOOST_INCLUDEDIR "${BOOST_INSTALL_PATH}" )
2023-01-14 19:27:30 +01:00
set ( BOOST_LIBRARYDIR "${BOOST_INSTALL_PATH}/lib/" )
2015-08-12 17:24:13 +02:00
2023-01-14 19:33:40 +01:00
SET ( Boost_DIR "${BOOST_INSTALL_PATH}/lib/cmake/Boost-1.81.0/" )
2022-02-09 15:27:32 +01:00
2015-08-12 17:24:13 +02:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-deprecated-declarations" )
2015-10-08 16:58:39 +02:00
2023-02-05 20:36:24 +01:00
set ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${BOOST_INSTALL_PATH}/lib;${GCC_INSTALL_PATH}/lib64" )
2015-10-08 16:58:39 +02:00
endif ( )
2015-08-13 17:34:28 +02:00
2022-05-02 16:18:15 +02:00
# We use hardcoded RPATH for our libraries only when we compile against our custom libraries
if ( DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD )
2015-08-13 17:34:28 +02:00
2022-05-02 16:18:15 +02:00
# Specify full RPATH for build tree
SET ( CMAKE_SKIP_BUILD_RPATH FALSE )
# Create builds in current folder with install RPATH
SET ( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
2023-01-16 14:30:10 +01:00
# We need to manually set RPATH to each of our custom libraries
# Otherwise our binaries will not able to find them as we use non standard path
2023-01-16 14:19:58 +01:00
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${HIREDIS_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LOG4CPP_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${MONGO_C_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${MONGO_C_CUSTOM_INSTALL_PATH}/lib64" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${GRPC_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH}/lib64" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CAPNP_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${OPENSSL_CUSTOM_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LIBBPF_CUSTOM_INSTALL_PATH}/lib64" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LIBELF_CUSTOM_INSTALL_PATH}/lib" )
2022-05-02 16:18:15 +02:00
2023-02-05 18:28:36 +01:00
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LIB_CPP_KAFKA_INSTALL_PATH}/lib" )
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LIB_RDKAFKA_INSTALL_PATH}/lib" )
2023-08-24 12:04:09 +02:00
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${LIBPCAP_CUSTOM_INSTALL_PATH}/lib" )
2022-05-02 16:18:15 +02:00
else ( )
# We do not need any RPATH alterations when we want to link with system libraries (i.e. upstream builds for Debian or RedHat family)
endif ( )
2014-11-28 15:22:27 +01:00
2023-07-11 21:22:15 +02:00
message ( STATUS "C++ default compilation flags: ${CMAKE_CXX_FLAGS}" )
message ( STATUS "C++ release compilation flags: ${CMAKE_CXX_FLAGS_RELEASE}" )
2022-03-13 16:18:21 +01:00
message ( STATUS "C++ debug compilation flags: ${CMAKE_CXX_FLAGS_DEBUG}" )
2014-12-18 11:23:56 +01:00
2014-12-19 09:42:10 +01:00
set ( FASTNETMON_PROFILER OFF )
set ( FASTNETMON_PROFILE_FLAGS "-g -pg" )
2022-03-13 16:18:21 +01:00
# set(CMAKE_BUILD_TYPE DEBUG)
2022-03-13 16:18:21 +01:00
2015-06-03 11:27:17 +02:00
if ( NOT CMAKE_BUILD_TYPE )
message ( STATUS "Setting build type to Release as none was specified." )
set ( CMAKE_BUILD_TYPE Release )
endif ( )
2014-12-19 09:42:10 +01:00
if ( FASTNETMON_PROFILER )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FASTNETMON_PROFILE_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FASTNETMON_PROFILE_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FASTNETMON_PROFILE_FLAGS}" )
endif ( )
2017-05-30 11:11:39 +02:00
execute_process ( COMMAND sh -c ". /etc/os-release; echo $ID" OUTPUT_VARIABLE OS_ID ERROR_QUIET )
2015-10-16 11:34:48 +02:00
### Executables definition
# Main tool
add_executable ( fastnetmon fastnetmon.cpp )
2015-09-30 13:00:09 +02:00
# Get last commit hash
execute_process ( COMMAND git rev-list HEAD COMMAND head -n 1 OUTPUT_VARIABLE GIT_LAST_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE )
2023-03-01 15:06:16 +01:00
# Short 8 symbol commit
execute_process ( COMMAND git rev-list HEAD COMMAND head -n 1 COMMAND cut -c1-8 OUTPUT_VARIABLE GIT_LAST_COMMIT_HASH_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE )
message ( STATUS "Commit hash: ${GIT_LAST_COMMIT_HASH_SHORT}" )
set ( FASTNETMON_APPLICATION_VERSION "${FASTNETMON_VERSION_MAJOR}.${FASTNETMON_VERSION_MINOR}.${FASTNETMON_VERSION_PATCH} ${GIT_LAST_COMMIT_HASH_SHORT}" )
2024-02-10 12:47:57 +01:00
# Set standard values which work for majority of platforms
set ( FASTNETMON_PID_PATH "/var/run/fastnetmon.pid" )
set ( FASTNETMON_CONFIGURATION_PATH "/etc/fastnetmon.conf" )
set ( FASTNETMON_LOG_FILE_PATH "/var/log/fastnetmon.log" )
set ( FASTNETMON_ATTACK_DETAILS_FOLDER "/var/log/fastnetmon_attacks" )
set ( FASTNETMON_NOTIFY_SCRIPT_PATH_DEFAULT "/usr/local/bin/notify_about_attack.sh" )
set ( FASTNETMON_NETWORK_WHITELIST_PATH "/etc/networks_whitelist" )
set ( FASTNETMON_NETWORKS_LIST_PATH "/etc/networks_list" )
2024-02-17 18:29:33 +01:00
set ( FASTNETMON_BACKTRACE_PATH "/var/log/fastnetmon_backtrace.dump" )
2024-02-10 12:47:57 +01:00
2024-02-10 20:11:48 +01:00
# For FreeBSD based platforms we need to adjust them
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "FreeBSD" OR ${ CMAKE_SYSTEM_NAME } STREQUAL "DragonFly" )
set ( FREEBSD_DEFAULT_PREFIX "/usr/local" )
set ( FASTNETMON_PID_PATH "/var/run/fastnetmon/fastnetmon.pid" )
set ( FASTNETMON_CONFIGURATION_PATH "${FREEBSD_DEFAULT_PREFIX}/etc/fastnetmon.conf" )
set ( FASTNETMON_LOG_FILE_PATH "/var/log/fastnetmon/fastnetmon.log" )
set ( FASTNETMON_ATTACK_DETAILS_FOLDER "/var/log/fastnetmon_attacks" )
set ( FASTNETMON_NOTIFY_SCRIPT_PATH_DEFAULT "${FREEBSD_DEFAULT_PREFIX}/bin/notify_about_attack.sh" )
set ( FASTNETMON_NETWORK_WHITELIST_PATH "${FREEBSD_DEFAULT_PREFIX}/etc/networks_whitelist" )
set ( FASTNETMON_NETWORKS_LIST_PATH "${FREEBSD_DEFAULT_PREFIX}/etc/networks_list" )
2024-02-17 18:29:33 +01:00
set ( FASTNETMON_BACKTRACE_PATH "/var/log/fastnetmon/fastnetmon_backtrace.dump" )
2024-02-10 20:11:48 +01:00
endif ( )
2022-06-26 16:10:12 +02:00
configure_file ( fast_platform.h.template "${PROJECT_SOURCE_DIR}/fast_platform.hpp" )
2015-06-04 13:08:25 +02:00
2018-02-04 14:19:44 +01:00
# Use new Memory Model Aware Atomic Operations
# You could enable it using: cmake .. -DUSE_NEW_ATOMIC_BUILTINS=ON
2022-05-05 01:24:33 +02:00
# We use it for exotic platforms where we have no specific functions in atomics library: https://salsa.debian.org/debian/fastnetmon/-/blob/master/debian/rules#L11
2018-02-04 14:19:44 +01:00
if ( USE_NEW_ATOMIC_BUILTINS )
message ( STATUS "Will use new memory model aware atomic builtins" )
add_definitions ( -DUSE_NEW_ATOMIC_BUILTINS )
endif ( )
2022-05-06 00:45:42 +02:00
# Be default we do not link with it but we need it on platforms without native support for atomic operations
# On these platforms we will use logic emulated by libatomic
set ( LINK_WITH_ATOMIC_LIBRARY OFF )
2018-02-05 23:21:12 +01:00
CHECK_CXX_SOURCE_COMPILES ( "
#include <cstdint>
i n t main ( ) {
u i n t 6 4 _ t x = 1 ;
__atomic_add_fetch ( &x, 0, __ATOMIC_RELAXED ) ;
r e t u r n x ;
}
" H A V E _ _ A T O M I C _ A D D _ F E T C H )
2022-05-04 13:10:44 +02:00
if ( HAVE__ATOMIC_ADD_FETCH )
message ( STATUS "We have __atomic_add_fetch on this platform" )
else ( )
message ( STATUS "We have no __atomic_add_fetch, will try linking with libatomic" )
2018-02-05 23:21:12 +01:00
check_library_exists ( atomic __atomic_add_fetch_8 "" HAVE_LIBATOMIC )
2022-05-04 13:10:44 +02:00
2018-02-05 23:21:12 +01:00
if ( HAVE_LIBATOMIC )
2022-05-04 13:52:58 +02:00
message ( STATUS "Linked with atomic library" )
2022-05-06 00:45:42 +02:00
set ( LINK_WITH_ATOMIC_LIBRARY ON )
2022-05-04 13:10:44 +02:00
else ( )
message ( STATUS "We have no support for __atomic_add_fetch in atomic library, skip linking" )
2018-02-05 23:21:12 +01:00
endif ( )
endif ( )
2022-05-04 13:52:58 +02:00
CHECK_CXX_SOURCE_COMPILES ( "
#include <cstdint>
i n t main ( ) {
u i n t 6 4 _ t x = 1 ;
__sync_fetch_and_add ( &x, 1 ) ;
r e t u r n x ;
}
" H A V E _ _ S Y N C _ F E T C H _ A N D _ A D D )
if ( HAVE__SYNC_FETCH_AND_ADD )
message ( STATUS "We have __sync_fetch_and_add on this platform" )
else ( )
# We know that it happens for mipsel platform due to https://reviews.llvm.org/D45691
message ( STATUS "We have no __sync_fetch_and_add on this platform, will try linking with libatomic" )
check_library_exists ( atomic __sync_fetch_and_add_8 "" HAVE_LIBATOMIC_SYNC_FETCH_AND_ADD )
if ( HAVE_LIBATOMIC_SYNC_FETCH_AND_ADD )
message ( STATUS "Linked with atomic library" )
2022-05-06 00:45:42 +02:00
set ( LINK_WITH_ATOMIC_LIBRARY ON )
2022-05-04 13:52:58 +02:00
else ( )
message ( STATUS "We have no support for __sync_fetch_and_add in atomic library, skip linking" )
endif ( )
endif ( )
2022-04-19 13:14:21 +02:00
option ( ENABLE_NETMAP_SUPPORT "Enable Netmap support" OFF )
2017-07-28 00:19:33 +02:00
2022-02-09 15:27:32 +01:00
CHECK_CXX_SOURCE_COMPILES ( "
i n t main ( ) {
__atomic_thread_fence ( __ATOMIC_RELEASE ) ;
__atomic_thread_fence ( __ATOMIC_ACQUIRE ) ;
r e t u r n 0 ;
}
" H A V E _ A T O M I C _ T H R E A D _ F E N C E )
# If we do not have it then we need to disable it
if ( NOT HAVE_ATOMIC_THREAD_FENCE )
set ( ENABLE_NETMAP_SUPPORT OFF )
message ( STATUS "Your system does not support __atomic_thread_fence, disabled Netmap plugin support" )
endif ( )
2017-07-28 00:19:33 +02:00
if ( ENABLE_NETMAP_SUPPORT )
message ( STATUS "We will build Netmap support for you" )
add_definitions ( -DNETMAP_PLUGIN )
endif ( )
2022-04-30 17:52:25 +02:00
# It's enabled by default but can be disabled using:
# cmake .. -DENABLE_CAPNP_SUPPORT=OFF
option ( ENABLE_CAPNP_SUPPORT "Enable Cap'N'Proto support build" ON )
if ( ENABLE_CAPNP_SUPPORT )
2022-04-30 17:58:18 +02:00
message ( STATUS "We will build Cap'N'Proto support" )
2022-05-01 15:51:54 +02:00
find_program ( CAPNP_BINARY capnp PATHS "${CAPNP_CUSTOM_INSTALL_PATH}/bin" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-04-30 17:18:01 +02:00
if ( CAPNP_BINARY )
message ( STATUS "Found capnp compiler: ${CAPNP_BINARY}" )
else ( )
message ( FATAL_ERROR "Can't find capnp compiler" )
endif ( )
2023-04-04 23:23:51 +02:00
# We need to explicitly provide PATH for capnp to allow it to find capnpc-c++
SET ( CAPNP_ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}" "PATH=$ENV{PATH}:${CAPNP_CUSTOM_INSTALL_PATH}/bin" )
# We cannot pass environment variables before tool call on Windows and we actually do need it
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
SET ( CAPNP_ENVIRONMENT "" )
endif ( )
2022-04-21 16:06:10 +02:00
# Generate capnp bindings
ADD_CUSTOM_COMMAND (
O U T P U T $ { P R O J E C T _ S O U R C E _ D I R } / s i m p l e _ p a c k e t _ c a p n p / s i m p l e _ p a c k e t . c a p n p . c + +
D E P E N D S $ { P R O J E C T _ S O U R C E _ D I R } / s i m p l e _ p a c k e t _ c a p n p / s i m p l e _ p a c k e t . c a p n p
2023-04-04 23:23:51 +02:00
C O M M A N D $ { C A P N P _ E N V I R O N M E N T } $ { C A P N P _ B I N A R Y } c o m p i l e - - o u t p u t c + + : $ { P R O J E C T _ S O U R C E _ D I R } / s i m p l e _ p a c k e t _ c a p n p - - s r c - p r e f i x = $ { P R O J E C T _ S O U R C E _ D I R } / s i m p l e _ p a c k e t _ c a p n p $ { P R O J E C T _ S O U R C E _ D I R } / s i m p l e _ p a c k e t _ c a p n p / s i m p l e _ p a c k e t . c a p n p
2022-04-21 16:06:10 +02:00
C O M M E N T " B u i l d C a p ' n ' P r o t o b i n d i n g f o r C + + "
)
2022-03-13 16:18:21 +01:00
add_library ( simple_packet_capnp STATIC simple_packet_capnp/simple_packet.capnp.c++ )
2022-04-30 17:52:25 +02:00
endif ( )
2014-11-28 15:58:12 +01:00
# Our LPM library
2022-05-24 14:51:25 +02:00
add_library ( patricia STATIC libpatricia/patricia.cpp )
2014-11-28 15:22:27 +01:00
2022-03-28 15:58:01 +02:00
# Graphite metrics
add_library ( graphite_metrics STATIC metrics/graphite.cpp )
target_link_libraries ( fastnetmon graphite_metrics )
2022-03-28 15:58:01 +02:00
# InfluxDB metrics
add_library ( influxdb_metrics STATIC metrics/influxdb.cpp )
target_link_libraries ( fastnetmon influxdb_metrics )
2022-03-28 15:58:01 +02:00
2015-07-22 14:16:13 +02:00
add_library ( fastnetmon_pcap_format STATIC fastnetmon_pcap_format.cpp )
2015-03-21 11:47:25 +01:00
# Our tools library
add_library ( fast_library STATIC fast_library.cpp )
2015-03-22 17:00:16 +01:00
# Our ipfix database library
2023-06-24 22:15:29 +02:00
add_library ( ipfix_rfc STATIC ipfix_fields/ipfix_rfc.cpp )
2015-03-22 17:00:16 +01:00
2022-05-27 22:16:17 +02:00
add_library ( bgp_protocol STATIC bgp_protocol.cpp )
2022-03-13 23:09:35 +01:00
# Our logic library
add_library ( fastnetmon_logic STATIC fastnetmon_logic.cpp )
2022-02-09 15:27:32 +01:00
CHECK_CXX_SOURCE_COMPILES ( "
2022-02-09 15:27:32 +01:00
#include <linux/if_packet.h>
i n t main ( ) {
r e t u r n T P A C K E T _ V 3 ;
}
" H A V E _ T P A C K E T _ V 3 )
if ( ${ HAVE_TPACKET_V3 } )
message ( STATUS "Your system has support for AF_PACKET v3" )
set ( ENABLE_AFPACKET_SUPPORT ON )
else ( )
message ( STATUS "Your system does not support AF_PACKET v3, disabled it" )
2015-09-01 14:37:50 +02:00
endif ( )
2015-09-01 10:41:55 +02:00
# -DENABLE_AFPACKET_SUPPORT=ON ..
if ( ENABLE_AFPACKET_SUPPORT )
add_definitions ( -DFASTNETMON_ENABLE_AFPACKET )
2015-10-03 18:09:37 +02:00
add_library ( afpacket_plugin STATIC afpacket_plugin/afpacket_collector.cpp )
2015-09-01 10:41:55 +02:00
endif ( )
2022-11-27 18:48:18 +01:00
# We need to check that kernel headers actually support it as it's relatively new thing
CHECK_CXX_SOURCE_COMPILES ( "
#include <linux/bpf.h>
i n t main ( ) {
b p f _ s t a t s _ t y p e m y _ b p f _ t y p e ;
r e t u r n 1 ;
}
" H A V E _ B P F _ S T A T S _ T Y P E )
if ( ${ HAVE_BPF_STATS_TYPE } )
message ( STATUS "Kernel has enum bpf_stats_type declared" )
else ( )
message ( STATUS "Kernel does not have enum bpf_stats_type declared. Try to declare our own to address libbpf issue: https://github.com/libbpf/libbpf/issues/249" )
add_definitions ( -DDECLARE_FAKE_BPF_STATS )
endif ( )
# We need to check that kernel headers actually include it
CHECK_CXX_SOURCE_COMPILES ( "
#include <linux/bpf.h>
i n t main ( ) {
b p f _ l i n k _ t y p e m y _ b p f _ t y p e ;
r e t u r n 1 ;
}
" H A V E _ B P F _ L I N K _ T Y P E )
if ( ${ HAVE_BPF_LINK_TYPE } )
message ( STATUS "Kernel has enum bpf_link_type declared" )
else ( )
message ( STATUS "Kernel does not have enum bpf_link_type declared. Try to declare our own to address libbpf issue: https://github.com/libbpf/libbpf/issues/249" )
add_definitions ( -DDECLARE_FAKE_BPF_LINK_TYPE )
endif ( )
2023-04-22 22:50:46 +02:00
# We enable XDP plugin build for all platforms which support it
# It can be disabled manually using flag: -DENABLE_AF_XDP_SUPPORT=FALSE
2023-04-22 22:40:38 +02:00
option ( ENABLE_AF_XDP_SUPPORT "Enables build for AF_XDP" ON )
2022-10-03 00:49:36 +02:00
CHECK_CXX_SOURCE_COMPILES ( "
#include <linux/if_xdp.h>
i n t main ( ) {
r e t u r n 1 ;
}
" H A V E _ A F _ X D P )
2023-04-22 22:40:38 +02:00
# If XDP build enabled then we need to confirm that system has support for it
if ( ${ ENABLE_AF_XDP_SUPPORT } )
2023-04-22 22:25:24 +02:00
2023-04-22 22:40:38 +02:00
if ( ${ HAVE_AF_XDP } )
2023-04-22 22:50:46 +02:00
message ( STATUS "Your system has support for AF_XDP and we will build XDP plugin" )
2023-04-22 22:40:38 +02:00
else ( )
2023-04-22 22:50:46 +02:00
# It may be old Linux, macOS, FreeBSD or Windows
message ( STATUS "Your system does not support AF_XDP, disabling compilation of XDP plugin" )
2023-04-22 22:40:38 +02:00
set ( ENABLE_AF_XDP_SUPPORT FALSE )
endif ( )
2022-10-03 00:49:36 +02:00
endif ( )
2022-10-03 00:13:16 +02:00
2022-10-02 20:50:10 +02:00
if ( ENABLE_AF_XDP_SUPPORT )
2022-10-02 23:11:49 +02:00
add_definitions ( -DFASTNETMON_ENABLE_AF_XDP )
2022-10-02 20:50:10 +02:00
add_library ( xdp_plugin STATIC xdp_plugin/xdp_collector.cpp )
2022-10-02 23:11:49 +02:00
set ( ENABLE_LIBBPF_SUPPORT TRUE )
2022-10-03 00:13:16 +02:00
set ( ENABLE_LIBELF_SUPPORT TRUE )
endif ( )
2023-02-05 18:28:36 +01:00
if ( KAFKA_SUPPORT )
# We need to enable it explicitly
add_definitions ( -DKAFKA )
# cpp-kafka uses these header files from their header too
include_directories ( "${LIB_RDKAFKA_INSTALL_PATH}/include" )
# cppkafka
find_library ( LIBKAFKA_CPP_LIBRARY_PATH names "cppkafka" PATHS "${LIB_CPP_KAFKA_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
include_directories ( "${LIB_CPP_KAFKA_INSTALL_PATH}/include" )
if ( NOT LIBKAFKA_CPP_LIBRARY_PATH )
message ( FATAL_ERROR "Could not find cppkafka library" )
else ( )
message ( STATUS "Will use cppkafka library from ${LIBKAFKA_CPP_LIBRARY_PATH}" )
endif ( )
endif ( )
2022-10-03 00:13:16 +02:00
if ( ENABLE_LIBELF_SUPPORT )
# We do not use it directly but we need it as dependency for libbpf
# include_directories("${LIBELF_CUSTOM_INSTALL_PATH/include")
2023-02-05 18:28:36 +01:00
find_library ( LIBELF_LIBRARY_PATH names "elf" PATHS "${LIBELF_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-10-03 00:13:16 +02:00
if ( NOT LIBELF_LIBRARY_PATH )
message ( FATAL_ERROR "Could not find libelf library" )
else ( )
message ( STATUS "Will use libelf library from ${LIBELF_LIBRARY_PATH}" )
endif ( )
2022-10-02 23:11:49 +02:00
endif ( )
if ( ENABLE_LIBBPF_SUPPORT )
include_directories ( "${LIBBPF_CUSTOM_INSTALL_PATH}/include" )
2023-01-14 21:22:09 +01:00
find_library ( LIBBPF_LIBRARY_PATH NAMES "bpf" PATHS "${LIBBPF_CUSTOM_INSTALL_PATH}/lib64" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-10-02 23:11:49 +02:00
if ( NOT LIBBPF_LIBRARY_PATH )
message ( FATAL_ERROR "Could not find libbpf library" )
else ( )
message ( STATUS "Will use libbpf from ${LIBBPF_LIBRARY_PATH}" )
endif ( )
endif ( )
2023-08-22 14:36:18 +02:00
### Look for libpcap
find_path ( LIBPCAP_INCLUDES_FOLDER NAMES pcap.h PATHS "${LIBPCAP_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( LIBPCAP_LIBRARY_PATH NAMES pcap PATHS "${LIBPCAP_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
if ( LIBPCAP_INCLUDES_FOLDER AND LIBPCAP_LIBRARY_PATH )
message ( STATUS "We found pcap library ${LIBPCAP_LIBRARY_PATH}" )
include_directories ( ${ LIBPCAP_INCLUDES_FOLDER } )
else ( )
message ( FATAL_ERROR "We can't find pcap library" )
endif ( )
2022-10-03 00:13:16 +02:00
2022-10-02 23:11:49 +02:00
if ( ENABLE_AF_XDP_SUPPORT )
2022-10-03 00:19:28 +02:00
target_link_libraries ( xdp_plugin ${ LIBBPF_LIBRARY_PATH } ${ LIBELF_LIBRARY_PATH } )
2022-10-02 20:50:10 +02:00
endif ( )
2022-02-11 13:38:08 +01:00
# Library with data types for parsing network structures
2022-02-10 21:29:43 +01:00
add_library ( network_data_structures STATIC network_data_structures.cpp )
2023-02-28 20:24:05 +01:00
# Speed counters lib
add_library ( speed_counters STATIC speed_counters.cpp )
target_link_libraries ( speed_counters fast_library )
2022-02-11 13:38:08 +01:00
# Our new parser for parsing traffic up to L4
add_library ( simple_packet_parser_ng STATIC simple_packet_parser_ng.cpp )
target_link_libraries ( simple_packet_parser_ng network_data_structures )
2022-02-13 16:45:40 +01:00
# Our own sFlow parser library
set_source_files_properties ( libsflow/libsflow.cpp PROPERTIES COMPILE_FLAGS -pedantic )
add_library ( libsflow STATIC libsflow/libsflow.cpp )
2022-02-11 13:38:08 +01:00
# sFlow plugin
2022-02-10 21:29:43 +01:00
add_library ( sflow_plugin STATIC sflow_plugin/sflow_collector.cpp )
2022-02-11 13:38:08 +01:00
# Link sFlow plugin with new traffic parser
target_link_libraries ( sflow_plugin simple_packet_parser_ng )
2014-12-01 21:26:08 +01:00
2022-02-13 16:45:40 +01:00
# Link sFlow plugin with libsflow
target_link_libraries ( sflow_plugin libsflow )
2023-06-19 19:25:19 +02:00
# Netflow templates
add_library ( netflow_template STATIC netflow_plugin/netflow_template.cpp )
2022-02-20 01:19:29 +01:00
# netflow library
add_library ( netflow STATIC netflow_plugin/netflow.cpp )
2015-01-26 10:10:35 +01:00
# netflow plugin
2015-01-23 17:49:37 +01:00
add_library ( netflow_plugin STATIC netflow_plugin/netflow_collector.cpp )
2023-06-19 19:25:19 +02:00
target_link_libraries ( netflow_plugin ipfix_rfc netflow netflow_template )
2015-01-23 17:49:37 +01:00
2023-04-02 21:08:29 +02:00
if ( ENABLE_PCAP_SUPPORT )
# pcap plugin
add_library ( pcap_plugin STATIC pcap_plugin/pcap_collector.cpp )
2023-08-22 14:17:26 +02:00
target_link_libraries ( pcap_plugin ${ LIBPCAP_LIBRARY_PATH } )
2023-04-02 21:08:29 +02:00
endif ( )
2015-01-26 14:37:12 +01:00
2015-06-02 22:27:49 +02:00
find_package ( Threads )
2022-03-24 02:29:11 +01:00
add_library ( exabgp_action STATIC actions/exabgp_action.cpp )
2022-05-23 18:47:57 +02:00
if ( LINK_WITH_ABSL )
2023-04-04 12:15:45 +02:00
find_package ( absl REQUIRED ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-05-23 18:47:57 +02:00
# TODO: check that we actually found it. Otherwise trigger fatal erorr
endif ( )
2023-04-02 20:57:29 +02:00
if ( ENABLE_PCAP_SUPPORT )
add_definitions ( -DENABLE_PCAP )
endif ( )
2015-10-03 21:17:58 +02:00
if ( ENABLE_GOBGP_SUPPORT )
2015-10-05 12:00:47 +02:00
add_definitions ( -DENABLE_GOBGP )
2023-08-05 15:06:42 +02:00
# GoBGP client library
add_library ( gobgp_client STATIC gobgp_client/gobgp_client.cpp )
2015-10-05 12:00:47 +02:00
add_library ( gobgp_action STATIC actions/gobgp_action.cpp )
2015-10-03 21:17:58 +02:00
2023-04-03 23:36:14 +02:00
# We use find_package for Windows as our approach for *nix platforms leads to bunch of linking errors
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
2023-04-04 23:14:01 +02:00
# Will be great to use this approach for all builds but it's relatively tricky to accomplish
# Debian 11 has no cmake files in official gRPC packages and only Debian Sid got them: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1006237
# gRPC bug tracker entry: https://github.com/grpc/grpc/issues/29977
# https://packages.debian.org/sid/amd64/libgrpc-dev/filelist
# Fedora has cmake files: https://packages.fedoraproject.org/pkgs/grpc/grpc-devel/fedora-38.html#files
# Epel 9 has cmake files: https://packages.fedoraproject.org/pkgs/grpc/grpc-devel/epel-9.html#files
# Both latest Ubuntu 22.04 and 22.10 does not offer it in official package: https://packages.ubuntu.com/kinetic/amd64/libgrpc-dev/filelist
# As Ubuntu and Debian our main platforms we will keep old logic for them until LTS / stable versions of Ubuntu and Debian receive it
# We need to offer smooth developer experience and allow options to build FastNetMon at least on these platforms without using custom compiled libraries
2023-04-04 12:15:45 +02:00
find_package ( gRPC CONFIG REQUIRED ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2023-04-03 23:36:14 +02:00
if ( gRPC_FOUND )
message ( STATUS "Found gRPC" )
else ( )
message ( FATAL_ERROR "NOT Found gRPC module" )
endif ( )
2023-08-05 15:06:42 +02:00
target_link_libraries ( gobgp_client gRPC::grpc gRPC::grpc++ )
target_link_libraries ( gobgp_action gRPC::grpc gRPC::grpc++ gobgp_client )
2023-04-03 23:36:14 +02:00
else ( )
2015-10-05 12:00:47 +02:00
2023-04-03 23:36:14 +02:00
find_path ( GRPC_INCLUDES_FOLDER NAMES grpc/grpc.h PATHS "${GRPC_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( GRPC_LIBRARY_GRPC_PATH NAMES grpc PATHS "${GRPC_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( GRPC_LIBRARY_GPR_PATH NAMES gpr PATHS "${GRPC_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( GRPC_LIBRARY_GRPC_CPP_PATH NAMES grpc++ PATHS "${GRPC_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
if ( GRPC_INCLUDES_FOLDER AND GRPC_LIBRARY_GRPC_PATH AND GRPC_LIBRARY_GPR_PATH AND GRPC_LIBRARY_GRPC_CPP_PATH )
2015-10-03 21:17:58 +02:00
include_directories ( ${ GRPC_INCLUDES_FOLDER } )
2015-10-05 12:00:47 +02:00
target_link_libraries ( gobgp_action ${ GRPC_LIBRARY_GRPC_PATH } )
target_link_libraries ( gobgp_action ${ GRPC_LIBRARY_GPR_PATH } )
2022-03-13 22:45:05 +01:00
target_link_libraries ( gobgp_action ${ GRPC_LIBRARY_GRPC_CPP_PATH } )
2023-08-05 15:06:42 +02:00
target_link_libraries ( gobgp_action gobgp_client )
target_link_libraries ( gobgp_client ${ GRPC_LIBRARY_GRPC_PATH } )
target_link_libraries ( gobgp_client ${ GRPC_LIBRARY_GPR_PATH } )
target_link_libraries ( gobgp_client ${ GRPC_LIBRARY_GRPC_CPP_PATH } )
2022-03-13 22:45:05 +01:00
message ( STATUS "Found gRPC library: ${GRPC_LIBRARY_GRPC_PATH} ${GRPC_LIBRARY_GPR_PATH} ${GRPC_LIBRARY_GRPC_CPP_PATH}" )
2023-04-03 23:36:14 +02:00
else ( )
2015-10-05 12:00:47 +02:00
message ( FATAL_ERROR "Could not find gRPC library" )
2023-04-03 23:36:14 +02:00
endif ( )
2015-10-04 12:53:06 +02:00
endif ( )
2022-05-23 18:47:57 +02:00
if ( LINK_WITH_ABSL )
target_link_libraries ( gobgp_action absl::base absl::synchronization )
endif ( )
2023-04-04 13:07:09 +02:00
if ( DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD )
2023-04-04 22:20:50 +02:00
# We add our custom path to Protobuf to top of search_list used by find_package: https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html
# This approach has advantage over Protobuf_DIR which requires us to set direct path to cmake folder of custom built dependency
# which resides in vendor specific folder with name lib which may be lib64 on CentOS platforms:
# protobuf_21_12/lib/cmake/protobuf or protobuf_21_12/lib64/cmake/protobuf on CentOS
list ( APPEND CMAKE_PREFIX_PATH ${ PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH } )
2024-02-13 23:30:47 +01:00
endif ( )
2015-10-05 12:00:47 +02:00
2024-02-13 23:30:47 +01:00
# Apparently it's required to set this flag because without this flag set it cannot find protoc when custom library path is in use
# https://github.com/protocolbuffers/protobuf/issues/1931
set ( protobuf_MODULE_COMPATIBLE true )
2023-04-04 14:06:07 +02:00
2024-02-13 23:30:47 +01:00
# Switch to use to configuration supplied by custom Protobuf installation as it may be better
find_package ( Protobuf CONFIG )
2015-10-04 12:53:06 +02:00
2024-02-13 23:30:47 +01:00
if ( NOT Protobuf_FOUND )
# Fall back to module supplied by cmake to search for Protobuf
# https://cmake.org/cmake/help/latest/module/FindProtobuf.html
find_package ( Protobuf MODULE REQUIRED )
endif ( )
2015-10-04 12:53:06 +02:00
2023-04-04 13:07:09 +02:00
if ( Protobuf_FOUND )
message ( STATUS "Found Protobuf ${Protobuf_VERSION}" )
2015-10-04 12:53:06 +02:00
2023-04-04 13:52:58 +02:00
# Empty checks are very tricky in cmake:
# https://cmake.org/pipermail/cmake/2011-October/046939.html
if ( "${Protobuf_PROTOC_EXECUTABLE}" STREQUAL "" )
message ( FATAL_ERROR "Protobuf was found but we did not find protoc" )
endif ( )
message ( STATUS "Found Protobuf compiler: '${Protobuf_PROTOC_EXECUTABLE}'" )
2023-04-04 13:35:24 +02:00
2023-04-04 13:07:09 +02:00
# We need to explicitly provide paths for our dependency libraries in environment variable LD_LIBRARY_PATH as we use non system path for them
# CentOS uses lib64 but Debian / Ubuntu still use lib for Protobuf, that's why we keep both of them
set ( ENV{LD_LIBRARY_PATH} "${GCC_INSTALL_PATH}/lib64:${PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH}/lib:${PROTOCOL_BUFFERS_CUSTOM_INSTALL_PATH}/lib64:${GRPC_CUSTOM_INSTALL_PATH}/lib" )
2023-01-04 13:08:49 +01:00
2023-04-04 21:44:39 +02:00
message ( STATUS "Protobuf include directory: ${Protobuf_INCLUDE_DIRS}" )
include_directories ( ${ Protobuf_INCLUDE_DIRS } )
2015-10-03 21:17:58 +02:00
else ( )
2023-04-04 13:07:09 +02:00
message ( FATAL_ERROR "NOT Found Protobuf module" )
2015-10-03 21:17:58 +02:00
endif ( )
2015-10-05 12:00:47 +02:00
2023-04-04 13:07:09 +02:00
target_link_libraries ( gobgp_action protobuf::libprotobuf )
# Search for gRPC plugin for Protobuf, it's just binary
2022-05-01 15:51:54 +02:00
find_program ( GRPC_CPP_PLUGIN grpc_cpp_plugin PATHS "${GRPC_CUSTOM_INSTALL_PATH}/bin" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-02-09 15:27:32 +01:00
2022-04-30 15:45:17 +02:00
if ( GRPC_CPP_PLUGIN )
message ( STATUS "Found Protobuf gRPC compiler plugin: ${GRPC_CPP_PLUGIN}" )
else ( )
message ( FATAL_ERROR "Can't find Protobuf gRPC compiler plugin" )
endif ( )
message ( STATUS "Building protobuf and gRPC mappings for C++" )
2015-10-05 12:00:47 +02:00
2023-08-05 14:31:27 +02:00
execute_process ( COMMAND ${ Protobuf_PROTOC_EXECUTABLE } -I ${ PROJECT_SOURCE_DIR } /gobgp_client --grpc_out= ${ PROJECT_SOURCE_DIR } /gobgp_client --plugin=protoc-gen-grpc= ${ GRPC_CPP_PLUGIN } ${ PROJECT_SOURCE_DIR } /gobgp_client/gobgp.proto ERROR_VARIABLE PROTOC_STDERR RESULT_VARIABLE PROTOC_RETURN_CODE OUTPUT_STRIP_TRAILING_WHITESPACE )
2015-10-05 12:00:47 +02:00
2022-02-09 15:27:32 +01:00
message ( STATUS "Protoc return code for gobgp.proto gRPC: ${PROTOC_RETURN_CODE} std err: ${PROTOC_STDERR}" )
2015-10-05 12:00:47 +02:00
2023-08-05 14:31:27 +02:00
execute_process ( COMMAND ${ Protobuf_PROTOC_EXECUTABLE } -I ${ PROJECT_SOURCE_DIR } /gobgp_client --cpp_out= ${ PROJECT_SOURCE_DIR } /gobgp_client ${ PROJECT_SOURCE_DIR } /gobgp_client/gobgp.proto ${ PROJECT_SOURCE_DIR } /gobgp_client/attribute.proto ERROR_VARIABLE PROTOC_STDERR RESULT_VARIABLE PROTOC_RETURN_CODE OUTPUT_STRIP_TRAILING_WHITESPACE )
2015-10-05 12:00:47 +02:00
2022-02-09 15:27:32 +01:00
message ( STATUS "Protoc return code for gobgp.proto and attribute.proto Protobuf: ${PROTOC_RETURN_CODE} std err: ${PROTOC_STDERR}" )
2015-10-05 12:00:47 +02:00
2023-02-12 13:16:02 +01:00
message ( STATUS "Building Protobuf bindings for C++ for Flow Data" )
2023-04-04 22:27:19 +02:00
execute_process ( COMMAND ${ Protobuf_PROTOC_EXECUTABLE } -I ${ PROJECT_SOURCE_DIR } /traffic_output_formats/protobuf --cpp_out= ${ PROJECT_SOURCE_DIR } /traffic_output_formats/protobuf ${ PROJECT_SOURCE_DIR } /traffic_output_formats/protobuf/traffic_data.proto ERROR_VARIABLE PROTOC_STDERR RESULT_VARIABLE PROTOC_RETURN_CODE OUTPUT_STRIP_TRAILING_WHITESPACE )
2023-02-12 13:16:02 +01:00
message ( STATUS "Protoc return code for FlowData Protobuf: ${PROTOC_RETURN_CODE} std err: ${PROTOC_STDERR}" )
2023-02-12 13:40:41 +01:00
# Build Flow Data binary
2023-03-01 13:36:56 +01:00
add_library ( traffic_data_library STATIC traffic_output_formats/protobuf/traffic_data.pb.cc )
2023-02-12 13:16:02 +01:00
2023-02-21 18:26:35 +01:00
add_library ( protobuf_traffic_format STATIC traffic_output_formats/protobuf/protobuf_traffic_format.cpp )
target_link_libraries ( protobuf_traffic_format traffic_data_library )
2023-02-12 13:40:41 +01:00
# Build gRPC and protocol buffers libraries and link they to gobgp_action
2023-08-05 14:31:27 +02:00
add_library ( gobgp_api_client_pb_cc STATIC gobgp_client/gobgp.pb.cc )
add_library ( gobgp_api_client_grpc_pb_cc STATIC gobgp_client/gobgp.grpc.pb.cc )
2015-10-05 12:00:47 +02:00
2023-04-04 00:11:27 +02:00
# It does not work without on Windows but works fine on *nix
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
target_link_libraries ( gobgp_api_client_grpc_pb_cc gRPC::grpc gRPC::grpc++ )
endif ( )
2015-10-05 12:00:47 +02:00
target_link_libraries ( gobgp_action gobgp_api_client_pb_cc )
target_link_libraries ( gobgp_action gobgp_api_client_grpc_pb_cc )
2015-10-13 18:45:27 +02:00
2022-02-09 15:27:32 +01:00
# Add attributes
2023-08-05 14:31:27 +02:00
add_library ( attribute_pb_cc STATIC gobgp_client/attribute.pb.cc )
2023-04-04 00:01:43 +02:00
2023-04-04 13:07:09 +02:00
target_link_libraries ( attribute_pb_cc protobuf::libprotobuf )
2023-04-04 00:01:43 +02:00
2022-02-09 15:27:32 +01:00
target_link_libraries ( gobgp_action attribute_pb_cc )
2015-10-13 18:45:27 +02:00
# FastNetMon API
2015-10-16 00:24:03 +02:00
add_definitions ( -DFASTNETMON_API )
2023-04-04 22:27:19 +02:00
execute_process ( COMMAND ${ Protobuf_PROTOC_EXECUTABLE } -I ${ PROJECT_SOURCE_DIR } --grpc_out= ${ PROJECT_SOURCE_DIR } --plugin=protoc-gen-grpc= ${ GRPC_CPP_PLUGIN } ${ PROJECT_SOURCE_DIR } /fastnetmon.proto ERROR_VARIABLE PROTOC_STDERR RESULT_VARIABLE PROTOC_RETURN_CODE OUTPUT_STRIP_TRAILING_WHITESPACE )
2015-10-13 18:45:27 +02:00
2022-02-09 15:27:32 +01:00
message ( STATUS "Protoc return code for gRPC fastnetmon.proto: ${PROTOC_RETURN_CODE} std err: ${PROTOC_STDERR}" )
2015-10-15 20:50:21 +02:00
2023-04-04 22:27:19 +02:00
execute_process ( COMMAND ${ Protobuf_PROTOC_EXECUTABLE } -I ${ PROJECT_SOURCE_DIR } --cpp_out= ${ PROJECT_SOURCE_DIR } ${ PROJECT_SOURCE_DIR } /fastnetmon.proto ERROR_VARIABLE PROTOC_STDERR RESULT_VARIABLE PROTOC_RETURN_CODE OUTPUT_STRIP_TRAILING_WHITESPACE )
2015-10-13 18:45:27 +02:00
2022-02-09 15:27:32 +01:00
message ( STATUS "Protoc return code for protobuf fastnetmon.proto: ${PROTOC_RETURN_CODE} std err: ${PROTOC_STDERR}" )
2015-10-15 20:50:21 +02:00
2015-10-13 18:45:27 +02:00
add_library ( fastnetmon_grpc_pb_cc STATIC fastnetmon.grpc.pb.cc )
add_library ( fastnetmon_pb_cc STATIC fastnetmon.pb.cc )
2015-10-15 22:39:16 +02:00
add_executable ( fastnetmon_api_client fastnetmon_api_client.cpp )
2015-10-15 22:30:11 +02:00
2022-05-23 18:47:57 +02:00
if ( LINK_WITH_ABSL )
target_link_libraries ( fastnetmon_api_client absl::base absl::synchronization )
endif ( )
2023-04-03 23:36:14 +02:00
# We use another way to specify dependencies for Windows as our standard approach clearly does not work
2023-04-03 23:50:51 +02:00
# https://www.f-ax.de/dev/2020/11/08/grpc-plugin-cmake-support.html
2023-04-03 23:36:14 +02:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
target_link_libraries ( fastnetmon_api_client gRPC::grpc gRPC::grpc++ )
else ( )
target_link_libraries ( fastnetmon_api_client ${ GRPC_LIBRARY_GPR_PATH } )
target_link_libraries ( fastnetmon_api_client ${ GRPC_LIBRARY_GRPC_CPP_PATH } )
target_link_libraries ( fastnetmon_api_client ${ GRPC_LIBRARY_GRPC_PATH } )
endif ( )
2015-10-15 22:30:11 +02:00
target_link_libraries ( fastnetmon_api_client fastnetmon_grpc_pb_cc )
target_link_libraries ( fastnetmon_api_client fastnetmon_pb_cc )
2023-04-03 23:50:51 +02:00
2023-04-04 13:07:09 +02:00
target_link_libraries ( fastnetmon_api_client protobuf::libprotobuf )
2015-10-13 18:45:27 +02:00
2023-02-05 19:34:43 +01:00
if ( KAFKA_SUPPORT )
target_link_libraries ( fastnetmon ${ LIBKAFKA_CPP_LIBRARY_PATH } )
endif ( )
2023-04-03 23:36:14 +02:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
target_link_libraries ( fastnetmon gRPC::grpc gRPC::grpc++ )
else ( )
target_link_libraries ( fastnetmon ${ GRPC_LIBRARY_GPR_PATH } )
target_link_libraries ( fastnetmon ${ GRPC_LIBRARY_GRPC_CPP_PATH } )
target_link_libraries ( fastnetmon ${ GRPC_LIBRARY_GRPC_PATH } )
endif ( )
2015-10-16 00:24:03 +02:00
target_link_libraries ( fastnetmon fastnetmon_grpc_pb_cc )
target_link_libraries ( fastnetmon fastnetmon_pb_cc )
2023-04-03 23:50:51 +02:00
2023-04-04 13:07:09 +02:00
target_link_libraries ( fastnetmon protobuf::libprotobuf )
2015-10-03 21:17:58 +02:00
endif ( )
2015-01-26 10:10:35 +01:00
# example plugin
add_library ( example_plugin STATIC example_plugin/example_collector.cpp )
2017-07-28 00:19:33 +02:00
if ( ENABLE_NETMAP_SUPPORT )
# Netmap plugin
set ( NETMAP_INCLUDE_DIRS "netmap_plugin/netmap_includes" )
include_directories ( ${ NETMAP_INCLUDE_DIRS } )
add_library ( netmap_plugin STATIC netmap_plugin/netmap_collector.cpp )
endif ( )
2015-03-10 15:18:52 +01:00
2014-12-22 16:39:46 +01:00
# Client tool
add_executable ( fastnetmon_client fastnetmon_client.cpp )
2014-11-28 15:22:27 +01:00
# Find boost: http://www.cmake.org/cmake/help/v3.0/module/FindBoost.html
2014-12-01 09:09:37 +01:00
# Enable detailed errors
2014-11-28 15:58:12 +01:00
set ( Boost_DETAILED_FAILURE_MSG ON )
2022-02-09 15:27:32 +01:00
# set(Boost_DEBUG ON)
2014-12-01 09:09:37 +01:00
2023-01-13 15:47:53 +01:00
# Boost.System is a library that, in essence, defines four classes to identify errors. All four classes were added to the standard library with C++11. If your development environment supports C++11, you don’ t need to use Boost.System. However, since many Boost libraries use Boost.System, you might encounter Boost.System through those other libraries.
# Boost.System is a library that, in essence, defines four classes to identify errors. All four classes were added to the standard library with C++11. If your development environment supports C++11, you don’ t need to use Boost.System. However, since many Boost libraries use Boost.System, you might encounter Boost.System through those other libraries.
# TODO: we may not need system at all
2023-04-04 12:15:45 +02:00
find_package ( Boost COMPONENTS serialization thread regex program_options system REQUIRED ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2014-11-28 15:58:12 +01:00
2014-11-28 15:22:27 +01:00
if ( Boost_FOUND )
2022-02-09 15:27:32 +01:00
message ( STATUS "Found Boost: ${Boost_LIBRARIES} ${Boost_INCLUDE_DIRS}" )
2023-01-13 15:47:53 +01:00
# We can get separate library paths for each library too
2023-01-13 15:53:18 +01:00
message ( STATUS "Found Boost library program_options: ${Boost_PROGRAM_OPTIONS_LIBRARY}" )
2023-01-13 15:47:53 +01:00
2014-11-28 15:22:27 +01:00
include_directories ( ${ Boost_INCLUDE_DIRS } )
target_link_libraries ( fastnetmon ${ Boost_LIBRARIES } )
2015-03-21 13:15:35 +01:00
target_link_libraries ( fast_library ${ Boost_LIBRARIES } )
2023-01-13 15:59:09 +01:00
target_link_libraries ( fastnetmon_client ${ Boost_PROGRAM_OPTIONS_LIBRARY } )
2014-11-28 15:22:27 +01:00
endif ( )
2015-05-29 14:45:02 +02:00
target_link_libraries ( fast_library patricia )
2015-07-22 14:16:13 +02:00
target_link_libraries ( fast_library fastnetmon_pcap_format )
2015-05-29 14:45:02 +02:00
2022-06-01 16:49:58 +02:00
# Try to find ncurses library
2014-11-28 15:58:12 +01:00
find_package ( Curses REQUIRED )
2023-04-02 22:56:28 +02:00
if ( CURSES_FOUND )
message ( STATUS "Found curses library: ${CURSES_LIBRARIES}" )
message ( STATUS "Found curses includes: ${CURSES_INCLUDE_DIRS}" )
2014-11-28 15:58:12 +01:00
include_directories ( ${ CURSES_INCLUDE_DIRS } )
2014-12-22 16:39:46 +01:00
target_link_libraries ( fastnetmon_client ${ CURSES_LIBRARIES } )
2023-04-02 22:57:43 +02:00
else ( )
message ( STATUS "We did not find curses library" )
2014-11-28 15:58:12 +01:00
endif ( )
2015-08-11 08:18:17 +02:00
### Move this code to cmake module
# Try to find hiredis in a specific folder
2022-05-01 15:51:54 +02:00
find_path ( HIREDIS_INCLUDES_FOLDER NAMES hiredis/hiredis.h PATHS "${HIREDIS_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2015-08-11 08:18:17 +02:00
# Try to find hiredis library path
2022-05-01 15:51:54 +02:00
find_library ( HIREDIS_LIBRARY_PATH NAMES hiredis PATHS "${HIREDIS_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2015-08-11 08:18:17 +02:00
if ( HIREDIS_INCLUDES_FOLDER AND HIREDIS_LIBRARY_PATH )
2022-03-13 22:45:05 +01:00
message ( STATUS "We found hiredis library ${HIREDIS_INCLUDES_FOLDER} ${HIREDIS_LIBRARY_PATH}" )
2015-08-11 08:18:17 +02:00
add_definitions ( -DREDIS )
include_directories ( ${ HIREDIS_INCLUDES_FOLDER } )
target_link_libraries ( fastnetmon ${ HIREDIS_LIBRARY_PATH } )
2022-03-13 23:09:35 +01:00
target_link_libraries ( fastnetmon_logic ${ HIREDIS_LIBRARY_PATH } )
2015-08-11 08:18:17 +02:00
else ( )
message ( STATUS "We can't find hiredis library and will disable Redis support" )
endif ( )
2015-03-19 10:40:58 +01:00
2022-03-13 16:18:21 +01:00
set ( ENABLE_OPENSSL_SUPPORT TRUE )
if ( ENABLE_OPENSSL_SUPPORT )
2022-05-01 15:51:54 +02:00
find_path ( OPENSSL_INCLUDES_FOLDER NAMES "openssl/rsa.h" PATHS "${OPENSSL_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-06-11 19:46:52 +02:00
# Check that we found headers
if ( OPENSSL_INCLUDES_FOLDER )
message ( STATUS "We found OpenSSL library headers: ${OPENSSL_INCLUDES_FOLDER}" )
include_directories ( ${ OPENSSL_INCLUDES_FOLDER } )
else ( )
message ( FATAL_ERROR "Could not find OpenSSL headers" )
endif ( )
2022-05-01 15:51:54 +02:00
find_library ( OPENSSL_LIBRARY_PATH NAMES ssl PATHS "${OPENSSL_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( OPENSSL_CRYPTO_LIBRARY_PATH NAMES crypto PATHS "${OPENSSL_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-03-13 16:18:21 +01:00
2022-06-11 19:46:52 +02:00
# Check that we found libraries
if ( OPENSSL_LIBRARY_PATH AND OPENSSL_CRYPTO_LIBRARY_PATH )
2022-03-13 22:45:05 +01:00
message ( STATUS "We found OpenSSL library: ${OPENSSL_LIBRARY_PATH} ${OPENSSL_CRYPTO_LIBRARY_PATH}" )
2022-03-13 16:18:21 +01:00
else ( )
2022-06-11 19:46:52 +02:00
message ( FATAL_ERROR "Could not find OpenSSL libraries" )
2022-03-13 16:18:21 +01:00
endif ( )
endif ( )
2022-04-30 17:52:25 +02:00
if ( ENABLE_CAPNP_SUPPORT )
add_definitions ( -DENABLE_CAPNP )
2022-03-13 16:18:21 +01:00
2022-05-01 15:51:54 +02:00
find_library ( CAPNP_LIBRARY_PATH NAMES capnp PATHS "${CAPNP_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( CAPNP_KJ_LIBRARY_PATH NAMES kj PATHS "${CAPNP_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2022-03-13 16:18:21 +01:00
if ( CAPNP_LIBRARY_PATH AND CAPNP_KJ_LIBRARY_PATH )
2022-03-13 22:40:27 +01:00
message ( STATUS "We found capnp and kj libraries: ${CAPNP_LIBRARY_PATH} ${CAPNP_KJ_LIBRARY_PATH}" )
2022-03-13 16:18:21 +01:00
else ( )
message ( FATAL_ERROR "Could not find capnp libraries" )
endif ( )
include_directories ( "${CAPNP_CUSTOM_INSTALL_PATH}/include" )
2022-04-30 17:52:25 +02:00
target_link_libraries ( simple_packet_capnp ${ CAPNP_LIBRARY_PATH } ${ CAPNP_KJ_LIBRARY_PATH } )
# Link it with cap'n'p stuff
target_link_libraries ( fast_library simple_packet_capnp )
endif ( )
2022-03-13 22:40:27 +01:00
2023-04-02 14:39:38 +02:00
# With this flag we can control MongoDB build via console: cmake .. -DENABLE_MONGODB_SUPPORT=ON
option ( ENABLE_MONGODB_SUPPORT "Enable MongoDB support build" ON )
2015-09-30 16:54:57 +02:00
2023-04-02 14:39:38 +02:00
if ( ENABLE_MONGODB_SUPPORT )
2015-09-30 16:54:57 +02:00
2023-04-02 14:39:38 +02:00
### Find mongo-c
find_path ( MONGOC_INCLUDES_FOLDER NAMES libmongoc-1.0/mongoc.h PATHS "${MONGO_C_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( MONGOC_LIBRARY_PATH NAMES mongoc-1.0 PATHS "${MONGO_C_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2015-09-30 16:54:57 +02:00
2023-04-02 14:39:38 +02:00
### find bson
find_path ( BSON_INCLUDES_FOLDER NAMES libbson-1.0/bson.h PATHS "${MONGO_C_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
find_library ( BSON_LIBRARY_PATH NAMES bson-1.0 PATHS "${MONGO_C_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
if ( MONGOC_INCLUDES_FOLDER AND MONGOC_LIBRARY_PATH AND BSON_INCLUDES_FOLDER AND BSON_LIBRARY_PATH )
message ( STATUS "We found mongo-c library ${MONGOC_INCLUDES_FOLDER} ${MONGOC_LIBRARY_PATH} ${BSON_INCLUDES_FOLDER} ${BSON_LIBRARY_PATH}" )
add_definitions ( -DMONGO )
# We add suffix name because cmake could not detect it correctly...
include_directories ( "${MONGOC_INCLUDES_FOLDER}/libmongoc-1.0" )
include_directories ( "${BSON_INCLUDES_FOLDER}/libbson-1.0" )
target_link_libraries ( fastnetmon ${ MONGOC_LIBRARY_PATH } ${ BSON_LIBRARY_PATH } )
target_link_libraries ( fastnetmon_logic ${ MONGOC_LIBRARY_PATH } ${ BSON_LIBRARY_PATH } )
else ( )
message ( FATAL_ERROR "We can't find Mongo C library" )
endif ( )
2015-09-30 16:54:57 +02:00
endif ( )
2015-08-12 19:27:29 +02:00
### Look for log4cpp
2015-08-11 10:24:08 +02:00
# Try to find log4cpp includes path
2022-05-01 15:51:54 +02:00
find_path ( LOG4CPP_INCLUDES_FOLDER NAMES log4cpp/Appender.hh PATHS "${LOG4CPP_CUSTOM_INSTALL_PATH}/include" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2015-02-10 11:42:48 +01:00
2015-08-11 10:24:08 +02:00
# Try to find log4cpp library path
2022-05-01 15:51:54 +02:00
find_library ( LOG4CPP_LIBRARY_PATH NAMES log4cpp PATHS "${LOG4CPP_CUSTOM_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
2015-01-29 11:27:55 +01:00
2015-08-11 10:24:08 +02:00
if ( LOG4CPP_INCLUDES_FOLDER AND LOG4CPP_LIBRARY_PATH )
include_directories ( ${ LOG4CPP_INCLUDES_FOLDER } )
2022-03-13 22:45:05 +01:00
message ( STATUS "We have found log4cpp: ${LOG4CPP_LIBRARY_PATH}" )
2015-08-11 10:24:08 +02:00
else ( )
2015-08-17 18:36:35 +02:00
message ( FATAL_ERROR "We can't find log4cpp. We can't build project" )
2015-02-10 14:07:53 +01:00
endif ( )
2022-03-13 16:18:21 +01:00
target_link_libraries ( fast_library ${ OPENSSL_LIBRARY_PATH } )
target_link_libraries ( fast_library ${ OPENSSL_CRYPTO_LIBRARY_PATH } )
2015-02-10 11:42:48 +01:00
target_link_libraries ( fastnetmon ${ LOG4CPP_LIBRARY_PATH } )
2015-06-02 22:27:49 +02:00
target_link_libraries ( fastnetmon ${ CMAKE_THREAD_LIBS_INIT } )
2014-11-28 15:22:27 +01:00
2022-10-15 16:39:50 +02:00
# We need it for boost::stacktrace
# To address undefined reference to symbol 'dladdr@@GLIBC_2.2.5
target_link_libraries ( fastnetmon ${ CMAKE_DL_LIBS } )
2014-11-28 15:58:12 +01:00
# Our libs
2014-12-16 09:01:07 +01:00
target_link_libraries ( fastnetmon patricia )
2015-07-22 14:16:13 +02:00
target_link_libraries ( fastnetmon fastnetmon_pcap_format )
2014-11-28 15:22:27 +01:00
2015-03-22 17:00:16 +01:00
target_link_libraries ( fastnetmon ipfix_rfc )
2022-04-02 23:23:52 +02:00
target_link_libraries ( fastnetmon_logic bgp_protocol exabgp_action )
2022-03-13 23:09:35 +01:00
2023-02-21 18:26:35 +01:00
target_link_libraries ( fastnetmon_logic protobuf_traffic_format )
2023-02-28 20:24:05 +01:00
target_link_libraries ( fastnetmon_logic speed_counters )
2015-03-21 11:47:25 +01:00
# Link to our functions
target_link_libraries ( fastnetmon fast_library )
2017-07-28 01:09:58 +02:00
# link to our unified parser
2022-03-13 16:18:21 +01:00
target_link_libraries ( fastnetmon ${ OPENSSL_LIBRARY_PATH } )
target_link_libraries ( fastnetmon ${ OPENSSL_CRYPTO_LIBRARY_PATH } )
2015-10-03 21:17:58 +02:00
if ( ENABLE_GOBGP_SUPPORT )
target_link_libraries ( fastnetmon gobgp_action )
endif ( )
2022-03-24 02:29:11 +01:00
target_link_libraries ( fastnetmon exabgp_action )
2015-09-01 10:41:55 +02:00
if ( ENABLE_AFPACKET_SUPPORT )
target_link_libraries ( fastnetmon afpacket_plugin )
endif ( )
2022-10-02 23:11:49 +02:00
if ( ENABLE_AF_XDP_SUPPORT )
target_link_libraries ( fastnetmon xdp_plugin )
endif ( )
2023-04-02 21:08:29 +02:00
target_link_libraries ( fastnetmon sflow_plugin netflow_plugin example_plugin )
if ( ENABLE_PCAP_SUPPORT )
target_link_libraries ( fastnetmon pcap_plugin )
endif ( )
2017-07-28 00:19:33 +02:00
2022-03-13 23:09:35 +01:00
target_link_libraries ( fastnetmon fastnetmon_logic )
2017-07-28 00:19:33 +02:00
if ( ENABLE_NETMAP_SUPPORT )
target_link_libraries ( fastnetmon netmap_plugin )
endif ( )
2015-05-29 13:42:01 +02:00
2022-05-06 00:45:42 +02:00
# According to YunQiang Su debian-mips@lists.debian.org
# Due to the limitation of gnu ld, -latomic should be put after library which calls it
# I decided that keeping it here as very last dependency is pretty good option to guarantee it
if ( LINK_WITH_ATOMIC_LIBRARY )
target_link_libraries ( fastnetmon atomic )
endif ( )
2015-05-29 13:42:01 +02:00
# cmake .. -DBUILD_PLUGIN_RUNNER=ON
if ( BUILD_PLUGIN_RUNNER )
add_executable ( fastnetmon_plugin_runner plugin_runner.cpp )
2015-09-01 10:41:55 +02:00
if ( ENABLE_AFPACKET_SUPPORT )
target_link_libraries ( fastnetmon_plugin_runner afpacket_plugin )
endif ( )
2015-06-16 17:00:10 +02:00
target_link_libraries ( fastnetmon_plugin_runner ${ CMAKE_THREAD_LIBS_INIT } )
2015-05-29 13:42:01 +02:00
target_link_libraries ( fastnetmon_plugin_runner patricia )
2015-07-22 14:16:13 +02:00
target_link_libraries ( fastnetmon_plugin_runner fastnetmon_pcap_format )
2015-05-29 13:42:01 +02:00
target_link_libraries ( fastnetmon_plugin_runner ${ LOG4CPP_LIBRARY_PATH } )
target_link_libraries ( fastnetmon_plugin_runner fast_library )
# Add all plugins
2017-07-28 00:19:33 +02:00
target_link_libraries ( fastnetmon_plugin_runner sflow_plugin netflow_plugin pcap_plugin example_plugin )
if ( ENABLE_NETMAP_SUPPORT )
target_link_libraries ( fastnetmon_plugin_runner netmap_plugin )
endif ( )
2015-05-29 13:42:01 +02:00
endif ( )
2015-03-23 17:39:44 +01:00
2015-05-29 14:08:12 +02:00
# cmake .. -DBUILD_PCAP_READER=ON
if ( BUILD_PCAP_READER )
add_executable ( fastnetmon_pcap_reader pcap_reader.cpp )
target_link_libraries ( fastnetmon_pcap_reader patricia )
2015-07-22 14:16:13 +02:00
target_link_libraries ( fastnetmon_pcap_reader fastnetmon_pcap_format )
2015-05-29 14:08:12 +02:00
target_link_libraries ( fastnetmon_pcap_reader fast_library )
target_link_libraries ( fastnetmon_pcap_reader ${ LOG4CPP_LIBRARY_PATH } )
2015-06-17 12:35:42 +02:00
target_link_libraries ( fastnetmon_pcap_reader netflow_plugin )
target_link_libraries ( fastnetmon_pcap_reader sflow_plugin )
2017-07-28 00:19:33 +02:00
if ( ENABLE_NETMAP_SUPPORT )
target_link_libraries ( fastnetmon_pcap_reader netmap_plugin )
endif ( )
2015-05-29 14:08:12 +02:00
endif ( )
2015-03-23 17:39:44 +01:00
2015-07-12 17:34:00 +02:00
# cmake -DBUILD_TESTS=ON ..
if ( BUILD_TESTS )
add_executable ( fastnetmon_tests fastnetmon_tests.cpp )
target_link_libraries ( fastnetmon_tests fast_library )
target_link_libraries ( fastnetmon_tests ${ CMAKE_THREAD_LIBS_INIT } )
target_link_libraries ( fastnetmon_tests ${ Boost_LIBRARIES } )
2015-07-13 10:05:26 +02:00
target_link_libraries ( fastnetmon_tests ${ LOG4CPP_LIBRARY_PATH } )
2023-02-28 18:24:46 +01:00
find_library ( GTEST_LIBRARY_PATH names "gtest" PATHS "${GTEST_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
if ( GTEST_LIBRARY_PATH )
message ( STATUS "Found gTest library: ${GTEST_LIBRARY_PATH}" )
else ( )
message ( FATAL_ERROR "Can't find gTest library" )
endif ( )
find_library ( GTEST_MAIN_LIBRARY_PATH names "gtest_main" PATHS "${GTEST_INSTALL_PATH}/lib" ${ DISABLE_DEFAULT_PATH_SEARCH_VAR } )
if ( GTEST_MAIN_LIBRARY_PATH )
message ( STATUS "Found gTest main library: ${GTEST_MAIN_LIBRARY_PATH}" )
else ( )
message ( FATAL_ERROR "Can't find gTest main library" )
endif ( )
2023-02-27 22:05:58 +01:00
set ( GOOGLE_TEST_INCLUDE_DIRS "${GTEST_INSTALL_PATH}/include" )
2015-07-12 17:34:00 +02:00
# Compiled Google Library
2015-07-13 10:05:26 +02:00
include_directories ( ${ GOOGLE_TEST_INCLUDE_DIRS } )
2023-02-28 18:24:46 +01:00
target_link_libraries ( fastnetmon_tests ${ GTEST_LIBRARY_PATH } ${ GTEST_MAIN_LIBRARY_PATH } )
2022-06-19 22:07:48 +02:00
add_executable ( traffic_structures_tests tests/traffic_structures_performance_tests.cpp )
target_link_libraries ( traffic_structures_tests ${ Boost_LIBRARIES } ${ CMAKE_THREAD_LIBS_INIT } ${ LOG4CPP_LIBRARY_PATH } fast_library )
2022-06-26 15:43:52 +02:00
2022-06-29 22:07:44 +02:00
add_executable ( traffic_structures_tests_real_traffic tests/traffic_structures_performance_tests_real_traffic.cpp )
target_link_libraries ( traffic_structures_tests_real_traffic ${ Boost_LIBRARIES } ${ CMAKE_THREAD_LIBS_INIT } ${ LOG4CPP_LIBRARY_PATH } fast_library )
2023-02-28 17:03:10 +01:00
add_executable ( speed_counters_performance_test tests/speed_counters_performance_test.cpp )
2023-02-28 20:24:05 +01:00
target_link_libraries ( speed_counters_performance_test ${ Boost_LIBRARIES } ${ CMAKE_THREAD_LIBS_INIT } fast_library ${ LOG4CPP_LIBRARY_PATH } speed_counters )
2023-02-28 17:03:10 +01:00
2022-06-26 15:43:52 +02:00
add_executable ( patricia_performance_tests tests/patricia_performance_tests.cpp )
2022-06-29 20:47:02 +02:00
target_link_libraries ( patricia_performance_tests patricia fast_library ${ LOG4CPP_LIBRARY_PATH } )
2015-07-12 17:34:00 +02:00
endif ( )
2022-06-17 13:42:39 +02:00
# Check default values prepared by CMAKE for us
message ( STATUS "Install BINDIR path: ${CMAKE_INSTALL_BINDIR}" )
message ( STATUS "Install SBINDIR path: ${CMAKE_INSTALL_SBINDIR}" )
message ( STATUS "Install SYSCONFDIR path: ${CMAKE_INSTALL_SYSCONFDIR}" )
message ( STATUS "Install MANDIR path: ${CMAKE_INSTALL_MANDIR}" )
2022-06-17 23:11:42 +02:00
# We use this flag on Debian upstream builds because we apparently need absolute paths here
# But for Homebrew we need option to disable it and use relative paths
# cmake .. -DSET_ABSOLUTE_INSTALL_PATH=OFF
option ( SET_ABSOLUTE_INSTALL_PATH "Enables use of absolute install paths" ON )
2015-06-04 17:13:43 +02:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "FreeBSD" OR ${ CMAKE_SYSTEM_NAME } STREQUAL "DragonFly" )
2017-05-29 16:45:36 +02:00
set ( CMAKE_INSTALL_BINDIR "bin" )
set ( CMAKE_INSTALL_SBINDIR "bin" )
set ( CMAKE_INSTALL_SYSCONFDIR "etc" )
2022-06-11 23:23:11 +02:00
elseif ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Linux" )
2022-06-17 23:11:42 +02:00
if ( SET_ABSOLUTE_INSTALL_PATH )
set ( CMAKE_INSTALL_BINDIR "/usr/bin" )
set ( CMAKE_INSTALL_SBINDIR "/usr/sbin" )
set ( CMAKE_INSTALL_SYSCONFDIR "/etc" )
set ( CMAKE_INSTALL_MANDIR "/usr/share/man" )
endif ( )
2022-06-17 13:18:34 +02:00
elseif ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Darwin" )
message ( STATUS "We run on Apple platform" )
2022-06-11 23:23:11 +02:00
else ( )
2022-06-11 23:42:25 +02:00
message ( STATUS "We run on platform ${CMAKE_SYSTEM_NAME} and we do not touch install paths" )
2022-06-11 23:23:11 +02:00
# Do not touch these variables and use default values
2017-05-29 16:45:36 +02:00
endif ( )
2015-06-02 22:26:04 +02:00
2017-05-29 16:45:36 +02:00
install ( TARGETS fastnetmon DESTINATION "${CMAKE_INSTALL_SBINDIR}" )
install ( TARGETS fastnetmon_client DESTINATION "${CMAKE_INSTALL_BINDIR}" )
2022-06-01 16:49:58 +02:00
install ( TARGETS fastnetmon_api_client DESTINATION "${CMAKE_INSTALL_BINDIR}" )
2015-06-04 17:13:43 +02:00
2017-05-29 16:45:36 +02:00
install ( FILES fastnetmon.conf DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}" )
# Install blank files for networks list and whitelist
install ( FILES networks_list DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}" )
install ( FILES networks_whitelist DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}" )
2015-06-04 10:15:32 +02:00
2015-06-04 15:13:22 +02:00
# man pages
2022-06-17 13:30:11 +02:00
install ( FILES man/fastnetmon.8 DESTINATION ${ CMAKE_INSTALL_MANDIR } /man8 )
install ( FILES man/fastnetmon_client.1 DESTINATION ${ CMAKE_INSTALL_MANDIR } /man1 )
2015-06-04 15:13:22 +02:00
2022-06-18 00:01:34 +02:00
if ( SET_ABSOLUTE_INSTALL_PATH )
# Unfortunately, we have no cross-platform option to install systemd units in current versions of cmake
set ( CMAKE_INSTALL_SYSTEMD_SERVICEDIR "/lib/systemd/system" CACHE PATH "Location for systemd service files" )
# Generate unit file
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
configure_file ( fastnetmon.service.in "${CMAKE_CURRENT_BINARY_DIR}/fastnetmon.service" @ONLY )
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/fastnetmon.service" DESTINATION ${ CMAKE_INSTALL_SYSTEMD_SERVICEDIR } )
endif ( )
else ( )
# We have no relative standard path for installation, skip any actions
2019-04-01 11:15:36 +02:00
endif ( )
2017-05-29 16:50:23 +02:00
2022-05-08 14:19:46 +02:00
# For Debian packages build please use our logic from upstream: https://salsa.debian.org/debian/fastnetmon
2015-05-30 20:45:28 +02:00
# Configure cpack package builder
# Run it with: cd build; cpack -G DEB ..
set ( CPACK_PACKAGE_NAME "fastnetmon" )
2022-02-10 14:38:13 +01:00
set ( CPACK_PACKAGE_VENDOR "fastnetmon.com" )
2015-05-30 20:45:28 +02:00
set ( CPACK_PACKAGE_CONTACT "pavel.odintsov@gmail.com" )
2022-05-08 14:19:46 +02:00
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "FastNetMon - very fast DoS/DDoS detector with sFlow/Netflow/mirror support" )
2015-05-30 20:45:28 +02:00
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "" )
# set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
2022-05-08 14:19:46 +02:00
if ( NOT DO_NOT_USE_SYSTEM_LIBRARIES_FOR_BUILD )
2015-05-30 20:45:28 +02:00
# Specify config for deb package
# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
2022-05-08 14:19:46 +02:00
# These dependencies are for Debian Bullseye
2022-05-08 14:49:47 +02:00
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-thread-dev, libboost-system-dev, libboost-regex-dev, libpcap-dev, libnuma-dev, liblog4cpp5-dev, libgrpc10, libgrpc++1, libcapnp-0.7.0, libmongoc-1.0-0, libbson-1.0-0, libboost-program-options1.74.0" )
2022-05-08 14:19:46 +02:00
endif ( )
2015-05-30 20:45:28 +02:00
# This must always be last!
include ( CPack )