2015-04-16 02:01:08 -07:00
|
|
|
# BuildLuajit(TARGET targetname CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
|
|
|
|
# Reusable function to build luajit, wraps ExternalProject_Add.
|
|
|
|
# Failing to pass a command argument will result in no command being run
|
|
|
|
function(BuildLuajit)
|
|
|
|
cmake_parse_arguments(_luajit
|
|
|
|
""
|
|
|
|
"TARGET"
|
|
|
|
"CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
|
|
|
|
${ARGN})
|
|
|
|
if(NOT _luajit_CONFIGURE_COMMAND AND NOT _luajit_BUILD_COMMAND
|
|
|
|
AND NOT _luajit_INSTALL_COMMAND)
|
|
|
|
message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
|
|
|
|
endif()
|
|
|
|
if(NOT _luajit_TARGET)
|
|
|
|
set(_luajit_TARGET "luajit")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
ExternalProject_Add(${_luajit_TARGET}
|
|
|
|
PREFIX ${DEPS_BUILD_DIR}
|
|
|
|
URL ${LUAJIT_URL}
|
|
|
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luajit
|
|
|
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DPREFIX=${DEPS_BUILD_DIR}
|
|
|
|
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/luajit
|
|
|
|
-DURL=${LUAJIT_URL}
|
|
|
|
-DEXPECTED_SHA256=${LUAJIT_SHA256}
|
|
|
|
-DTARGET=${_luajit_TARGET}
|
2015-09-08 03:09:44 -07:00
|
|
|
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
2015-04-16 02:01:08 -07:00
|
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
|
|
|
CONFIGURE_COMMAND "${_luajit_CONFIGURE_COMMAND}"
|
|
|
|
BUILD_IN_SOURCE 1
|
|
|
|
BUILD_COMMAND "${_luajit_BUILD_COMMAND}"
|
|
|
|
INSTALL_COMMAND "${_luajit_INSTALL_COMMAND}")
|
2019-09-30 03:50:22 -07:00
|
|
|
|
|
|
|
# Create symlink for development version manually.
|
|
|
|
if(UNIX)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET ${_luajit_TARGET}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink luajit-2.1.0-beta3 ${DEPS_BIN_DIR}/luajit)
|
|
|
|
endif()
|
2015-04-16 02:01:08 -07:00
|
|
|
endfunction()
|
|
|
|
|
2019-11-17 13:55:25 -07:00
|
|
|
check_c_compiler_flag(-fno-stack-check HAS_NO_STACK_CHECK)
|
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND HAS_NO_STACK_CHECK)
|
|
|
|
set(NO_STACK_CHECK "CFLAGS+=-fno-stack-check")
|
|
|
|
else()
|
|
|
|
set(NO_STACK_CHECK "")
|
|
|
|
endif()
|
2018-04-02 02:08:11 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
|
|
|
set(AMD64_ABI "LDFLAGS=-lpthread -lc++abi")
|
|
|
|
else()
|
|
|
|
set(AMD64_ABI "")
|
|
|
|
endif()
|
2015-04-16 02:01:08 -07:00
|
|
|
set(INSTALLCMD_UNIX ${MAKE_PRG} CFLAGS=-fPIC
|
|
|
|
CFLAGS+=-DLUA_USE_APICHECK
|
2021-10-29 08:54:59 -07:00
|
|
|
CFLAGS+=-funwind-tables
|
2019-11-17 13:55:25 -07:00
|
|
|
${NO_STACK_CHECK}
|
2018-04-02 02:08:11 -07:00
|
|
|
${AMD64_ABI}
|
2015-04-16 02:01:08 -07:00
|
|
|
CCDEBUG+=-g
|
2015-11-10 04:19:08 -07:00
|
|
|
Q=
|
2021-10-30 03:10:19 -07:00
|
|
|
install)
|
2015-04-16 02:01:08 -07:00
|
|
|
|
|
|
|
if(UNIX)
|
2018-10-15 17:35:15 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2020-11-28 08:14:30 -07:00
|
|
|
if(CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
|
|
set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
|
|
|
else()
|
|
|
|
# Use the same target as our nightly builds
|
|
|
|
set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=10.11")
|
|
|
|
endif()
|
2018-10-15 17:35:15 -07:00
|
|
|
else()
|
|
|
|
set(DEPLOYMENT_TARGET "")
|
|
|
|
endif()
|
|
|
|
|
2015-04-16 02:01:08 -07:00
|
|
|
BuildLuaJit(INSTALL_COMMAND ${INSTALLCMD_UNIX}
|
2018-10-15 17:35:15 -07:00
|
|
|
CC=${DEPS_C_COMPILER} PREFIX=${DEPS_INSTALL_DIR}
|
|
|
|
${DEPLOYMENT_TARGET})
|
2015-04-16 02:01:08 -07:00
|
|
|
|
|
|
|
elseif(MINGW AND CMAKE_CROSSCOMPILING)
|
|
|
|
|
|
|
|
# Build luajit for the host
|
|
|
|
BuildLuaJit(TARGET luajit_host
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BUILD_COMMAND ""
|
|
|
|
INSTALL_COMMAND ${INSTALLCMD_UNIX}
|
|
|
|
CC=${HOST_C_COMPILER} PREFIX=${HOSTDEPS_INSTALL_DIR})
|
|
|
|
|
|
|
|
# Build luajit for the target
|
|
|
|
BuildLuaJit(
|
|
|
|
# Similar to Unix + cross - fPIC
|
|
|
|
INSTALL_COMMAND
|
|
|
|
${MAKE_PRG} PREFIX=${DEPS_INSTALL_DIR}
|
|
|
|
BUILDMODE=static install
|
|
|
|
TARGET_SYS=${CMAKE_SYSTEM_NAME}
|
|
|
|
CROSS=${CROSS_TARGET}-
|
|
|
|
HOST_CC=${HOST_C_COMPILER} HOST_CFLAGS=${HOST_C_FLAGS}
|
|
|
|
HOST_LDFLAGS=${HOST_EXE_LINKER_FLAGS}
|
|
|
|
FILE_T=luajit.exe
|
2015-11-10 04:19:08 -07:00
|
|
|
Q=
|
2015-04-16 02:01:08 -07:00
|
|
|
INSTALL_TSYMNAME=luajit.exe)
|
|
|
|
|
2015-05-05 17:13:40 -07:00
|
|
|
elseif(MINGW)
|
|
|
|
|
2018-05-21 03:32:19 -07:00
|
|
|
if(CMAKE_GENERATOR MATCHES "Ninja")
|
|
|
|
set(LUAJIT_MAKE_PRG ${MAKE_PRG})
|
|
|
|
else()
|
|
|
|
set(LUAJIT_MAKE_PRG ${CMAKE_MAKE_PROGRAM})
|
|
|
|
endif()
|
|
|
|
BuildLuaJit(BUILD_COMMAND ${LUAJIT_MAKE_PRG} CC=${DEPS_C_COMPILER}
|
2015-05-05 17:13:40 -07:00
|
|
|
PREFIX=${DEPS_INSTALL_DIR}
|
|
|
|
CFLAGS+=-DLUA_USE_APICHECK
|
2021-10-29 08:54:59 -07:00
|
|
|
CFLAGS+=-funwind-tables
|
2015-05-05 17:13:40 -07:00
|
|
|
CCDEBUG+=-g
|
|
|
|
BUILDMODE=static
|
|
|
|
# Build a DLL too
|
2018-05-21 03:32:19 -07:00
|
|
|
COMMAND ${LUAJIT_MAKE_PRG} CC=${DEPS_C_COMPILER} BUILDMODE=dynamic
|
2015-05-05 17:13:40 -07:00
|
|
|
|
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/luajit.exe ${DEPS_INSTALL_DIR}/bin
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_INSTALL_DIR}/bin
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/lib
|
|
|
|
# Luarocks searches for lua51.dll in lib
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_INSTALL_DIR}/lib
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/libluajit.a ${DEPS_INSTALL_DIR}/lib
|
2019-09-30 03:50:22 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/include/luajit-2.1
|
|
|
|
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/luajit/src/*.h -DTO=${DEPS_INSTALL_DIR}/include/luajit-2.1 -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
|
2021-12-18 10:53:27 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin/lua/jit
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_BUILD_DIR}/src/luajit/src/jit ${DEPS_INSTALL_DIR}/bin/lua/jit
|
|
|
|
)
|
2015-05-05 17:13:40 -07:00
|
|
|
elseif(MSVC)
|
2015-04-16 02:01:08 -07:00
|
|
|
|
|
|
|
BuildLuaJit(
|
2015-12-19 21:50:20 -07:00
|
|
|
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${DEPS_BUILD_DIR}/src/luajit/src ${DEPS_BUILD_DIR}/src/luajit/src/msvcbuild.bat
|
2015-04-16 02:01:08 -07:00
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/luajit.exe ${DEPS_INSTALL_DIR}/bin
|
2015-12-19 21:50:20 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_INSTALL_DIR}/bin
|
2015-04-16 02:01:08 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/lib
|
2018-02-28 18:14:27 -07:00
|
|
|
# Luarocks searches for lua51.lib
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_INSTALL_DIR}/lib/lua51.lib
|
|
|
|
# Luv searches for luajit.lib
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_INSTALL_DIR}/lib/luajit.lib
|
2019-09-30 03:50:22 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/include/luajit-2.1
|
2021-12-18 10:53:27 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/luajit/src/*.h -DTO=${DEPS_INSTALL_DIR}/include/luajit-2.1 -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin/lua/jit
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_BUILD_DIR}/src/luajit/src/jit ${DEPS_INSTALL_DIR}/bin/lua/jit
|
|
|
|
)
|
2015-04-16 02:01:08 -07:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Trying to build luajit in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}")
|
|
|
|
endif()
|
2015-03-09 06:24:21 -07:00
|
|
|
|
2015-03-10 03:04:06 -07:00
|
|
|
list(APPEND THIRD_PARTY_DEPS luajit)
|