Private
Public Access
2
0

nodejs: add infra to detect nodejs version

This introduces FindNodes.cmake which finds the v8 version and the nodejs
interp version and passes the information to SWIG via SWIG_V8_VERSION

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-03-18 12:20:54 +00:00
parent 824618ccf1
commit 128f0a22da
3 changed files with 69 additions and 14 deletions

View File

@@ -1,20 +1,17 @@
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs)
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
)
find_package (Nodejs)
include_directories (
${NODE_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/..
)
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is required
set_source_files_properties (mraajs.i PROPERTIES SWIG_FLAGS "-node;-I${CMAKE_BINARY_DIR}/src")
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
# to be a problem for a little while!
#set_source_files_properties (mraajs.i PROPERTIES SWIG_FLAGS "-node;-DV8_VERSION=0x0${V8_VERSION_HEX};-I${CMAKE_BINARY_DIR}/src")
#set_source_files_properties (mraajs.i PROPERTIES SWIG_FLAGS "-node;-I${CMAKE_BINARY_DIR}/src")
set_property (SOURCE mraajs.i PROPERTY SWIG_FLAGS "-node"
"-I${CMAKE_BINARY_DIR}/src" "-DV8_VERSION=0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH}")
set_source_files_properties (mraajs.i PROPERTIES CPLUSPLUS ON)
swig_add_module (mraajs javascript mraajs.i ${mraa_LIB_SRCS})

View File

@@ -1,7 +1,6 @@
%module (docstring="Javascript interface to libmraa") mraa
%feature("autodoc", "3");
#define NODE012
%include carrays.i
%include cpointer.i
@@ -29,7 +28,7 @@ namespace mraa {
class Spi;
%typemap(out) uint8_t*
{
#ifdef NODE012
#if V8_VERSION > 0x032872
$result = node::Buffer::New((char*) $1, arg3);
#else
$result = node::Buffer::New((char*) $1, arg3)->handle_;
@@ -60,7 +59,7 @@ class Spi;
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
SWIGV8_RETURN(SWIGV8_UNDEFINED());
}
#ifdef NODE012
#if V8_VERSION > 0x032872
$result = node::Buffer::New((char*) $1, result);
#else
$result = node::Buffer::New((char*) $1, result)->handle_;