<div dir="ltr">Hi Joshua,<div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-15 4:18 GMT+01:00 Joshua Baergen <span dir="ltr"><<a href="mailto:joshuabaergen@gmail.com" target="_blank">joshuabaergen@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>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:</div><div><br></div><div> target_link_libraries(A B)</div><div><br></div><div>However, when building unittests for A (done in a subdirectory), we instead want:</div><div><br></div><div> target_link_libraries(A MockB)</div><div><br></div><div>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?</div></div></blockquote><div><br></div><div><br></div><div>Since you want link-time choice I bet you should have a look to some kind of generator expression </div><div>see doc here: <a href="https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html">https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html</a></div><div><br></div><div>genex may be used in target_link_libraries.</div><div><br></div></div>for example if you can set some property on (all) your unit test target</div><div class="gmail_extra">(I personnally do that globally by defining my own mytest_add_executable macro)</div><div class="gmail_extra"><br></div><div class="gmail_extra">set_target_properties(<YourTestTarget> PROPERTIES <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">UNITTEST 1)</span></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div class="gmail_extra">then may be you can use some genex which check whether an executable if a unitest:</div><div class="gmail_extra"><br></div><div class="gmail_extra">set(GenEx_IsTest $<STREQUAL:$<TARGET_PROPERTY:<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">UNITTEST</span>>,1>)<br clear="all"><div><br></div><div>and then use some other genex using the previous one in target_link_libraries</div><div><br></div><div>like here for automatic instantiation of source:</div><div><a href="https://cmake.org/pipermail/cmake/2015-January/059669.html">https://cmake.org/pipermail/cmake/2015-January/059669.html</a><br class="gmail-Apple-interchange-newline"><br></div><div>I lack time to craft the complete example but I think it's doable with genex.</div><div><br></div><div>It seems that others already played along this line:</div><div><a href="https://developer.blender.org/T46725">https://developer.blender.org/T46725</a><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div>
</div></div>