Execute git describe in custom_target
<p>I would like to write output of <code>git describe</code> as a string to a file, so I can embed the information in my binary (C++). This has to work across platforms.</p>

<p>The best I can yet come up with was:</p>

<pre><code>add_custom_target( SubmarineGitVersion
    COMMAND cmd /c "${CMAKE_EXECUTABLE}" echo czstring GIT_VERSION = STRINGIFY\( &gt; "${CMAKE_CURRENT_BINARY_DIR}/GitVersion.hpp"
    COMMAND cmd /c "${GIT_EXECUTABLE}" describe --tags --always &gt;&gt; "${CMAKE_CURRENT_BINARY_DIR}/GitVersion.hpp"
    COMMAND cmd /c "${CMAKE_EXECUTABLE}" echo \) &gt;&gt; "${CMAKE_CURRENT_BINARY_DIR}/GitVersion.hpp"
)
</code></pre>

<p>This roughly works on Windows (is missing a <code>;</code> at the end):</p>

<pre><code>czstring GIT_VERSION = STRINGIFY(
tag-343434
)
</code></pre>

<p>Is there any better/more cross-platform way of doing this?</p>