Add CMake package config files

This commit is contained in:
Rocka 2022-02-11 16:26:19 +08:00
parent 0ab5db21e8
commit 50c100526b
No known key found for this signature in database
GPG Key ID: 28031158FFDD6853
2 changed files with 53 additions and 4 deletions

View File

@ -38,8 +38,14 @@ if(LUA_BUILD_AS_CXX)
endif() endif()
add_library(lua_static STATIC ${LUA_LIB_SRCS}) add_library(lua_static STATIC ${LUA_LIB_SRCS})
set_target_properties(lua_static PROPERTIES OUTPUT_NAME "lua") set_target_properties(lua_static PROPERTIES
target_include_directories(lua_static PUBLIC "include") OUTPUT_NAME "lua"
VERSION "${PACKAGE_VERSION}"
)
target_include_directories(lua_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(UNIX) if(UNIX)
set(LUA_DEFINITIONS) set(LUA_DEFINITIONS)
@ -49,7 +55,7 @@ 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_link_libraries(lua_static INTERFACE ${LIBM}) target_link_libraries(lua_static INTERFACE m)
list(APPEND LUA_DEFINITIONS LUA_USE_POSIX) list(APPEND LUA_DEFINITIONS LUA_USE_POSIX)
if(LUA_SUPPORT_DL) if(LUA_SUPPORT_DL)
@ -81,10 +87,43 @@ if(LUA_BUILD_BINARY)
target_link_libraries(lua PUBLIC readline) target_link_libraries(lua PUBLIC readline)
endif() endif()
endif() endif()
if(LUA_BUILD_COMPILER) if(LUA_BUILD_COMPILER)
add_executable(luac "src/luac.c") add_executable(luac "src/luac.c")
target_link_libraries(luac PUBLIC lua_static) target_link_libraries(luac PUBLIC lua_static)
set_target_properties(luac PROPERTIES set_target_properties(luac PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
) )
endif() endif()
install(TARGETS lua_static
EXPORT LuaTargets
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
install(DIRECTORY include/ TYPE INCLUDE)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
LuaConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install(EXPORT LuaTargets
FILE LuaTargets.cmake
DESTINATION "lib/cmake"
)
configure_package_config_file(
LuaConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/LuaConfig.cmake"
INSTALL_DESTINATION "lib/cmake"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LuaConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LuaConfigVersion.cmake"
DESTINATION "lib/cmake"
)

View File

@ -0,0 +1,10 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/LuaTargets.cmake")
set_and_check(LUA_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
set_and_check(LUA_LIBRARY "${PACKAGE_PREFIX_DIR}/lib/liblua.a")
set(LUA_LIBRARIES "${LUA_LIBRARY}")
add_library(Lua::Library ALIAS lua_static)
check_required_components(Lua)