VS: sequence of COMMANDS in add_custom_command not executing
Here is a minimal example of the problem. I have this CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(trying-npm
LANGUAGES
NONE
)
set(PACKAGEJSON_STAMP ${PROJECT_BINARY_DIR}/package.json.stamp)
add_custom_command(
OUTPUT
${PACKAGEJSON_STAMP}
COMMAND
${CMAKE_COMMAND} -E echo before
COMMAND
npm --version
COMMAND
${CMAKE_COMMAND} -E echo after
COMMAND
${CMAKE_COMMAND} -E touch ${PROJECT_BINARY_DIR}/package.json.stamp
DEPENDS
${PROJECT_SOURCE_DIR}/package.json
)
add_custom_target(vsix
ALL
DEPENDS
${PACKAGEJSON_STAMP}
)
The package.json file also exists but it can just be empty.
When I try to build, I see the before echo but I do not see the after echo.
Here is a transcript:
C:\dev\trying-npm\build>cmake --build .
CMake is re-running because C:/dev/trying-npm/build/CMakeFiles/generate.stamp is out-of-date.
the file 'C:/dev/trying-npm/CMakeLists.txt'
is newer than 'C:/dev/trying-npm/build/CMakeFiles/generate.stamp.depend'
result='-1'
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19042.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev/trying-npm/build
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Generating package.json.stamp
before
6.14.4
This is boiled down from an example of running npm install
and generating a time stamp. This works fine on my Mac but fails on Windows.
I remove the npm command and then I can see the after echo.
npm --version has a 0 exit code and I cannot imagine what is happening to prevent the execution of subsequent commands.
Edited by Brad King