In my CMakeLists.txt, I use add_custom_command in conjunction with add_custom_target to call a code generation step.
If the code generation step succeeds, but one of the files mentioned in the OUTPUT argument to add_custom_command is missing, make is removing the first file mentioned in OUTPUT, for reasons outlined in Why does GNU make delete a file
(The first OUTPUT file because that is the "main" file that is associated with the command in the generated Makefile)
So far, so good. The issue I have is that this does not fail the build immediately. Instead, when the generated code is actually being used in the compilation, the compiler complains about a missing header, which ironically is not the file that the generator did not generate, but the file make removed.
The message explaining that the file was removed also only appears when make is run with VERBOSE=1, leaving me in the dark for way too long.
Deleting primary custom command output "/app/tests/eclipseProject/projects/math/build/aragen/matrix2Component/matrix2/includes/serviceInterfaces/matrix/proxy_Mat_SI.h" because another output "/app/tests/eclipseProject/projects/math/build/aragen/matrix2Component/matrix2/vsomeip/serviceInterfaces/matrix/proxy_vsomeip_Mat_SI.h" does not exist.
How can I make sure the build fails when trying to build the generation target, before compilation is executed?