node-cmake icon indicating copy to clipboard operation
node-cmake copied to clipboard

N-API support

Open computerquip-streamlabs opened this issue 6 years ago • 5 comments

N-API is starting to gain traction. This should have the ability to compile against it similar to a node runtime I feel like.

computerquip-streamlabs avatar Nov 01 '18 21:11 computerquip-streamlabs

Actually, I guess I can choose just any given runtime that supports a given version of N-API? Herm.... some clarification on this would be cool.

computerquip-streamlabs avatar Nov 01 '18 21:11 computerquip-streamlabs

Seems it's difficult to get node-addon-api into the include path reliably. That would be great to have.

computerquip-streamlabs avatar Nov 02 '18 00:11 computerquip-streamlabs

I need to think through the implications of using N-API instead of / adjacent to(?) NaN and just in general with this tool, but I was largely waiting for things to stabilize. I haven't completely kept up with that recently so I'll need to take a look, but I'll put this high on my list for the next major release as I definitely want to support it (it seems like its the intended path forward).

cjntaylor avatar Nov 02 '18 05:11 cjntaylor

I've made an napi module using this cmake module. The example can be found here: https://github.com/computerquip-streamlabs/node-win32-np/blob/master/CMakeLists.txt

Notice the include_directories statement there for node-addon-api (which is separate from the officially support node_api headers bundled with the runtime itself). This isn't that hard to do frankly and maybe it's better if it's kept separate of the runtime headers regardless. Not sure.

computerquip-streamlabs avatar Nov 08 '18 15:11 computerquip-streamlabs

For the C++ node-addon-api:

Just npm install --save node-addon-api and add this to your existing node-cmake CMakeLists.txt

execute_process(COMMAND node -p "require('node-addon-api').include" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE NODE_ADDON_API_DIR)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})

target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${NODE_ADDON_API_DIR})

TomMettam avatar May 17 '21 14:05 TomMettam