[CMake] add_custom_command question

Michael Hertling mhertling at online.de
Thu Oct 20 08:16:05 EDT 2011


On 10/20/2011 12:37 PM, Łukasz Tasz wrote:
> Hi all,
> 
> In my cmake project I have few commands that are creating outputs.
> 
> But Unfortunately those outputs are used across many directories.
> 
> So my question is what's the real scope of output_command? only
> Current_CmakeLists.txt?

Yes, a custom command's OUTPUT must be referred to by an ADD_LIBRARY/
EXECUTABLE() or an ADD_CUSTOM_TARGET() within the same CMakeLists.txt
file; otherwise, it is silently ignored.

> Can I somehow make make_target that is creating output registered in
> global scope?

Mention the custom command's OUTPUT in a custom target's DEPENDS clause
in the same CMakeLists.txt, and use ADD_DEPENDENCIES() to ensure that
the custom target is triggered at the proper time. Note the issues
w.r.t. relative paths in this regard.

> I'm familiar with pattern of attaching custom target with custom
> command, but I would like to avoid managing separately target, and
> output name.

AFAIK, there's currently no chance to do this in another way, but a
custom command can generate more than one output file, and a custom
target can refer to more than one prerequisite, so you can possibly
aggregate and don't need an own target/command per output file.

> thanks in advance
> Lukasz

Regards,

Michael


More information about the CMake mailing list