Files
dusk/cmake/modules/Findlua.cmake
Dominic Masters 9f507be7bc
Some checks failed
Build Dusk / build-linux (push) Failing after 2m56s
Build Dusk / build-psp (push) Failing after 1m49s
Lua script something
2025-12-04 00:02:26 -06:00

60 lines
1.9 KiB
CMake

# 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()