OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]" OFF)
OPTION(ENABLE_COVERAGE "Build rspamd with code coverage options [default: OFF]" OFF)
+# Additonal Modules
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
+
INCLUDE(FindArch.cmake)
TARGET_ARCHITECTURE(ARCH)
############################# 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"
- "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}")
- ELSE(ENABLE_LUAJIT MATCHES "ON")
- MESSAGE(STATUS "Found lua ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
- 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}")
# 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_LUAJIT)
+ find_package(LuaJIT 2.0 REQUIRED)
+endif()
+
+if (NOT LUAJIT_FOUND)
+ find_package(Lua 5.1 REQUIRED)
+endif()
IF(ENABLE_JEMALLOC MATCHES "ON")
ProcessPackage(JEMALLOC LIBRARY jemalloc INCLUDE jemalloc.h INCLUDE_SUFFIXES include/jemalloc
LIST(APPEND RSPAMD_REQUIRED_LIBRARIES db)
ENDIF(WITH_DB)
+if (LUAJIT_FOUND)
+ # config.h
+ set(WITH_LUAJIT 1)
+ set(WITH_LUA 1)
+
+ include_directories(${LUAJIT_INCLUDE_DIR})
+ list(APPEND RSPAMD_REQUIRED_LIBRARIES "${LUAJIT_LIBRARY}")
+else()
+ # config.h
+ set(WITH_LUA 1)
-LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${LUA_LIBRARY}")
+ include_directories(${LUA_INCLUDE_DIR})
+ list(APPEND RSPAMD_REQUIRED_LIBRARIES "${LUA_LIBRARY}")
+endif()
IF(GLIB_COMPAT)
LIST(APPEND RSPAMD_REQUIRED_LIBRARIES glibadditions)
--- /dev/null
+# - Try to find LuaJIT
+# Once done this will define
+#
+# LUAJIT_FOUND - system has LuaJIT
+# LUAJIT_INCLUDE_DIR - the LuaJIT include directory
+# LUAJIT_LIBRARIES - Link these to use LuaJIT
+# LUAJIT_DEFINITIONS - Compiler switches required for using LuaJIT
+#
+#=============================================================================
+# Copyright (c) 2016 Andrea Schneider <asn@cryptomilk.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+#
+
+if (UNIX)
+ find_package(PkgConfig)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(_LUAJIT luajit)
+ endif (PKG_CONFIG_FOUND)
+endif (UNIX)
+
+set(_LUAJIT_ROOT_HINTS
+ ${RSPAMD_SEARCH_PATH}
+ ${LUAJIT_ROOT_DIR}
+ ENV LUAJIT_ROOT_DIR
+)
+
+find_path(LUAJIT_INCLUDE_DIR
+ NAMES
+ luajit.h
+ PATHS
+ ${_LUAJIT_INCLUDEDIR}
+ HINTS
+ ${_LUAJIT_ROOT_HINTS}
+ PATH_SUFFIXES
+ luajit-5_1-2.0
+ luajit-5_2-2.0
+ luajit-5_3-2.0
+)
+
+find_library(LUAJIT_LIBRARY
+ NAMES
+ luajit
+ luajit-5.1
+ luajit-5.2
+ luajit-5.3
+ HINTS
+ ${_LUAJIT_ROOT_HINTS}
+ PATHS
+ ${_LUAJIT_LIBDIR}
+)
+
+if (LUAJIT_LIBRARY)
+ set(LUAJIT_LIBRARIES
+ ${LUAJIT_LIBRARIES}
+ ${LUAJIT_LIBRARY}
+ )
+endif (LUAJIT_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LuaJIT DEFAULT_MSG LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR)
+
+# show the LUAJIT_INCLUDE_DIR and LUAJIT_LIBRARIES variables only in the advanced view
+mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARIES)
+