File: FindNPM.cmake

package info (click to toggle)
warzone2100 4.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 660,332 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (63 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# FindNPM
# --------
#
# This module finds an installed npm.
# It sets the following variables:
#
#  NPM_FOUND - True when NPM is found
#  NPM_GLOBAL_PREFIX_DIR - The global prefix 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)

if (NPM_EXECUTABLE)

	# Get the global npm prefix
	execute_process(COMMAND ${NPM_EXECUTABLE} prefix -g
		OUTPUT_VARIABLE NPM_GLOBAL_PREFIX_DIR
		ERROR_VARIABLE NPM_prefix_g_error
		RESULT_VARIABLE NPM_prefix_g_result_code
	)
	# Remove spaces and newlines
	string (STRIP ${NPM_GLOBAL_PREFIX_DIR} NPM_GLOBAL_PREFIX_DIR)
	if (NPM_prefix_g_result_code)
		if(NPM_FIND_REQUIRED)
			message(SEND_ERROR "Command \"${NPM_EXECUTABLE} prefix -g\" failed with output:\n${NPM_prefix_g_error}")
		else()
			message(STATUS "Command \"${NPM_EXECUTABLE} prefix -g\" failed with output:\n${NPM_prefix_g_error}")
		endif()
	endif()
	unset(NPM_prefix_g_error)
	unset(NPM_prefix_g_result_code)

	# Get 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 spaces and newlines
	string (STRIP ${NPM_VERSION} NPM_VERSION)
else()
	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_GLOBAL_PREFIX_DIR
	VERSION_VAR NPM_VERSION
)

mark_as_advanced(NPM_GLOBAL_PREFIX_DIR NPM_EXECUTABLE NPM_VERSION)