/span> magic.h INCLUDE_SUFFIXES include/libmagic ROOT ${LIBMAGIC_ROOT_DIR} MODULES magic) ProcessPackage(LIBZ LIBRARY z INCLUDE zlib.h INCLUDE_SUFFIXES include/zlib ROOT ${LIBZ_ROOT_DIR} MODULES z) IF(ENABLE_HYPERSCAN MATCHES "ON") ProcessPackage(HYPERSCAN LIBRARY hs INCLUDE hs.h INCLUDE_SUFFIXES hs include/hs ROOT ${HYPERSCAN_ROOT_DIR} MODULES libhs) SET(WITH_HYPERSCAN 1) ENDIF() IF (ENABLE_FANN MATCHES "ON") ProcessPackage(FANN LIBRARY fann INCLUDE fann.h INCLUDE_SUFFIXES include/fann ROOT ${FANN_ROOT_DIR} MODULES fann) SET(WITH_FANN 1) ENDIF () IF (ENABLE_GD MATCHES "ON") ProcessPackage(GD LIBRARY gd INCLUDE gd.h INCLUDE_SUFFIXES include/gd include/libgd ROOT ${GD_ROOT_DIR} MODULES gd) LIST(APPEND CMAKE_REQUIRED_INCLUDES "${GD_INCLUDE}") LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${GD_LIBRARY}") CHECK_SYMBOL_EXISTS(gdImageSetInterpolationMethod gd.h GD_INTERPOLATION) CHECK_SYMBOL_EXISTS(gdImageScale gd.h GD_SCALE) CHECK_SYMBOL_EXISTS(gdImageGrayScale gd.h GD_GRAYSCALE) CHECK_SYMBOL_EXISTS(gdImageCreateFromJpegPtr gd.h GD_JPEG) CHECK_SYMBOL_EXISTS(gdImageCreateFromPngPtr gd.h GD_PNG) CHECK_SYMBOL_EXISTS(gdImageCreateFromBmpPtr gd.h GD_BMP) CHECK_SYMBOL_EXISTS(gdImageCreateFromGifPtr gd.h GD_GIF) IF(GD_INTERPOLATION AND GD_SCALE AND GD_GRAYSCALE AND GD_JPEG AND GD_PNG AND GD_GIF AND GD_BMP) SET(USABLE_GD 1) ELSE() MESSAGE(STATUS "Libgd is found but it is unusable") ENDIF() ENDIF () #Check for openssl (required for dkim) SET(HAVE_OPENSSL 1) # Google performance tools IF(ENABLE_GPERF_TOOLS MATCHES "ON") ProcessPackage(GPERF LIBRARY profiler INCLUDE profiler.h INCLUDE_SUFFIXES include/google ROOT ${GPERF_ROOT_DIR}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer") SET(WITH_GPERF_TOOLS 1) ENDIF(ENABLE_GPERF_TOOLS MATCHES "ON") IF (ENABLE_HYPERSCAN MATCHES "ON") IF(${HYPERSCAN_LIBRARY} MATCHES ".*[.]a$" OR STATIC_HYPERSCAN) ENABLE_LANGUAGE(CXX) SET(USE_CXX_LINKER 1) ENDIF() ENDIF() # Process with warn flags SET(CMAKE_C_WARN_FLAGS "") CHECK_C_COMPILER_FLAG(-Wall SUPPORT_WALL) CHECK_C_COMPILER_FLAG(-W SUPPORT_W) CHECK_C_COMPILER_FLAG(-Wpointer-arith SUPPORT_WPOINTER) CHECK_C_COMPILER_FLAG(-Wno-unused-parameter SUPPORT_WPARAM) CHECK_C_COMPILER_FLAG(-Wno-unused-function SUPPORT_WFUNCTION) CHECK_C_COMPILER_FLAG(-Wunused-variable SUPPORT_WUNUSED_VAR) CHECK_C_COMPILER_FLAG(-Wno-pointer-sign SUPPORT_WPOINTER_SIGN) CHECK_C_COMPILER_FLAG(-Wno-sign-compare SUPPORT_WSIGN_COMPARE) CHECK_C_COMPILER_FLAG(-Wstrict-prototypes SUPPORT_WSTRICT_PROTOTYPES) CHECK_C_COMPILER_FLAG(-pedantic SUPPORT_PEDANTIC_FLAG) CHECK_C_COMPILER_FLAG(-Wno-unused-const-variable SUPPORT_WNO_UNUSED_CONST) # GCC 6 specific CHECK_C_COMPILER_FLAG(-Wnull-dereference SUPPORT_WNULL_DEREFERENCE) CHECK_C_COMPILER_FLAG(-Wduplicated-cond SUPPORT_WDUPLICATED_COND) # GCC 7 specific CHECK_C_COMPILER_FLAG(-Wimplicit-fallthrough SUPPORT_WIMPLICIT_FALLTHROUGH) IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES SunPro) CHECK_C_COMPILER_FLAG("-std=c11" SUPPORT_STD11_FLAG) CHECK_C_COMPILER_FLAG("-std=c99" SUPPORT_STD99_FLAG) ENDIF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES SunPro) IF(SUPPORT_W) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -W") ENDIF(SUPPORT_W) IF(SUPPORT_WALL) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wall") ENDIF(SUPPORT_WALL) IF(SUPPORT_WPOINTER) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wpointer-arith") ENDIF(SUPPORT_WPOINTER) IF(SUPPORT_WPARAM) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-parameter") ENDIF(SUPPORT_WPARAM) IF(SUPPORT_WFUNCTION) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-function") ENDIF(SUPPORT_WFUNCTION) IF(SUPPORT_WUNUSED_VAR) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wunused-variable") ENDIF(SUPPORT_WUNUSED_VAR) IF(SUPPORT_WPOINTER_SIGN) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-pointer-sign") ENDIF(SUPPORT_WPOINTER_SIGN) IF(SUPPORT_WSTRICT_PROTOTYPES) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wstrict-prototypes") ENDIF(SUPPORT_WSTRICT_PROTOTYPES) #IF(SUPPORT_PEDANTIC_FLAG) # SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -pedantic") #ENDIF(SUPPORT_PEDANTIC_FLAG) IF(SUPPORT_WNULL_DEREFERENCE) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wnull-dereference") ENDIF() IF(SUPPORT_WDUPLICATED_COND) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wduplicated-cond") ENDIF() IF(SUPPORT_WLOGICAL_OP) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wlogical-op") ENDIF() IF(SUPPORT_WNO_UNUSED_CONST) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-const-variable") ENDIF() IF(SUPPORT_WSIGN_COMPARE) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-sign-compare") ENDIF() IF(SUPPORT_STD11_FLAG) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c11") ELSE(SUPPORT_STD11_FLAG) IF(SUPPORT_STD99_FLAG) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c99") ENDIF(SUPPORT_STD99_FLAG) ENDIF(SUPPORT_STD11_FLAG) IF(SUPPORT_WIMPLICIT_FALLTHROUGH) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-implicit-fallthrough") ENDIF(SUPPORT_WIMPLICIT_FALLTHROUGH) CHECK_C_COMPILER_FLAG(-fPIC SUPPORT_FPIC) IF(SUPPORT_FPIC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") ENDIF(SUPPORT_FPIC) # Optimization flags IF(NOT CMAKE_C_OPT_FLAGS) IF(ENABLE_OPTIMIZATION MATCHES "ON") CHECK_C_COMPILER_FLAG(-flto SUPPORT_FLTO) IF(SUPPORT_FLTO) IF(NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB) FIND_PROGRAM(CMAKE_GCC_AR NAMES "gcc-ar") FIND_PROGRAM(CMAKE_GCC_RANLIB NAMES "gcc-ranlib") MARK_AS_ADVANCED(CMAKE_GCC_AR CMAKE_GCC_RANLIB) ENDIF() IF(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB) SET(CMAKE_C_OPT_FLAGS "-g -O3 -fstrict-aliasing -flto") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") SET(CMAKE_C_ARCHIVE_CREATE "${CMAKE_GCC_AR} cr <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_C_ARCHIVE_APPEND "${CMAKE_GCC_AR} r <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_C_ARCHIVE_FINISH "${CMAKE_GCC_RANLIB} <TARGET>") SET(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_GCC_AR} cr <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_CXX_ARCHIVE_APPEND "${CMAKE_GCC_AR} r <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_CXX_ARCHIVE_FINISH "${CMAKE_GCC_RANLIB} <TARGET>") ENDIF() ELSE() SET(CMAKE_C_OPT_FLAGS "-g -O3 -fstrict-aliasing") ENDIF() ELSE(ENABLE_OPTIMIZATION MATCHES "ON") IF(ENABLE_FULL_DEBUG MATCHES "ON") SET(CMAKE_C_OPT_FLAGS "-g -O0 -fstrict-aliasing") ELSE(ENABLE_FULL_DEBUG MATCHES "ON") SET(CMAKE_C_OPT_FLAGS "-g -O2 -fstrict-aliasing") ENDIF(ENABLE_FULL_DEBUG MATCHES "ON") ENDIF(ENABLE_OPTIMIZATION MATCHES "ON") ENDIF(NOT CMAKE_C_OPT_FLAGS) IF(ENABLE_COVERAGE) SET(CMAKE_C_OPT_FLAGS "-g -O0 -fno-strict-aliasing") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") ENDIF(ENABLE_COVERAGE) IF(ENABLE_LUA_TRACE) SET(WITH_LUA_TRACE 1) ENDIF(ENABLE_LUA_TRACE) SET(CMAKE_C_FLAGS "${CMAKE_C_OPT_FLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS}") ADD_DEFINITIONS(-DHAVE_CONFIG_H) # Check platform specific includes CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H) CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H) CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H) CHECK_INCLUDE_FILES(math.h HAVE_MATH_H) CHECK_INCLUDE_FILES(stdio.h HAVE_STDIO_H) CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H) CHECK_INCLUDE_FILES(string.h HAVE_STRING_H) CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H) CHECK_INCLUDE_FILES(time.h HAVE_TIME_H) CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) CHECK_INCLUDE_FILES(sysexits.h HAVE_SYSEXITS_H) CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H) CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H) CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H) CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H) CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H) CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H) CHECK_INCLUDE_FILES(sys/queue.h HAVE_SYS_QUEUE_H) CHECK_INCLUDE_FILES(sys/socket.h HAVE_SYS_SOCKET_H) CHECK_INCLUDE_FILES(sys/mman.h HAVE_SYS_MMAN_H) CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN_H) CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H) CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H) CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H) CHECK_INCLUDE_FILES(sys/cdefs.h HAVE_SYS_CDEFS_H) CHECK_INCLUDE_FILES(sys/file.h HAVE_SYS_FILE_H) CHECK_INCLUDE_FILES(sys/utsname.h HAVE_SYS_UTSNAME_H) CHECK_INCLUDE_FILES(sys/resource.h HAVE_SYS_RESOURCE_H) CHECK_INCLUDE_FILES(netinet/in.h HAVE_NETINET_IN_H) CHECK_INCLUDE_FILES(netinet/tcp.h HAVE_NETINET_TCP_H) CHECK_INCLUDE_FILES(arpa/inet.h HAVE_ARPA_INET_H) CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H) CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H) CHECK_INCLUDE_FILES(siginfo.h HAVE_SIGINFO_H) CHECK_INCLUDE_FILES(locale.h HAVE_LOCALE_H) CHECK_INCLUDE_FILES(libgen.h HAVE_LIBGEN_H) CHECK_INCLUDE_FILES(search.h HAVE_SEARCH_H) CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H) CHECK_INCLUDE_FILES(grp.h HAVE_GRP_H) CHECK_INCLUDE_FILES(glob.h HAVE_GLOB_H) CHECK_INCLUDE_FILES(poll.h HAVE_POLL_H) CHECK_INCLUDE_FILES(readpassphrase.h HAVE_READPASSPHRASE_H) CHECK_INCLUDE_FILES(termios.h HAVE_TERMIOS_H) CHECK_INCLUDE_FILES(paths.h HAVE_PATHS_H) CHECK_INCLUDE_FILES(ctype.h HAVE_CTYPE_H) CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H) CHECK_INCLUDE_FILES(linux/falloc.h HAVE_LINUX_FALLOC_H) CHECK_INCLUDE_FILES(sys/eventfd.h HAVE_SYS_EVENTFD_H) CHECK_INCLUDE_FILES(aio.h HAVE_AIO_H) CHECK_INCLUDE_FILES(libaio.h HAVE_LIBAIO_H) CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) CHECK_INCLUDE_FILES(cpuid.h HAVE_CPUID_H) CHECK_INCLUDE_FILES(dirent.h HAVE_DIRENT_H) CHECK_INCLUDE_FILES(stropts.h HAVE_STROPS_H) CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H) CHECK_INCLUDE_FILES(ucontext.h HAVE_UCONTEXT_H) CHECK_INCLUDE_FILES(sys/ucontext.h HAVE_SYS_UCONTEXT_H) # OSX specific # Check platform API CHECK_FUNCTION_EXISTS(setproctitle HAVE_SETPROCTITLE) CHECK_FUNCTION_EXISTS(getpagesize HAVE_GETPAGESIZE) CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP) CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK) CHECK_FUNCTION_EXISTS(wait4 HAVE_WAIT4) CHECK_FUNCTION_EXISTS(waitpid HAVE_WAITPID) CHECK_FUNCTION_EXISTS(flock HAVE_FLOCK) CHECK_FUNCTION_EXISTS(tanhl HAVE_TANHL) CHECK_FUNCTION_EXISTS(tanh HAVE_TANH) CHECK_FUNCTION_EXISTS(expl HAVE_EXPL) CHECK_FUNCTION_EXISTS(exp2l HAVE_EXP2L) CHECK_FUNCTION_EXISTS(sendfile HAVE_SENDFILE) CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP) CHECK_FUNCTION_EXISTS(setitimer HAVE_SETITIMER) CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON) CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME) CHECK_FUNCTION_EXISTS(memset_s HAVE_MEMSET_S) CHECK_FUNCTION_EXISTS(explicit_bzero HAVE_EXPLICIT_BZERO) CHECK_C_SOURCE_COMPILES( "#include <stddef.h> void cmkcheckweak() __attribute__((weak)); int main(int argc, char** argv) { return cmkcheckweak == NULL; }" HAVE_WEAK_SYMBOLS) CHECK_C_SOURCE_COMPILES( "#include <time.h> extern char *tzname[2]; extern long timezone; extern int daylight; int main(int argc, char** argv) { tzset(); return timezone; }" HAVE_SANE_TZSET) IF(WITH_ICONV) CHECK_C_SOURCE_COMPILES(" #include <iconv.h> int main(){ iconv_t conv = 0; const char* in = 0; size_t ilen = 0; char* out = 0; size_t olen = 0; iconv(conv, &in, &ilen, &out, &olen); return 0; } " ICONV_SECOND_ARGUMENT_IS_CONST) ENDIF(WITH_ICONV) # Check macros CHECK_SYMBOL_EXISTS(PATH_MAX limits.h HAVE_PATH_MAX) CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN) CHECK_SYMBOL_EXISTS(MAP_SHARED sys/mman.h HAVE_MMAP_SHARED) CHECK_SYMBOL_EXISTS(MAP_ANON sys/mman.h HAVE_MMAP_ANON) CHECK_SYMBOL_EXISTS(MAP_NOCORE sys/mman.h HAVE_MMAP_NOCORE) CHECK_SYMBOL_EXISTS(O_DIRECT fcntl.h HAVE_O_DIRECT) CHECK_SYMBOL_EXISTS(IPV6_V6ONLY "sys/socket.h;netinet/in.h" HAVE_IPV6_V6ONLY) CHECK_SYMBOL_EXISTS(posix_fadvise fcntl.h HAVE_FADVISE) CHECK_SYMBOL_EXISTS(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) CHECK_SYMBOL_EXISTS(fallocate fcntl.h HAVE_FALLOCATE) CHECK_SYMBOL_EXISTS(fdatasync unistd.h HAVE_FDATASYNC) CHECK_SYMBOL_EXISTS(_SC_NPROCESSORS_ONLN unistd.h HAVE_SC_NPROCESSORS_ONLN) CHECK_SYMBOL_EXISTS(setbit sys/param.h PARAM_H_HAS_BITSET) CHECK_SYMBOL_EXISTS(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO) CHECK_SYMBOL_EXISTS(sched_yield "sched.h" HAVE_SCHED_YIELD) CHECK_SYMBOL_EXISTS(__get_cpuid "cpuid.h" HAVE_GET_CPUID) CHECK_SYMBOL_EXISTS(nftw "sys/types.h;ftw.h" HAVE_NFTW) IF(ENABLE_PCRE2 MATCHES "ON") LIST(APPEND CMAKE_REQUIRED_INCLUDES "${PCRE_INCLUDE}") CHECK_SYMBOL_EXISTS(PCRE2_CONFIG_JIT "pcre2.h" HAVE_PCRE_JIT) ELSE() LIST(APPEND CMAKE_REQUIRED_INCLUDES "${PCRE_INCLUDE}") CHECK_SYMBOL_EXISTS(PCRE_CONFIG_JIT "pcre.h" HAVE_PCRE_JIT) ENDIF() CHECK_SYMBOL_EXISTS(SOCK_SEQPACKET "sys/types.h;sys/socket.h" HAVE_SOCK_SEQPACKET) CHECK_SYMBOL_EXISTS(I_SETSIG "sys/types.h;sys/ioctl.h" HAVE_SETSIG) CHECK_SYMBOL_EXISTS(O_ASYNC "sys/types.h;sys/fcntl.h" HAVE_OASYNC) CHECK_SYMBOL_EXISTS(O_NOFOLLOW "sys/types.h;sys/fcntl.h" HAVE_ONOFOLLOW) CHECK_SYMBOL_EXISTS(O_CLOEXEC "sys/types.h;sys/fcntl.h" HAVE_OCLOEXEC) LIST(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSL_INCLUDE}") CHECK_SYMBOL_EXISTS(SSL_set_tlsext_host_name "openssl/ssl.h" HAVE_SSL_TLSEXT_HOSTNAME) CHECK_SYMBOL_EXISTS(dirfd "sys/types.h;unistd.h;dirent.h" HAVE_DIRFD) CHECK_SYMBOL_EXISTS(fpathconf "sys/types.h;unistd.h" HAVE_FPATHCONF) CHECK_SYMBOL_EXISTS(sigaltstack "signal.h" HAVE_SIGALTSTACK) CHECK_SYMBOL_EXISTS(clock_getcpuclockid "sys/types.h;time.h" HAVE_CLOCK_GETCPUCLOCKID) CHECK_SYMBOL_EXISTS(RUSAGE_SELF "sys/types.h;sys/resource.h" HAVE_RUSAGE_SELF) IF(ENABLE_PCRE2 MATCHES "ON") IF(HAVE_PCRE_JIT) SET(HAVE_PCRE_JIT_FAST 1) ENDIF() ELSE() LIST(APPEND CMAKE_REQUIRED_INCLUDES "${PCRE_INCLUDE}") IF(PCRE_LIBRARY_PATH) SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};-L${PCRE_LIBRARY_PATH};${PCRE_LIBRARY}") ELSE(PCRE_LIBRARY_PATH) SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};-lpcre") ENDIF(PCRE_LIBRARY_PATH) # Some PCRE implementations are lacking of pcre_jit_exec fast path SET(_PCRE_FAST_TEST " #include \"pcre.h\" int main (void) { int rc; int ovector[30]; pcre *re; pcre_extra *extra; pcre_jit_stack *jit_stack; re = pcre_compile(\"abc\", 0, NULL, NULL, NULL); extra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, NULL); jit_stack = pcre_jit_stack_alloc(32*1024, 512*1024); pcre_assign_jit_stack(extra, NULL, jit_stack); rc = pcre_jit_exec(re, extra, \"abc\", 3, 0, 0, ovector, 30, jit_stack); return rc; } ") CHECK_C_SOURCE_COMPILES("${_PCRE_FAST_TEST}" HAVE_PCRE_JIT_FAST) IF(HAVE_PCRE_JIT_FAST) MESSAGE(STATUS "pcre_jit_exec is supported") ELSE(HAVE_PCRE_JIT_FAST) MESSAGE(STATUS "pcre_jit_exec is -NOT- supported") ENDIF(HAVE_PCRE_JIT_FAST) ENDIF() FILE(WRITE ${CMAKE_BINARY_DIR}/pthread_setpshared.c " #include <pthread.h> #include <stdlib.h> int main (void) { pthread_mutexattr_t mattr; if (pthread_mutexattr_init(&mattr) != 0) return 0; if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) return 0; if (pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST) != 0) return 0; return 1; } ") TRY_RUN(_CAN_RUN _CAN_COMPILE "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/pthread_setpshared.c" CMAKE_FLAGS CMAKE_C_FLAGS="-pthread") IF(_CAN_RUN EQUAL 1) SET(HAVE_PTHREAD_PROCESS_SHARED 1 CACHE INTERNAL "") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "-lpthread") ENDIF(_CAN_RUN EQUAL 1) IF(HAVE_PTHREAD_PROCESS_SHARED) MESSAGE(STATUS "pthread_mutexattr_setpshared is supported") ELSE(HAVE_PTHREAD_PROCESS_SHARED) MESSAGE(STATUS "pthread_mutexattr_setpshared is -NOT- supported") ENDIF(HAVE_PTHREAD_PROCESS_SHARED) IF(NOT HAVE_GETADDRINFO) MESSAGE(FATAL_ERROR "Your system does not support getaddrinfo call, please consider upgrading it to run rspamd") ENDIF(NOT HAVE_GETADDRINFO) IF(HAVE_SIGINFO_H) CHECK_SYMBOL_EXISTS(SA_SIGINFO "signal.h;siginfo.h" HAVE_SA_SIGINFO) ELSE(HAVE_SIGINFO_H) CHECK_SYMBOL_EXISTS(SA_SIGINFO "signal.h" HAVE_SA_SIGINFO) ENDIF(HAVE_SIGINFO_H) # Some hack for libevent 2.0 CHECK_C_SOURCE_COMPILES ("#include <event.h> #if _EVENT_NUMERIC_VERSION < 0x02000000 #error Unsupported #endif int main() { return 0;}" HAVE_LIBEVENT2) IF(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS") IF(HAVE_CLOCK_GETTIME) CHECK_SYMBOL_EXISTS(CLOCK_PROCESS_CPUTIME_ID time.h HAVE_CLOCK_PROCESS_CPUTIME_ID) CHECK_SYMBOL_EXISTS(CLOCK_VIRTUAL time.h HAVE_CLOCK_VIRTUAL) ELSE(HAVE_CLOCK_GETTIME) CHECK_INCLUDE_FILES(sys/timeb.h HAVE_SYS_TIMEB_H) ENDIF(HAVE_CLOCK_GETTIME) # Check asm pause instruction CHECK_C_SOURCE_COMPILES ("#include <sys/types.h> int main (int argc, char **argv) { __asm __volatile(\"pause\"); return 0; }" HAVE_ASM_PAUSE) ENDIF(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS") CHECK_C_SOURCE_RUNS(" #include <stdbool.h> int main(int argc, char **argv) { int a = 0, b = 0; if (__atomic_compare_exchange_n(&a, &b, 1, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED)) { return 0; } return -1; } " HAVE_ATOMIC_BUILTINS) IF(NOT HAVE_ATOMIC_BUILTINS) MESSAGE(STATUS "atomic builtins are -NOT- supported") ELSE() MESSAGE(STATUS "atomic builtins are supported") ENDIF() CHECK_C_SOURCE_RUNS(" #include <x86intrin.h> int main(int argc, char **argv) { __builtin_ia32_lfence (); if (__builtin_ia32_rdtsc()) { return 0; } return -1; } " HAVE_RDTSC) IF(NOT HAVE_RDTSC) MESSAGE(STATUS "rdtsc intrinsic is -NOT- supported") ELSE() MESSAGE(STATUS "rdtsc intrinsic is supported") ENDIF() IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") # In linux, we need to mount /run/shm to test which could be unavailable # on a build system. On the other hand, we know that linux has stupid # but compatible shmem support, so we assume this macro as true SET(HAVE_SANE_SHMEM 1) ELSE() CHECK_C_SOURCE_RUNS(" #include <sys/mman.h> #include <fcntl.h> #include <unistd.h> #define TEST_NAME \"/test-shmem-work\" int main (int argc, char **argv) { int fd; fd = shm_open (TEST_NAME, O_RDWR | O_CREAT | O_EXCL, 00600); if (fd == -1) { return -1; } if (ftruncate (fd, 100) == -1) { shm_unlink (TEST_NAME); close (fd); return -1; } if (ftruncate (fd, 200) == -1) { shm_unlink (TEST_NAME); close (fd); return -1; } if (ftruncate (fd, 300) == -1) { shm_unlink (TEST_NAME); close (fd); return -1; } close (fd); shm_unlink (TEST_NAME); return 0; } " HAVE_SANE_SHMEM) IF(NOT HAVE_SANE_SHMEM) MESSAGE(STATUS "shmem support is NOT compatible with POSIX") ELSE() MESSAGE(STATUS "shmem support is compatible with POSIX") ENDIF() ENDIF() # Check queue.h compatibility IF(NOT HAVE_COMPATIBLE_QUEUE_H) INCLUDE_DIRECTORIES(compat) ENDIF(NOT HAVE_COMPATIBLE_QUEUE_H) IF(ENABLE_URL_INCLUDE MATCHES "ON") FIND_LIBRARY(LIBFETCH_LIBRARY HINTS "${RSPAMD_SEARCH_PATH}" NAMES fetch PATHS PATH_SUFFIXES lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS} DOC "Path where the libfetch library can be found") IF(LIBFETCH_LIBRARY) FIND_FILE(HAVE_FETCH_H HINTS "${RSPAMD_SEARCH_PATH}" NAMES fetch.h PATH_SUFFIXES include PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS} DOC "Path to libfetch header") ELSE(LIBFETCH_LIBRARY) # Try to find libcurl ProcessPackage(CURL LIBRARY curl INCLUDE curl.h INCLUDE_SUFFIXES include/curl ROOT ${CURL_ROOT}) IF(NOT WITH_CURL) MESSAGE(WARNING "Neither libcurl nor libfetch were found, no support of URL includes in configuration") ENDIF(NOT WITH_CURL) ENDIF(LIBFETCH_LIBRARY) ENDIF(ENABLE_URL_INCLUDE MATCHES "ON") IF(NOT DESTDIR) SET(DESTDIR $ENV{DESTDIR}) ENDIF(NOT DESTDIR) ################################ SUBDIRS SECTION ########################### ADD_SUBDIRECTORY(contrib/hiredis) SET(WITH_HIREDIS 1) INCLUDE_DIRECTORIES(BEFORE "${CMAKE_SOURCE_DIR}/contrib/hiredis") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES ucl) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rdns) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES ottery) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES event) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES xxhash) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-actrie) IF(HAVE_FETCH_H) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES fetch) ENDIF(HAVE_FETCH_H) IF(WITH_DB) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES db) ENDIF(WITH_DB) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${LUA_LIBRARY}") IF(GLIB_COMPAT) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES glibadditions) ENDIF(GLIB_COMPAT) ADD_SUBDIRECTORY(contrib/xxhash) ADD_SUBDIRECTORY(contrib/cdb) ADD_SUBDIRECTORY(contrib/http-parser) ADD_SUBDIRECTORY(contrib/lc-btrie) ADD_SUBDIRECTORY(contrib/libottery) ADD_SUBDIRECTORY(contrib/zstd) IF(ENABLE_SNOWBALL MATCHES "ON") ADD_SUBDIRECTORY(contrib/snowball) SET(WITH_SNOWBALL 1) ENDIF() ADD_SUBDIRECTORY(contrib/libucl) ADD_SUBDIRECTORY(contrib/librdns) ADD_SUBDIRECTORY(contrib/aho-corasick) ADD_SUBDIRECTORY(contrib/lua-lpeg) ADD_SUBDIRECTORY(contrib/linenoise) ADD_SUBDIRECTORY(contrib/t1ha) IF (ENABLE_SNOWBALL MATCHES "ON") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES stemmer) ENDIF() LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-hiredis) IF(ENABLE_HYPERSCAN MATCHES "OFF") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-actrie) ENDIF() LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-t1ha) IF(ENABLE_CLANG_PLUGIN MATCHES "ON") ADD_SUBDIRECTORY(clang-plugin) ENDIF() IF(ENABLE_TORCH MATCHES "ON") IF(WITH_LUAJIT) ADD_SUBDIRECTORY(contrib/lua-torch/paths) ADD_SUBDIRECTORY(contrib/lua-torch/torch7) ADD_SUBDIRECTORY(contrib/lua-torch/nn) ADD_SUBDIRECTORY(contrib/lua-torch/optim) ADD_SUBDIRECTORY(contrib/lua-torch/decisiontree) SET(WITH_TORCH 1) ELSE() MESSAGE(FATAL_ERROR "Cannot enable torch without luajit") ENDIF() ENDIF() ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(utils) ############################ TARGETS SECTION ############################### CONFIGURE_FILE(config.h.in src/config.h) ADD_DEFINITIONS("HAVE_CONFIG_H") ##################### INSTALLATION ########################################## # Binaries # Configs INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${CONFDIR})") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${EXAMPLESDIR})") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/lua)") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${RULESDIR})") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR})") # Install configs only if they are unchanged LIST(LENGTH CONFFILES CONFLIST_COUNT) MATH(EXPR CONFLIST_MAX ${CONFLIST_COUNT}-1) FILE(GLOB_RECURSE CONF_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/conf" "${CMAKE_CURRENT_SOURCE_DIR}/conf/*" ) FOREACH(CONF_FILE ${CONF_FILES}) GET_FILENAME_COMPONENT(_rp ${CONF_FILE} PATH) INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${CONFDIR}/${_rp})") INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/conf/${CONF_FILE}" DESTINATION ${CONFDIR}/${_rp}) ENDFOREACH(CONF_FILE) SET(MAIN_CONF "conf/rspamd.conf") IF(BUILD_PORT) INSTALL_IF_NOT_EXISTS(${MAIN_CONF} ${CONFDIR} "rspamd.conf" ".sample") ELSE(BUILD_PORT) INSTALL_IF_NOT_EXISTS(${MAIN_CONF} ${CONFDIR} "rspamd.conf" "") ENDIF(BUILD_PORT) IF(INSTALL_EXAMPLES MATCHES "ON") INSTALL(FILES ${MAIN_CONF} DESTINATION ${EXAMPLESDIR}) ENDIF(INSTALL_EXAMPLES MATCHES "ON") # Lua plugins FILE(GLOB LUA_PLUGINS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua" "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua/*.lua" ) FOREACH(LUA_PLUGIN ${LUA_PLUGINS}) GET_FILENAME_COMPONENT(_rp ${LUA_PLUGIN} PATH) INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/lua/${_rp})") INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${PLUGINSDIR}/lua/${_rp}) ENDFOREACH(LUA_PLUGIN) # Install TLD list INSTALL(FILES "contrib/publicsuffix/effective_tld_names.dat" DESTINATION "${PLUGINSDIR}") # Install languages data INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/languages)") FILE(GLOB LANGUAGES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/languages-data/*.json") FOREACH(_LANG ${LANGUAGES}) INSTALL(FILES "${_LANG}" DESTINATION ${PLUGINSDIR}/languages) ENDFOREACH() INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/languages-data/stop_words" DESTINATION ${PLUGINSDIR}/languages) # Lua config FILE(GLOB_RECURSE LUA_CONFIGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/rules" "${CMAKE_CURRENT_SOURCE_DIR}/rules/*.lua") FOREACH(LUA_CONF ${LUA_CONFIGS}) GET_FILENAME_COMPONENT(_rp ${LUA_CONF} PATH) INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${RULESDIR}/${_rp})") INSTALL(FILES "rules/${LUA_CONF}" DESTINATION ${RULESDIR}/${_rp}) ENDFOREACH(LUA_CONF) # Lua libs FILE(GLOB_RECURSE LUA_LIBS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/lualib" "${CMAKE_CURRENT_SOURCE_DIR}/lualib/*.lua") FOREACH(LUA_LIB ${LUA_LIBS}) GET_FILENAME_COMPONENT(_rp ${LUA_LIB} PATH) INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR}/${_rp})") INSTALL(FILES "lualib/${LUA_LIB}" DESTINATION ${LUALIBDIR}/${_rp}) ENDFOREACH(LUA_LIB) # Install lua fun library INSTALL(FILES "contrib/lua-fun/fun.lua" DESTINATION ${LUALIBDIR}) INSTALL(FILES "contrib/lua-argparse/argparse.lua" DESTINATION ${LUALIBDIR}) INSTALL(FILES "contrib/lua-tableshape/tableshape.lua" DESTINATION ${LUALIBDIR}) IF(ENABLE_TORCH MATCHES "ON") INSTALL(FILES "contrib/lua-moses/moses.lua" DESTINATION ${LUALIBDIR}) ENDIF() # systemd unit IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND WANT_SYSTEMD_UNITS MATCHES "ON") INSTALL(FILES "rspamd.service" DESTINATION ${SYSTEMDDIR}) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND WANT_SYSTEMD_UNITS MATCHES "ON") # Manual pages INSTALL(FILES "doc/rspamd.8" DESTINATION ${MANDIR}/man8) INSTALL(FILES "doc/rspamc.1" DESTINATION ${MANDIR}/man1) INSTALL(FILES "doc/rspamadm.1" DESTINATION ${MANDIR}/man1) # Utils INSTALL(PROGRAMS "utils/rspamd_stats.pl" RENAME rspamd_stats DESTINATION bin) # Install webui IF(INSTALL_WEBUI MATCHES "ON") INSTALL(DIRECTORY "interface/" DESTINATION ${WWWDIR} PATTERN ".git" EXCLUDE) ENDIF(INSTALL_WEBUI MATCHES "ON") INSTALL(DIRECTORY "contrib/elastic/" DESTINATION "${PLUGINSDIR}/elastic" PATTERN ".git" EXCLUDE) ADD_CUSTOM_TARGET(dist ${CMAKE_SOURCE_DIR}/dist.sh "${CMAKE_BINARY_DIR}/rspamd-${RSPAMD_VERSION}.tar.xz" "${TAR}" COMMENT "Create source distribution" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) IF(NOT DEBIAN_BUILD) ADD_CUSTOM_TARGET(check DEPENDS rspamd-test) ADD_CUSTOM_TARGET(run-test DEPENDS check COMMAND test/rspamd-test) ENDIF(NOT DEBIAN_BUILD)