aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2016-11-28 13:47:00 +0100
committerAndreas Schneider <asn@cryptomilk.org>2016-11-28 17:41:40 +0100
commitea6f08a5645b6ceb88a4a8142062cc51a29f0f90 (patch)
tree63703b3c1ed2a21990d60e2443a6d6acdd0c032d
parent902ebce8b6c60a0a1cc1501c6da1ada1d2b2b4a5 (diff)
downloadrspamd-ea6f08a5645b6ceb88a4a8142062cc51a29f0f90.tar.gz
rspamd-ea6f08a5645b6ceb88a4a8142062cc51a29f0f90.zip
cmake: Use Find Modules to find Luajit and Lua
-rw-r--r--CMakeLists.txt162
-rw-r--r--cmake/Modules/FindLuaJIT.cmake71
2 files changed, 94 insertions, 139 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9dbbd7219..91a245c6d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,6 +63,9 @@ OPTION(ENABLE_PCRE2 "Enable pcre2 instead of pcre [default: OFF]"
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)
@@ -199,119 +202,6 @@ 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"
- "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}")
@@ -627,31 +517,13 @@ 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_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
@@ -1205,8 +1077,20 @@ IF(WITH_DB)
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)
diff --git a/cmake/Modules/FindLuaJIT.cmake b/cmake/Modules/FindLuaJIT.cmake
new file mode 100644
index 000000000..432aabb12
--- /dev/null
+++ b/cmake/Modules/FindLuaJIT.cmake
@@ -0,0 +1,71 @@
+# - 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)
+