blob: 50307688bd1429d54cb192593fd2daa836c9fd54 [file] [log] [blame]
Mislav Novakovica827b5f2016-02-29 11:47:22 +01001 # Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
2 macro(add_include_dir dir)
3 if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
4 set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
5 endif()
6endmacro()
7
8
9find_program (NODEJS_EXECUTABLE NAMES node nodejs
10 HINTS
11 $ENV{NODE_DIR}
12 PATH_SUFFIXES bin
13 DOC "Node.js interpreter"
14)
15
16include (FindPackageHandleStandardArgs)
17
18# If compat-libuv package exists, it must be at start of include path
19find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
20if (UV_ROOT_DIR)
21 # set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
22 add_include_dir(${UV_ROOT_DIR})
23endif()
24
25# Now look for node. Flag an error if not found
26find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
27 PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
28if (NODE_ROOT_DIR)
29 add_include_dir(${NODE_ROOT_DIR}/src)
30 add_include_dir(${NODE_ROOT_DIR}/node)
31 add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
32 add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
33else()
34 unset(NODEJS_INCLUDE_DIRS)
35 message(ERROR " - node.h not found")
36endif()
37
38# Check that v8.h is in NODEJS_INCLUDE_DIRS
39find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
40if (NOT V8_ROOT_DIR)
41 unset(NODEJS_INCLUDE_DIRS)
42 message(ERROR " - v8.h not found")
43endif()
44
45# Check that uv.h is in NODEJS_INCLUDE_DIRS
46find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
47if (NOT UV_ROOT_DIR)
48 unset(NODEJS_INCLUDE_DIRS)
49 message(ERROR " - uv.h not found")
50endif()
51
52find_package_handle_standard_args (Nodejs DEFAULT_MSG
53 NODEJS_EXECUTABLE
54 NODEJS_INCLUDE_DIRS
55)
56
57if (NODEJS_EXECUTABLE)
58 execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
59 OUTPUT_VARIABLE _VERSION
60 RESULT_VARIABLE _NODE_VERSION_RESULT)
61 execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
62 OUTPUT_VARIABLE _V8_VERSION
63 RESULT_VARIABLE _V8_RESULT)
64 if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
65 string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
66 string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
67 list (GET _VERSION_LIST 0 NODE_VERSION_MAJOR)
68 list (GET _VERSION_LIST 1 NODE_VERSION_MINOR)
69 list (GET _VERSION_LIST 2 NODE_VERSION_PATCH)
70 set (V8_VERSION_STRING ${_V8_VERSION})
71 string (REPLACE "." ";" _V8_VERSION_LIST "${_V8_VERSION}")
72 list (GET _V8_VERSION_LIST 0 V8_VERSION_MAJOR)
73 list (GET _V8_VERSION_LIST 1 V8_VERSION_MINOR)
74 list (GET _V8_VERSION_LIST 2 V8_VERSION_PATCH)
75 # we end up with a nasty newline so strip everything that isn't a number
76 string (REGEX MATCH "^[0-9]*" V8_VERSION_PATCH ${V8_VERSION_PATCH})
77 else ()
78 set (NODE_VERSION_STRING "0.10.30")
79 set (NODE_VERSION_MAJOR "0")
80 set (NODE_VERSION_MINOR "10")
81 set (NODE_VERSION_PATCH "30")
82 set (V8_VERSION_MAJOR "3")
83 set (V8_VERSION_MINOR"14")
84 set (V8_VERSION_PATCH "5")
85 set (V8_VERSION_STRING "3.28.72")
86 message ("defaulted to node 0.10.30")
87 endif ()
88 string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
89 string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
90 message ("INFO - Node version is " ${NODE_VERSION_STRING})
91 message ("INFO - Node using v8 " ${V8_VERSION_STRING})
92 mark_as_advanced (NODEJS_EXECUTABLE)
93endif ()
94