CMakeLists.txt 7.34 KB
Newer Older
1
cmake_minimum_required(VERSION 3.5)
Pavel Doležal's avatar
Pavel Doležal committed
2
project("DNS Probe" VERSION 0.6.1)
Pavel Doležal's avatar
Pavel Doležal committed
3 4 5 6

set(AF_PACKET_BACKEND ON CACHE BOOL "Define backend for packet processing")
set(DPDK_BACKEND OFF CACHE BOOL "Define backend for packet processing")
set(DPDK_LEGACY_MEM OFF CACHE BOOL "Enable legacy memory management for DPDK")
7
set(BUILD_COLLECTOR ON CACHE BOOL "Build collector for data from probe's remote export")
Pavel Doležal's avatar
Pavel Doležal committed
8
set(BUILD_TESTING OFF CACHE BOOL "Enable build testing binaries")
9
set(BUILD_DOC ON CACHE BOOL "Generate Sphinx and Doxygen documentation")
10
set(PROBE_CRYPTOPANT ON CACHE BOOL "Enable IP anonymization with cryptopANT library")
11 12
set(PROBE_PARQUET ON CACHE BOOL "Enable export to Parquet format with Apache Arrow library")
set(PROBE_CDNS ON CACHE BOOL "Enable export to C-DNS format with C-DNS library")
Pavel Doležal's avatar
Pavel Doležal committed
13 14

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
15
set(CMAKE_CXX_STANDARD 14)
Pavel Doležal's avatar
Pavel Doležal committed
16 17 18 19 20
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

## Find required libraries
find_package(Threads REQUIRED)
find_package(PCAP REQUIRED)
Pavel Doležal's avatar
Pavel Doležal committed
21
find_package(Boost REQUIRED)
22
find_package(OpenSSL REQUIRED)
23
find_package(Yaml-cpp REQUIRED)
24
find_package(Doxygen)
Pavel Doležal's avatar
Pavel Doležal committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-msse4 SSE4_FLAG)
if (NOT SSE4_FLAG)
    message(FATAL_ERROR "SSE4 is required for compilation!")
endif ()

# Common library for all backends
file(GLOB PROBE_HEADERS CONFIGURE_DEPENDS src/core/Probe.h
        src/core/*.h
        src/communication/*.h
        src/config/*.h
        src/export/*.h
        src/platform/*.h
        src/utils/*.h
        )

file(GLOB PROBE_SOURCES CONFIGURE_DEPENDS src/core/Probe.cpp
        src/communication/*.cpp
        src/config/*.cpp
        src/core/*.cpp
        src/export/*.cpp
        src/platform/*.cpp
        src/utils/*.cpp
        )

add_library(DNSProbe INTERFACE)
52
target_link_libraries(DNSProbe INTERFACE ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES} PCAP::PCAP Threads::Threads OpenSSL::SSL)
Pavel Doležal's avatar
Pavel Doležal committed
53
target_compile_definitions(DNSProbe INTERFACE $<$<CONFIG:Debug>:PRINT_DEBUG>)
54
target_include_directories(DNSProbe INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS} ${YAML_CPP_INCLUDE_DIR})
Pavel Doležal's avatar
Pavel Doležal committed
55 56
target_compile_options(DNSProbe INTERFACE -msse4)

57 58 59 60
if (OPENSSL_VERSION VERSION_LESS "1.1.0")
    target_compile_definitions(DNSProbe INTERFACE PROBE_OPENSSL_LEGACY)
endif()

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
if ((NOT PROBE_PARQUET) AND (NOT PROBE_CDNS))
    message(FATAL_ERROR "You must set at least one of available export formats (PROBE_PARQUET, PROBE_CDNS)!")
endif()

if (PROBE_PARQUET)
    find_package(Arrow REQUIRED)
    find_package(Parquet REQUIRED)
    target_link_libraries(DNSProbe INTERFACE Arrow::Arrow Parquet::Parquet)
    target_compile_definitions(DNSProbe INTERFACE PROBE_PARQUET)
    file(GLOB PARQUET_HEADERS CONFIGURE_DEPENDS src/export/parquet/*.h)
    file(GLOB PARQUET_SOURCES CONFIGURE_DEPENDS src/export/parquet/*.cpp)
endif()

if (PROBE_CDNS)
    find_package(CDNS REQUIRED)
    target_link_libraries(DNSProbe INTERFACE CDNS::CDNS)
    target_compile_definitions(DNSProbe INTERFACE PROBE_CDNS)
    file(GLOB CDNS_HEADERS CONFIGURE_DEPENDS src/export/cdns/*.h)
    file(GLOB CDNS_SOURCES CONFIGURE_DEPENDS src/export/cdns/*.cpp)
endif()

82 83 84 85 86
if (PROBE_CRYPTOPANT)
    find_package(cryptopANT REQUIRED)
    target_link_libraries(DNSProbe INTERFACE cryptopANT::cryptopANT)
    target_compile_definitions(DNSProbe INTERFACE PROBE_CRYPTOPANT)
endif()
Pavel Doležal's avatar
Pavel Doležal committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

# Add warning flags
function(set_warning param)
    check_cxx_compiler_flag(-W${param} WARNING_${param})
    if (WARNING_${param})
        target_compile_options(DNSProbe INTERFACE -W${param})
    endif ()
endfunction()

set_warning(all)
set_warning(extra)
set_warning(no-address-of-packed-member)

include(GNUInstallDirs)

# Settings for AF Packet version
if (AF_PACKET_BACKEND)
    file(GLOB AF_PACKET_HEADERS CONFIGURE_DEPENDS src/non-dpdk/*.h)
    file(GLOB AF_PACKET_SOURCES CONFIGURE_DEPENDS src/non-dpdk/*.cpp)

107 108
    set(AF_FILES ${AF_PACKET_HEADERS} ${AF_PACKET_SOURCES} ${PROBE_HEADERS} ${PROBE_SOURCES}
        ${PARQUET_HEADERS} ${PARQUET_SOURCES} ${CDNS_HEADERS} ${CDNS_SOURCES})
Pavel Doležal's avatar
Pavel Doležal committed
109 110 111 112 113
    add_executable(dns-probe-af src/application/dp.cpp ${AF_FILES})
    target_link_libraries(dns-probe-af PUBLIC DNSProbe)
    install(TARGETS dns-probe-af RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

    set(BACKEND af)
114
    configure_file(${CMAKE_SOURCE_DIR}/src/application/dp-runner.sh ${CMAKE_BINARY_DIR}/dp-af @ONLY)
115
    configure_file(${CMAKE_SOURCE_DIR}/systemd/dns-probe@.service.in ${CMAKE_BINARY_DIR}/systemd/dns-probe-af@.service)
Pavel Doležal's avatar
Pavel Doležal committed
116
    install(PROGRAMS ${CMAKE_BINARY_DIR}/dp-af DESTINATION ${CMAKE_INSTALL_BINDIR})
117
    install(FILES ${CMAKE_SOURCE_DIR}/data-model/dns-probe.yml DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/dns-probe-af)
118
    install(FILES ${CMAKE_BINARY_DIR}/systemd/dns-probe-af@.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system)
119
    target_compile_definitions(dns-probe-af PUBLIC PROBE_CONFIG="${CMAKE_INSTALL_DIR}/${CMAKE_INSTALL_SYSCONFDIR}/dns-probe-af/dns-probe.yml")
Pavel Doležal's avatar
Pavel Doležal committed
120 121 122 123
endif ()

# Settings for DPDK version
if (DPDK_BACKEND)
124
    find_package(DPDK REQUIRED)
Pavel Doležal's avatar
Pavel Doležal committed
125 126 127 128

    file(GLOB DPDK_HEADERS CONFIGURE_DEPENDS src/dpdk/*.h)
    file(GLOB DPDK_SOURCES CONFIGURE_DEPENDS src/dpdk/*.cpp)

129 130
    set(DPDK_FILES ${DPDK_HEADERS} ${DPDK_SOURCES} ${PROBE_HEADERS} ${PROBE_SOURCES}
        ${PARQUET_HEADERS} ${PARQUET_SOURCES} ${CDNS_HEADERS} ${CDNS_SOURCES})
Pavel Doležal's avatar
Pavel Doležal committed
131
    add_executable(dns-probe-dpdk src/application/ddp.cpp ${DPDK_FILES})
132
    target_link_libraries(dns-probe-dpdk PUBLIC DNSProbe DPDK::DPDK)
Pavel Doležal's avatar
Pavel Doležal committed
133 134 135 136 137 138
    target_compile_definitions(dns-probe-dpdk PUBLIC USE_DPDK)

    if (DPDK_LEGACY_MEM)
        target_compile_definitions(dns-probe-dpdk PRIVATE DPDK_LEGACY_MEM)
    endif ()

139
    if (libdpdk_VERSION VERSION_LESS "18.05")
140 141
        target_compile_definitions(dns-probe-dpdk PRIVATE DPDK_LEGACY)
    endif()
Pavel Doležal's avatar
Pavel Doležal committed
142 143 144 145

    install(TARGETS dns-probe-dpdk RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

    set(BACKEND dpdk)
146
    configure_file(${CMAKE_SOURCE_DIR}/src/application/dp-runner.sh ${CMAKE_BINARY_DIR}/dp-dpdk @ONLY)
Pavel Doležal's avatar
Pavel Doležal committed
147
    install(PROGRAMS ${CMAKE_BINARY_DIR}/dp-dpdk DESTINATION ${CMAKE_INSTALL_BINDIR})
148 149 150
    configure_file(${CMAKE_SOURCE_DIR}/systemd/dns-probe@.service.in ${CMAKE_BINARY_DIR}/systemd/dns-probe-dpdk@.service)
    install(FILES ${CMAKE_SOURCE_DIR}/data-model/dns-probe.yml DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/dns-probe-dpdk)
    install(FILES ${CMAKE_BINARY_DIR}/systemd/dns-probe-dpdk@.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system)
151
    target_compile_definitions(dns-probe-dpdk PUBLIC PROBE_CONFIG="${CMAKE_INSTALL_DIR}/${CMAKE_INSTALL_SYSCONFDIR}/dns-probe-dpdk/dns-probe.yml")
Pavel Doležal's avatar
Pavel Doležal committed
152 153 154 155
endif ()

add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/Uninstall.cmake")

156 157 158 159 160
#Build collector
if (BUILD_COLLECTOR)
    add_subdirectory("collector")
endif()

Pavel Doležal's avatar
Pavel Doležal committed
161 162 163 164 165 166
#Add tests
enable_testing()
if (BUILD_TESTING)
    add_subdirectory(tests/gtests)
endif ()

167 168 169 170 171 172 173 174
#Add Doxygen documentation
if (BUILD_DOC)
    if (DOXYGEN_FOUND)
        set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
        set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

        configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

175
        add_custom_target(doxygen
176 177 178 179 180 181
            COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
            COMMENT "Generating Doxygen documentation"
            VERBATIM
        )
    else (DOXYGEN_FOUND)
182
        message("Install Doxygen to generate Doxygen documentation")
183
    endif(DOXYGEN_FOUND)
184 185

    add_subdirectory("doc")
186 187
endif(BUILD_DOC)