# # Rspamd - rapid antispam system # # Cmake configuration file # ############################# INITIAL SECTION ############################################# CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR) PROJECT(rspamd C) ENABLE_LANGUAGE(ASM) SET(RSPAMD_VERSION_MAJOR 1) SET(RSPAMD_VERSION_MINOR 8) SET(RSPAMD_VERSION_PATCH 0) # Keep two digits all the time SET(RSPAMD_VERSION_MAJOR_NUM ${RSPAMD_VERSION_MAJOR}0) SET(RSPAMD_VERSION_MINOR_NUM ${RSPAMD_VERSION_MINOR}0) SET(RSPAMD_VERSION_PATCH_NUM ${RSPAMD_VERSION_PATCH}0) IF(GIT_ID) SET(GIT_VERSION 1) SET(RSPAMD_ID "${GIT_ID}") ENDIF() SET(RSPAMD_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}") SET(RSPAMD_MASTER_SITE_URL "https://rspamd.com") IF(NOT RSPAMD_USER) SET(RSPAMD_USER "nobody") SET(RSPAMD_GROUP "nobody") ENDIF(NOT RSPAMD_USER) # Default for SysV Init SET(RSPAMD_WORKER_NORMAL "*:11333") SET(RSPAMD_WORKER_CONTROLLER "*:11334") SET_PROPERTY(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1) ############################# OPTIONS SECTION ############################################# OPTION(ENABLE_OPTIMIZATION "Enable extra optimizations [default: OFF]" OFF) OPTION(SKIP_RELINK_RPATH "Skip relinking and full RPATH for the install tree" OFF) OPTION(ENABLE_REDIRECTOR "Enable redirector install [default: OFF]" OFF) OPTION(ENABLE_GPERF_TOOLS "Enable google perftools [default: OFF]" OFF) OPTION(ENABLE_STATIC "Enable static compiling [default: OFF]" OFF) OPTION(ENABLE_LUAJIT "Link with libluajit [default: ON]" ON) OPTION(ENABLE_DB "Find and link with DB library [default: OFF]" OFF) OPTION(ENABLE_URL_INCLUDE "Enable urls in ucl includes (requires libcurl or libfetch) [default: OFF]" OFF) OPTION(NO_SHARED "Build internal libs static [default: ON]" ON) OPTION(INSTALL_EXAMPLES "Install examples [default: OFF]" OFF) OPTION(INSTALL_WEBUI "Install web interface [default: ON]" ON) OPTION(WANT_SYSTEMD_UNITS "Install systemd unit files on Linux [default: OFF]" OFF) OPTION(ENABLE_SNOWBALL "Enable snowball stemmer [default: ON]" ON) OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]" OFF) OPTION(ENABLE_HYPERSCAN "Enable hyperscan for fast regexp processing [default: OFF]" OFF) OPTION(ENABLE_FANN "Enable fann for neural network plugin [default: OFF]" OFF) OPTION(ENABLE_PCRE2 "Enable pcre2 instead of pcre [default: OFF]" OFF) OPTION(ENABLE_GD "Enable libgd for images processing [default: OFF]" OFF) OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]" OFF) OPTION(ENABLE_COVERAGE "Build rspamd with code coverage options [default: OFF]" OFF) OPTION(ENABLE_FULL_DEBUG "Build rspamd with all possible debug [default: OFF]" OFF) OPTION(ENABLE_UTILS "Build rspamd internal utils [default: OFF]" OFF) OPTION(ENABLE_TORCH "Install torch7 with Rspamd [default: ON]" ON) OPTION(ENABLE_LIBUNWIND "Use libunwind to print crash traces [default: OFF]" OFF) OPTION(ENABLE_LUA_TRACE "Trace all Lua C API invocations [default: OFF]" OFF) INCLUDE(FindArch.cmake) TARGET_ARCHITECTURE(ARCH) INCLUDE(FindRagel.cmake) IF(NOT RAGEL_FOUND) MESSAGE(FATAL_ERROR "Ragel is required to build rspamd") ENDIF() IF (NOT "${ARCH}" STREQUAL "x86_64") MESSAGE(STATUS "Hyperscan support is possible only for x86_64 architecture") SET(ENABLE_HYPERSCAN "OFF") ENDIF() IF(ENABLE_PCRE2 MATCHES "ON") SET(WITH_PCRE2 1) # For utf8 API LIST(APPEND CMAKE_REQUIRED_DEFINITIONS "-DPCRE2_CODE_UNIT_WIDTH=8") ENDIF() # Build optimized code for following CPU (default i386) #SET(CPU_TUNE "i686") # Now CMAKE_INSTALL_PREFIX is a base prefix for everything # CONFDIR - for configuration # LOCAL_CONFDIR - for local configuration # MANDIR - for manual pages # RUNDIR - for runtime files # DBDIR - for static files # LOGDIR - for log files # EXAMPLESDIR - for examples files IF(NOT CONFDIR) SET(CONFDIR "${CMAKE_INSTALL_PREFIX}/etc/rspamd") ENDIF(NOT CONFDIR) IF(NOT LOCAL_CONFDIR) SET(LOCAL_CONFDIR "${CONFDIR}") ENDIF(NOT LOCAL_CONFDIR) IF(NOT MANDIR) SET(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man") ENDIF(NOT MANDIR) IF(NOT RUNDIR) SET(RUNDIR "/var/run/rspamd") ENDIF(NOT RUNDIR) IF(NOT DBDIR) SET(DBDIR "/var/lib/rspamd") ENDIF(NOT DBDIR) IF(NOT LOGDIR) SET(LOGDIR "/var/log/rspamd") ENDIF(NOT LOGDIR) IF(NOT EXAMPLESDIR) SET(EXAMPLESDIR "${CMAKE_INSTALL_PREFIX}/share/examples/rspamd") ENDIF(NOT EXAMPLESDIR) IF(NOT PLUGINSDIR) SET(PLUGINSDIR "${CMAKE_INSTALL_PREFIX}/share/rspamd") ENDIF(NOT PLUGINSDIR) IF(NOT RULESDIR) SET(RULESDIR "${PLUGINSDIR}/rules") ENDIF(NOT RULESDIR) IF(NOT LUALIBDIR) SET(LUALIBDIR "${PLUGINSDIR}/lib") ENDIF(NOT LUALIBDIR) IF(NOT WWWDIR) SET(WWWDIR "${CMAKE_INSTALL_PREFIX}/share/rspamd/www") ENDIF(NOT WWWDIR) # Set libdir IF(NOT LIBDIR) SET(RSPAMD_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib/rspamd") ELSE(NOT LIBDIR) SET(RSPAMD_LIBDIR "${LIBDIR}") ENDIF(NOT LIBDIR) SET(CMAKE_MACOSX_RPATH ON) SET(CMAKE_INSTALL_RPATH "${RSPAMD_LIBDIR}") # Set includedir IF(NOT INCLUDEDIR) SET(INCLUDEDIR include/rspamd) ENDIF(NOT INCLUDEDIR) IF(NOT SYSTEMDDIR) SET(SYSTEMDDIR ${CMAKE_INSTALL_PREFIX}/lib/systemd/system) ENDIF(NOT SYSTEMDDIR) SET(RSPAMD_DEFAULT_INCLUDE_PATHS "/opt;/usr;/usr/local;/opt/local;/usr/pkg;/opt/csw;/sw") SET(RSPAMD_DEFAULT_LIBRARY_PATHS "/usr/local;/usr/pkg;/usr;/Library/Frameworks;/sw;/opt/local;/opt/csw;/opt") IF(ENABLE_STATIC MATCHES "ON") MESSAGE(STATUS "Static build of rspamd implies that the target binary will be *GPL* licensed") SET(GPL_RSPAMD_BINARY 1) SET(CMAKE_SKIP_INSTALL_RPATH ON) SET(BUILD_STATIC 1) SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") SET(BUILD_SHARED_LIBRARIES OFF) SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") SET(LINK_TYPE "STATIC") SET(NO_SHARED "ON") # Dirty hack for cmake SET(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic SET(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) SET(CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS) SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # remove -rdynamic SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) ELSE(ENABLE_STATIC MATCHES "ON") IF (NO_SHARED MATCHES "OFF") SET(LINK_TYPE "SHARED") ELSE(NO_SHARED MATCHES "OFF") SET(LINK_TYPE "STATIC") ENDIF (NO_SHARED MATCHES "OFF") ENDIF (ENABLE_STATIC MATCHES "ON") ############################# INCLUDE SECTION ############################################# INCLUDE(CheckIncludeFiles) INCLUDE(CheckFunctionExists) INCLUDE(CheckSymbolExists) INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceRuns) INCLUDE(CheckLibraryExists) INCLUDE(CheckCCompilerFlag) INCLUDE(CMakeParseArguments) FIND_PACKAGE(PkgConfig REQUIRED) FIND_PACKAGE(Perl REQUIRED) ############################# MACRO SECTION ############################################# # Find lua installation MACRO(FindLua) # Find lua libraries UNSET(LUA_INCLUDE_DIR CACHE) UNSET(LUA_LIBRARY CACHE) CMAKE_PARSE_ARGUMENTS(LUA "" "VERSION_MAJOR;VERSION_MINOR;ROOT" "" ${ARGN}) IF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR) MESSAGE(FATAL_ERROR "Invalid FindLua invocation: ${ARGN}") ENDIF() IF(ENABLE_LUAJIT MATCHES "ON") MESSAGE(STATUS "Check for luajit ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}") FIND_PATH(LUA_INCLUDE_DIR luajit.h HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES "include/luajit-2.0" "include/luajit-2.1" "include/luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "include/luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "include/luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "include/luajit-${LUA_VERSION_MAJOR}_${LUA_VERSION_MINOR}-2.0" "include/luajit-${LUA_VERSION_MAJOR}_${LUA_VERSION_MINOR}-2.1" "include/luajit" "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" include/lua include PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS} ) FIND_LIBRARY(LUA_LIBRARY NAMES luajit "luajit-2.0" "luajit2.0" "luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS} DOC "Lua library" ) IF(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR) MESSAGE(STATUS "Fallback from luajit to plain lua") SET(ENABLE_LUAJIT "OFF") MESSAGE(STATUS "Check for lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}") FIND_PATH(LUA_INCLUDE_DIR lua.h HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" include/lua include PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS} ) FIND_LIBRARY(LUA_LIBRARY NAMES lua "lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS} DOC "Lua library" ) ELSE() SET(WITH_LUAJIT 1) ENDIF() ELSE(ENABLE_LUAJIT MATCHES "ON") MESSAGE(STATUS "Check for lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}") FIND_PATH(LUA_INCLUDE_DIR lua.h HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" include/lua include PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS} ) FIND_LIBRARY(LUA_LIBRARY NAMES lua "lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" "lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" HINTS "${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}" $ENV{LUA_DIR} PATH_SUFFIXES lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS} DOC "Lua library" ) ENDIF(ENABLE_LUAJIT MATCHES "ON") IF(LUA_LIBRARY AND LUA_INCLUDE_DIR) SET(LUA_FOUND 1) IF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR) SET(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR}) SET(LUA_VERSION_MINOR ${LUA_VERSION_MINOR}) ENDIF(NOT LUA_VERSION_MAJOR OR NOT LUA_VERSION_MINOR) IF(ENABLE_LUAJIT MATCHES "ON") MESSAGE(STATUS "Found luajit ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} in lib:${LUA_LIBRARY}, headers:${LUA_INCLUDE_DIR}") ELSE(ENABLE_LUAJIT MATCHES "ON") MESSAGE(STATUS "Found lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} in lib:${LUA_LIBRARY}, headers:${LUA_INCLUDE_DIR}") ENDIF(ENABLE_LUAJIT MATCHES "ON") ENDIF(LUA_LIBRARY AND LUA_INCLUDE_DIR) ENDMACRO() FUNCTION(INSTALL_IF_NOT_EXISTS src dest destname suffix) IF(NOT IS_ABSOLUTE "${src}") SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") ENDIF() GET_FILENAME_COMPONENT(src_name "${src}" NAME) GET_FILENAME_COMPONENT(dest_name "${destname}" NAME) IF(NOT IS_ABSOLUTE "${dest}") SET(dest "${CMAKE_INSTALL_PREFIX}/${dest}") ENDIF() INSTALL(CODE " IF(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${dest_name}${suffix}\") #FILE(INSTALL \"${src}\" DESTINATION \"${dest}\") MESSAGE(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${dest_name}${suffix}\") EXECUTE_PROCESS(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\$ENV{DESTDIR}${dest}/${dest_name}${suffix}\" RESULT_VARIABLE copy_result ERROR_VARIABLE error_output) IF(copy_result) MESSAGE(FATAL_ERROR \${error_output}) ENDIF() ELSE() MESSAGE(STATUS \"Skipping : \$ENV{DESTDIR}${dest}/${dest_name}${suffix}\") ENDIF() ") ENDFUNCTION(INSTALL_IF_NOT_EXISTS) # Process required package by using FindPackage and calling for INCLUDE_DIRECTORIES and # setting list of required libraries # Usage: # ProcessPackage(VAR [OPTIONAL] [ROOT path] [INCLUDE path] # [LIBRARY path] [INCLUDE_SUFFIXES path1 path2 ...] [LIB_SUFFIXES path1 path2 ...] # [MODULES module1 module2 ...]) # params: # OPTIONAL - do not fail if a package has not been found # ROOT - defines root directory for a package # INCLUDE - name of the include file to check # LIBRARY - name of the library to check # INCLUDE_SUFFIXES - list of include suffixes (relative to ROOT) # LIB_SUFFIXES - list of library suffixes # MODULES - modules to search using pkg_config MACRO(ProcessPackage PKG_NAME) CMAKE_PARSE_ARGUMENTS(PKG "OPTIONAL" "ROOT;INCLUDE" "LIBRARY;INCLUDE_SUFFIXES;LIB_SUFFIXES;MODULES" ${ARGN}) IF(NOT PKG_LIBRARY) SET(PKG_LIBRARY "${PKG_NAME}") ENDIF() IF(NOT PKG_INCLUDE) SET(PKG_INCLUDE "${PKG_NAME}.h") ENDIF() IF(NOT PKG_ROOT AND PKG_MODULES) PKG_SEARCH_MODULE(${PKG_NAME} ${PKG_MODULES}) ENDIF() IF(${PKG_NAME}_FOUND) MESSAGE(STATUS "Found package ${PKG_NAME} in pkg-config modules ${PKG_MODULES}") SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "") IF(ENABLE_STATIC MATCHES "ON") SET(_XPREFIX "${PKG_NAME}_STATIC") ELSE(ENABLE_STATIC MATCHES "ON") SET(_XPREFIX "${PKG_NAME}") ENDIF(ENABLE_STATIC MATCHES "ON") FOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) INCLUDE_DIRECTORIES("${_arg}") SET(${PKG_NAME}_INCLUDE "${_arg}" CACHE INTERNAL "") ENDFOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) FOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) LINK_DIRECTORIES("${_arg}") SET(${PKG_NAME}_LIBRARY_PATH "${_arg}" CACHE INTERNAL "") ENDFOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) # Handle other CFLAGS and LDFLAGS FOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_arg}") ENDFOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) FOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_arg}") ENDFOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${${_XPREFIX}_LIBRARIES}") INCLUDE_DIRECTORIES(${${_XPREFIX}_INCLUDEDIR}) ELSE() IF(NOT ${PKG_NAME}_GUESSED) # Try some more heuristic FIND_LIBRARY(_lib NAMES ${PKG_LIBRARY} HINTS ${PKG_ROOT} ${RSPAMD_SEARCH_PATH} PATH_SUFFIXES ${PKG_LIB_SUFFIXES} lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}) IF(NOT _lib) IF(PKG_OPTIONAL) MESSAGE(STATUS "Cannot find library ${PKG_LIBRARY} for package ${PKG_NAME}, ignoring") ELSE() MESSAGE(FATAL_ERROR "Cannot find library ${PKG_LIBRARY} for package ${PKG_NAME}") ENDIF() ENDIF(NOT _lib) FIND_PATH(_incl ${PKG_INCLUDE} HINTS ${PKG_ROOT} ${RSPAMD_SEARCH_PATH} PATH_SUFFIXES ${PKG_INCLUDE_SUFFIXES} include PATHS {RSPAMD_DEFAULT_INCLUDE_PATHS}) IF(NOT _incl) IF(PKG_OPTIONAL) MESSAGE(STATUS "Cannot find header ${PKG_INCLUDE} for package ${PKG_NAME}") ELSE() MESSAGE(FATAL_ERROR "Cannot find header ${PKG_INCLUDE} for package ${PKG_NAME}") ENDIF() ENDIF(NOT _incl) IF(_incl AND _lib) # We need to apply heuristic to find the real dir name STRING(REGEX REPLACE "/[^/]+$" "" _incl_path "${PKG_INCLUDE}") STRING(REGEX REPLACE "${_incl_path}/$" "" _stripped_incl "${_incl}") GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH) INCLUDE_DIRECTORIES("${_stripped_incl}") LINK_DIRECTORIES("${_lib_path}") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES ${_lib}) SET(${PKG_NAME}_INCLUDE "${_stripped_incl}" CACHE INTERNAL "") SET(${PKG_NAME}_LIBRARY_PATH "${_lib_path}" CACHE INTERNAL "") SET(${PKG_NAME}_LIBRARY "${_lib}" CACHE INTERNAL "") SET(${PKG_NAME}_GUESSED 1 CACHE INTERNAL "") SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "") MESSAGE(STATUS "Found package ${PKG_NAME} in '${_lib_path}' (${_lib}) and '${_stripped_incl}' (${PKG_INCLUDE}).") ENDIF() ELSE() MESSAGE(STATUS "Found package ${PKG_NAME} (cached)") INCLUDE_DIRECTORIES("${${PKG_NAME}_INCLUDE}") LINK_DIRECTORIES("${${PKG_NAME}_LIBRARY_PATH}") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${${PKG_NAME}_LIBRARY}") ENDIF() ENDIF(${PKG_NAME}_FOUND) UNSET(_lib CACHE) UNSET(_incl CACHE) ENDMACRO(ProcessPackage name) MACRO(ADD_PRECOMPILED_HEADER _target _input) GET_FILENAME_COMPONENT(_name ${_input} NAME) SET(_outdir "${CMAKE_BINARY_DIR}/${_name}.pch") MAKE_DIRECTORY(${_outdir}) SET(_output "${_outdir}/${_name}.pch") STRING(TOUPPER "CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name) SET(_compiler_FLAGS ${${_flags_var_name}}) GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES) FOREACH(item ${_directory_flags}) LIST(APPEND _compiler_FLAGS "-I${item}") ENDFOREACH(item) INCLUDE_DIRECTORIES(${_outdir}) IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") IF(NOT TARGET ${_name}_pch) MESSAGE("${CMAKE_C_COMPILER} -DPCHCOMPILE ${CMAKE_C_FLAGS} -x c-header -o ${_output} ${_input}") ADD_CUSTOM_COMMAND(OUTPUT ${_output} COMMAND ${CMAKE_C_COMPILER} -DPCHCOMPILE ${_compiler_FLAGS} -x c-header -o ${_output} ${_input} DEPENDS ${_input}) ADD_CUSTOM_TARGET(${_name}_pch DEPENDS ${_output}) ENDIF() ADD_CUSTOM_TARGET(${_target}_pch DEPENDS ${_name}_pch) ADD_DEPENDENCIES(${_target} ${_target}_pch) SET_TARGET_PROPERTIES(${_target} PROPERTIES COMPILE_FLAGS "-include ${_name} -Winvalid-pch") ENDIF() ENDMACRO() ############################# CONFIG SECTION ############################################# # Initial set # Prefer local include dirs to system ones INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/" "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/src/libutil" "${CMAKE_SOURCE_DIR}/src/libserver" "${CMAKE_SOURCE_DIR}/src/libmime" "${CMAKE_SOURCE_DIR}/src/libstat" "${CMAKE_SOURCE_DIR}/src/libcryptobox" "${CMAKE_SOURCE_DIR}/contrib/libucl" "${CMAKE_SOURCE_DIR}/contrib/linenoise" "${CMAKE_SOURCE_DIR}/contrib/uthash" "${CMAKE_SOURCE_DIR}/contrib/http-parser" "${CMAKE_SOURCE_DIR}/contrib/libottery" "${CMAKE_SOURCE_DIR}/contrib/xxhash" "${CMAKE_SOURCE_DIR}/contrib/cdb" "${CMAKE_SOURCE_DIR}/contrib/snowball/include" "${CMAKE_SOURCE_DIR}/contrib/librdns" "${CMAKE_SOURCE_DIR}/contrib/aho-corasick" "${CMAKE_SOURCE_DIR}/contrib/lc-btrie" "${CMAKE_SOURCE_DIR}/contrib/lua-lpeg" "${CMAKE_BINARY_DIR}/src" #Stored in the binary dir "${CMAKE_BINARY_DIR}/src/libcryptobox") IF(CMAKE_INSTALL_PREFIX) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) ENDIF(CMAKE_INSTALL_PREFIX) LIST(APPEND CMAKE_REQUIRED_LIBRARIES m) SET(POE_LOOP "Loop::IO_Poll") SET(TAR "tar") # Platform specific configuration IF(CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly") ADD_DEFINITIONS(-DFREEBSD -D_BSD_SOURCE) CONFIGURE_FILE(freebsd/rspamd.sh.in freebsd/rspamd @ONLY) IF(ENABLE_REDIRECTOR MATCHES "ON") CONFIGURE_FILE(freebsd/redirector.sh.in freebsd/redirector @ONLY) ENDIF(ENABLE_REDIRECTOR MATCHES "ON") MESSAGE(STATUS "Configuring for BSD system") # Find util library ProcessPackage(LIBUTIL LIBRARY util INCLUDE libutil.h ROOT ${LIBUTIL_ROOT_DIR} OPTIONAL) IF(WITH_LIBUTIL) SET(HAVE_LIBUTIL_H 1) LIST(APPEND RSPAMD_REQUIRED_LIBRARIES util) LIST(APPEND CMAKE_REQUIRED_LIBRARIES util) CHECK_FUNCTION_EXISTS(pidfile_open HAVE_PIDFILE) CHECK_FUNCTION_EXISTS(pidfile_fileno HAVE_PIDFILE_FILENO) ENDIF() IF(CMAKE_SYSTEM_NAME MATCHES "^NetBSD$") LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) ENDIF() SET(POE_LOOP "Loop::Kqueue") SET(TAR "gtar") ENDIF() IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DDARWIN") SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup") IF(ENABLE_LUAJIT MATCHES "ON") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000") ENDIF(ENABLE_LUAJIT MATCHES "ON") MESSAGE(STATUS "Configuring for Darwin") SET(TAR "gnutar") SET(CMAKE_FIND_FRAMEWORK "NEVER") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") ADD_DEFINITIONS(-D_GNU_SOURCE -DLINUX) # Workaround with architecture specific includes #IF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") # INCLUDE_DIRECTORIES("/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") # LIST(APPEND CMAKE_REQUIRED_INCLUDES "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") #ENDIF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv) LIST(APPEND CMAKE_REQUIRED_LIBRARIES nsl) MESSAGE(STATUS "Configuring for Linux") IF(EXISTS "/etc/debian_version") SET(LINUX_START_SCRIPT "rspamd_debian.in") ELSE(EXISTS "/etc/debian_version") SET(LINUX_START_SCRIPT "rspamd_rh.in") ENDIF(EXISTS "/etc/debian_version") SET(POE_LOOP "XS::Loop::EPoll") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") IF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xa -xregs=no%frameptr -xstrconst -xc99") IF(ENABLE_OPTIMIZATION MATCHES "ON") SET(CMAKE_C_OPT_FLAGS "-fast -xdepend") ELSE(ENABLE_OPTIMIZATION MATCHES "ON") SET(CMAKE_C_OPT_FLAGS "-xO0") ENDIF(ENABLE_OPTIMIZATION MATCHES "ON") ENDIF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__EXTENSIONS__ -DSOLARIS -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L") LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv) LIST(APPEND CMAKE_REQUIRED_LIBRARIES nsl) LIST(APPEND CMAKE_REQUIRED_LIBRARIES socket) LIST(APPEND CMAKE_REQUIRED_LIBRARIES umem) # Ugly hack, but FindOpenSSL on Solaris does not link with libcrypto SET(CMAKE_VERBOSE_MAKEFILE ON) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${RSPAMD_LIBDIR}") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") # Now find libraries and headers IF(ENABLE_LUAJIT MATCHES "ON") #ProcessPackage(LUAJIT luajit) SET(WITH_LUA 1) FindLua(VERSION_MAJOR "5" VERSION_MINOR "1" ROOT "${LUA_ROOT}") IF(NOT LUA_FOUND) MESSAGE(FATAL_ERROR "Lua not found, lua support is required") ELSE(NOT LUA_FOUND) SET(WITH_LUA 1) INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") ENDIF(NOT LUA_FOUND) ELSE(ENABLE_LUAJIT MATCHES "ON") FindLua(VERSION_MAJOR "5" VERSION_MINOR "3" ROOT "${LUA_ROOT}") IF(NOT LUA_FOUND) FindLua(VERSION_MAJOR "5" VERSION_MINOR "2" ROOT "${LUA_ROOT}") IF(NOT LUA_FOUND) FindLua(VERSION_MAJOR "5" VERSION_MINOR "1" ROOT "${LUA_ROOT}") ENDIF(NOT LUA_FOUND) ENDIF(NOT LUA_FOUND) IF(NOT LUA_FOUND) MESSAGE(FATAL_ERROR "Lua not found, lua support is required") ELSE(NOT LUA_FOUND) SET(WITH_LUA 1) INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") ENDIF(NOT LUA_FOUND) ENDIF(ENABLE_LUAJIT MATCHES "ON") IF(ENABLE_JEMALLOC MATCHES "ON") ProcessPackage(JEMALLOC LIBRARY jemalloc INCLUDE jemalloc.h INCLUDE_SUFFIXES include/jemalloc ROOT ${JEMALLOC_ROOT_DIR} MODULES jemalloc) SET(WITH_JEMALLOC "1") LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "-lpthread") ENDIF() IF(ENABLE_LIBUNWIND MATCHES "ON") ProcessPackage(LIBUNWIND LIBRARY unwind INCLUDE libunwind.h INCLUDE_SUFFIXES include/libunwind ROOT ${LIBUNWIND_ROOT_DIR} MODULES libunwind) SET(WITH_LIBUNWIND "1") ENDIF() ProcessPackage(GTHREAD2 LIBRARY gthread-2.0 INCLUDE glib.h INCLUDE_SUFFIXES include/glib include/glib-2.0 ROOT ${GLIB_ROOT_DIR} MODULES gthread-2.0>=2.28) ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h INCLUDE_SUFFIXES include/glib include/glib-2.0 ROOT ${GLIB_ROOT_DIR} MODULES glib-2.0>=2.28) IF(ENABLE_PCRE2 MATCHES "ON") ProcessPackage(PCRE LIBRARY pcre2 pcre2-8 INCLUDE pcre2.h INCLUDE_SUFFIXES include/pcre2 ROOT ${PCRE_ROOT_DIR} MODULES pcre2 pcre2-8 libpcre2 libpcre2-8) ELSE() ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre ROOT ${PCRE_ROOT_DIR} MODULES pcre libpcre pcre3 libpcre3) ENDIF() ProcessPackage(LIBEVENT LIBRARY event INCLUDE event.h INCLUDE_SUFFIXES include/event ROOT ${LIBEVENT_ROOT_DIR} MODULES event libevent) ProcessPackage(SQLITE3 LIBRARY sqlite3 INCLUDE sqlite3.h INCLUDE_SUFFIXES include/sqlite3 include/sqlite ROOT ${SQLITE3_ROOT_DIR} MODULES sqlite3 sqlite) ProcessPackage(ICUDATA LIBRARY icudata INCLUDE unicode/ucnv.h ROOT ${ICU_ROOT_DIR} MODULES icu-i18n) ProcessPackage(ICUC LIBRARY icuuc INCLUDE unicode/ucnv.h ROOT ${ICU_ROOT_DIR} MODULES icu-i18n) ProcessPackage(ICUI18N LIBRARY icui18n INCLUDE unicode/ucnv.h ROOT ${ICU_ROOT_DIRstatsplain