<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The library linking against "originalLibraryForward" has to be<br>
compiled from the original sources too. Actually performing the </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
linking step should be sufficient. Is there a way to accomplish that?<br></blockquote><div><br></div><div>Object libraries are what you need here.  See <a href="https://cmake.org/cmake/help/v3.7/manual/cmake-buildsystem.7.html#object-libraries">https://cmake.org/cmake/help/v3.7/manual/cmake-buildsystem.7.html#object-libraries</a> .  Essentially you'll do something like this:<br><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">add_library(fooObj OBJECT ${foo_Common_Sources})<br></span></div><div><span style="font-family:monospace,monospace">add_library(foo     $<TARGET_OBJECTS:fooObj>  ${foo_RealOnly_Sources})<br></span></div><div><span style="font-family:monospace,monospace">add_library(fooMock $<TARGET_OBJECTS:fooObj>  ${foo_MockOnly_Sources})</span></div><div> <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

The function does not work when the library passed to<br>
AddMockedLibrary() uses target_link_libraries() with IMPORTED targets<br>
from, e. g. calls to find_package(). In order to make creating the<br>
_MOCK-Library work I have to duplicate the original call to<br>
find_package() before calling AddMockedLibrary(). Is there a way to<br>
automate this as well?<br></blockquote><div><br></div><div>You might be able to go down the route of creating an INTERFACE library with all of the common properties necessary for both the actual and mock libraries.  You could then add the interface lib as a public dependency with target_link_libraries(foo PUBLIC fooInterface) and target_link_libraries(fooMock PUBLIC fooInterface).  It's a bit convoluted but I think it could work well here for you.<br></div></div><br></div><div class="gmail_extra">- Chuck<br></div></div>