Correct LUA_LIBRARIES in cmake config

This commit is contained in:
Rocka 2023-02-19 15:40:29 +08:00
parent b4d597e122
commit 8b773b191c
No known key found for this signature in database
GPG Key ID: 28031158FFDD6853
2 changed files with 22 additions and 6 deletions

View File

@ -35,6 +35,8 @@ set(LUA_LIB_SRCS
set(TARGETS_TO_INSTALL lua_internal lua_include) set(TARGETS_TO_INSTALL lua_internal lua_include)
set(LUA_LINKED_LIBRARIES)
if(LUA_BUILD_AS_CXX) if(LUA_BUILD_AS_CXX)
set_source_files_properties(${LUA_LIB_SRCS} "src/lua.c" "src/luac.c" PROPERTIES LANGUAGE CXX ) set_source_files_properties(${LUA_LIB_SRCS} "src/lua.c" "src/luac.c" PROPERTIES LANGUAGE CXX )
endif() endif()
@ -87,14 +89,17 @@ if(UNIX)
if(NOT LIBM) if(NOT LIBM)
message(FATAL_ERROR "libm not found and is required by lua") message(FATAL_ERROR "libm not found and is required by lua")
endif() endif()
target_compile_definitions(lua_internal INTERFACE "LUA_USE_POSIX")
target_link_libraries(lua_internal INTERFACE m) target_link_libraries(lua_internal INTERFACE m)
list(APPEND LUA_LINKED_LIBRARIES m)
target_compile_definitions(lua_internal
INTERFACE LUA_USE_POSIX
)
if(LUA_SUPPORT_DL) if(LUA_SUPPORT_DL)
find_library(LIBDL "${CMAKE_DL_LIBS}")
if(NOT LIBDL)
message(FATAL_ERROR "libdl not found and is required by lua")
endif()
target_compile_definitions(lua_internal INTERFACE "LUA_USE_DLOPEN") target_compile_definitions(lua_internal INTERFACE "LUA_USE_DLOPEN")
target_link_libraries(lua_internal INTERFACE dl) target_link_libraries(lua_internal INTERFACE "${CMAKE_DL_LIBS}")
list(APPEND LUA_LINKED_LIBRARIES "${CMAKE_DL_LIBS}")
endif() endif()
endif() endif()

View File

@ -4,6 +4,17 @@ include("${CMAKE_CURRENT_LIST_DIR}/LuaTargets.cmake")
set_and_check(LUA_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") set_and_check(LUA_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
add_library(Lua::Library ALIAS "Lua::@LUA_EXPORT_LIBRARY@") add_library(Lua::Library ALIAS "Lua::@LUA_EXPORT_LIBRARY@")
set(LUA_LIBRARIES "Lua::Library") get_target_property(LUA_CONFIG "Lua::@LUA_EXPORT_LIBRARY@" IMPORTED_CONFIGURATIONS)
get_target_property(LUA_LIBRARY "Lua::@LUA_EXPORT_LIBRARY@" "IMPORTED_LOCATION_${LUA_CONFIG}")
set(LUA_LIBRARIES "${LUA_LIBRARY}")
foreach(LIB_NAME @LUA_LINKED_LIBRARIES@)
find_library(LIB_LOCATION "${LIB_NAME}")
if(NOT LIB_LOCATION)
message(FATAL_ERROR "lib${LIB_NAME} not found and is required by lua")
else()
list(APPEND LUA_LIBRARIES "${LIB_LOCATION}")
endif()
endforeach()
check_required_components(Lua) check_required_components(Lua)