[CMake] add_library/add_executable ordering

Hai Nguyen chaoticbob at gmail.com
Thu Jun 25 22:13:29 EDT 2009


Apologies. I found the error. I had used two variables to refer to the
library name and the dependency - thinking they were the same thing. There
was a mixup between the names due to using set_target_properties to change
the alter the prefix.

- Hai

On Wed, Jun 24, 2009 at 6:56 PM, Bill Hoffman <bill.hoffman at kitware.com>wrote:

> Tyler Roscoe wrote:
>
>> On Wed, Jun 24, 2009 at 03:30:33PM -0700, Hai Nguyen wrote:
>>
>>> add_library( libB ... )
>>> add_executable( ExecB ... )
>>> target_link_libraries( ExecB libB )
>>>
>>> but the build order now is: ExecB, libB
>>>
>>> I'm getting link errors because libB doesn't exist yet. If I comment out
>>> the
>>> ExecB stuff, it builds libB.
>>>
>>> Can someone give me a clue on what criteria CMake is using to determine
>>> what
>>> builds first?
>>>
>>
>> I think the order is undefined unless there are dependencies to resolve.
>>
>> I'm a litle surprised that your B example doesn't work, since I thought
>> CMake was smart enough to notice that execB needs libB and would thus
>> build libB first.
>>
>> Anyway, the way to get the correct build order is by using
>> add_dependencies(). If you do add_dependencies(execB libB) then
>> everything should work as expected.
>>
>>
> I don't think your example is complete.   That should work fine, and you do
> not need add_dependencies ever for library to executable stuff.
>
> -Bill
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090625/12a02fab/attachment.htm>


More information about the CMake mailing list