1
0

Use system Lua, if available, to generate bindings.

Closes #1031.
This commit is contained in:
Mattes D 2016-07-17 16:23:29 +02:00
parent 0e24a0beae
commit 430b623223
4 changed files with 72 additions and 23 deletions

View File

@ -92,6 +92,18 @@ endif()
set(BUILD_TOOLS OFF CACHE BOOL "") set(BUILD_TOOLS OFF CACHE BOOL "")
set(SELF_TEST OFF CACHE BOOL "") set(SELF_TEST OFF CACHE BOOL "")
# Check whether Lua 5.1 is installed locally:
include(CheckLua.cmake)
if(HAS_LUA_INTERPRETER AND ("${LUA_INTERPRETER_VERSION}" STREQUAL "5.1"))
message(STATUS "Lua 5.1 has been found in your system and will be used for the build.")
else()
if (CROSSCOMPILE)
message(FATAL "To crosscompile, you need to have Lua 5.1 installed in your system and available in PATH.")
endif()
message(STATUS "Lua 5.1 has NOT been found in your system, the build will use its own Lua implementation.")
endif()
# This has to be done before any flags have been set up. # This has to be done before any flags have been set up.
if(${BUILD_TOOLS}) if(${BUILD_TOOLS})
message("Building tools") message("Building tools")

23
CheckLua.cmake Normal file
View File

@ -0,0 +1,23 @@
# CheckLua.cmake
# Checks whether the Lua standalone interpreter is installed on the host system
# If found, sets HAS_LUA_INTERPRETER to 1 and LUA_INTERPRETER_VERSION to the version reported ("5.1" etc.)
# If not found, unsets HAS_LUA_INTERPRETER
execute_process(
COMMAND lua -e "io.stdout:write(string.match(_VERSION, '%d+%.%d+'))"
RESULT_VARIABLE LUA_EXECUTED
OUTPUT_VARIABLE LUA_INTERPRETER_VERSION
)
if ("${LUA_EXECUTED}" STREQUAL "0")
set(HAS_LUA_INTERPRETER 1)
else()
unset(HAS_LUA_INTERPRETER)
unset(LUA_INTERPRETER_VERSION)
endif()
unset(LUA_EXECUTED)

View File

@ -56,7 +56,6 @@ set (BINDING_OUTPUTS
) )
set(BINDING_DEPENDENCIES set(BINDING_DEPENDENCIES
tolua
../Bindings/AllToLua.pkg ../Bindings/AllToLua.pkg
../Bindings/BindingsProcessor.lua ../Bindings/BindingsProcessor.lua
../Bindings/LuaFunctions.h ../Bindings/LuaFunctions.h
@ -139,17 +138,21 @@ set(BINDING_DEPENDENCIES
) )
if (NOT MSVC) if (NOT MSVC)
ADD_CUSTOM_COMMAND( if (HAS_LUA_INTERPRETER)
# add any new generated bindings here ADD_CUSTOM_COMMAND(
OUTPUT ${BINDING_OUTPUTS} OUTPUT ${BINDING_OUTPUTS}
COMMAND lua BindingsProcessor.lua
# Regenerate bindings: WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg DEPENDS ${BINDING_DEPENDENCIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
else()
# add any new generation dependencies here ADD_CUSTOM_COMMAND(
DEPENDS ${BINDING_DEPENDENCIES} OUTPUT ${BINDING_OUTPUTS}
) COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${BINDING_DEPENDENCIES} tolua
)
endif()
endif () endif ()
set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE) set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE)

View File

@ -252,6 +252,10 @@ else ()
foreach (hdr ${FOLDER_HDRS}) foreach (hdr ${FOLDER_HDRS})
list(APPEND SOURCE "${folder}/${hdr}") list(APPEND SOURCE "${folder}/${hdr}")
endforeach(hdr) endforeach(hdr)
# Include this folder's CMakeLists.txt in the project:
list(APPEND SOURCE "${folder}/CMakeLists.txt")
source_group("${folder}" FILES "${folder}/CMakeLists.txt")
endforeach(folder) endforeach(folder)
list(APPEND SOURCE "${SRCS}") list(APPEND SOURCE "${SRCS}")
@ -315,19 +319,26 @@ if (MSVC)
list (APPEND BINDINGS_DEPENDENCIES "Bindings/${dep}") list (APPEND BINDINGS_DEPENDENCIES "Bindings/${dep}")
endforeach(dep) endforeach(dep)
ADD_CUSTOM_COMMAND( if (HAS_LUA_INTERPRETER)
OUTPUT ${BINDING_OUTPUTS} ADD_CUSTOM_COMMAND(
OUTPUT ${BINDING_OUTPUTS}
COMMAND lua BindingsProcessor.lua
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/
DEPENDS ${BINDINGS_DEPENDENCIES}
)
else()
ADD_CUSTOM_COMMAND(
OUTPUT ${BINDING_OUTPUTS}
# Copy the Lua DLL into the Bindings folder, so that tolua can run from there: # Copy the Lua DLL into the Bindings folder, so that tolua can run from there:
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/Server/lua51.dll ./lua51.dll COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/Server/lua51.dll ./lua51.dll
# Regenerate bindings: # Regenerate bindings:
COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/
DEPENDS ${BINDINGS_DEPENDENCIES} tolua
# add any new generation dependencies here )
DEPENDS ${BINDINGS_DEPENDENCIES} endif()
)
endif() endif()
add_executable(${EXECUTABLE} ${SOURCE}) add_executable(${EXECUTABLE} ${SOURCE})