charto / nbind

:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:
MIT License
1.98k stars 119 forks source link

Alternative build solution #68

Open simon-p-r opened 7 years ago

simon-p-r commented 7 years ago

Seeing as gyp and node-gyp are being depreciated soon, would you be interested in switching build to cmake and in particular the excellent cmake-js module. I am trying to create a working fork at the moment.

dav-sap commented 7 years ago

I've been also looking into this. I liked node-cmake more. What do u think?

kirbysayshi commented 7 years ago

node-cmake is nice because it allows a drop-in CMakeModule file to both manage nodejs versions (+electron) and integrate with existing code!

simon-p-r commented 7 years ago

Guess I need to check out node-cmake!

jjrv commented 7 years ago

Contributions would be very welcome, for example a simple project that compiles successfully. Especially if it also works with Emscripten. That would speed up adding official support.

skolesnyk commented 7 years ago

+1 to cmake!

computerquip-streamlabs commented 7 years ago

autogyp doesn't do much in simple cases as far as I can see. I was able to get it working in node-cmake by doing the following:

Assuming you're not building with asm.js, add the following files to each module you build:

Add the following directories to your include path:

Assuming you're not building with asm.js, add the following definitions to each build:

Simply adding a cmake module to simplify this can probably be the equivalent of "adding cmake support". I can't imagine a module you can create that wouldn't work on both cmake-js and node-cmake.

sambhare commented 7 years ago

I was able to get cmake-js (and node-cmake) work. Eventually I ended up going with cmake-js as was easier to integrate with Electron. Some snippets from my CMakeLists.txt that people may find useful:

add_definitions(-DBUILDING_NODE_EXTENSION)    
add_definitions(-DUSING_V8_SHARED)
add_definitions(-DUSING_UV_SHARED)     
add_definitions(-DV8_DEPRECATION_WARNINGS) 

...

include_directories(include)
include_directories(${CMAKE_JS_INC})   
include_directories(node_modules/nbind/include)

...

add_subdirectory(src)
file(GLOB NBIND_SOURCE_FILES node_modules/nbind/src/*.cc node_modules/nbind/src/v8/*.cc)

...

add_library(nbind SHARED ${SOURCE} ${NBIND_SOURCE_FILES})
set_target_properties(nbind PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(nbind ${CMAKE_JS_LIB})

And my corresponding package.json:

{
  "scripts": {
    "install": "cmake-js compile",
    "start": "electron ."
  },
  "devDependencies": {
    "cmake-js": "^3.5.0"
  },
  "dependencies": {
    "electron": "~1.7.6",
    "nbind": "^0.3.13"
  },
  "cmake-js": {
    "runtime": "electron",
    "runtimeVersion": "1.7.6",
    "arch": "x64"
  }
}
BotellaA commented 6 years ago

It would be great that nbind supports cmake. The majority of C++ projects are cmake projects.

What do you need to support cmake? Is the previous comment not enough?