Custom command error handling broken with Visual Studio & CMP0147
Steps to reproduce
- Create a simple
CMakeLists.txt
with a failing custom command with CMP0147 enabled (CMake >=3.27), e.g.:cmake_minimum_required(VERSION 3.27) project(myproj) add_custom_target(mytgt ALL COMMAND oopsie-this-command-doesnt-exist)
- Configure with Visual Studio generator
- Try to build
mytgt
- Observe second line in the error about
VCEnd
:1> 'oopsie-this-command-doesnt-exist' is not recognized as an internal or external command, operable program or batch file. The system cannot find the batch label specified - VCEnd C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(237,5): error MSB8066: Custom build for 'C:\Users\StevenWdV\Downloads\cmaketest\build\CMakeFiles\9ef0abe342bf60f8c32deec84aa0c866\mytgt.rule' exited with code 1. [C:\Users\StevenWdV\Downloads\cmaketest\build\mytgt.vcxproj]
Expected behavior
Just 'oopsie-this-command-doesnt-exist' is not recognized as an internal or external command, operable program or batch file.
.
Not The system cannot find the batch label specified - VCEnd
.
Cause
With CMP0147 NEW, CMake adds <BuildInParallel>true</BuildInParallel>
to the generated <CustomBuild>
. This makes it a ParallelCustomBuild
instead of a CustomBuild
according to a condition in Microsoft.CppCommon.targets
, as can also be observed by the line numbers in the error: 237
(ParallelCustomBuild
) above, but 254
(CustomBuild
) with CMP0147
set to OLD (in which case we don't see the VCEnd
error).
While CustomBuild
has BuildSuffix
set to (newline):VCEnd
, ParallelCustomBuild
does not, meaning the if %errorlevel% neq 0 goto :VCEnd
in the script generated by CMake fails. Looking at the ParallelCustomBuild
docs, it looks like BuildSuffix
does not exist.