mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
CMake: Update FindNpm module and usage
FindNpm REQUIRE functionality was not provided by FindNpm.cmake. UpdatedUpdated FindNpm to extract version, global node_modules directory, and to fail if REQUIRE was set and npm was not found. Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
7d83e8c569
commit
6f72c52a44
@ -151,11 +151,6 @@ if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
if (BUILDTESTS)
|
||||
find_package (Npm REQUIRED)
|
||||
if(NPM_EXECUTABLE)
|
||||
message(STATUS "NPM Executable found at: ${NPM_EXECUTABLE}")
|
||||
else()
|
||||
message(FATAL_ERROR "Please install NPM first, you can't run tests without it")
|
||||
endif()
|
||||
endif (BUILDTESTS)
|
||||
endif (BUILDSWIGNODE)
|
||||
|
||||
|
@ -1,13 +1,71 @@
|
||||
# Finding and pointing a variable to the npm executable if found
|
||||
# Only works on Linux systems as of now
|
||||
# FindNpm
|
||||
# --------
|
||||
#
|
||||
# Find npm
|
||||
#
|
||||
# This module finds an installed npm. It sets the following variables:
|
||||
#
|
||||
# NPM_FOUND - Set to true if npm is found
|
||||
# NPM_DIR - The directory where npm is installed
|
||||
# NPM_GLOBAL_NODE_MODULE_DIR - The global node_modules directory
|
||||
# NPM_EXECUTABLE - The path to the npm executable
|
||||
# NPM_VERSION - The version number of the npm executable
|
||||
|
||||
find_program(NPM_EXECUTABLE NAMES npm
|
||||
HINTS
|
||||
/usr
|
||||
)
|
||||
find_program(NPM_EXECUTABLE NAMES npm HINTS /usr)
|
||||
|
||||
if(NPM_EXECUTABLE)
|
||||
message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}")
|
||||
# If npm was found, fill in the rest
|
||||
if (NPM_EXECUTABLE)
|
||||
# Set the global node_modules location
|
||||
execute_process(COMMAND ${NPM_EXECUTABLE} root -g
|
||||
OUTPUT_VARIABLE NPM_GLOBAL_NODE_MODULE_DIR
|
||||
ERROR_VARIABLE NPM_root_g_error
|
||||
RESULT_VARIABLE NPM_root_g_result_code)
|
||||
# Remove and newlines
|
||||
string (STRIP ${NPM_GLOBAL_NODE_MODULE_DIR} NPM_GLOBAL_NODE_MODULE_DIR)
|
||||
if(NPM_root_g_result_code)
|
||||
if(NPM_FIND_REQUIRED)
|
||||
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
|
||||
else ()
|
||||
message(STATUS "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
|
||||
endif ()
|
||||
endif()
|
||||
unset(NPM_root_g_error)
|
||||
unset(NPM_root_g_result_code)
|
||||
|
||||
# Set the NPM dir
|
||||
if (EXISTS "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
|
||||
set(NPM_DIR "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
|
||||
endif()
|
||||
|
||||
# Set the VERSION
|
||||
execute_process(COMMAND ${NPM_EXECUTABLE} -v
|
||||
OUTPUT_VARIABLE NPM_VERSION
|
||||
ERROR_VARIABLE NPM_version_error
|
||||
RESULT_VARIABLE NPM_version_result_code)
|
||||
|
||||
if(NPM_version_result_code)
|
||||
if(NPM_FIND_REQUIRED)
|
||||
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
|
||||
else()
|
||||
message(STATUS "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
|
||||
endif ()
|
||||
endif ()
|
||||
unset(NPM_version_error)
|
||||
unset(NPM_version_result_code)
|
||||
|
||||
# Remove and newlines
|
||||
string (STRIP ${NPM_VERSION} NPM_VERSION)
|
||||
|
||||
set (NPM_FOUND TRUE)
|
||||
else()
|
||||
message(ERROR "Unable to find NPM installation, please install NPM")
|
||||
endif()
|
||||
# Fail on REQUIRED
|
||||
if (Npm_FIND_REQUIRED)
|
||||
message(SEND_ERROR "Failed to find npm executable")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
find_package_handle_standard_args(NPM
|
||||
REQUIRED_VARS NPM_EXECUTABLE NPM_DIR
|
||||
VERSION_VAR NPM_VERSION )
|
||||
|
||||
mark_as_advanced(NPM_DIR NPM_GLOBAL_NODE_MODULE_DIR NPM_EXECUTABLE NPM_VERSION)
|
||||
|
Loading…
x
Reference in New Issue
Block a user