<div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 10:19 PM Andy <<a href="mailto:borucki.andrzej@gmail.com">borucki.andrzej@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">
<div>(previously I send this mail not to mail list, but user)<br></div><div>Maybe my <span class="gmail-m_-8192764788000016718gmail-il">cmake</span> files are bad?</div><div>
I have created test project
<br><a class="gmail-m_-8192764788000016718gmail-m_-1418135889951633247gmail-moz-txt-link-freetext" href="https://gitlab.com/andrzejbor/test_rebuild_all" target="_blank">https://gitlab.com/andrzejbor/test_rebuild_all</a>
<br>after commit is rebuild whole project
<br>what I might change?
<br>I don't want moving all but .git to one directory src/
</div>
</div></div><br></blockquote><div><br></div><div>The problem is that you add the GIT variables as compile time defines, which means that after every commit you will have different compile command lines, which trigger recompilation of whole project because you have used <font face="monospace, monospace">add_definitions</font>.</div><div><br></div><div>You should instead write those GIT variables in a file, like this:</div><div><br></div><div><font face="monospace, monospace">file(WRITE ${CMAKE_BINARY_DIR}/<a href="http://git_version.h.in">git_version.h.in</a> "</font></div><div><font face="monospace, monospace">#define GIT_SHA1 \"@GIT_SHA@\"</font></div><div><font face="monospace, monospace">#define GIT_TAG \"@GIT_TAG@\"</font></div><div><font face="monospace, monospace">#define GIT_LOCAL_CHANGES \"@GIT_LOCAL_CHANGES@\""</font></div><div><font face="monospace, monospace">)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">configure_file(${CMAKE_BINARY_DIR}/<a href="http://git_version.h.in">git_version.h.in</a></font></div><div><font face="monospace, monospace"> ${CMAKE_BINARY_DIR}/git_version.h @ONLY)</font></div><div><br></div><div>Make sure you have <font face="monospace, monospace">${CURRENT_BINARY_DIR}</font> as part of your target's include directories. And then somewhere in your code do an <font face="monospace, monospace">#include "git_version.h"</font>.</div><div><br></div><div>Cheers,</div><div>Cristian. </div></div></div></div>