[node-api] rework port, rename to node-api-headers, apply upstream's versioning (#29743)

This commit is contained in:
Leonid Pospelov 2023-04-14 01:50:12 +06:00 committed by GitHub
parent 971343dedc
commit 78c1f5bc5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 98 additions and 128 deletions

View File

@ -1,9 +1,9 @@
if(NOT TARGET unofficial::node-addon-api::node-addon-api)
include(CMakeFindDependencyMacro)
find_dependency(unofficial-node-api CONFIG)
find_dependency(unofficial-node-api-headers CONFIG)
add_library(unofficial::node-addon-api::node-addon-api IMPORTED INTERFACE)
target_link_libraries(unofficial::node-addon-api::node-addon-api INTERFACE unofficial::node-api::node-api)
target_link_libraries(unofficial::node-addon-api::node-addon-api INTERFACE unofficial::node-api-headers::node-api-headers)
set_target_properties(unofficial::node-addon-api::node-addon-api PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/../../include/"

View File

@ -1,12 +1,13 @@
{
"name": "node-addon-api",
"version": "6.0.0",
"port-version": 1,
"description": "Module for using Node-API from C++",
"homepage": "https://github.com/nodejs/node-addon-api",
"license": "MIT",
"supports": "((windows & !arm) | linux | osx) & !uwp",
"dependencies": [
"node-api",
"node-api-headers",
{
"name": "vcpkg-cmake",
"host": true

View File

@ -0,0 +1,15 @@
project(nodelib C)
add_custom_target(nodelib ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/node.lib)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/node.lib
COMMAND ${CMAKE_AR}
/def:${CMAKE_CURRENT_SOURCE_DIR}/def/node_api.def
/out:${CMAKE_CURRENT_BINARY_DIR}/node.lib
${CMAKE_STATIC_LINKER_FLAGS}
$<$<CONFIG:Debug>:${CMAKE_STATIC_LINKER_FLAGS_DEBUG}>
$<$<CONFIG:Release>:${CMAKE_STATIC_LINKER_FLAGS_RELEASE}>
COMMENT "Building import library for NodeJS"
)
install(FILES ${CMAKE_BINARY_DIR}/node.lib DESTINATION lib)

View File

@ -0,0 +1,19 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nodejs/node-api-headers
REF "v${VERSION}"
SHA512 095cff78b1bc4ca7cc81de30e941fb369f41596b3ae9d092100b1a5baf2c00ef9a4ac14016605346bc0532eb459b6a7dea10ed53fa595cf65825010ce75fcb67
HEAD_REF main
)
if(VCPKG_TARGET_IS_WINDOWS)
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}")
vcpkg_cmake_install()
endif()
file(INSTALL "${SOURCE_PATH}/include" DESTINATION "${CURRENT_PACKAGES_DIR}/include" RENAME "node")
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-${PORT}-config.cmake.in" "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" @ONLY)

View File

@ -0,0 +1,34 @@
if(NOT TARGET unofficial::node-api-headers::node-api-headers)
if(WIN32)
add_library(unofficial::node-api-headers::node-api-headers UNKNOWN IMPORTED)
else()
add_library(unofficial::node-api-headers::node-api-headers INTERFACE IMPORTED)
endif()
set(node-api-headers_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../include/node)
set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${node-api-headers_INCLUDE_DIR}"
)
if(APPLE)
set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
INTERFACE_LINK_OPTIONS "LINKER:SHELL:-undefined dynamic_lookup"
)
endif()
if(WIN32)
find_library(node-api-headers_LIBRARY_RELEASE NAMES node PATHS "${CMAKE_CURRENT_LIST_DIR}/../../lib" NO_DEFAULT_PATH REQUIRED)
set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
IMPORTED_LOCATION_RELEASE "${node-api-headers_LIBRARY_RELEASE}"
IMPORTED_CONFIGURATIONS RELEASE
)
if("@VCPKG_BUILD_TYPE@" STREQUAL "")
find_library(node-api-headers_LIBRARY_DEBUG NAMES node PATHS "${CMAKE_CURRENT_LIST_DIR}/../../debug/lib" NO_DEFAULT_PATH REQUIRED)
set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
IMPORTED_LOCATION_DEBUG "${node-api-headers_LIBRARY_DEBUG}"
)
set_property(TARGET unofficial::node-api-headers::node-api-headers APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
endif()
endif()
endif()

View File

@ -1,19 +1,20 @@
{
"name": "node-api",
"version-semver": "18.12.1",
"port-version": 2,
"name": "node-api-headers",
"version": "0.0.5",
"description": "NodeJS API for writing modules in C++",
"homepage": "https://nodejs.org/api/addons.html",
"license": null,
"supports": "((windows & !arm) | linux | osx) & !uwp",
"license": "MIT",
"supports": "(windows & !arm & !uwp) | linux | osx",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
"host": true,
"platform": "windows"
},
{
"name": "vcpkg-cmake-config",
"host": true
"host": true,
"platform": "windows"
}
]
}

View File

@ -1,76 +0,0 @@
set(SHA512 0)
if(VCPKG_TARGET_IS_WINDOWS)
set(SHA512 ee66d0c03d2e48046a42616abf7639a3983e7db24c04d8643b9141cb9209a50643e31873c5a4918853a4344e822d653480558510a4db9a2ab481396891d79917)
set(DIST_URL "https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-headers.tar.gz")
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
vcpkg_download_distfile(
out_win_lib
URLS "https://nodejs.org/dist/v${VERSION}/win-x64/node.lib"
FILENAME "node.lib"
SHA512 95c4b053bf88f758b6124b4a576719901545485613767f1ab996bb019ea7bb0d303c511b357f830e5a14d463dd74c6b412f126103f21d12e31ca00c7de86d853
)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
vcpkg_download_distfile(
out_win_lib
URLS "https://nodejs.org/dist/v${VERSION}/win-x86/node.lib"
FILENAME "node.lib"
SHA512 0baa54a7870088a3290f817f6362446d304e8710ee36f99075925d110bce5c1eac377aa5c4ed6cf30161f98f39032d848eeb8d459add57b1c6458b8c91c72073
)
endif()
elseif(VCPKG_TARGET_IS_OSX)
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(SHA512 8eb1713afdce23b0e8408d81aa47b3ea0955de328105d666a57efef8955b286c707c107377cff36164d8455558829ab65567b9cbe5997085afc841d95128fcd5)
set(DIST_URL "https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-darwin-arm64.tar.gz")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(SHA512 ffe7e878fd5e424b0ff0d2e7db5e9c02f283792df2f1a748bd6381226701bcd9f93ae48f88d295412afb10d1c924ca068f70aba9857236c8893a2b812eacf248)
set(DIST_URL "https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-darwin-x64.tar.gz")
endif()
elseif(VCPKG_TARGET_IS_LINUX)
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(SHA512 f137a0dba52ded9f2f6b304c5f41fd2c75ba069ee31cfb89811b14254552c0d5ba10890f7001e64e8a6fee277302cb0ba915e0a417c047577384ac495c4ff447)
set(DIST_URL "https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-linux-x64.tar.gz")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(SHA512 a0b2f522b0ecdc4b642f3104fd2eb08b8dfa6dc2b116b5a331722b8c6d96b2b6d5df0e691ef2b56e0463e1f30d37c98c686c5d306e1aa8cd927b306c4eef0770)
set(DIST_URL "https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-linux-arm64.tar.gz")
endif()
endif()
get_filename_component(DIST_FILENAME "${DIST_URL}" NAME)
if(out_win_lib)
# nodejs requires the same node.lib to be used for both debug and release builds
file(COPY "${out_win_lib}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
file(COPY "${out_win_lib}" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
endif()
# download dist
vcpkg_download_distfile(
out_dist
URLS "${DIST_URL}"
FILENAME "${DIST_FILENAME}"
SHA512 "${SHA512}"
)
# extract dist
vcpkg_extract_source_archive(
OUT_SOURCE_PATH
ARCHIVE "${out_dist}"
)
# copy headers
set(suffix "include/node")
set(source_path "${OUT_SOURCE_PATH}/${suffix}")
file(COPY "${source_path}" DESTINATION "${CURRENT_PACKAGES_DIR}/include" FILES_MATCHING PATTERN "*.h")
# we do not take the license from the dist file because for windows it is not included as we download the headers only
set(license_url "https://raw.githubusercontent.com/nodejs/node/v${VERSION}/LICENSE")
vcpkg_download_distfile(
out_license
URLS "${license_url}"
FILENAME "LICENSE"
SHA512 2d79b49a12178a078cf1246ef7589d127189914403cd6f4dfe277ced2b3ef441a6e6ee131f1c75f996d1c1528b7e1ae332e83c1dc44580b2b51a933ed0c50c48
)
file(INSTALL "${out_license}" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-node-api-config.cmake.in" "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-node-api-config.cmake" @ONLY)

View File

@ -1,38 +0,0 @@
if(NOT TARGET unofficial::node-api::node-api)
if(WIN32)
add_library(unofficial::node-api::node-api UNKNOWN IMPORTED)
else()
add_library(unofficial::node-api::node-api INTERFACE IMPORTED)
endif()
find_path(node-api_INCLUDE_DIR
NAMES node.h
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../include/node"
NO_DEFAULT_PATH
REQUIRED
)
set_target_properties(unofficial::node-api::node-api PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${node-api_INCLUDE_DIR}"
)
if(APPLE)
set_target_properties(unofficial::node-api::node-api PROPERTIES
INTERFACE_LINK_OPTIONS "LINKER:SHELL:-undefined dynamic_lookup"
)
endif()
if(WIN32)
find_library(node-api_LIBRARY_RELEASE NAMES node PATHS "${CMAKE_CURRENT_LIST_DIR}/../../lib" NO_DEFAULT_PATH REQUIRED)
set_target_properties(unofficial::node-api::node-api PROPERTIES
IMPORTED_LOCATION_RELEASE "${node-api_LIBRARY_RELEASE}"
IMPORTED_CONFIGURATIONS RELEASE
)
if("@VCPKG_BUILD_TYPE@" STREQUAL "")
find_library(node-api_LIBRARY_DEBUG NAMES node PATHS "${CMAKE_CURRENT_LIST_DIR}/../../debug/lib" NO_DEFAULT_PATH REQUIRED)
set_target_properties(unofficial::node-api::node-api PROPERTIES
IMPORTED_LOCATION_DEBUG "${node-api_LIBRARY_DEBUG}"
)
set_property(TARGET unofficial::node-api::node-api APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
endif()
endif()
endif()

View File

@ -5550,11 +5550,11 @@
},
"node-addon-api": {
"baseline": "6.0.0",
"port-version": 0
"port-version": 1
},
"node-api": {
"baseline": "18.12.1",
"port-version": 2
"node-api-headers": {
"baseline": "0.0.5",
"port-version": 0
},
"nonius": {
"baseline": "2019-04-20",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "cfdebff816f735bc5922266b54623e0a70b667cf",
"version": "6.0.0",
"port-version": 1
},
{
"git-tree": "45cf82eea2cea9f8fa60b8a476f6484f75f81ca5",
"version": "6.0.0",

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "d8703d51a9b88c204782885707fc580ab490e9f4",
"version": "0.0.5",
"port-version": 0
}
]
}