[CMake] Custom message if target fails

Daniel Wirtz daniel.wirtz at simtech.uni-stuttgart.de
Thu Nov 12 05:05:31 EST 2015


Hey,

neat idea, i've tried and it works (i have custom targets there).
However, the "nice" colored build text output of such a solution gets 
lost completely (pipes etc); are there any alternative ideas/solutions?

thanks again!

Dr. Daniel Wirtz
Dipl. Math. Dipl. Inf.
SRC SimTech
Pfaffenwaldring 5a
+49 711 685 60044

On 11/12/2015 10:10 AM, Nils Gladitz wrote:
> 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