<div dir="ltr">I have a feeling that you could do this with generator expressions. You would have the interface link line for I have a generator expression that switches between IA and IB. Than you would setup ExeA and ExeB to trigger this switch. Maybe using something like $<TARGET_PROPERTY:prop>? </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 17, 2017 at 8:28 AM, Etan Kissling <span dir="ltr"><<a href="mailto:kissling@oberon.ch" target="_blank">kissling@oberon.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, and thanks for the quick reaction :-)<br>
<br>
The approach with forward declaration looks interesting. However, I don't think that it will resolve all the problems.<br>
<br>
One issue is that there are multiple apps, each using separate implementations.<br>
• ExeA uses the generic libraries Foo and Bar, as well as the **IA** implementation of interface library I.<br>
• ExeB uses the generic libraries Foo and Bar, as well as the **IB** implementation of interface library I.<br>
<br>
On top of that, I'd like to be able to build Foo and Bar independently as static libraries, without IA or IB being present.<br>
<br>
Is it possible to replace references to interface library I with implementation IA, but only while ExeA is being compiled, and vice versa for ExeB?<br>
There are only static libraries involved, so the compilation of Foo / Bar should be the same in both cases.<br>
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888"><br>
Etan<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> On 16 May 2017, at 10:39, Patrick Boettcher <<a href="mailto:patrick.boettcher@posteo.de">patrick.boettcher@posteo.de</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> On Mon, 15 May 2017 12:30:10 +0000<br>
> Etan Kissling <<a href="mailto:kissling@oberon.ch">kissling@oberon.ch</a>> wrote:<br>
>> I have a project with a layer consisting of interface libraries:<br>
>>      add_library(I INTERFACE)<br>
>><br>
>> These interface libraries are then implemented several times, to fit<br>
>> the different environments of applications: add_library(IA STATIC ...)<br>
>>      target_link_libraries(IA PUBLIC I)<br>
>><br>
>>      add_library(IB STATIC ...)<br>
>>      target_link_libraries(IB PUBLIC I)<br>
>><br>
>> There are also application independent libraries, that make use of<br>
>> the interface libraries. add_library(Foo STATIC ...)<br>
>>      target_link_libraries(Foo PUBLIC I)<br>
>><br>
>>      add_library(Bar STATIC ...)<br>
>>      target_link_libraries(Bar PUBLIC I)<br>
>><br>
>> And finally, the application defines which implementation of the<br>
>> interface library layer is being used.<br>
>><br>
>>      add_executable(ExeA ...)<br>
>>      target_link_libraries(ExeA Foo Bar IA)<br>
>><br>
>>      add_executable(ExeB ...)<br>
>>      target_link_libraries(ExeB Foo Bar IB)<br>
>><br>
>><br>
>> Luckily, this is okay, as long as IA is listed after Foo and Bar in<br>
>> the synthesized link command.<br>
>><br>
>> However, certain implementations of I make use of the application<br>
>> independent libraries again. On these environments, the link command<br>
>> line becomes something like this:<br>
>><br>
>> IA Foo Bar<br>
>><br>
>> While it should be<br>
>><br>
>> Foo Bar IA Foo Bar<br>
>><br>
>> This make sense, because there is no explicit dependency being<br>
>> described that Foo / Bar depend on IA while compiling ExeA. In the<br>
>> simple case, we just get lucky, because it happens to be the default<br>
>> that link command line has the same order as in the<br>
>> target_link_libraries call.<br>
><br>
> I wouldn't try my luck if I were you. Always be explicit, especially<br>
> with dependencies, otherwise, at some point in time, cmake won't get it<br>
> right when generating the order of link.<br>
><br>
> What you could try is "forward" declaring a<br>
> platform/app-dependent dependencies with interface libraries:<br>
><br>
> In CMakeLists.txt<br>
><br>
>  add_library(top-level-I INTERFACE)<br>
>  target_link_libraries(top-<wbr>level-I INTERFACE app-dependent-I)<br>
>    # here we forward declare app-dependent-I<br>
><br>
>  add_subdirectory(app) # app-dependent<br>
><br>
>  add_executable(test2 test2.cpp)<br>
>  target_link_libraries(test2 top-level-I) # will link with IA and IB<br>
><br>
> In app/CMakeLists.txt<br>
><br>
>  add_library(app-dependent-I INTERFACE)<br>
>  target_link_libraries(app-<wbr>dependent-I INTERFACE IA IB)<br>
>    # here we "implement"<br>
><br>
>  add_library(IA ...)<br>
>  add_library(IB ...)<br>
><br>
> app-dependent-I is a forward declared libraries - cmake will evaluate<br>
> this at generation-time. This will get you the dependencies right.<br>
><br>
> I hope I correctly understood your question.<br>
><br>
> --<br>
> Patrick.<br>
<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/cmake</a></div></div></blockquote></div><br></div>