<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Could you share more details about your CMake version, the platform you're on, and the generator you're using?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I haven't run into this issue (and it's pretty counter to how I'd expect CMake to behave). The only similar setting I'm aware of is
<a href="https://cmake.org/cmake/help/latest/prop_tgt/LINK_DEPENDS_NO_SHARED.html">
https://cmake.org/cmake/help/latest/prop_tgt/LINK_DEPENDS_NO_SHARED.html</a>, but that's for shared libraries, not static libraries.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">As an experiment, I used the following CMakeLists.txt:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">cmake_minimum_required(VERSION 3.4.3)<o:p></o:p></p>
<p class="MsoNormal">project(cmtest C)<o:p></o:p></p>
<p class="MsoNormal">add_library(mylib STATIC source.c)<o:p></o:p></p>
<p class="MsoNormal">add_executable(mytest test.c)<o:p></o:p></p>
<p class="MsoNormal">target_link_libraries(mytest mylib)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm running CMake 3.12.3 on macOS 10.14.1, and I tried both the Makefile and Ninja generators. With both, any modification to source.c causes mytest to be rebuilt, as I'd expect (and unlike what you're seeing).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If you're able to provide a small self-contained CMakeLists.txt that reproduces the issue, that'd also be helpful for debugging.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Shoaib Meenai<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">CMake <cmake-bounces@cmake.org> on behalf of Stephan Menzel <stephan.menzel@gmail.com><br>
<b>Date: </b>Wednesday, April 3, 2019 at 10:56 PM<br>
<b>To: </b>cmake <cmake@cmake.org><br>
<b>Subject: </b>Re: [CMake] Fake dependencies of executables to static libs<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hello again, <o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Like this:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">set (SRC<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">MySource1.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">MySource2.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">set (HDR<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">MySource1.hpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">MySource2.hpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">)<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">add_library(mylib STATIC ${SRC} ${HDR})<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">add_executable(myexecutable main.cpp)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">target_link_libraries(myexecutable <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">mylib <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">)<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">add_dependencies(myexecutable ${SRC})<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">This leads to errors though:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">CMake Error at CMakeLists.txt:79 (add_dependencies):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">  The dependency target "MySource1.cpp" of target "myexecutable" does not exist.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Stephan<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Tue, Apr 2, 2019 at 5:54 AM Stephan Menzel <<a href="mailto:stephan.menzel@gmail.com">stephan.menzel@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hello List, <o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">add_library(mylib STATIC mysources)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">add_excecutable(mytest mytest.cpp)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">target_link_libraries(mytest mylib)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">My question is, can I fake that dependency somehow? Perhaps by some hack or using some workaround?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Is that possible somehow?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Stephan<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>