mingw32-make is "Deleting primary custom command output because another output does not exist"
While creating the testcase for #17071 I found a strange issue with mingw32-make. For a custom command like
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/version.h
${CMAKE_BINARY_DIR}/hello.rc
non-existing.txt # force to execute on every build
COMMAND
${CMAKE_COMMAND} [...]
which is supposed to create version.h
and hello.rc
(while non-existing.txt
is actually not created but should force the command to run on every build) mingw32-make decides to delete version.h
after successfully creating it because it's missing the non-existing file!
Full output of mingw32-make for the testcase: test.zip
$ VERBOSE=1 mingw32-make
C:\msys64\mingw64\bin\cmake.exe -HE:\test -BE:\test\build --check-build-system CMakeFiles\Makefile.cmake 0
C:\msys64\mingw64\bin\cmake.exe -E cmake_progress_start E:\test\build\CMakeFiles E:\test\build\CMakeFiles\progress.marks
C:/msys64/mingw64/bin/mingw32-make -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory 'E:/test/build'
C:/msys64/mingw64/bin/mingw32-make -f CMakeFiles\hello.dir\build.make CMakeFiles/hello.dir/depend
mingw32-make[2]: Entering directory 'E:/test/build'
[ 25%] Generating version.h, hello.rc, non-existing.txt
C:\msys64\mingw64\bin\cmake.exe -DSOURCE_DIR=E:/test -DBINARY_DIR=E:/test/build -P E:/test/version.cmake
C:\msys64\mingw64\bin\cmake.exe -E cmake_depends "MinGW Makefiles" E:\test E:\test E:\test\build E:\test\build E:\test\build\CMakeFiles\hello.dir\DependInfo.cmake --color=
Deleting primary custom command output "E:/test/build/version.h" because another output "E:/test/build/non-existing.txt" does not exist.
Dependee "E:\test\build\CMakeFiles\hello.dir\DependInfo.cmake" is newer than depender "E:/test/build/CMakeFiles/hello.dir/depend.internal".
Dependee "E:/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "E:/test/build/CMakeFiles/hello.dir/depend.internal".
Scanning dependencies of target hello
mingw32-make[2]: Leaving directory 'E:/test/build'
C:/msys64/mingw64/bin/mingw32-make -f CMakeFiles\hello.dir\build.make CMakeFiles/hello.dir/build
mingw32-make[2]: Entering directory 'E:/test/build'
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
C:\msys64\mingw64\bin\g++.exe @CMakeFiles/hello.dir/includes_CXX.rsp -o CMakeFiles\hello.dir\hello.cpp.obj -c E:\test\hello.cpp
E:\test\hello.cpp:2:9: fatal error: version.h: No such file or directory
#include<version.h>
^~~~~~~~~~~
compilation terminated.
mingw32-make[2]: *** [CMakeFiles\hello.dir\build.make:73: CMakeFiles/hello.dir/hello.cpp.obj] Error 1
mingw32-make[2]: Leaving directory 'E:/test/build'
mingw32-make[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/hello.dir/all] Error 2
mingw32-make[1]: Leaving directory 'E:/test/build'
mingw32-make: *** [Makefile:83: all] Error 2
Note the line Deleting primary custom command output "E:/test/build/version.h" because another output "E:/test/build/non-existing.txt" does not exist.
Interestingly one can trick cmake/mingw32-make into working by simply switching the order of the outputs like
add_custom_command(
OUTPUT
non-existing.txt # force to execute on every build
${CMAKE_BINARY_DIR}/version.h
${CMAKE_BINARY_DIR}/hello.rc
COMMAND
${CMAKE_COMMAND} [...]
I don't know if this is "by design" or a limitation, but it certainly seems strange...
System information
cmake 3.8.2 and mingw32-make 4.2.1 on MSYS2 (specifically mingw-w64-x86_64-cmake 3.8.2-2 and mingw-w64-x86_64-make 4.2.1-1)