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.
This commit is contained in:
Markus Mäkelä 2018-08-07 16:52:54 +03:00
parent 2539183be2
commit 785507b002
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19

View File

@ -13,10 +13,17 @@ if (${NODEJS_EXECUTABLE} MATCHES "NOTFOUND")
unset(NODEJS_EXECUTABLE)
else()
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE VERSION_VAR)
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}")
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()