[CMake] Can you add sources to a target library after add_library()?

Marcel Loose loose at astron.nl
Mon Jan 11 05:34:43 EST 2010


Hi Eric,

Your solution is one possibility to tackle my problem.

What I am trying to accomplish is to record version information into
some (but not all) of the libraries/executables in my project.
So, this version file -- let's call it version.cc -- may, or may not be
part of the list of sources to add to a library. Moreover, version.cc is
generated, based on information from, a.o., Subversion.

I just re-read the thread "Embedding up-to-date version info in built
library" from mid-December 2009. I think I'll have to study that
solution more carefully, cause the subject is very close to what I'm
currently facing.

Best regards,
Marcel Loose.

On Mon, 2010-01-11 at 11:14 +0100, Eric Noulard wrote:
> 2010/1/11 Marcel Loose <loose at astron.nl>:
> > Too bad. I was hoping I could do this without having to use a list
> > variable to collect all my sources. In my case, the use of
conditionals
> > is somewhat awkward.
> 
> Personnally I sometime use several variable like:
> 
> add_library(blah
>                  ${BLAH_SOURCE}
>                  ${BLAH_SOURCE_OPT1}
>                  ${BLAH_SOURCE_OPT2}
>                  ${BLAH_SOURCE_OPT3})
> 
> xxx_OPTy var may contains source or may be void and off course
> should be defined BEFORE add_library is called.
> 
> It is mostly like conditionnally adding the same content to a list but
> may required less conditionnal because xxx_OPTy may defaulted to void
content.
> 
> Would you explain us why you need to add source AFTER add_library
> and may be why conditionnal is awkward?




More information about the CMake mailing list