Skip to content

Commit

Permalink
Allow setting existing system LuaJIT prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekingMeaning committed Jan 14, 2020
1 parent 8c6ccd0 commit b54d94e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmake/Modules/GetLuaJIT.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
include(FindPackageHandleStandardArgs)

if(DEFINED LUAJIT_INSTALL_PREFIX)
set(USE_SYSTEM_LUAJIT 1)
else()
set(USE_SYSTEM_LUAJIT 0)
endif()

set(LUAJIT_VERSION_MAJOR 2)
set(LUAJIT_VERSION_MINOR 0)
set(LUAJIT_VERSION_BASE ${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR})
set(LUAJIT_VERSION_EXTRA .5)
set(LUAJIT_BASENAME "LuaJIT-${LUAJIT_VERSION_BASE}${LUAJIT_VERSION_EXTRA}")
if(NOT USE_SYSTEM_LUAJIT)
set(LUAJIT_URL "https://luajit.org/download/${LUAJIT_BASENAME}.tar.gz")
set(LUAJIT_TAR "${PROJECT_BINARY_DIR}/${LUAJIT_BASENAME}.tar.gz")
set(LUAJIT_SOURCE_DIR "${PROJECT_BINARY_DIR}/${LUAJIT_BASENAME}")
endif()
set(LUAJIT_HEADER_BASENAMES lua.h lualib.h lauxlib.h luaconf.h)
if(WIN32)
if(NOT USE_SYSTEM_LUAJIT)
set(LUAJIT_INSTALL_PREFIX "${LUAJIT_SOURCE_DIR}/src")
endif()
set(LUAJIT_INCLUDE_DIR "${LUAJIT_INSTALL_PREFIX}")
set(LUAJIT_LIBRARY_NAME_WE "${LUAJIT_INSTALL_PREFIX}/lua51")
set(LUAJIT_EXECUTABLE "${LUAJIT_INSTALL_PREFIX}/luajit.exe")
else()
if(NOT USE_SYSTEM_LUAJIT)
set(LUAJIT_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/luajit")
endif()
set(LUAJIT_INCLUDE_DIR "${LUAJIT_INSTALL_PREFIX}/include/luajit-${LUAJIT_VERSION_BASE}")
set(LUAJIT_LIBRARY_NAME_WE "${LUAJIT_INSTALL_PREFIX}/lib/libluajit-5.1")
set(LUAJIT_EXECUTABLE "${LUAJIT_INSTALL_PREFIX}/bin/luajit-${LUAJIT_VERSION_BASE}${LUAJIT_VERSION_EXTRA}")
Expand All @@ -33,12 +45,14 @@ string(CONCAT
"${CMAKE_SHARED_LIBRARY_SUFFIX}"
)

if(NOT USE_SYSTEM_LUAJIT)
file(DOWNLOAD "${LUAJIT_URL}" "${LUAJIT_TAR}")

execute_process(
COMMAND "${CMAKE_COMMAND}" -E tar xzf "${LUAJIT_TAR}"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endif()

foreach(LUAJIT_HEADER ${LUAJIT_HEADER_BASENAMES})
list(APPEND LUAJIT_INSTALL_HEADERS "${LUAJIT_INCLUDE_DIR}/${LUAJIT_HEADER}")
Expand All @@ -54,6 +68,7 @@ if(UNIX AND NOT APPLE)
)
endif()

if(NOT USE_SYSTEM_LUAJIT)
if(WIN32)
add_custom_command(
OUTPUT ${LUAJIT_STATIC_LIBRARY} ${LUAJIT_SHARED_LIBRARY_PATHS} ${LUAJIT_EXECUTABLE} ${LUAJIT_INSTALL_HEADERS}
Expand Down Expand Up @@ -109,6 +124,7 @@ else()
VERBATIM
)
endif()
endif()

foreach(LUAJIT_HEADER ${LUAJIT_HEADER_BASENAMES})
list(APPEND LUAJIT_HEADERS ${PROJECT_BINARY_DIR}/include/terra/${LUAJIT_HEADER})
Expand All @@ -134,7 +150,7 @@ foreach(LUAJIT_HEADER ${LUAJIT_HEADER_BASENAMES})
)
endforeach()

if(TERRA_SLIB_INCLUDE_LUAJIT)
if(TERRA_SLIB_INCLUDE_LUAJIT AND NOT USE_SYSTEM_LUAJIT)
set(LUAJIT_OBJECT_DIR "${PROJECT_BINARY_DIR}/lua_objects")
file(MAKE_DIRECTORY "${LUAJIT_OBJECT_DIR}")

Expand Down

0 comments on commit b54d94e

Please sign in to comment.