1 find_package (Nodejs) 2 3 include_directories ( 4 ${NODE_INCLUDE_DIRS} 5 ${CMAKE_CURRENT_SOURCE_DIR}/.. 6 ) 7 8 # SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is 9 # required. This hardcodes V8_VERSION to be <10 but I assume that's not going 10 # to be a problem for a little while! SWIG uses a padded SWIG_V8 version which 11 # we hack together from our findnode module. 12 set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH}) 13 string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length) 14 while (V8_VERSION_HEX_length LESS 8) 15 set (V8_VERSION_HEX "${V8_VERSION_HEX}0") 16 message (DEBUG " - Padded V8 version to match SWIG format") 17 string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length) 18 endwhile () 19 20 set_property (SOURCE mraajs.i PROPERTY SWIG_FLAGS "-node" 21 "-I${CMAKE_BINARY_DIR}/src" "-DV8_VERSION=${V8_VERSION_HEX}") 22 set_source_files_properties (mraajs.i PROPERTIES CPLUSPLUS ON) 23 24 swig_add_module (mraajs javascript mraajs.i ${mraa_LIB_SRCS}) 25 swig_link_libraries (mraajs ${NODE_LIBRARIES} ${mraa_LIBS}) 26 27 set_target_properties (mraajs PROPERTIES 28 COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIGJAVASCRIPT=${SWIG_FOUND}" 29 PREFIX "" 30 OUTPUT_NAME mraa 31 SUFFIX ".node" 32 ) 33 34 if (${V8_VERSION_MAJOR} GREATER 3) 35 message (INFO " - Using V8 version > 3 so requiring C++11 compiler") 36 # Node 0.12.x V8 engine major version is '3'. 37 # Node 2.1.0 V8 engine major version is '4'. 38 set_property (TARGET mraajs PROPERTY CXX_STANDARD 11) 39 set_property (TARGET mraajs PROPERTY CXX_STANDARD_REQUIRED ON) 40 endif () 41 42 macro (mraa_CREATE_INSTALL_PACKAGE_JSON generated_file install_location) 43 configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY) 44 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location}) 45 endmacro (mraa_CREATE_INSTALL_PACKAGE_JSON) 46 mraa_create_install_package_json (package.json lib/node_modules/mraa) 47 48 macro (mraa_CREATE_BINDING_GYP generated_file) 49 set (mraa_LIB_SRCS_GYP "") 50 set (mraa_NPM_SRCS ${mraa_LIB_SRCS_NOAUTO} 51 ${mraa_LIB_ARM_SRCS_NOAUTO} 52 ${mraa_LIB_X86_SRCS_NOAUTO} 53 ) 54 foreach (srcfile ${mraa_NPM_SRCS}) 55 file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${srcfile}) 56 set (mraa_LIB_SRCS_GYP "'${rel}',\n${mraa_LIB_SRCS_GYP}") 57 endforeach (srcfile) 58 foreach (includedir ${mraa_LIB_INCLUDE_DIRS}) 59 file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${includedir}) 60 set (mraa_LIB_INCLUDE_DIRS_GYP "'${rel}',\n${mraa_LIB_INCLUDE_DIRS_GYP}") 61 endforeach (includedir) 62 configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY) 63 endmacro (mraa_CREATE_BINDING_GYP) 64 mraa_create_binding_gyp (binding.gyp) 65 66 add_custom_target (npmpkg) 67 add_custom_command (TARGET npmpkg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy 68 ${CMAKE_CURRENT_BINARY_DIR}/mraajsJAVASCRIPT_wrap.cxx ${CMAKE_SOURCE_DIR}/src 69 COMMAND ${CMAKE_COMMAND} -E copy 70 ${CMAKE_BINARY_DIR}/src/version.c ${CMAKE_SOURCE_DIR}/src 71 COMMAND ${CMAKE_COMMAND} -E copy 72 ${CMAKE_CURRENT_BINARY_DIR}/package.json ${CMAKE_SOURCE_DIR} 73 COMMAND sed -i "'s/mraa.node/build\\/Release\\/mraa.node/'" 74 ${CMAKE_SOURCE_DIR}/package.json 75 COMMAND ${CMAKE_COMMAND} -E copy 76 ${CMAKE_CURRENT_BINARY_DIR}/binding.gyp ${CMAKE_SOURCE_DIR} 77 COMMAND ${CMAKE_COMMAND} -E copy 78 ${CMAKE_SOURCE_DIR}/docs/npm.md ${CMAKE_SOURCE_DIR}/READMEFIRST) 79 add_dependencies (npmpkg mraajs) 80 81 if (BUILDDOC) 82 find_package(Yuidoc) 83 if (YUIDOC_FOUND) 84 add_custom_target(jsdoc ALL 85 COMMAND ${CMAKE_SOURCE_DIR}/doxygen2jsdoc/docgen.js -m mraa i xml/ -o jsdoc -c ${CMAKE_CURRENT_SOURCE_DIR}/doxygen2jsdoc_custom.json --strict -h 86 COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers ${CMAKE_SOURCE_DIR}/doxygen2jsdoc/generators/yuidoc/tmpl/mraa/helper.js --themedir ${CMAKE_SOURCE_DIR}/doxygen2jsdoc/generators/yuidoc/tmpl/mraa -o html/node jsdoc/yuidoc/mraa 87 COMMAND ${CMAKE_SOURCE_DIR}/doxygen2jsdoc/tolower.js -i html/node 88 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 89 DEPENDS doc 90 COMMENT "Generating API documentation with Yuidoc" VERBATIM 91 ) 92 else () 93 message (INFO " - Failed to find Yuidoc. node.js API doc will not be generated") 94 endif () 95 endif () 96 97 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.node 98 DESTINATION lib/node_modules/mraa) 99