From b3690306d812aca1f0f43a7d0ad4be8de1e27033 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Wed, 10 Jul 2019 14:56:57 -0500 Subject: [PATCH] Add ability to link to system Lua5.3 --- CMakeLists.txt | 22 ++++++++++- cmake/FindLua53.cmake | 90 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 cmake/FindLua53.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 589367b82..ca65210e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) option(FORCE_SYSTEM_FREETYPE "Use system-provided FreeType instead of internal library." OFF) option(FORCE_SYSTEM_BULLET "Use system-provided BULLET instead of internal library." OFF) +option(FORCE_SYSTEM_LUA "Use system-provided Lua instead of internal library." OFF) # Detect system FreeType @@ -52,7 +53,23 @@ if (OPENTOMB_INTERNAL_BULLET) set(BULLET_LIBRARIES bullet) endif () -add_subdirectory(extern/lua) +if (FORCE_SYSTEM_LUA) + find_package(Lua53 QUIET) + if (NOT LUA53_FOUND) + message(WARNING "Lua not found. Enabling internal Lua support.") + set(OPENTOMB_INTERNAL_LUA ON) + else() + set(OPENTOMB_INTERNAL_LUA OFF) + endif () +else () + set(OPENTOMB_INTERNAL_LUA ON) +endif () + +if (OPENTOMB_INTERNAL_BULLET) + add_subdirectory(extern/lua) + set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/lua") + set(LUA_LIBRARY lua5.3) +endif () set(OPENTOMB_SRCS src/core/gui/gui_obj.c @@ -280,6 +297,7 @@ target_include_directories( ${PROJECT_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS} ${BULLET_INCLUDE_DIRS} + ${LUA_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} @@ -291,7 +309,7 @@ target_link_libraries( ${PROJECT_NAME} ${FREETYPE_LIBRARIES} ${BULLET_LIBRARIES} - lua5.3 + ${LUA_LIBRARY} ${PNG_LIBRARIES} ${OPENAL_LIBRARY} ${SDL2_LIBRARY} diff --git a/cmake/FindLua53.cmake b/cmake/FindLua53.cmake new file mode 100644 index 000000000..7f34e33f8 --- /dev/null +++ b/cmake/FindLua53.cmake @@ -0,0 +1,90 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindLua53 +--------- + + + +Locate Lua library This module defines + +:: + + LUA53_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/ +#]=======================================================================] + +find_path(LUA_INCLUDE_DIR lua.h + HINTS + ENV LUA_DIR + PATH_SUFFIXES include/lua53 include/lua5.3 include/lua-5.3 include/lua include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(LUA_LIBRARY + NAMES lua53 lua5.3 lua-5.3 lua + HINTS + ENV LUA_DIR + PATH_SUFFIXES lib lib/lua53 + 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 AND NOT BEOS AND NOT HAIKU) + 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() + 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(${CMAKE_MODULE_PATH}/FindPackageHandleStandardArgs.cmake) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua53 + 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) +