summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-03-17 17:41:19 +0100
committerToni Uhlig <matzeton@googlemail.com>2021-03-17 17:41:19 +0100
commitc68c1750ba4b00096efab74829f5be7408261eed (patch)
tree679e9116516829ff04d49a23d5b56e4be1727789 /CMakeLists.txt
parent1c3ef69faa6927ac732a079c7f8efcb20bf1020e (diff)
Switched to CMake build system.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt102
1 files changed, 102 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 000000000..efd10b58e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,102 @@
+cmake_minimum_required(VERSION 3.13)
+project(nDPId C)
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+find_package(PkgConfig REQUIRED)
+
+option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF)
+option(ENABLE_SANITIZER_THREAD "Enable TSAN (does not work together with ASAN)." OFF)
+option(ENABLE_MEMORY_PROFILING "Enable dynamic memory tracking." OFF)
+option(BUILD_EXAMPLES "Build C examples." ON)
+
+set(STATIC_LIBNDPI_INSTALLDIR "" CACHE STRING "Path to a installation directory of libnDPI e.g. /opt/libnDPI/usr")
+
+add_executable(nDPId nDPId.c utils.c)
+add_executable(nDPIsrvd nDPIsrvd.c utils.c)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -DJSMN_STATIC=1 -DJSMN_STRICT=1")
+
+if(ENABLE_MEMORY_PROFILING)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_MEMORY_PROFILING=1 -Duthash_malloc=nDPIsrvd_uthash_malloc -Duthash_free=nDPIsrvd_uthash_free")
+endif()
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3 -fno-omit-frame-pointer -fno-inline")
+endif()
+
+if(ENABLE_SANITIZER AND ENABLE_SANITIZER_THREAD)
+ message(STATUS_FATAL "ENABLE_SANITIZER and ENABLE_SANITIZER_THREAD can not be used together!")
+endif()
+
+if(ENABLE_SANITIZER)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=enum -fsanitize=leak")
+endif()
+
+if(ENABLE_SANITIZER_THREAD)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fsanitize=enum -fsanitize=thread")
+endif()
+
+if(NOT STATIC_LIBNDPI_INSTALLDIR STREQUAL "")
+ option(NDPI_WITH_GCRYPT "Link static libndpi library against libgcrypt." ON)
+ option(NDPI_WITH_PCRE "Link static libndpi library against libpcre." OFF)
+ option(NDPI_WITH_MAXMINDDB "Link static libndpi library against libmaxminddb." ON)
+
+ if(NDPI_WITH_GCRYPT)
+ find_package(GCRYPT "1.4.2" REQUIRED)
+ endif()
+
+ if(NDPI_WITH_PCRE)
+ pkg_check_modules(PCRE REQUIRED libpcre)
+ endif()
+ if(NDPI_WITH_MAXMINDDB)
+ pkg_check_modules(MAXMINDDB REQUIRED libmaxminddb)
+ endif()
+
+ find_package(PCAP "1.8.1" REQUIRED)
+ target_compile_options(nDPId PRIVATE "-pthread")
+ target_include_directories(nDPId PRIVATE "${STATIC_LIBNDPI_INSTALLDIR}/include/ndpi")
+ target_link_libraries(nDPId "${STATIC_LIBNDPI_INSTALLDIR}/lib/libndpi.a"
+ "${GCRYPT_LIBRARY}" "${PCAP_LIBRARY}"
+ "${pkgcfg_lib_MAXMINDDB_maxminddb}" "-pthread")
+ target_include_directories(nDPIsrvd PRIVATE
+ "${CMAKE_SOURCE_DIR}"
+ "${CMAKE_SOURCE_DIR}/dependencies"
+ "${CMAKE_SOURCE_DIR}/dependencies/jsmn"
+ "${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
+else()
+ pkg_check_modules(NDPI "3.6.0" REQUIRED)
+endif()
+
+if(BUILD_EXAMPLES)
+ add_executable(nDPIsrvd-collectd examples/c-collectd/c-collectd.c)
+ target_include_directories(nDPIsrvd-collectd PRIVATE
+ "${CMAKE_SOURCE_DIR}"
+ "${CMAKE_SOURCE_DIR}/dependencies"
+ "${CMAKE_SOURCE_DIR}/dependencies/jsmn"
+ "${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
+ add_executable(nDPIsrvd-captured examples/c-captured/c-captured.c utils.c)
+ target_include_directories(nDPIsrvd-captured PRIVATE
+ "${CMAKE_SOURCE_DIR}"
+ "${CMAKE_SOURCE_DIR}/dependencies"
+ "${CMAKE_SOURCE_DIR}/dependencies/jsmn"
+ "${CMAKE_SOURCE_DIR}/dependencies/uthash/src")
+ target_link_libraries(nDPIsrvd-captured "${PCAP_LIBRARY}")
+ add_executable(nDPIsrvd-json-dump examples/c-json-stdout/c-json-stdout.c)
+ target_include_directories(nDPIsrvd-json-dump PRIVATE
+ "${CMAKE_SOURCE_DIR}"
+ "${CMAKE_SOURCE_DIR}/dependencies"
+ "${CMAKE_SOURCE_DIR}/dependencies/jsmn")
+endif()
+
+message(STATUS "--------------------------")
+message(STATUS "CMAKE_BUILD_TYPE.........: ${CMAKE_BUILD_TYPE}")
+message(STATUS "CMAKE_C_FLAGS............: ${CMAKE_C_FLAGS}")
+message(STATUS "ENABLE_SANITIZER.........: ${ENABLE_SANITIZER}")
+message(STATUS "ENABLE_SANITIZER_THREAD..: ${ENABLE_SANITIZER_THREAD}")
+message(STATUS "ENABLE_MEMORY_PROFILING..: ${ENABLE_MEMORY_PROFILING}")
+message(STATUS "STATIC_LIBNDPI_INSTALLDIR: ${STATIC_LIBNDPI_INSTALLDIR}")
+if(NOT STATIC_LIBNDPI_INSTALLDIR STREQUAL "")
+message(STATUS "`- NDPI_WITH_GCRYPT......: ${NDPI_WITH_GCRYPT}")
+message(STATUS "`- NDPI_WITH_PCRE........: ${NDPI_WITH_PCRE}")
+message(STATUS "`- NDPI_WITH_MAXMINDDB...: ${NDPI_WITH_MAXMINDDB}")
+endif()
+message(STATUS "--------------------------")