diff options
| author | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
|---|---|---|
| committer | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
| commit | 54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch) | |
| tree | d915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/node-api-headers | |
Diffstat (limited to 'vcpkg/ports/node-api-headers')
| -rw-r--r-- | vcpkg/ports/node-api-headers/CMakeLists.txt | 29 | ||||
| -rw-r--r-- | vcpkg/ports/node-api-headers/portfile.cmake | 21 | ||||
| -rw-r--r-- | vcpkg/ports/node-api-headers/unofficial-node-api-headers-config.cmake.in | 41 | ||||
| -rw-r--r-- | vcpkg/ports/node-api-headers/usage | 23 | ||||
| -rw-r--r-- | vcpkg/ports/node-api-headers/vcpkg.json | 20 |
5 files changed, 134 insertions, 0 deletions
diff --git a/vcpkg/ports/node-api-headers/CMakeLists.txt b/vcpkg/ports/node-api-headers/CMakeLists.txt new file mode 100644 index 0000000..cf8a3f6 --- /dev/null +++ b/vcpkg/ports/node-api-headers/CMakeLists.txt @@ -0,0 +1,29 @@ +project(nodelib C) + +if (MINGW) +add_custom_target(nodelib ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libnode.a) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libnode.a + COMMAND ${CMAKE_DLLTOOL} + -d "${CMAKE_CURRENT_SOURCE_DIR}/def/node_api.def" + -l "${CMAKE_CURRENT_BINARY_DIR}/libnode.a" + ${CMAKE_MODULE_LINKER_FLAGS} + $<$<CONFIG:Debug>:${CMAKE_MODULE_LINKER_FLAGS_DEBUG}> + $<$<CONFIG:Release>:${CMAKE_MODULE_LINKER_FLAGS_RELEASE}> + COMMENT "Building import library for NodeJS" +) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnode.a DESTINATION lib) +else() +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_CURRENT_BINARY_DIR}/node.lib DESTINATION lib) +endif() diff --git a/vcpkg/ports/node-api-headers/portfile.cmake b/vcpkg/ports/node-api-headers/portfile.cmake new file mode 100644 index 0000000..ae4e32a --- /dev/null +++ b/vcpkg/ports/node-api-headers/portfile.cmake @@ -0,0 +1,21 @@ +vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO nodejs/node-api-headers
+ REF "v${VERSION}"
+ SHA512 af4d4672193f16b81984b6fea19bfdd72d3af343f417339afa6484b078b799d1aa21c91e7d2ca0dd677000b22750f4d14c6a6ebdf06981dd7655558f8aa743a3
+ 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)
+
+file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+
+configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-${PORT}-config.cmake.in" "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" @ONLY)
diff --git a/vcpkg/ports/node-api-headers/unofficial-node-api-headers-config.cmake.in b/vcpkg/ports/node-api-headers/unofficial-node-api-headers-config.cmake.in new file mode 100644 index 0000000..7eb5751 --- /dev/null +++ b/vcpkg/ports/node-api-headers/unofficial-node-api-headers-config.cmake.in @@ -0,0 +1,41 @@ +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)
+ # setting those properties like cmake-js does
+ # https://github.com/cmake-js/cmake-js/blob/272ec1883bc1207205abae948022eecdea02e225/lib/toolset.js#L126
+ set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
+ INTERFACE_LINK_OPTIONS "LINKER:SHELL:-undefined dynamic_lookup"
+ )
+ set_target_properties(unofficial::node-api-headers::node-api-headers PROPERTIES
+ INTERFACE_COMPILE_DEFINITIONS "_DARWIN_USE_64_BIT_INODE=1;_LARGEFILE_SOURCE;_FILE_OFFSET_BITS=64"
+ )
+ endif()
+
+ set_property(TARGET unofficial::node-api-headers::node-api-headers APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "BUILDING_NODE_EXTENSION")
+
+ 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()
diff --git a/vcpkg/ports/node-api-headers/usage b/vcpkg/ports/node-api-headers/usage new file mode 100644 index 0000000..09bf0b3 --- /dev/null +++ b/vcpkg/ports/node-api-headers/usage @@ -0,0 +1,23 @@ +node-api-headers provides CMake targets: + + find_package(unofficial-node-api-headers CONFIG REQUIRED) + target_link_libraries(main PRIVATE unofficial::node-api-headers::node-api-headers) + +Add this to your CMakeLists.txt to build a Node.js addon: + add_library(addon SHARED main.cpp ...) + set_target_properties(addon PROPERTIES OUTPUT_NAME "my-addon" PREFIX "" SUFFIX ".node") + + find_package(unofficial-node-api-headers CONFIG REQUIRED) + target_link_libraries(addon PRIVATE unofficial::node-api-headers::node-api-headers) + +You will be able to load your addon in JavaScript code: + const addon = require("/path/to/addon/my-addon.node"); + +Make sure that your Node.js OS/architecture matches vcpkg triplet you use. + +Also, make sure to register a module in your C/C++ code like official example does: +https://github.com/nodejs/node-addon-examples/blob/main/1_hello_world/napi/hello.c + +This port doesn't have specific functionality for publishing npm packages. + +See https://nodejs.org/api/n-api.html diff --git a/vcpkg/ports/node-api-headers/vcpkg.json b/vcpkg/ports/node-api-headers/vcpkg.json new file mode 100644 index 0000000..524af72 --- /dev/null +++ b/vcpkg/ports/node-api-headers/vcpkg.json @@ -0,0 +1,20 @@ +{ + "name": "node-api-headers", + "version": "1.5.0", + "description": "NodeJS API for writing modules in C++", + "homepage": "https://nodejs.org/api/addons.html", + "license": "MIT", + "supports": "(windows & !arm & !uwp) | linux | osx", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true, + "platform": "windows" + }, + { + "name": "vcpkg-cmake-config", + "host": true, + "platform": "windows" + } + ] +} |