1find_program (NODE_EXECUTABLE NAMES node 2 HINTS 3 $ENV{NODE_DIR} 4 PATH_SUFFIXES bin 5 DOC "Node.js interpreter" 6) 7 8include (FindPackageHandleStandardArgs) 9 10find_path (NODE_ROOT_DIR "node/node.h" "src/node.h" 11 PATHS /usr/include/nodejs /usr/local/include/nodejs) 12 13set (NODE_INCLUDE_DIRS 14 ${NODE_ROOT_DIR}/src 15 ${NODE_ROOT_DIR}/node 16 ${NODE_ROOT_DIR}/deps/v8/include 17 ${NODE_ROOT_DIR}/deps/uv/include 18) 19 20find_package_handle_standard_args (Node DEFAULT_MSG 21 NODE_EXECUTABLE 22 NODE_INCLUDE_DIRS 23) 24 25if (NODE_EXECUTABLE) 26 execute_process(COMMAND ${NODE_EXECUTABLE} --version 27 OUTPUT_VARIABLE _VERSION 28 RESULT_VARIABLE _NODE_VERSION_RESULT) 29 execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)" 30 OUTPUT_VARIABLE _V8_VERSION 31 RESULT_VARIABLE _V8_RESULT) 32 if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT) 33 string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}") 34 string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}") 35 list (GET _VERSION_LIST 0 NODE_VERSION_MAJOR) 36 list (GET _VERSION_LIST 1 NODE_VERSION_MINOR) 37 list (GET _VERSION_LIST 2 NODE_VERSION_PATCH) 38 set (V8_VERSION_STRING ${_V8_VERSION}) 39 string (REPLACE "." ";" _V8_VERSION_LIST "${_V8_VERSION}") 40 string (REPLACE "." "" V8_DEFINE_STRING "${_V8_VERSION}") 41 string (STRIP ${V8_DEFINE_STRING} V8_DEFINE_STRING) 42 list (GET _V8_VERSION_LIST 0 V8_VERSION_MAJOR) 43 list (GET _V8_VERSION_LIST 1 V8_VERSION_MINOR) 44 list (GET _V8_VERSION_LIST 2 V8_VERSION_PATCH) 45 # we end up with a nasty newline so strip everything that isn't a number 46 string (REGEX MATCH "^[0-9]*" V8_VERSION_PATCH ${V8_VERSION_PATCH}) 47 else () 48 set (NODE_VERSION_STRING "0.10.30") 49 set (NODE_VERSION_MAJOR "0") 50 set (NODE_VERSION_MINOR "10") 51 set (NODE_VERSION_PATCH "30") 52 set (V8_VERSION_MAJOR "3") 53 set (V8_VERSION_MINOR "28") 54 set (V8_VERSION_PATCH "72") 55 set (V8_VERSION_STRING "3.28.72") 56 message ("defaulted to node 0.10.30") 57 endif () 58 message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING}) 59endif () 60 61mark_as_advanced (NODE_EXECUTABLE) 62