Skip to content

Commit

Permalink
Fixed FindLua52 to only match Lua 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ilpincy committed Nov 9, 2019
1 parent fba07de commit b666cad
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/cmake/FindLua52.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

# Find the folder that contains lua.h
find_path(LUA_INCLUDE_DIR lua.h
HINTS
ENV LUA_DIR
ENV LUA_DIR
PATH_SUFFIXES include/lua52 include/lua5.2 include/lua-5.2 include/lua include
PATHS
~/Library/Frameworks
Expand All @@ -36,12 +37,25 @@ find_path(LUA_INCLUDE_DIR lua.h
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
)
# Make sure that the version number is 5.2
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_major_define REGEX "^#define[ \t]+LUA_VERSION_MAJOR")
file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_minor_define REGEX "^#define[ \t]+LUA_VERSION_MINOR")
if(lua_version_major_define AND lua_version_minor_define)
string(REGEX MATCH "[0-9]+" lua_version_major ${lua_version_major_define})
string(REGEX MATCH "[0-9]+" lua_version_minor ${lua_version_minor_define})
set(LUA_VERSION_STRING "${lua_version_major}.${lua_version_minor}")
if(${LUA_VERSION_STRING} VERSION_EQUAL "5.2")
set(LUA_CORRECT_VERSION 1)
endif()
endif()
endif()

find_library(LUA_LIBRARY
NAMES lua52 lua5.2 lua-5.2 lua
HINTS
ENV LUA_DIR
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
Expand All @@ -50,32 +64,24 @@ find_library(LUA_LIBRARY
/opt/local
/opt/csw
/opt
)
)

if(LUA_LIBRARY)
# include the math library for Unix
if(UNIX AND NOT APPLE AND NOT BEOS)
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
# For Windows and Mac, don't need to explicitly include the math library
else()
set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
endif()
endif()

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)
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR LUA_CORRECT_VERSION
VERSION_VAR LUA_VERSION_STRING)

mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)

0 comments on commit b666cad

Please sign in to comment.