[cmake-developers] New OBJECT library feature

Eric Noulard eric.noulard at gmail.com
Mon Mar 19 14:25:55 EDT 2012


2012/3/19 Brad King <brad.king at kitware.com>:
> On 3/19/2012 1:56 PM, Eric Noulard wrote:
>>
>> That's a great feature.
>
>
> Thanks.
>
>
>> Is there a feature that could guarantee the order of appearance of
>> those objects / object library on the link line generated for
>> add_executable ?
>
> Currently no order is guaranteed other than that all the object files
> from directly compiled sources, external objects, and object libraries
> will all come before any _linked_ libraries.  I'm not sure whether it
> is even possible to guarantee an order in all our target build systems.
>
> Can you enumerate use cases when the order of objects matters?  Unlike
> static libraries *all* objects will be included.  If there are duplicate
> symbols it is an error.  If there are not duplicate symbols then how
> does order matter?

I have to dig into an exotic build system I converted from makefile to CMake
in order to fully understand why. As far as I remember it was
mandatory but I cannot
remember the reason.

This use cases I do compile object using add_library and a single
file using a custom command because the final link step
(done with a custom command as well)  requires this last object object file
to be given first on the command line.

The custom command likn step looks like:
COMMAND ${CMAKE_LINKER} --oformat binary -Ttext ${BM_IMAGE_ADDRESS}
-melf_i386 -e _start -o ${BM_APPNAME}.bin ${BM_STARTUPOBJ}
--start-group $<TARGET_LINKER_FILE:system> $<TARGET_LINKER_FILE:xc>
$<TARGET_LINKER_FILE:${BM_APPNAME}> --end-group ${BM_LDSCRIPT}

${BM_STARTUPOBJ} is the specific object file compiled on its own using
custom command.

Now that I think about it, before that I was forced to create a custom
command in order
to compile the file ('with the same option as the one compiled by add_library)
but now I will be able to build an "OBJECT library" containing a single file
and refer to it using $<TARGET_OBJECTS:objlib> which is perfectly fine for
ensuring the ordering I may need for the link step.

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



More information about the cmake-developers mailing list