<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello again,<div><br></div><div>no ideas so far? Perhaps I can elaborate. I have tried multiple approaches over the years. Most recently adding the source files of the lib explicitly as dependencies to the created executable.</div><div><br></div><div>Like this:</div><div><br></div><div><div>set (SRC</div><div><span style="white-space:pre"> </span>MySource1.cpp</div><div><span style="white-space:pre"> </span>MySource2.cpp</div><div>)</div><div><br></div><div>set (HDR</div><div><span style="white-space:pre"> </span>MySource1.hpp</div><div><span style="white-space:pre"> </span>MySource2.hpp</div><div>)</div></div><div><br></div><div><div>add_library(mylib STATIC ${SRC} ${HDR})<br></div></div><div><br></div><div><div>add_executable(myexecutable main.cpp)</div><div>target_link_libraries(myexecutable </div><div><span style="white-space:pre"> </span>mylib </div><div>)</div></div><div><br></div><div><div>add_dependencies(myexecutable ${SRC})</div></div><div><br></div><div>This leads to errors though:</div><div><br></div><div><div>CMake Error at CMakeLists.txt:79 (add_dependencies):</div><div> The dependency target "MySource1.cpp" of target "myexecutable" does not exist.</div></div><div><br></div><div>Obviously, I cannot simply state a filename and treat it as a target. I have however seen something similar been done when it comes to code generation. I have also seen explicit subtargets for files being created and then depend on those subtargets. But I don't really know how to do this the right way.</div><div><br></div><div>Alternatively I would also appreciate input about what exactly the problem with depending on static libs is. The explanations I remember from my last efforts to tackle this weren't really satisfying. If I understood in more detail why this isn't possible I may be able to better craft a workaround on my own.</div><div><br></div><div>Really, anything helps. I am losing time and nerve every day because of this and have been paying this price for so many years that I think it really is time to come up with a solution.</div><div><br></div><div>Cheers,</div><div>Stephan</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 2, 2019 at 5:54 AM Stephan Menzel <<a href="mailto:stephan.menzel@gmail.com">stephan.menzel@gmail.com</a>> wrote:<br></div><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"><div dir="ltr">Hello List,<div><br><div>In our projects we are using static linkage on Windows (MSVC) and Linux. A number of static libs are created and then linked into executables, such as unit tests, tools and the actual production artifacts. Very normal stuff.</div></div><div><br></div><div>add_library(mylib STATIC mysources)</div><div>add_excecutable(mytest mytest.cpp)</div><div>target_link_libraries(mytest mylib)</div><div><br></div><div>Now although I don't understand the exact reasons behind that, over the years came to accept that depedencies between the lib and the resulting artifcats are not working. Like, when I change a source file to mylib, the lib will get rebuilt but the resulting test tool won't be relinked.</div><div>For test driven development or busy change cycles that can put quite a strain on effort, especially on windows. My normal workflow is that I always click in mytest.cpp, add and remove a space to mark it dirty as quickly as possible and thereby cause the rebuild. But sometimes I forget this and this caused me quite a bit of extra work.</div><div>My question is, can I fake that dependency somehow? Perhaps by some hack or using some workaround?</div><div><br></div><div>What I want to achieve is that when I change the lib, the unit test (or any other test tool using it) that depends on it will be relinked, even if it has not changed.</div><div><br></div><div>Is that possible somehow?</div><div><br></div><div>Cheers,</div><div>Stephan</div></div></div>
</blockquote></div></div>