Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to link to system Lua5.3 #609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong condition

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
Expand Down Expand Up @@ -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}
Expand All @@ -291,7 +309,7 @@ target_link_libraries(
${PROJECT_NAME}
${FREETYPE_LIBRARIES}
${BULLET_LIBRARIES}
lua5.3
${LUA_LIBRARY}
${PNG_LIBRARIES}
${OPENAL_LIBRARY}
${SDL2_LIBRARY}
Expand Down
90 changes: 90 additions & 0 deletions cmake/FindLua53.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't the cmake provided FindLua suffice?

# 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 <lua/lua.h>

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)