Hello,
What is the expected behavior when one of the COMMANDs given to add_custom_command()
fail ? Are the following commands processed ?
Is there a log ? Does the CMake command return an error code ?
Thanks.
Hello,
What is the expected behavior when one of the COMMANDs given to add_custom_command()
fail ? Are the following commands processed ?
Is there a log ? Does the CMake command return an error code ?
Thanks.
Custom commands run at build time, which means their behaviour is controlled by the build driver (e.g. make, msbuild) more than it’s controlled by CMake. Since CMake docs don’t specify otherwise, I’ve always expected them to behave like other build steps:
COMMAND
s from the same add_custom_command
processed.OK, I tried to find the info from Visual Studio. There is not realy documentation about this point, but by reading the Post-Build events, I see the %errorlevel% system variable is set when any command fails.
Does CMake read this value ? Can I get it in order to check it ?
%errorlevel%
is the Windows syntax for getting the exit code of the last command run, similar to $?
in Unix.
Please note that at build-time, it’s not CMake which executes the build steps such as compilation, linking, and custom commands. Unless you build using cmake --build
, CMake is not even running at build time.
If you need complex custom command processing and logic, I suggest you create a script in an appropriate shell or scripting language (including perhaps CMake with execution via cmake -P
) and use that as your custom command, instead of putting too much logic into the add_custom_command()
call itself.
Actually, I intended to test $ENV{ERRORLEVEL}
to potententially exit with a message(FAILURE ...)
.
The purpose is to exit from CMake with a status error so that our Jenkins see the building process as failed.
But this post le me think an execute_process()
may be needed…
It might be the case that execute_process()
is what you’re looking for. That is for running code when CMake is running to generate your buildsystem, which seems to be what you want.
Your original post contains add_custom_command()
, which is for defining commands that will run as part of the build, at build time.
I use add_custom_command()
to retrieve the needed Qt dependencies (which are determined from the built files) and to generate a MD5 file. So I guess it is the appropriate command.
But from the post, what I should do is not so clear…