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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

Marek Vojtko

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?


Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe: