Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lua] Export cmake targets, rewrite CMakeLists and delete usage #15921

Merged
merged 12 commits into from
Aug 12, 2021
34 changes: 31 additions & 3 deletions ports/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ ENDIF ()
#DLL
ADD_LIBRARY ( lua ${SRC_LIBLUA} )
SET_PROPERTY (TARGET lua PROPERTY POSITION_INDEPENDENT_CODE ON)
IF (COMPILE_AS_CPP)
SET_TARGET_PROPERTIES(lua PROPERTIES OUTPUT_NAME "lua-c++")
ENDIF()

IF (BUILD_SHARED_LIBS AND WIN32)
TARGET_COMPILE_DEFINITIONS (lua PUBLIC -DLUA_BUILD_AS_DLL )
Expand All @@ -74,11 +71,42 @@ IF (UNIX)
ENDIF ()

INSTALL ( TARGETS lua
EXPORT unofficial-lua-config
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)

install(EXPORT unofficial-lua-config DESTINATION share/unofficial-lua)

IF (COMPILE_AS_CPP)
ADD_LIBRARY ( lua-cpp ${SRC_LIBLUA} )
SET_TARGET_PROPERTIES(lua-cpp PROPERTIES OUTPUT_NAME "lua-c++")
IF (BUILD_SHARED_LIBS AND WIN32)
TARGET_COMPILE_DEFINITIONS (lua-cpp PUBLIC -DLUA_BUILD_AS_DLL )
ENDIF ()
IF (UNIX)
IF (APPLE)
TARGET_COMPILE_DEFINITIONS (lua-cpp PUBLIC -DLUA_USE_DLOPEN)
ELSE ()
FIND_LIBRARY (LIB_DLOPEN NAMES dl)
IF (LIB_DLOPEN)
TARGET_COMPILE_DEFINITIONS (lua-cpp PUBLIC -DLUA_USE_DLOPEN)
TARGET_LINK_LIBRARIES (lua-cpp ${LIB_DLOPEN})
ENDIF ()
ENDIF ()
ENDIF ()

INSTALL ( TARGETS lua-cpp
EXPORT unofficial-lua-cpp-config
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)

install(EXPORT unofficial-lua-cpp-config DESTINATION share/unofficial-lua-cpp)
ENDIF()

IF (INSTALL_TOOLS)
ADD_EXECUTABLE ( luac src/luac.c ${SRC_LIBLUA} ) # compiler uses non-exported APIs, so must include sources directly.
ADD_EXECUTABLE ( luai src/lua.c ) # interpreter
Expand Down
32 changes: 14 additions & 18 deletions ports/lua/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,39 @@ vcpkg_extract_source_archive_ex(

file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})

# Used in cmake wrapper
set(ENABLE_LUA_CPP 0)
if ("cpp" IN_LIST FEATURES)
set(ENABLE_LUA_CPP 1)
endif()

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
cpp COMPILE_AS_CPP
tools INSTALL_TOOLS
)
if(VCPKG_TARGET_IS_IOS AND "tools" IN_LIST FEATURES)
message(FATAL_ERROR "lua[tools] is not supported for iOS platform build")
endif()

set(ENABLE_LUA_CPP 0)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_RELEASE
${FEATURE_OPTIONS}
OPTIONS
-DCOMPILE_AS_CPP=OFF
${FEATURE_OPTIONS}
OPTIONS_DEBUG
-DSKIP_INSTALL_HEADERS=ON
)
vcpkg_install_cmake()

if("cpp" IN_LIST FEATURES) # lua[cpp] will create lua-c++, which uses C++ name mangling.
set(ENABLE_LUA_CPP 1)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
${FEATURE_OPTIONS}
-DCOMPILE_AS_CPP=ON
OPTIONS_DEBUG
-DSKIP_INSTALL_HEADERS=ON
)
vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-lua TARGET_PATH share/unofficial-lua)

if("cpp" IN_LIST FEATURES)
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-lua-cpp TARGET_PATH share/unofficial-lua-cpp)
endif()

vcpkg_copy_pdbs()
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/lua)
#vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/lua)

if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
if(VCPKG_TARGET_IS_WINDOWS)
Expand All @@ -59,7 +55,7 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
endif()
endif()

# Handle post-build CMake instructions
# Suitable for old version
configure_file(${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake @ONLY)
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})

Expand Down
4 changes: 0 additions & 4 deletions ports/lua/usage
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
Use this package via the module FindLua that comes with CMake. To use in your CMakeLists.txt:
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

include(FindLua)
find_package(Lua REQUIRED)
target_link_libraries(main PRIVATE ${LUA_LIBRARIES})
target_include_directories(main PRIVATE ${LUA_INCLUDE_DIR})

For more information about the variables set by this module, please see:
https://cmake.org/cmake/help/latest/module/FindLua.html
25 changes: 21 additions & 4 deletions ports/lua/vcpkg-cmake-wrapper.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
_find_package(${ARGS})
set(REQUIRES )
foreach(ARG IN_LISTS ${ARGS})
if (ARG STREQUAL "REQUIRED")
set(REQUIRES "REQUIRED")
endif()
endforeach()

_find_package(unofficial-lua CONFIG ${REQUIRES})

if (@ENABLE_LUA_CPP@)
find_library(lua_cpp NAMES lua-c++ liblua-c++ REQUIRED)
set(LUA_LIBRARIES ${LUA_LIBRARIES} ${lua_cpp})
endif()
_find_package(unofficial-lua-cpp CONFIG ${REQUIRES})
endif()

get_filename_component(LUA_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH)
get_filename_component(LUA_INCLUDE_DIR "${LUA_INCLUDE_DIR}" PATH)
set(LUA_INCLUDE_DIR ${LUA_INCLUDE_DIR}/include)

list(APPEND LUA_LIBRARIES lua)
if (TARGET lua-cpp)
list(APPEND LUA_LIBRARIES lua-cpp)
endif()

set(LUA_FOUND 1)
2 changes: 1 addition & 1 deletion ports/lua/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lua",
"version-string": "5.4.3",
"port-version": 1,
"port-version": 2,
"description": "A powerful, fast, lightweight, embeddable scripting language",
"homepage": "https://www.lua.org",
"features": {
Expand Down