2016-01-22 16:54:27 -08:00
|
|
|
# Macro to add directory to NODE_INCLUDE_DIRS if it exists and is not /usr/include
|
|
|
|
macro(add_include_dir dir)
|
|
|
|
if (IS_DIRECTORY ${dir})
|
|
|
|
set(NODE_INCLUDE_DIRS ${NODE_INCLUDE_DIRS} ${dir})
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
|
|
find_program (NODE_EXECUTABLE NAMES node nodejs
|
2015-05-20 10:48:18 -07:00
|
|
|
HINTS
|
|
|
|
$ENV{NODE_DIR}
|
|
|
|
PATH_SUFFIXES bin
|
|
|
|
DOC "Node.js interpreter"
|
|
|
|
)
|
|
|
|
|
|
|
|
include (FindPackageHandleStandardArgs)
|
|
|
|
|
2016-01-22 16:54:27 -08:00
|
|
|
# If compat-libuv package exists, it must be at start of include path
|
|
|
|
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
|
|
|
|
if (UV_ROOT_DIR)
|
|
|
|
# set (NODE_INCLUDE_DIRS ${UV_ROOT_DIR})
|
|
|
|
add_include_dir(${UV_ROOT_DIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Now look for node. Flag an error if not found
|
2015-05-20 10:48:18 -07:00
|
|
|
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
2016-01-22 16:54:27 -08:00
|
|
|
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
|
|
|
if (NODE_ROOT_DIR)
|
|
|
|
add_include_dir(${NODE_ROOT_DIR}/src)
|
|
|
|
add_include_dir(${NODE_ROOT_DIR}/node)
|
|
|
|
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
|
|
|
|
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
|
|
|
else()
|
|
|
|
unset(NODE_INCLUDE_DIRS)
|
|
|
|
message(ERROR " - node.h not found")
|
|
|
|
endif()
|
2015-05-20 10:48:18 -07:00
|
|
|
|
2016-01-22 16:54:27 -08:00
|
|
|
# Check that v8.h is in NODE_INCLUDE_DIRS
|
|
|
|
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODE_INCLUDE_DIRS})
|
|
|
|
if (NOT V8_ROOT_DIR)
|
|
|
|
unset(NODE_INCLUDE_DIRS)
|
|
|
|
message(ERROR " - v8.h not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Check that uv.h is in NODE_INCLUDE_DIRS
|
|
|
|
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODE_INCLUDE_DIRS})
|
|
|
|
if (NOT UV_ROOT_DIR)
|
|
|
|
unset(NODE_INCLUDE_DIRS)
|
|
|
|
message(ERROR " - uv.h not found")
|
|
|
|
endif()
|
2015-05-20 10:48:18 -07:00
|
|
|
|
2016-01-22 16:54:27 -08:00
|
|
|
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
2015-05-20 10:48:18 -07:00
|
|
|
NODE_EXECUTABLE
|
|
|
|
NODE_INCLUDE_DIRS
|
|
|
|
)
|
|
|
|
|
|
|
|
if (NODE_EXECUTABLE)
|
|
|
|
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
|
|
|
OUTPUT_VARIABLE _VERSION
|
|
|
|
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
|
|
|
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
|
|
|
|
OUTPUT_VARIABLE _V8_VERSION
|
|
|
|
RESULT_VARIABLE _V8_RESULT)
|
|
|
|
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
|
|
|
string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
|
|
|
|
string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
|
|
|
|
list (GET _VERSION_LIST 0 NODE_VERSION_MAJOR)
|
|
|
|
list (GET _VERSION_LIST 1 NODE_VERSION_MINOR)
|
|
|
|
list (GET _VERSION_LIST 2 NODE_VERSION_PATCH)
|
|
|
|
set (V8_VERSION_STRING ${_V8_VERSION})
|
|
|
|
string (REPLACE "." ";" _V8_VERSION_LIST "${_V8_VERSION}")
|
|
|
|
list (GET _V8_VERSION_LIST 0 V8_VERSION_MAJOR)
|
|
|
|
list (GET _V8_VERSION_LIST 1 V8_VERSION_MINOR)
|
|
|
|
list (GET _V8_VERSION_LIST 2 V8_VERSION_PATCH)
|
|
|
|
# we end up with a nasty newline so strip everything that isn't a number
|
|
|
|
string (REGEX MATCH "^[0-9]*" V8_VERSION_PATCH ${V8_VERSION_PATCH})
|
|
|
|
else ()
|
|
|
|
set (NODE_VERSION_STRING "0.10.30")
|
|
|
|
set (NODE_VERSION_MAJOR "0")
|
|
|
|
set (NODE_VERSION_MINOR "10")
|
|
|
|
set (NODE_VERSION_PATCH "30")
|
|
|
|
set (V8_VERSION_MAJOR "3")
|
2016-01-22 16:54:27 -08:00
|
|
|
set (V8_VERSION_MINOR"14")
|
|
|
|
set (V8_VERSION_PATCH "5")
|
2015-05-20 10:48:18 -07:00
|
|
|
set (V8_VERSION_STRING "3.28.72")
|
|
|
|
message ("defaulted to node 0.10.30")
|
|
|
|
endif ()
|
2016-01-22 16:54:27 -08:00
|
|
|
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
|
|
|
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
|
|
|
message ("INFO - Node version is " ${NODE_VERSION_STRING})
|
|
|
|
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
|
|
|
|
mark_as_advanced (NODE_EXECUTABLE)
|
2015-05-20 10:48:18 -07:00
|
|
|
endif ()
|
|
|
|
|
2016-01-22 16:54:27 -08:00
|
|
|
|