Skip to content

Commit

Permalink
Add support for Lua 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
markand committed Dec 18, 2013
1 parent 7bbb9eb commit b374705
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 13 deletions.
32 changes: 19 additions & 13 deletions 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)")


Expand Down Expand Up @@ -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)
Expand All @@ -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()


Expand Down
81 changes: 81 additions & 0 deletions 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 <lua/lua.h>
# 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)

0 comments on commit b374705

Please sign in to comment.