hypermcpe/cmake/LuaJIT.cmake
Kirill Sokolov 110cb2a896 Infinite world, LuaJIT mod API, WorldEdit port, skins and music
- Infinite world: streamed chunk cache, multi-region storage (old chunks.dat
  still loads), per-chunk entity/tile entity persistence, client chunk
  streaming, protocol version 10, view-distance server property
- LuaJIT mod host (mods/, lua/prelude.lua) with events, commands, world and
  player API; WorldEdit command set ported to it (mods/worldedit)
- /skin command, SetSkinPacket and bundled skins
- OGG music player (data/music is ignored, tools/convert-music.ps1)
- package-windows.ps1 builds client and dedicated server for Windows

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 21:08:09 +03:00

70 lines
2.5 KiB
CMake

# Builds LuaJIT (static) from source and exposes it as the imported target "luajit".
#
# * MSVC: runs LuaJIT's own msvcbuild.bat inside the matching Visual Studio environment
# * others: runs LuaJIT's Makefile (make / mingw32-make)
CPMAddPackage(
NAME "luajit"
GIT_REPOSITORY "https://github.com/LuaJIT/LuaJIT.git"
GIT_TAG "dd3b24369ddfaa83c78cd6fdd91d157c8968ec8d"
DOWNLOAD_ONLY YES
)
set(LUAJIT_SRC "${luajit_SOURCE_DIR}/src")
if (MSVC)
set(LUAJIT_LIB "${LUAJIT_SRC}/lua51.lib")
# <VS>/VC/Tools/MSVC/<ver>/bin/Hostx64/x64/cl.exe -> <VS>/VC/Auxiliary/Build/vcvarsall.bat
get_filename_component(_cl_dir "${CMAKE_C_COMPILER}" DIRECTORY)
get_filename_component(_vc_root "${_cl_dir}/../../../../../.." ABSOLUTE)
set(_vcvars "${_vc_root}/Auxiliary/Build/vcvarsall.bat")
if (NOT EXISTS "${_vcvars}")
message(FATAL_ERROR "vcvarsall.bat not found at ${_vcvars}")
endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_vcarch x64)
else()
set(_vcarch x86)
endif()
file(TO_NATIVE_PATH "${_vcvars}" _vcvars_native)
file(TO_NATIVE_PATH "${LUAJIT_SRC}" _src_native)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/build_luajit.bat" _bat_native)
# LuaJIT needs the Visual Studio command line environment, so run it from a batch file
# (msvcbuild.bat runs the tools it just built by bare name, which needs the current directory in the search path)
set(_bat "@echo off\r\nset NoDefaultCurrentDirectoryInExePath=\r\n")
string(APPEND _bat "call \"${_vcvars_native}\" ${_vcarch} || exit /b 1\r\n")
string(APPEND _bat "cd /d \"${_src_native}\" || exit /b 1\r\n")
string(APPEND _bat "call .\\msvcbuild.bat static || exit /b 1\r\n")
file(WRITE "${CMAKE_BINARY_DIR}/build_luajit.bat" "${_bat}")
add_custom_command(
OUTPUT "${LUAJIT_LIB}"
COMMAND cmd /c "${_bat_native}"
WORKING_DIRECTORY "${LUAJIT_SRC}"
COMMENT "Building LuaJIT"
VERBATIM
)
else()
set(LUAJIT_LIB "${LUAJIT_SRC}/libluajit.a")
find_program(_make NAMES make gmake mingw32-make REQUIRED)
add_custom_command(
OUTPUT "${LUAJIT_LIB}"
COMMAND "${_make}" BUILDMODE=static
WORKING_DIRECTORY "${LUAJIT_SRC}"
COMMENT "Building LuaJIT"
VERBATIM
)
endif()
add_custom_target(luajit_build DEPENDS "${LUAJIT_LIB}")
add_library(luajit STATIC IMPORTED GLOBAL)
set_target_properties(luajit PROPERTIES
IMPORTED_LOCATION "${LUAJIT_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${LUAJIT_SRC}"
)
add_dependencies(luajit luajit_build)