summaryrefslogtreecommitdiff
path: root/cmake/npm.cmake
blob: bb456666e2dcacab0a6a809571887d9c0fce4e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function(cache_executable_path name variable)
    # Obtain paths to node and npm and cache it, so when e.g. Xcode reruns CMake, we still have the
    # variables from the original invocation
    if(NOT ${variable})
        set(_which_output)
        execute_process(
            COMMAND which ${name}
            OUTPUT_VARIABLE _which_output
            OUTPUT_STRIP_TRAILING_WHITESPACE)
        if(_which_output STREQUAL "")
            message(STATUS "Using cached ${name}: ${${variable}}")
        else()
            set(${variable} "${_which_output}" CACHE PATH "Path to ${name} executable")
            message(STATUS "Using ${name}: ${${variable}}")
        endif()
    endif()
endfunction()

cache_executable_path(node _node)
cache_executable_path(npm _npm)