npm: add node-gyp build support
This commit adds all the infrastructure necessary for doing node-gyp builds of mraa. Note this will only build the mraa js bindings and will dirty your git tree whilst doing it. It also assumes the user does not have SWIG installed on their machines and so the swig wrapper is static. The target to use this feature is 'npmpkg'. Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -11,3 +11,11 @@ build/
|
||||
# Temp files
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# npmpub files
|
||||
src/mraajsJAVASCRIPT_wrap.cxx
|
||||
src/version.c
|
||||
package.json
|
||||
binding.gyp
|
||||
READMEFIRST
|
||||
npm-debug.log
|
||||
|
||||
27
docs/npm.md
Normal file
27
docs/npm.md
Normal file
@@ -0,0 +1,27 @@
|
||||
mraa NPM pkg {#npmpkg}
|
||||
============
|
||||
|
||||
What you are looking at is a tarball made after 'make npmpkg' has been run on
|
||||
our build system. It contains a few prebuilt files in order to build easily
|
||||
with node-gyp on most systems. Note that this is not the preffered way of
|
||||
building libmraa and if you'd like to contribute, please learn how the build
|
||||
system works and get your sources from git.
|
||||
|
||||
Any patches for mraajsJAVASCRIPT_wrap.cxx or version.c will be ignored as these
|
||||
are automatically generated files. When you execute a build from node-gyp/npm
|
||||
you do not generate the mraajsJAVASCRIPT_wrap.cxx file but rather use one that
|
||||
we have generated for you.
|
||||
|
||||
Recreating tarball
|
||||
------------------
|
||||
|
||||
From a checkout of mraa you can do the following to 'generate' this tarball
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DBUILDSWIGNODE=ON ..
|
||||
make npmpkg
|
||||
cd ../
|
||||
tar czv --exclude='build/*' --exclude='.git/*' -f /tmp/mraa.tar.gz .
|
||||
~~~~~~~~~~~~~
|
||||
@@ -1,10 +1,14 @@
|
||||
include_directories(
|
||||
set (mraa_LIB_INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/api
|
||||
${PROJECT_SOURCE_DIR}/api/mraa
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS
|
||||
include_directories(
|
||||
${mraa_LIB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/mraa.c
|
||||
${PROJECT_SOURCE_DIR}/src/gpio/gpio.c
|
||||
${PROJECT_SOURCE_DIR}/src/i2c/i2c.c
|
||||
@@ -17,6 +21,10 @@ set (mraa_LIB_SRCS
|
||||
${PROJECT_SOURCE_DIR}/src/intel_edison_fab_c.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_de3815.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_minnow_max.c
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS
|
||||
${mraa_LIB_SRCS_NOAUTO}
|
||||
# autogenerated version file
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.c
|
||||
)
|
||||
|
||||
@@ -37,5 +37,32 @@ macro (mraa_CREATE_INSTALL_PACKAGE_JSON generated_file install_location)
|
||||
endmacro (mraa_CREATE_INSTALL_PACKAGE_JSON)
|
||||
mraa_create_install_package_json (package.json lib/node_modules/mraa)
|
||||
|
||||
macro (mraa_CREATE_BINDING_GYP generated_file)
|
||||
set (mraa_LIB_SRCS_GYP "")
|
||||
foreach (srcfile ${mraa_LIB_SRCS_NOAUTO})
|
||||
file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${srcfile})
|
||||
set (mraa_LIB_SRCS_GYP "'${rel}',\n${mraa_LIB_SRCS_GYP}")
|
||||
endforeach (srcfile)
|
||||
foreach (includedir ${mraa_LIB_INCLUDE_DIRS})
|
||||
file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${includedir})
|
||||
set (mraa_LIB_INCLUDE_DIRS_GYP "'${rel}',\n${mraa_LIB_INCLUDE_DIRS_GYP}")
|
||||
endforeach (includedir)
|
||||
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
|
||||
endmacro (mraa_CREATE_BINDING_GYP)
|
||||
mraa_create_binding_gyp (binding.gyp)
|
||||
|
||||
add_custom_target (npmpkg)
|
||||
add_custom_command (TARGET npmpkg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraajsJAVASCRIPT_wrap.cxx ${CMAKE_SOURCE_DIR}/src
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_BINARY_DIR}/src/version.c ${CMAKE_SOURCE_DIR}/src
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/package.json ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/binding.gyp ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_SOURCE_DIR}/docs/npm.md ${CMAKE_SOURCE_DIR}/READMEFIRST)
|
||||
add_dependencies (npmpkg mraajs)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.node
|
||||
DESTINATION lib/node_modules/mraa)
|
||||
|
||||
18
src/javascript/binding.gyp.cmake
Normal file
18
src/javascript/binding.gyp.cmake
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'mraa',
|
||||
'sources': [
|
||||
@mraa_LIB_SRCS_GYP@
|
||||
'src/version.c',
|
||||
'src/mraajsJAVASCRIPT_wrap.cxx' ],
|
||||
'include_dirs': [
|
||||
@mraa_LIB_INCLUDE_DIRS_GYP@
|
||||
],
|
||||
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
|
||||
'cflags!': [ '-fno-exceptions' ],
|
||||
'defines' : [ 'SWIG',
|
||||
'SWIGNODE' ],
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,9 +1,22 @@
|
||||
{
|
||||
"name" : "mraa",
|
||||
"description": "IO library that helps you use I2c, SPI, gpio, uart, pwm, analog inputs (aio) and more on a number of platforms such as the Intel galileo, the Intel edison and others",
|
||||
"keywords":["gpio", "edison","galileo","io", "mraajs", "spi", "i2c", "minnow", "intel"],
|
||||
"homepage": "http://github.com/intel-iot-devkit/mraa",
|
||||
|
||||
|
||||
"repository" : {
|
||||
"type" : "git",
|
||||
"url" : "http://github.com/intel-iot-devkit/mraa.git"
|
||||
},
|
||||
"main" : "./mraa.node",
|
||||
"engines": {
|
||||
"node": ">= 1.0.x"
|
||||
},
|
||||
"bugs": {
|
||||
"url" : "http://github.com/intel-iot-devkit/mraa/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"version": "@VERSION@"
|
||||
"version": "@VERSION@",
|
||||
"authors": "See github.com/intel-iot-devkit/mraa/graphs/contributors"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user