diff --git a/cmake/macros/FindNPM.cmake b/cmake/macros/FindNPM.cmake new file mode 100644 index 0000000000..c66114f878 --- /dev/null +++ b/cmake/macros/FindNPM.cmake @@ -0,0 +1,14 @@ +# +# FindNPM.cmake +# cmake/macros +# +# Created by Thijs Wenker on 01/23/18. +# Copyright 2018 High Fidelity, Inc. +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http:#www.apache.org/licenses/LICENSE-2.0.html +# + +macro(find_npm) + find_program(NPM_EXECUTABLE "npm") +endmacro() diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 130848fc08..b03a4637d0 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -41,6 +41,8 @@ endif() file(GLOB_RECURSE INTERFACE_SRCS "src/*.cpp" "src/*.h") GroupSources("src") +find_npm() + # Add SpeechRecognizer if on Windows or OS X, otherwise remove if (WIN32) # Use .cpp and .h files as is. @@ -297,22 +299,38 @@ if (APPLE) set(SCRIPTS_INSTALL_DIR "${INTERFACE_INSTALL_APP_PATH}/Contents/Resources") + if (NPM_EXECUTABLE) + set(EXTRA_COPY_COMMANDS + COMMAND "${CMAKE_COMMAND}" -E make_directory + "$/../Resources/auto-complete" + COMMAND "${CMAKE_COMMAND}" -E copy + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" + "$/../Resources/auto-complete" + ) + endif() + # copy script files beside the executable add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/scripts" "$/../Resources/scripts" - COMMAND "${CMAKE_COMMAND}" -E make_directory - "$/../Resources/auto-complete" - COMMAND "${CMAKE_COMMAND}" -E copy - "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" - "$/../Resources/auto-complete" + + ${EXTRA_COPY_COMMANDS} ) # call the fixup_interface macro to add required bundling commands for installation fixup_interface() else (APPLE) + if (NPM_EXECUTABLE) + set(EXTRA_COPY_COMMANDS + COMMAND "${CMAKE_COMMAND}" -E make_directory + "$/resources/auto-complete" + COMMAND "${CMAKE_COMMAND}" -E copy + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" + "$/resources/auto-complete" + ) + endif() # copy the resources files beside the executable add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory @@ -321,11 +339,8 @@ else (APPLE) COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/scripts" "$/scripts" - COMMAND "${CMAKE_COMMAND}" -E make_directory - "$/resources/auto-complete" - COMMAND "${CMAKE_COMMAND}" -E copy - "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" - "$/resources/auto-complete" + + ${EXTRA_COPY_COMMANDS} ) # link target to external libraries diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index ac920d930d..53d7fc2836 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,8 +2,11 @@ add_subdirectory(scribe) set_target_properties(scribe PROPERTIES FOLDER "Tools") -add_subdirectory(jsdoc) -set_target_properties(jsdoc PROPERTIES FOLDER "Tools") +find_npm() +if (NPM_EXECUTABLE) + add_subdirectory(jsdoc) + set_target_properties(jsdoc PROPERTIES FOLDER "Tools") +endif() if (BUILD_TOOLS) add_subdirectory(udt-test) diff --git a/tools/jsdoc/CMakeLists.txt b/tools/jsdoc/CMakeLists.txt index 36c2af4265..b52d229130 100644 --- a/tools/jsdoc/CMakeLists.txt +++ b/tools/jsdoc/CMakeLists.txt @@ -2,6 +2,8 @@ set(TARGET_NAME jsdoc) add_custom_target(${TARGET_NAME}) +find_npm() + SET(JSDOC_WORKING_DIR ${CMAKE_SOURCE_DIR}/tools/jsdoc) file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR}/node_modules/.bin/jsdoc JSDOC_PATH) file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR}/config.json JSDOC_CONFIG_PATH) @@ -9,7 +11,7 @@ file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR}/out OUTPUT_DIR) file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR} NATIVE_JSDOC_WORKING_DIR) add_custom_command(TARGET ${TARGET_NAME} - COMMAND (npm --no-progress install) && (${JSDOC_PATH} ${NATIVE_JSDOC_WORKING_DIR} -c ${JSDOC_CONFIG_PATH} -d ${OUTPUT_DIR}) + COMMAND (${NPM_EXECUTABLE} --no-progress install) && (${JSDOC_PATH} ${NATIVE_JSDOC_WORKING_DIR} -c ${JSDOC_CONFIG_PATH} -d ${OUTPUT_DIR}) WORKING_DIRECTORY ${JSDOC_WORKING_DIR} COMMENT "generate the JSDoc JSON for the JSConsole auto-completer" )