Add lua diff
All checks were successful
Build Dusk / build-linux (push) Successful in 1m51s
Build Dusk / build-psp (push) Successful in 2m2s

This commit is contained in:
2025-12-04 00:39:09 -06:00
parent 77d3c54ebb
commit 8c74ee31e0
2 changed files with 12 additions and 61 deletions

View File

@@ -1,59 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
if(NOT TARGET lua)
message(STATUS "Looking for Lua...")
set(LUA_FOUND FALSE CACHE INTERNAL "Lua found")
set(LUA_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/_lua")
set(LUA_SEARCH_ROOTS
"${LUA_ROOT}"
"$ENV{LUADEV}"
"$ENV{HOME}/luadev"
"/usr/local/luadev"
"/opt/luadev"
"/usr/luadev"
"${LUA_DOWNLOAD_DIR}/luadev"
)
foreach(root IN LISTS LUA_SEARCH_ROOTS)
list(APPEND LUA_BIN_HINTS "${root}/bin")
list(APPEND LUA_INCLUDE_HINTS "${root}/include")
list(APPEND LUA_LIB_HINTS "${root}/lib")
endforeach()
# Find Lua interpreter
find_program(LUA_EXECUTABLE NAMES lua HINTS ${LUA_BIN_HINTS})
# Find Lua headers and library
find_path(LUA_INCLUDE_DIR lua.h HINTS ${LUA_INCLUDE_HINTS})
find_library(LUA_LIBRARY NAMES lua HINTS ${LUA_LIB_HINTS})
# If not found, use FetchContent to download and build Lua
if(NOT LUA_EXECUTABLE OR NOT LUA_INCLUDE_DIR OR NOT LUA_LIBRARY)
message(STATUS "Lua not found in system paths. Using FetchContent to download and build Lua.")
include(FetchContent)
FetchContent_Declare(
lua
GIT_REPOSITORY https://github.com/lua/lua.git
GIT_TAG v5.4.6 # Change to desired version
)
FetchContent_MakeAvailable(lua)
# Try to locate built Lua
set(LUA_INCLUDE_DIR "${lua_SOURCE_DIR}")
set(LUA_LIBRARY "${lua_BINARY_DIR}/liblua.a")
set(LUA_EXECUTABLE "${lua_BINARY_DIR}/lua")
endif()
if(LUA_EXECUTABLE AND LUA_INCLUDE_DIR AND LUA_LIBRARY)
set(LUA_FOUND TRUE CACHE INTERNAL "Lua found")
add_library(lua INTERFACE IMPORTED)
set_target_properties(lua PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARY}"
)
message(STATUS "Lua found: ${LUA_EXECUTABLE}")
endif()
endif()

View File

@@ -5,7 +5,17 @@
find_package(cglm REQUIRED)
find_package(libzip REQUIRED)
find_package(lua REQUIRED)
find_package(Lua REQUIRED)
if(Lua_FOUND AND NOT TARGET Lua::Lua)
add_library(Lua::Lua INTERFACE IMPORTED)
set_target_properties(
Lua::Lua
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
)
endif()
# Libs
target_link_libraries(${DUSK_TARGET_NAME}
@@ -13,8 +23,8 @@ target_link_libraries(${DUSK_TARGET_NAME}
m
cglm
zip
lua
pthread
Lua::Lua
)
# Includes