++
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
set(LUA_VERSION "lua52" CACHE STRING "Lua version to use")
|
||||
set_property(CACHE LUA_VERSION PROPERTY STRINGS luajit lua51 lua52 lua53 lua54)
|
||||
MESSAGE(STATUS "Lua version: ${LUA_VERSION}")
|
||||
|
||||
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
|
||||
cmake_policy(SET CMP0135 NEW)
|
||||
endif()
|
||||
|
||||
option(LUA_STATIC "link lua statically" OFF)
|
||||
if (LUA_STATIC)
|
||||
MESSAGE(STATUS "Lua linking: static")
|
||||
else()
|
||||
MESSAGE(STATUS "Lua linking: dynamic")
|
||||
endif()
|
||||
|
||||
if (LUA_VERSION MATCHES "luajit")
|
||||
add_subdirectory(luajit)
|
||||
else()
|
||||
add_subdirectory(lua)
|
||||
endif()
|
||||
@@ -1,134 +0,0 @@
|
||||
# BSD-3-Clause
|
||||
# Copyright (c) 2022, Rochet2 <[email protected]>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
project ( lua C )
|
||||
|
||||
# LUA_VERSION must be one of lua51, lua52, lua53, lua54
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
lua51
|
||||
URL https://www.lua.org/ftp/lua-5.1.5.tar.gz
|
||||
URL_HASH SHA256=2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333
|
||||
)
|
||||
FetchContent_Declare(
|
||||
lua52
|
||||
URL https://www.lua.org/ftp/lua-5.2.4.tar.gz
|
||||
URL_HASH SHA256=b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b
|
||||
)
|
||||
FetchContent_Declare(
|
||||
lua53
|
||||
URL https://www.lua.org/ftp/lua-5.3.6.tar.gz
|
||||
URL_HASH SHA256=fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60
|
||||
)
|
||||
FetchContent_Declare(
|
||||
lua54
|
||||
URL https://www.lua.org/ftp/lua-5.4.4.tar.gz
|
||||
URL_HASH SHA256=164c7849653b80ae67bec4b7473b884bf5cc8d2dca05653475ec2ed27b9ebf61
|
||||
)
|
||||
FetchContent_MakeAvailable(${LUA_VERSION})
|
||||
|
||||
# Easen warnings
|
||||
string(REGEX REPLACE "( |^)/W[0-9]( |$)" "\\1/W2\\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REGEX REPLACE "( |^)/W[0-9]( |$)" "\\1/W2\\2" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
|
||||
set(LUA_SOURCE_FOLDER "${${LUA_VERSION}_SOURCE_DIR}/src")
|
||||
|
||||
file(GLOB LOCAL_SOURCES_H ${LUA_SOURCE_FOLDER}/*.h)
|
||||
file(GLOB LOCAL_SOURCES_C ${LUA_SOURCE_FOLDER}/*.c)
|
||||
# Compile lua as C++ so it uses exceptions instead of longjmp
|
||||
# Disabled for now as some libraries expect lua to be C
|
||||
# set_source_files_properties(${LOCAL_SOURCES_H} ${LOCAL_SOURCES_C} PROPERTIES LANGUAGE CXX )
|
||||
list(REMOVE_ITEM LOCAL_SOURCES_C ${LUA_SOURCE_FOLDER}/lua.c)
|
||||
list(REMOVE_ITEM LOCAL_SOURCES_C ${LUA_SOURCE_FOLDER}/luac.c)
|
||||
|
||||
if (LUA_STATIC)
|
||||
add_library(lualib STATIC ${LOCAL_SOURCES_H} ${LOCAL_SOURCES_C})
|
||||
set_property(TARGET lualib PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
else()
|
||||
add_library(lualib SHARED ${LOCAL_SOURCES_H} ${LOCAL_SOURCES_C})
|
||||
set_property(TARGET lualib PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
set_target_properties(lualib PROPERTIES LINKER_LANGUAGE C)
|
||||
target_include_directories(lualib PUBLIC "${LUA_SOURCE_FOLDER}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
if (WIN32)
|
||||
set_target_properties(lualib PROPERTIES OUTPUT_NAME ${LUA_VERSION})
|
||||
install(TARGETS lualib DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
if (NOT LUA_STATIC)
|
||||
install(FILES $<TARGET_PDB_FILE:lualib> DESTINATION "${CMAKE_INSTALL_PREFIX}" OPTIONAL)
|
||||
endif()
|
||||
else()
|
||||
set_target_properties(lualib PROPERTIES PUBLIC_HEADER "${LOCAL_SOURCES_H};${CMAKE_CURRENT_SOURCE_DIR}/lua.hpp")
|
||||
install(TARGETS lualib
|
||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
|
||||
)
|
||||
endif()
|
||||
if (WIN32)
|
||||
target_compile_definitions(lualib PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
if (NOT LUA_STATIC)
|
||||
target_compile_definitions(lualib PRIVATE LUA_BUILD_AS_DLL)
|
||||
endif()
|
||||
elseif (APPLE)
|
||||
target_compile_definitions(lualib PUBLIC LUA_USE_MACOSX)
|
||||
target_compile_options(lualib PRIVATE -Wno-deprecated-declarations -Wno-empty-body)
|
||||
target_link_libraries(lualib readline)
|
||||
elseif (UNIX)
|
||||
target_compile_definitions(lualib PUBLIC LUA_USE_LINUX)
|
||||
target_link_libraries(lualib ${CMAKE_DL_LIBS} m readline)
|
||||
set_target_properties(lualib PROPERTIES OUTPUT_NAME ${LUA_VERSION})
|
||||
endif()
|
||||
|
||||
#add_executable(lua_interpreter ${LUA_SOURCE_FOLDER}/lua.c)
|
||||
#target_link_libraries(lua_interpreter lualib)
|
||||
#target_compile_definitions(lua_interpreter PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
#set_target_properties(lua_interpreter PROPERTIES OUTPUT_NAME ${LUA_VERSION}_interpreter)
|
||||
#if (WIN32)
|
||||
# install(TARGETS lua_interpreter DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
# install(FILES $<TARGET_PDB_FILE:lua_interpreter> DESTINATION "${CMAKE_INSTALL_PREFIX}" OPTIONAL)
|
||||
#else()
|
||||
# install(TARGETS lua_interpreter DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
|
||||
#endif()
|
||||
#install(TARGETS lualib
|
||||
# DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||
# LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lua/lib"
|
||||
# RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/lua/lib"
|
||||
# ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lua/lib"
|
||||
#)
|
||||
|
||||
#add_executable(lua_compiler ${LUA_SOURCE_FOLDER}/luac.c)
|
||||
#target_link_libraries(lua_compiler lualib)
|
||||
#target_compile_definitions(lua_compiler PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
#set_target_properties(lua_compiler PROPERTIES OUTPUT_NAME ${LUA_VERSION}_compiler)
|
||||
#if (WIN32)
|
||||
# install(TARGETS lua_compiler DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
# install(FILES $<TARGET_PDB_FILE:lua_compiler> DESTINATION "${CMAKE_INSTALL_PREFIX}" OPTIONAL)
|
||||
#else()
|
||||
# install(TARGETS lua_compiler DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
|
||||
#endif()
|
||||
@@ -1,10 +0,0 @@
|
||||
// Some lua sources include this file and some do not,
|
||||
// so here is the file to be used with all lua sources as some libraries expect it to exist.
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
# BSD-3-Clause
|
||||
# Copyright (c) 2022, Rochet2 <[email protected]>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
project ( lua C )
|
||||
|
||||
# Download source
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
luajit21
|
||||
GIT_REPOSITORY https://github.com/LuaJIT/LuaJIT.git
|
||||
GIT_TAG a91d0d9d3bba1a936669cfac3244509a0f2ac0e3 # 2.1.0-beta3+ where mac builds without extra setup
|
||||
)
|
||||
FetchContent_MakeAvailable(luajit21)
|
||||
|
||||
set(LUA_SRC_FOLDER "${luajit21_SOURCE_DIR}")
|
||||
set(LUA_BIN_FOLDER "${luajit21_BINARY_DIR}")
|
||||
# note that the / at the end means that we copy folder contents, not the folder itself
|
||||
file(COPY ${LUA_SRC_FOLDER}/ DESTINATION ${LUA_BIN_FOLDER})
|
||||
|
||||
if (WIN32)
|
||||
if (LUA_STATIC)
|
||||
# build luajit static
|
||||
add_custom_command(
|
||||
OUTPUT ${LUA_BIN_FOLDER}/src/lua51.lib ${LUA_BIN_FOLDER}/src/luajit.exe
|
||||
WORKING_DIRECTORY ${LUA_BIN_FOLDER}/src
|
||||
COMMAND call msvcbuild.bat static
|
||||
)
|
||||
|
||||
# add it as a library target
|
||||
add_custom_target(luajit_target DEPENDS ${LUA_BIN_FOLDER}/src/lua51.lib)
|
||||
add_library(lualib STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(lualib luajit_target)
|
||||
set_target_properties(lualib
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION ${LUA_BIN_FOLDER}/src/lua51.lib
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_FOLDER}/src"
|
||||
)
|
||||
|
||||
# install generated files
|
||||
install(FILES ${LUA_BIN_FOLDER}/src/lua51.lib ${LUA_BIN_FOLDER}/src/luajit.exe DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
install(DIRECTORY ${LUA_BIN_FOLDER}/src/jit DESTINATION "${CMAKE_INSTALL_PREFIX}/lua")
|
||||
else()
|
||||
# build luajit dll
|
||||
add_custom_command(
|
||||
OUTPUT ${LUA_BIN_FOLDER}/src/lua51.dll ${LUA_BIN_FOLDER}/src/lua51.lib ${LUA_BIN_FOLDER}/src/luajit.exe
|
||||
WORKING_DIRECTORY ${LUA_BIN_FOLDER}/src
|
||||
# COMMAND echo luajit built on platform $(Platform)
|
||||
# COMMAND cd $(VSInstallDir)/VC
|
||||
# COMMAND if \"$(Platform)\"==\"Win32\" echo \"luajit building $(Platform)\" & call $(VSInstallDir)/VC/vcvarsall.bat $(Platform) & call msvcbuild.bat
|
||||
# COMMAND if \"$(Platform)\"==\"Win32\" echo \"luajit building 64bit\" & call $(VSInstallDir)/VC/vcvarsall.bat x64
|
||||
# COMMAND if \"$(Platform)\"==\"Win64\" echo luajit building 64bit
|
||||
# COMMAND if \"$(Platform)\"==\"Win64\" call $(VSInstallDir)/VC/vcvarsall.bat x64
|
||||
# COMMAND cd ${LUA_BIN_FOLDER}/src
|
||||
COMMAND call msvcbuild.bat
|
||||
# COMMAND ${CMAKE_COMMAND} -E copy ${LUA_BIN_FOLDER}/src/lua51.dll ${CMAKE_BINARY_DIR}/$(ConfigurationName)/
|
||||
# COMMAND ${CMAKE_COMMAND} -E copy ${LUA_BIN_FOLDER}/src/lua51.lib ${CMAKE_BINARY_DIR}/$(ConfigurationName)/
|
||||
# COMMAND ${CMAKE_COMMAND} -E copy ${LUA_BIN_FOLDER}/src/luajit.exe ${CMAKE_BINARY_DIR}/$(ConfigurationName)/
|
||||
)
|
||||
|
||||
# add it as a library target
|
||||
add_custom_target(luajit_target DEPENDS ${LUA_BIN_FOLDER}/src/lua51.lib)
|
||||
add_library(lualib SHARED IMPORTED GLOBAL)
|
||||
add_dependencies(lualib luajit_target)
|
||||
set_target_properties(lualib
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION ${LUA_BIN_FOLDER}/src/lua51.dll
|
||||
IMPORTED_IMPLIB ${LUA_BIN_FOLDER}/src/lua51.lib
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_FOLDER}/src"
|
||||
)
|
||||
|
||||
# install generated files
|
||||
install(FILES ${LUA_BIN_FOLDER}/src/lua51.dll ${LUA_BIN_FOLDER}/src/lua51.lib ${LUA_BIN_FOLDER}/src/luajit.exe DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
install(DIRECTORY ${LUA_BIN_FOLDER}/src/jit DESTINATION "${CMAKE_INSTALL_PREFIX}/lua")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (UNIX OR APPLE)
|
||||
#option(LUA_USR "Use /usr/local/ as lua library location" OFF)
|
||||
#if (LUA_USR)
|
||||
# set(LUA_INSTALL_PATH "/usr/local")
|
||||
#else()
|
||||
set(LUA_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/BIN")
|
||||
#endif()
|
||||
|
||||
if (LUA_STATIC)
|
||||
set(LUAJIT_LIB_PATH "${LUA_INSTALL_PATH}/lib/libluajit-5.1.a")
|
||||
else()
|
||||
if (APPLE)
|
||||
set(LUAJIT_LIB_PATH "${LUA_INSTALL_PATH}/lib/libluajit-5.1.2.1.0.dylib")
|
||||
elseif(UNIX)
|
||||
set(LUAJIT_LIB_PATH "${LUA_INSTALL_PATH}/lib/libluajit-5.1.so.2.1.0")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# build luajit
|
||||
# if (LUA_USR)
|
||||
# add_custom_command(
|
||||
# OUTPUT ${LUAJIT_LIB_PATH}
|
||||
# COMMAND $(MAKE) -C ${LUA_BIN_FOLDER}
|
||||
# COMMAND $(MAKE) -C ${LUA_BIN_FOLDER} install
|
||||
# )
|
||||
# else ()
|
||||
add_custom_command(
|
||||
OUTPUT ${LUAJIT_LIB_PATH}
|
||||
# COMMAND $(MAKE) -C ${LUA_BIN_FOLDER} PREFIX=${LUA_INSTALL_PATH}
|
||||
COMMAND $(MAKE) -C ${LUA_BIN_FOLDER} install PREFIX=${LUA_INSTALL_PATH}
|
||||
)
|
||||
# endif()
|
||||
add_custom_target(luajit_target DEPENDS ${LUAJIT_LIB_PATH})
|
||||
|
||||
# add it as a library target
|
||||
if (LUA_STATIC)
|
||||
add_library(lualib STATIC IMPORTED GLOBAL)
|
||||
# on static build the libraries are not a part of the luajit archive
|
||||
target_link_libraries(lualib INTERFACE ${CMAKE_DL_LIBS})
|
||||
else()
|
||||
add_library(lualib SHARED IMPORTED GLOBAL)
|
||||
endif()
|
||||
add_dependencies(lualib luajit_target)
|
||||
set_target_properties(lualib
|
||||
PROPERTIES
|
||||
# IMPORTED_LOCATION ${LUAJIT_LIB_PATH} # cmake bullshit. spent days figuring this and turns out set_target_properties does squat shit while set_property works fine.
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_FOLDER}/src"
|
||||
)
|
||||
set_property(TARGET lualib PROPERTY IMPORTED_LOCATION ${LUAJIT_LIB_PATH})
|
||||
|
||||
# install generated files
|
||||
install(DIRECTORY ${LUA_INSTALL_PATH}/ DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
Reference in New Issue
Block a user