From b37470526c798c5b4d7411c6eb9dc060a129557a Mon Sep 17 00:00:00 2001 From: David Demelier Date: Wed, 18 Dec 2013 13:36:36 +0100 Subject: [PATCH] Add support for Lua 5.2 --- CMakeLists.txt | 32 ++++++++------ cmake/Modules/FindLua52.cmake | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 cmake/Modules/FindLua52.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fecd37..1f53740 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ project(Lua-cURL C) -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8) option(USE_LUA "Use Lua (also called 'C' Lua) version 5.1 includes (default)" ON) -#option(USE_LUA52 "Use Lua (also called 'C' Lua) version 5.2 includes (currelty unsupported)") +option(USE_LUA52 "Use Lua (also called 'C' Lua) version 5.2 includes (currelty unsupported)") option(USE_LUAJIT "Use LuaJIT includes instead of 'C' Lua ones (recommended, if you're using LuaJIT, but disabled by default)") @@ -31,21 +31,23 @@ if(USE_LUAJIT) find_package(LuaJIT REQUIRED) set(USE_LUA52 OFF) set(USE_LUA OFF) -endif() - -#if(USE_LUA52) -##TODO -# find_package(Lua52 REQUIRED) -# unset(USE_LUA) -#endif() - -if(USE_LUA) +elseif(USE_LUA52) + find_package(Lua52 REQUIRED) + set(USE_LUA OFF) + set(USE_LUAJIT OFF) +elseif(USE_LUA) find_package(Lua51 REQUIRED) + set(USE_LUA52 OFF) + set(USE_LUAJIT OFF) endif() find_package(CURL REQUIRED) -include_directories(${LUA_INCLUDE_DIR}) + +include_directories( + ${LUA_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} +) set(_MODULE_LINK "${CURL_LIBRARY}") get_filename_component(_lua_lib_dir ${LUA_LIBRARY} PATH) @@ -62,7 +64,11 @@ if(WIN32) # Windows sprintf()/strtod() handle NaN/inf differently. Not supported. add_definitions(-DDISABLE_INVALID_NUMBERS) else() - set(_lua_module_dir "${_lua_lib_dir}/lua/5.1") + if (USE_LUA52) + set(_lua_module_dir "${_lua_lib_dir}/lua/5.2") + else () + set(_lua_module_dir "${_lua_lib_dir}/lua/5.1") + endif () endif() diff --git a/cmake/Modules/FindLua52.cmake b/cmake/Modules/FindLua52.cmake new file mode 100644 index 0000000..6a45f74 --- /dev/null +++ b/cmake/Modules/FindLua52.cmake @@ -0,0 +1,81 @@ +# Locate Lua library +# This module defines +# LUA52_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# 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. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(LUA_INCLUDE_DIR lua.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES include/lua52 include/lua5.2 include/lua include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_LIBRARY(LUA_LIBRARY + NAMES lua52 lua5.2 lua-5.2 lua + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +IF(LUA_LIBRARY) + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUA_MATH_LIBRARY m) + SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +ENDIF(LUA_LIBRARY) + +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua52 + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) +