logswan

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

CMakeLists.txt (2489B)


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