[cmake-developers] GCC link options

J Decker d3ck0r at gmail.com
Wed Jul 25 16:57:04 EDT 2012


Is there a super simple way to get the current build command for say
exectuable, string(replace) it, and then execute it in a custom
target?

On Wed, Jul 25, 2012 at 11:31 AM, Brad King <brad.king at kitware.com> wrote:
> On 07/25/2012 02:12 PM, J Decker wrote:
>> target_link_libraries(  playcard --whole-archive
>> eltanin_sdl_deadstart_end --no-whole-archive ${COMMON_LIBRARIES} )
>> (the output link line looks like .....  libplaycard.a --whole-archive
>> eltanin_sdl_deadstart_end.a libcommon.a --no-whole-archive )
>
> The only ordering guarantee is that the target being linked
> (final executable or shared library) has its own sequence
> first as specified by target_link_libraries.  Transitive
> dependencies of the libraries named at the first level will
> all appear in order but may have other things inserted.
>
that is the behavior I observe, but, I don't understand why a library
would be inserted in the middle of a set of libraries...



> The only reliable place to put flags is in the top-level call
> to target_link_libraries for the target getting linked.  For
> example:
>
>  add_executable(foo foo.c)
>  target_link_libraries(foo ${libs}
>    --whole-archive ${special} --no-whole-archive)
>
> will result in
>
>  -o foo ${libs} --whole-archive ${special} --no-whole-archive ${depends}
>

which goes back to remove all implied dependencies and make one big list.....

>
> Alternatively, using CMake 2.8.8 you can also use an object library:
>
>  add_library(eltanin_sdl_deadstart_end OBJECT src.c)
>  add_executable(foo foo.c $<TARGET_OBJECTS:eltanin_sdl_deadstart_end>)
>  target_link_libraries(foo ${libs})
>
> That will ensure the desired objects end up in the executable.
> They will be listed explicitly on the link line as ".o" files.
>

Ya, but some of the items added to the deadstart section are in .a
files, so it has to be after all of those also....

Migrating to shared libraries can also solve this; but, turns out they
used circular references in the libraries....

None of this is good news :(

Thanx though.

> -Brad



More information about the cmake-developers mailing list