[CMake] CMake link order

Fred Baksik fdk17 at ftml.net
Fri Oct 18 12:24:46 EDT 2019



On Fri, Oct 18, 2019, at 11:55 AM, Fred Baksik wrote:
> 
> In target_link_libraries it states that "The library dependency graph is normally acyclic (a DAG)". I recall from my own experience that the DAG is not always created the same way when generating the project. It has to do with the way with this part of CMake is implemented (C++ containers and that sort of thing) so while all the inputs are the same the order is Not the same so it produces a different DAG which changed the ordering of the components build order which also altered the link order.
> 
> For the GHS Generator to ensure that the exact same project files are output we sorted the components by name into a vector first (instead of just using a set) before supplying it to this algorithm. Then the results were always the same.
> 

Sorry, I wanted to clarify this a bit. The DAG is correct. For example lets say A depends on B and C and then C on D. This DAG always comes out the same. But when you try to extract the dependents of A it sometimes returns something that will give you B then C or C then B when accessing them in a linear order. So there were differences if you inspected these items with the debugger.

When I ran across these kinds of things with the GHS Generator we sort things in lexicographical order to produce the same results every time.

Best regards,
Fred
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191018/b66df534/attachment.html>


More information about the CMake mailing list