[CMake] Link-Time Dependency Injection for Unit Tests

Joshua Baergen joshuabaergen at gmail.com
Wed Mar 14 23:18:31 EDT 2018


Hello,

I'm attempting to implement link-time dependency injection. In brief, what
this means is that, for a library A that depends on B, we would normally
have:

  target_link_libraries(A B)

However, when building unittests for A (done in a subdirectory), we instead
want:

  target_link_libraries(A MockB)

I've spent a bunch of time looking through CMake documentation and I'm not
sure how to express this without resorting to manually specifying the link
line when A is in use. Could someone give me some guidance?

Thanks!
Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180315/21beb92f/attachment.html>


More information about the CMake mailing list