Change how to find npm (#15001)

This commit is contained in:
Changming Sun 2023-03-15 11:10:10 -07:00 committed by GitHub
parent 32533dd1c2
commit 5213546e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 29 deletions

View file

@ -4,11 +4,12 @@
set(JS_ROOT ${REPO_ROOT}/js)
set(JS_COMMON_ROOT ${JS_ROOT}/common)
set(JS_NODE_ROOT ${JS_ROOT}/node)
if (WIN32)
set(NPM_CLI cmd /c npm)
else()
set(NPM_CLI npm)
endif()
find_program(NPM_CLI
NAMES "npm.cmd" "npm"
DOC "NPM command line client"
REQUIRED
)
# verify Node.js and NPM
execute_process(COMMAND node --version
@ -113,4 +114,4 @@ endif()
add_dependencies(js_common_npm_ci js_npm_ci)
add_dependencies(nodejs_binding_wrapper js_common_npm_ci)
add_dependencies(nodejs_binding_wrapper onnxruntime)
endif()
endif()

View file

@ -153,28 +153,13 @@ function(AddTest)
xctest_add_test(xctest.${_UT_TARGET} ${_UT_TARGET}_xc)
else()
if (onnxruntime_BUILD_WEBASSEMBLY)
# the following code are copied from onnxruntime_nodejs.cmake
if (CMAKE_HOST_WIN32)
set(NPM_CLI npm.cmd)
else()
set(NPM_CLI npm)
endif()
# verify Node.js and NPM
execute_process(COMMAND node --version
OUTPUT_VARIABLE node_version
RESULT_VARIABLE had_error
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(had_error)
message(FATAL_ERROR "Failed to find Node.js: " ${had_error})
endif()
execute_process(COMMAND ${NPM_CLI} --version
OUTPUT_VARIABLE npm_version
RESULT_VARIABLE had_error
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(had_error)
message(FATAL_ERROR "Failed to find NPM: " ${had_error})
endif()
# We might have already executed the following "find_program" code when we build ORT nodejs binding.
# Then the program is found the result is stored in the variable and the search will not be repeated.
find_program(NPM_CLI
NAMES "npm.cmd" "npm"
DOC "NPM command line client"
REQUIRED
)
if (onnxruntime_WEBASSEMBLY_RUN_TESTS_IN_BROWSER)
add_custom_command(TARGET ${_UT_TARGET} POST_BUILD
@ -1129,7 +1114,7 @@ if(onnxruntime_ENABLE_EAGER_MODE)
GTest::gtest
re2::re2
onnxruntime_flatbuffers
flatbuffers::flatbuffers
flatbuffers::flatbuffers
${CMAKE_DL_LIBS}
)
if(onnxruntime_ENABLE_TRAINING)