MaxScale/cmake/FindNodeJS.cmake
Markus Mäkelä 785507b002
Check return value of nodejs --version
FindNodeJS.cmake once failed due to an error executing the program. To see
why it failed, the error output of the command should be printed.
2018-08-09 12:54:06 +03:00

30 lines
995 B
CMake

# Find the Node.js executable
#
# The following variables are set:
# NODEJS_FOUND True if Node.js was found
# NODEJS_EXECUTABLE Path to the Node.js executable
# NODEJS_VERSION Node.js version
find_program(NODEJS_EXECUTABLE NAMES node nodejs)
if (${NODEJS_EXECUTABLE} MATCHES "NOTFOUND")
message(STATUS "Could not find Node.js")
set(NODEJS_FOUND FALSE CACHE INTERNAL "")
unset(NODEJS_EXECUTABLE)
else()
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE VERSION_VAR
ERROR_VARIABLE ERROR_VAR
RESULT_VARIABLE RESULT_VAR)
if (RESULT_VAR EQUAL 0)
string(REGEX REPLACE "[v]" "" VERSION_VAR ${VERSION_VAR})
string(STRIP ${VERSION_VAR} VERSION_VAR)
set(NODEJS_VERSION ${VERSION_VAR} CACHE INTERNAL "")
set(NODEJS_FOUND TRUE CACHE INTERNAL "")
message(STATUS "Found Node.js version ${NODEJS_VERSION}: ${NODEJS_EXECUTABLE}")
else()
message(WARNING "Failed to execute NodeJS --version command: ${ERROR_VAR}")
endif()
endif()