logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

CMakeLists.txt (2731B)


      1 #
      2 # Logswan 2.1.13
      3 # Copyright (c) 2015-2022, Frederic Cambus
      4 # https://www.logswan.org
      5 #
      6 # Created:      2015-05-31
      7 # Last Updated: 2022-05-06
      8 #
      9 # Logswan is released under the BSD 2-Clause license.
     10 # See LICENSE file for details.
     11 #
     12 # SPDX-License-Identifier: BSD-2-Clause
     13 #
     14 
     15 cmake_minimum_required(VERSION 3.1)
     16 
     17 set(CMAKE_C_STANDARD 11)
     18 set(CMAKE_C_STANDARD_REQUIRED ON)
     19 set(CMAKE_C_EXTENSIONS OFF)
     20 
     21 project(logswan C)
     22 
     23 include(CheckFunctionExists)
     24 include(GNUInstallDirs)
     25 
     26 # Conditional build options
     27 set(ENABLE_SECCOMP 0 CACHE BOOL "Enable building with seccomp")
     28 
     29 # Check if system has pledge and strtonum
     30 list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_OPENBSD_SOURCE)
     31 check_function_exists(pledge HAVE_PLEDGE)
     32 check_function_exists(strtonum HAVE_STRTONUM)
     33 
     34 if(ENABLE_SECCOMP)
     35   # Check if system has seccomp
     36   message(STATUS "Looking for seccomp")
     37   find_path(SECCOMP NAMES "linux/seccomp.h")
     38   if(SECCOMP)
     39     message(STATUS "Looking for seccomp - found")
     40     add_definitions(-DHAVE_SECCOMP)
     41   else()
     42     message(STATUS "Looking for seccomp - not found")
     43   endif()
     44 endif(ENABLE_SECCOMP)
     45 
     46 # Additional include directories for compat functions + dependencies
     47 include_directories("compat")
     48 include_directories("deps/hll")
     49 
     50 # libmaxminddb
     51 find_path(GEOIP2_INCLUDE_DIRS maxminddb.h)
     52 find_library(GEOIP2_LIBRARIES NAMES maxminddb REQUIRED)
     53 include_directories(${GEOIP2_INCLUDE_DIRS})
     54 
     55 # Jansson
     56 find_path(JANSSON_INCLUDE_DIRS jansson.h)
     57 find_library(JANSSON_LIBRARIES NAMES jansson REQUIRED)
     58 include_directories(${JANSSON_INCLUDE_DIRS})
     59 
     60 set(DEPS deps/hll/hll.c deps/MurmurHash3/MurmurHash3.c)
     61 set(SRC src/logswan.c src/config.c src/continents.c src/countries.c
     62     src/output.c src/parse.c)
     63 
     64 if(NOT HAVE_PLEDGE)
     65   set(SRC ${SRC} compat/pledge.c)
     66 endif()
     67 
     68 if(NOT HAVE_STRTONUM)
     69   set(SRC ${SRC} compat/strtonum.c)
     70 endif()
     71 
     72 set(GEOIP2DIR ${CMAKE_INSTALL_PREFIX}/share/dbip
     73     CACHE PATH "Path to GeoIP2 databases")
     74 set(GEOIP2DB "dbip-country-lite.mmdb" CACHE PATH "GeoIP2 database file")
     75 
     76 add_definitions(-D_GNU_SOURCE -Wall -Wextra -pedantic)
     77 add_definitions(-DGEOIP2DIR="${GEOIP2DIR}/")
     78 add_definitions(-DGEOIP2DB="${GEOIP2DB}")
     79 add_executable(logswan ${SRC} ${DEPS})
     80 
     81 target_link_libraries(logswan ${GEOIP2_LIBRARIES} ${JANSSON_LIBRARIES} m)
     82 
     83 install(TARGETS logswan DESTINATION ${CMAKE_INSTALL_BINDIR})
     84 install(FILES logswan.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/)
     85 
     86 enable_testing()
     87 add_test(logswan logswan)
     88 add_test(usage logswan -h)
     89 add_test(version logswan -v)
     90 add_test(processing logswan ${PROJECT_SOURCE_DIR}/tests/logswan.log)
     91 add_test(invalid logswan ${PROJECT_SOURCE_DIR}/tests/invalid.log)
     92 add_test(geolocation logswan -g -d ${PROJECT_SOURCE_DIR}/tests/logswan.mmdb
     93          ${PROJECT_SOURCE_DIR}/tests/logswan.log)