[CMake] Custom message if target fails

Nils Gladitz nilsgladitz at gmail.com
Thu Nov 12 04:10:30 EST 2015


On 11/12/2015 09:54 AM, Daniel Wirtz wrote:
> Dear all,
>
> i've been thinking on this for a while but i can't seem to get my head 
> around how to solve this.
> The task is simple: How can i display a custom error message if a 
> target fails to build for whatever reason?
> - cmake ..
> - make
> - <build starts, stuff goes wrong, error out>
> - below the (compile-tool dependent error output) i'd like to print 
> something like "Whoops it went wrong, type this and that or visit this 
> or that website for help"
>

There is no generic build system feature for this.

You haven't provided any details on what kind of target this concerns or 
what is to be diagnosed specifically but ...

Assuming this is a custom target / custom command you could replace the 
actual command with a wrapper (e.g. cmake -P script) that:
     - runs the actual command (e.g. execute_process())
     - outputs a message based on the actual command's exit status (e.g. 
message("This and that"))
     - exits with (roughly) the same exit status as the actual command 
(e.g. message(FATAL_ERROR) on failure))

For regular build targets (executables, libraries) there is nothing to 
be done at build time.
Depending on what it is you are actually diagnosing you might want to 
try to diagnose it during configuration rather than during the build.

Nils


More information about the CMake mailing list