2015-04-16 02:01:08 -07:00
|
|
|
function(BuildLuajit)
|
|
|
|
cmake_parse_arguments(_luajit
|
|
|
|
""
|
2024-03-23 13:28:46 -07:00
|
|
|
""
|
2022-06-24 08:34:57 -07:00
|
|
|
"CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND;DEPENDS"
|
2015-04-16 02:01:08 -07:00
|
|
|
${ARGN})
|
|
|
|
|
2024-03-18 04:23:53 -07:00
|
|
|
get_externalproject_options(luajit ${DEPS_IGNORE_SHA})
|
2024-03-23 13:28:46 -07:00
|
|
|
ExternalProject_Add(luajit
|
|
|
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luajit
|
2015-04-16 02:01:08 -07:00
|
|
|
CONFIGURE_COMMAND "${_luajit_CONFIGURE_COMMAND}"
|
|
|
|
BUILD_IN_SOURCE 1
|
|
|
|
BUILD_COMMAND "${_luajit_BUILD_COMMAND}"
|
2022-06-24 08:34:57 -07:00
|
|
|
INSTALL_COMMAND "${_luajit_INSTALL_COMMAND}"
|
2023-11-20 04:42:54 -07:00
|
|
|
DEPENDS "${_luajit_DEPENDS}"
|
|
|
|
${EXTERNALPROJECT_OPTIONS})
|
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)
|
2023-03-02 14:50:43 -07:00
|
|
|
if(APPLE AND HAS_NO_STACK_CHECK)
|
2019-11-17 13:55:25 -07:00
|
|
|
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()
|
2023-02-24 13:17:23 -07:00
|
|
|
set(BUILDCMD_UNIX ${MAKE_PRG} -j CFLAGS=-fPIC
|
2022-06-24 08:34:57 -07:00
|
|
|
CFLAGS+=-DLUA_USE_APICHECK
|
|
|
|
CFLAGS+=-funwind-tables
|
|
|
|
${NO_STACK_CHECK}
|
|
|
|
${AMD64_ABI}
|
|
|
|
CCDEBUG+=-g
|
|
|
|
Q=)
|
2015-04-16 02:01:08 -07:00
|
|
|
|
2022-07-19 07:10:59 -07:00
|
|
|
# Setting MACOSX_DEPLOYMENT_TARGET is mandatory for LuaJIT; use version set by
|
|
|
|
# cmake.deps/CMakeLists.txt (either environment variable or current system version).
|
2023-03-02 14:50:43 -07:00
|
|
|
if(APPLE)
|
2022-07-19 07:10:59 -07:00
|
|
|
set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
2022-06-24 08:34:57 -07:00
|
|
|
endif()
|
2018-10-15 17:35:15 -07:00
|
|
|
|
2024-03-23 13:28:46 -07:00
|
|
|
if(UNIX)
|
2022-06-24 08:34:57 -07:00
|
|
|
BuildLuaJit(INSTALL_COMMAND ${BUILDCMD_UNIX}
|
2018-10-15 17:35:15 -07:00
|
|
|
CC=${DEPS_C_COMPILER} PREFIX=${DEPS_INSTALL_DIR}
|
2022-06-24 08:34:57 -07:00
|
|
|
${DEPLOYMENT_TARGET} install)
|
|
|
|
|
2022-05-17 06:08:24 -07:00
|
|
|
elseif(MINGW)
|
|
|
|
|
|
|
|
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}
|
|
|
|
PREFIX=${DEPS_INSTALL_DIR}
|
|
|
|
CFLAGS+=-DLUA_USE_APICHECK
|
|
|
|
CFLAGS+=-funwind-tables
|
|
|
|
CCDEBUG+=-g
|
|
|
|
BUILDMODE=static
|
|
|
|
# Build a DLL too
|
|
|
|
COMMAND ${LUAJIT_MAKE_PRG} CC=${DEPS_C_COMPILER} BUILDMODE=dynamic
|
|
|
|
|
2023-03-05 07:21:46 -07:00
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/luajit.exe ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_LIB_DIR}
|
2022-05-17 06:08:24 -07:00
|
|
|
# Luarocks searches for lua51.dll in lib
|
2023-03-05 07:21:46 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_LIB_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/libluajit.a ${DEPS_LIB_DIR}
|
2022-05-17 06:08:24 -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
|
2023-08-21 07:24:31 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_BUILD_DIR}/src/luajit/src/jit ${DEPS_INSTALL_DIR}/share/luajit-2.1/jit
|
2022-05-17 06:08:24 -07:00
|
|
|
)
|
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
|
2023-03-05 07:21:46 -07:00
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/luajit.exe ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_BIN_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_LIB_DIR}
|
2018-02-28 18:14:27 -07:00
|
|
|
# Luarocks searches for lua51.lib
|
2023-03-05 07:21:46 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_LIB_DIR}/lua51.lib
|
2018-02-28 18:14:27 -07:00
|
|
|
# Luv searches for luajit.lib
|
2023-03-05 07:21:46 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_LIB_DIR}/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
|
2023-08-21 07:24:31 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_BUILD_DIR}/src/luajit/src/jit ${DEPS_INSTALL_DIR}/share/luajit-2.1/jit
|
2021-12-18 10:53:27 -07:00
|
|
|
)
|
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()
|