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] Fix library type and usage #24436

Merged
merged 13 commits into from
May 13, 2022
28 changes: 28 additions & 0 deletions ports/lua/CMakeLists-cpp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SET(SRC_LIBLUACPP ${SRC_LIBLUA})
ADD_LIBRARY ( lua-cpp ${SRC_LIBLUACPP} ${HDR_LIBLUACPP} )
SET_TARGET_PROPERTIES(lua-cpp PROPERTIES OUTPUT_NAME "lua-c++")
SET_SOURCE_FILES_PROPERTIES(${SRC_LIBLUACPP} PROPERTIES LANGUAGE CXX)
TARGET_INCLUDE_DIRECTORIES(lua-cpp PRIVATE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> PUBLIC $<INSTALL_INTERFACE:include>)
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 bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

INSTALL(EXPORT unofficial-lua-cpp-config DESTINATION share/unofficial-lua-cpp)
82 changes: 25 additions & 57 deletions ports/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,16 @@
PROJECT ( lua )


CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET (HDR_LIBLUA
src/lapi.h src/lauxlib.h src/lcode.h src/lctype.h src/ldebug.h src/ldo.h src/lfunc.h
src/lgc.h src/llex.h src/llimits.h src/lmem.h src/lobject.h src/lopcodes.h src/lparser.h
src/lstate.h src/lstring.h src/ltable.h src/ltm.h src/lua.h src/luaconf.h src/lualib.h
src/lundump.h src/lvm.h src/lzio.h
)
CMAKE_MINIMUM_REQUIRED(VERSION 3.18)

# Build Libraries
SET (SRC_LIBLUA
src/lapi.c src/lauxlib.c src/lbaselib.c src/lcode.c src/lcorolib.c
src/lctype.c src/ldblib.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c
src/linit.c src/liolib.c src/llex.c src/lmathlib.c src/lmem.c src/loadlib.c src/lobject.c
src/lopcodes.c src/loslib.c src/lparser.c src/lstate.c src/lstring.c src/lstrlib.c
src/ltable.c src/ltablib.c src/ltm.c src/lundump.c src/lutf8lib.c src/lvm.c src/lzio.c
)

IF (COMPILE_AS_CPP)
SET_SOURCE_FILES_PROPERTIES(${SRC_LIBLUA} src/lua.c src/luac.c PROPERTIES LANGUAGE CXX)
ELSE ()
SET (CMAKE_C_STANDARD 99)
ENDIF ()
FILE(GLOB HDR_LIBLUA "${CMAKE_SOURCE_DIR}/src/*.h")
# For luac.c
LIST(REMOVE_ITEM HDR_LIBLUA "${CMAKE_SOURCE_DIR}/src/lopnames.h")

# append headers to sources to make them show up in MSVC GUI
LIST(APPEND SRC_LIBLUA ${HDR_LIBLUA})
FILE(GLOB SRC_LIBLUA "${CMAKE_SOURCE_DIR}/src/*.c")
# Executables luac and luai
LIST(REMOVE_ITEM SRC_LIBLUA "${CMAKE_SOURCE_DIR}/src/luac.c" "${CMAKE_SOURCE_DIR}/src/lua.c")

IF (WIN32)
# remove warnings
Expand All @@ -50,9 +34,13 @@ IF (UNIX)
ENDIF ()
ENDIF ()

#DLL
ADD_LIBRARY ( lua ${SRC_LIBLUA} )
# C library
SET (CMAKE_C_STANDARD 99)
SET(SRC_LIBLUAC ${SRC_LIBLUA})
ADD_LIBRARY ( lua ${SRC_LIBLUAC} ${HDR_LIBLUA} )
TARGET_INCLUDE_DIRECTORIES(lua PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> PUBLIC $<INSTALL_INTERFACE:include>)
SET_PROPERTY (TARGET lua PROPERTY POSITION_INDEPENDENT_CODE ON)
SET_SOURCE_FILES_PROPERTIES(${SRC_LIBLUAC} PROPERTIES LANGUAGE C)

IF (BUILD_SHARED_LIBS AND WIN32)
TARGET_COMPILE_DEFINITIONS (lua PUBLIC -DLUA_BUILD_AS_DLL )
Expand All @@ -72,45 +60,25 @@ 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
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

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

# CXX library
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)
ADD_SUBDIRECTORY(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
TARGET_LINK_LIBRARIES ( luai lua )
# compiler uses non-exported APIs, so must include sources directly.
ADD_EXECUTABLE ( luac ${CMAKE_SOURCE_DIR}/src/luac.c ${SRC_LIBLUA} ${CMAKE_SOURCE_DIR}/src/lopnames.h )
ADD_EXECUTABLE ( luai ${CMAKE_SOURCE_DIR}/src/lua.c ) # interpreter

TARGET_INCLUDE_DIRECTORIES(luac PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src)
TARGET_LINK_LIBRARIES ( luai PRIVATE lua )
SET_TARGET_PROPERTIES ( luai PROPERTIES OUTPUT_NAME lua PDB_NAME luai )
IF (UNIX)
IF (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
Expand All @@ -127,7 +95,7 @@ IF (INSTALL_TOOLS)
ENDIF ()
ENDIF ()
ENDIF ()
INSTALL ( TARGETS luai luac RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/tools/lua )
INSTALL ( TARGETS luai luac RUNTIME DESTINATION tools/lua )
ENDIF ()

IF (NOT SKIP_INSTALL_HEADERS)
Expand Down
18 changes: 3 additions & 15 deletions ports/lua/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,20 @@ vcpkg_download_distfile(ARCHIVE
)
vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
ARCHIVE "${ARCHIVE}"
PATCHES
vs2015-impl-c99.patch
fix-ios-system.patch
)

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)
if (VCPKG_TARGET_IS_UWP)
message(FATAL_ERROR "Feature cpp does not support uwp.")
endif()
set(ENABLE_LUA_CPP 1)
endif()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/CMakeLists-cpp.txt" DESTINATION "${SOURCE_PATH}/cpp" RENAME "CMakeLists.txt")

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
cpp COMPILE_AS_CPP
cpp COMPILE_AS_CPP # Also used in cmake wrapper
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()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
Expand Down Expand Up @@ -62,5 +51,4 @@ endif()
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}")

# Handle copyright
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/COPYRIGHT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
2 changes: 1 addition & 1 deletion ports/lua/vcpkg-cmake-wrapper.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endforeach()

_find_package(unofficial-lua CONFIG ${REQUIRES})

if (@ENABLE_LUA_CPP@)
if (@COMPILE_AS_CPP@)
_find_package(unofficial-lua-cpp CONFIG ${REQUIRES})
endif()

Expand Down
9 changes: 6 additions & 3 deletions ports/lua/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "lua",
"version": "5.4.4",
"port-version": 1,
"port-version": 2,
"description": "A powerful, fast, lightweight, embeddable scripting language",
"homepage": "https://www.lua.org",
"license": null,
"dependencies": [
{
"name": "vcpkg-cmake",
Expand All @@ -16,10 +17,12 @@
],
"features": {
"cpp": {
"description": "Builds Lua for C++ linkage"
"description": "Builds Lua for C++ linkage",
"supports": "!uwp"
},
"tools": {
"description": "Builds Lua compiler and interpreter"
"description": "Builds Lua compiler and interpreter",
"supports": "!ios"
}
}
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4302,7 +4302,7 @@
},
"lua": {
"baseline": "5.4.4",
"port-version": 1
"port-version": 2
},
"luabridge": {
"baseline": "2.6",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/lua.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "1443185b76c2f6e0e74c425ed0b3176e98a5fb01",
"version": "5.4.4",
"port-version": 2
},
{
"git-tree": "26701e6e610ff6eaee198ca1aaa0b9125e4b2d6f",
"version": "5.4.4",
Expand Down