Upstream: Should be Reason: Use pkgconfig to find luajit diff --git a/cmake/Modules/FindLuaJIT.cmake b/cmake/Modules/FindLuaJIT.cmake index 0d0786e..3ab8602 100644 --- a/cmake/Modules/FindLuaJIT.cmake +++ b/cmake/Modules/FindLuaJIT.cmake @@ -1,55 +1,72 @@ +# - 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 2007-2009 Kitware, Inc. -# Copyright 2013 Rolf Eike Beer +# Copyright (c) 2016 Andrea Schneider # -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. +# 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. +# 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. #============================================================================= -# We use code from the CMake project to detect the Lua version. - -# Locate LuaJIT library -# This module defines -# LUAJIT_FOUND, if false, do not try to link to Lua JIT -# LUAJIT_LIBRARIES -# LUAJIT_INCLUDE_DIR, where to find lua.h # -# Additionally it defines the Lua API/ABI version: -# LUA_VERSION_STRING - the version of Lua found -# LUA_VERSION_MAJOR - the major version of Lua -# LUA_VERSION_MINOR - the minor version of Lua -# LUA_VERSION_PATCH - the patch version of Lua - -FIND_PATH(LUAJIT_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES luajit-2.0 luajit-2.1) -FIND_LIBRARY(LUAJIT_LIBRARIES NAMES luajit-5.1 luajit) - -if (LUAJIT_INCLUDE_DIR AND EXISTS "${LUAJIT_INCLUDE_DIR}/lua.h") - # At least 5.[012] have different ways to express the version - # so all of them need to be tested. Lua 5.2 defines LUA_VERSION - # and LUA_RELEASE as joined by the C preprocessor, so avoid those. - file(STRINGS "${LUAJIT_INCLUDE_DIR}/lua.h" lua_version_strings - REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") - - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};") - if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};") - set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}") - else () - string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") - if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") - endif () - string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}") - endif () - - unset(lua_version_strings) -endif() - -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUAJIT DEFAULT_MSG LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR) + +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) + +