[CMake] [VS] Error Code Return from add_custom_command() Suppresses Console Output

Marek Vojtko marek.vojtko at oxidegames.com
Wed Sep 18 14:55:55 EDT 2019


Hi,

I have a custom command that calls an in-house compiler that generates a source file set up like this:

add_custom_command(OUTPUT "generatedFile.h" COMMAND "myCompiler.exe -someParam" [..])

The compiler prints information to STDOUT like lines where errors or warnings occurred.

When the command succeeds (i.e. the compilation succeeds and myCompiler.exe returns 0), the compiler's output is correctly printed into the compile output (the Build Output window in Visual Studio):

> Generating generatedFile.h
>
> <path/to/myCompiler.exe> -someParam
>
> [output from the compiler, including file names and line numbers for warnings]

However, when the command fails (i.e. the compilation fails and myCompiler.exe returns a non-zero return code), I don't see the compiler's output. Instead I get:

> C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exited with code -2147483645.

I get this behavior on CMake 3.12 and 3.15. I have tried adding VERBATIM and USES_TERMINAL to my add_custom_command() call, but neither helped.

How can I get the custom command's output even when it returns a non-zero return code?

Thanks,
Marek


More information about the CMake mailing list