Skip to content

Commit

Permalink
project and patch simplification: node-addon-api
Browse files Browse the repository at this point in the history
* add cmake build support (header-only INTERFACE library)
* issue #367
  • Loading branch information
Scott M Anderson committed Dec 30, 2022
1 parent d0e459f commit e72f8dc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
39 changes: 39 additions & 0 deletions patches/node-addon-api.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..50585bd
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 3.24)
+project(node-addon-api)
+include(GNUInstallDirs)
+include(flags OPTIONAL)
+if(COMMAND xpFindPkg)
+ set(XP_MODULE_PATH ${CMAKE_MODULE_PATH})
+ xpFindPkg(PKGS node)
+endif()
+set(lib_name ${PROJECT_NAME})
+########################################
+set(libsrcs
+ napi-inl.deprecated.h
+ napi-inl.h
+ napi.h
+ )
+########################################
+add_library(${lib_name} INTERFACE ${libsrcs})
+target_include_directories(${lib_name} INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+target_compile_definitions(${lib_name} INTERFACE NODE_ADDON_API_DISABLE_DEPRECATED NAPI_CPP_EXCEPTIONS)
+if(TARGET xpro::node)
+ target_link_libraries(${lib_name} INTERFACE xpro::node)
+endif()
+########################################
+set(targetsFile ${PROJECT_NAME}-targets)
+install(TARGETS ${lib_name} EXPORT ${targetsFile})
+install(FILES ${libsrcs} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
+if(DEFINED XP_NAMESPACE)
+ set(nameSpace NAMESPACE ${XP_NAMESPACE}::)
+endif()
+if(NOT DEFINED XP_INSTALL_CMAKEDIR)
+ set(XP_INSTALL_CMAKEDIR ${CMAKE_INSTALL_DATADIR}/cmake)
+endif()
+install(EXPORT ${targetsFile} DESTINATION ${XP_INSTALL_CMAKEDIR} ${nameSpace})
2 changes: 1 addition & 1 deletion projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
|[LLVM](http://llvm.org/ 'LLVM website')|[open](https://releases.llvm.org/11.0.0/LICENSE.TXT 'Apache License v2.0 with LLVM Exceptions')|The LLVM Compiler Infrastructure [cmake]|11.0.0|[repo](https://github.com/llvm/llvm-project 'llvm repo on github')|none|
|[Lua](http://www.lua.org/ 'Lua website')|[open](http://www.lua.org/license.html 'MIT license')|a powerful, fast, lightweight, embeddable scripting language [cmake-patch]|5.2.3|[repo](https://github.com/LuaDist/lua 'lua repo on github')|[diff](https://github.com/smanders/lua/compare/LuaDist:5.2.3...xp5.2.3 'patch/diff')|
|[nasm](https://www.nasm.us/ 'nasm website')|[BSD](https://www.nasm.us/ 'Simplified (2-clause) BSD license')|The Netwide Assembler - an 80x86 and x86-64 assembler|2.14.02|none|none|
|[node-addon-api](https://github.com/nodejs/node-addon-api 'node-addon-api on github')|[open](https://github.com/nodejs/node-addon-api/blob/3.0.2/LICENSE.md 'The MIT License - http://opensource.org/licenses/mit-license.php')|Module for using N-API from C++|3.0.2|[repo](https://github.com/nodejs/node-addon-api 'node-addon-api repo on github')|none|
|[node-addon-api](https://github.com/nodejs/node-addon-api 'node-addon-api on github')|[open](https://github.com/nodejs/node-addon-api/blob/3.0.2/LICENSE.md 'The MIT License - http://opensource.org/licenses/mit-license.php')|Module for using N-API from C++|3.0.2|[repo](https://github.com/nodejs/node-addon-api 'node-addon-api repo on github')|[diff](https://github.com/smanders/node-addon-api/compare/nodejs:3.0.2...xp3.0.2 'patch/diff')|
|[Node.js](http://nodejs.org 'Node.js website')|[open](https://raw.githubusercontent.com/nodejs/node/v14.17.6/LICENSE 'MIT license')|platform to build scalable network applications [gyp]|14.17.6|[repo](https://github.com/nodejs/node 'node repo on github')|[diff](https://github.com/smanders/node/compare/nodejs:v14.17.6...xp14.17.6 'patch/diff')|
|[OpenH264](http://www.openh264.org/ 'OpenH264 website')|[open](http://www.openh264.org/faq.html 'Two-Clause BSD license')|a codec library which supports H.264 encoding and decoding [cmake-scratch]|1.4.0|[repo](https://github.com/cisco/openh264 'openh264 repo on github')|[diff](https://github.com/smanders/openh264/compare/cisco:v1.4.0...xp1.4.0 'patch/diff')|
|[OpenSSL](http://www.openssl.org/ 'OpenSSL website')|[open](http://www.openssl.org/source/license.html 'OpenSSL, SSLeay License: BSD-style')|Cryptography and SSL/TLS Toolkit [cmake-scratch]|1.1.1l|[repo](https://github.com/openssl/openssl 'openssl repo on github')|[diff](https://github.com/smanders/openssl/compare/openssl:OpenSSL_1_1_1l...xp_1_1_1l 'patch/diff')|
Expand Down
42 changes: 21 additions & 21 deletions projects/node-addon-api.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# node-addon-api
# xpbuild:cmake-scratch
xpProOption(node-addon-api)
set(VER 3.0.2)
set(REPO github.com/nodejs/node-addon-api)
set(FORK github.com/smanders/node-addon-api)
set(PRO_NODE-ADDON-API
NAME node-addon-api
WEB "node-addon-api" https://${REPO} "node-addon-api on github"
Expand All @@ -10,11 +12,16 @@ set(PRO_NODE-ADDON-API
REPO "repo" https://${REPO} "node-addon-api repo on github"
GRAPH BUILD_DEPS nodejs
VER ${VER}
GIT_ORIGIN https://${REPO}.git
GIT_TAG ${VER}
GIT_ORIGIN https://${FORK}.git
GIT_UPSTREAM https://${REPO}.git
GIT_TRACKING_BRANCH main
GIT_TAG xp${VER} # what to 'git checkout'
GIT_REF ${VER} # create patch from this tag to 'git checkout'
DLURL https://${REPO}/archive/${VER}.tar.gz
DLMD5 020c40cbb9af791f7934fa66f87c904c
DLNAME node-addon-api-${VER}.tar.gz
PATCH ${PATCH_DIR}/node-addon-api.patch
DIFF https://${FORK}/compare/nodejs:
)
########################################
function(build_node_addon_api)
Expand All @@ -24,26 +31,19 @@ function(build_node_addon_api)
xpBuildDeps(depTgts ${PRO_NODE-ADDON-API})
xpGetArgValue(${PRO_NODE-ADDON-API} ARG NAME VALUE NAME)
xpGetArgValue(${PRO_NODE-ADDON-API} ARG VER VALUE VER)
set(XP_CONFIGURE
-DCMAKE_INSTALL_INCLUDEDIR=include/${NAME}_${VER}
-DXP_INSTALL_CMAKEDIR=share/cmake/tgt-${NAME}
-DXP_NAMESPACE:STRING=xpro
)
set(FIND_DEPS "xpFindPkg(PKGS node)\n")
set(LIBRARY_HDR xpro::${NAME})
set(LIBRARY_INCLUDEDIRS include/${NAME}_${VER})
set(INTERFACE_PROPERTIES "
INTERFACE_LINK_LIBRARIES xpro::node
INTERFACE_COMPILE_DEFINITIONS \"NODE_ADDON_API_DISABLE_DEPRECATED;NAPI_CPP_EXCEPTIONS\"")
configure_file(${PRO_DIR}/use/template-hdr-tgt.cmake
${STAGE_DIR}/share/cmake/usexp-${NAME}-config.cmake
set(TARGETS_FILE tgt-${NAME}/${NAME}-targets.cmake)
string(TOUPPER ${NAME} PRJ)
set(USE_VARS "set(${PRJ}_LIBRARIES xpro::${NAME})\n")
set(USE_VARS "${USE_VARS}list(APPEND reqVars ${PRJ}_LIBRARIES)\n")
configure_file(${MODULES_DIR}/usexp.cmake.in ${STAGE_DIR}/share/cmake/usexp-${NAME}-config.cmake
@ONLY NEWLINE_STYLE LF
)
ExternalProject_Get_Property(${NAME} SOURCE_DIR)
set(headers ${SOURCE_DIR}/*.h)
ExternalProject_Add(${NAME}_bld DEPENDS ${depTgts} ${NAME}
DOWNLOAD_COMMAND "" DOWNLOAD_DIR ${NULL_DIR} CONFIGURE_COMMAND ""
SOURCE_DIR ${SOURCE_DIR} BINARY_DIR ${NULL_DIR}
INSTALL_DIR ${STAGE_DIR}/${LIBRARY_INCLUDEDIRS}/${NAME}
BUILD_COMMAND ${CMAKE_COMMAND} -Dsrc:STRING=${headers}
-Ddst:STRING=<INSTALL_DIR> -P ${MODULES_DIR}/cmscopyfiles.cmake
INSTALL_COMMAND ""
)
set_property(TARGET ${NAME}_bld PROPERTY FOLDER ${bld_folder})
message(STATUS "target ${NAME}_bld")
set(BUILD_CONFIGS Release) # this project is only copying headers
xpCmakeBuild(${NAME} "${depTgts}" "${XP_CONFIGURE}")
endfunction()

0 comments on commit e72f8dc

Please sign in to comment.