[CMake] add_custom_command which generates new sources which I want to specify before

Eric Noulard eric.noulard at gmail.com
Thu Feb 28 18:25:01 EST 2013


2013/3/1 Baradé <barade.barade at web.de>:
> Hi,
> assuming I have the following statements:
>
> add_library(targetName src1 src2 ... generatedSrc)
> add_custom_command(TARGET targetName PRE_BUILD COMMAND bash -c "bla bla
> bla")
>
> and the custom command generates sources which are specified before in
> "add_library" CMake/build process will abort since they don't exist
> already when specified (not needed actually).

Yes they should be flagged as GENERATED, see

cmake --help-property GENERATED

> Unfortunately, since it is an automated process I cannot easily get the
> names of the generated sources, they're just included in the usual
> sources variable (I can't separate them from the others).

You mean you GLOB them or you list them ?
If you list them then

set_source_files_properties(${generatedSrc}
                                     PROPERTIES GENERATED TRUE)

should be enough.

> Is there any possibility to get this working without knowing the source
> file names?

No I don't think so.

I shall add that this doesn't seem wise not to know the files you'll
have to compile.

if this was possible how would you ensure "clean rebuild" if
you don't even know which would be the generated files?

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list