How to idiomatically set the version number in a CMAKE/CPACK project?
<p>I'm trying to edit the CPack settings so that the outputted package file has the correct version number in it.  But that's not all.  I'd like CMake/CPack to have all the places where the version number is updated also be set. The .so file should also be set.  And whatever else needs it.</p>

<p>From where I sit, the <a href="https://cmake.org/Wiki/CMake:Packaging_With_CPack" rel="nofollow noreferrer">CPack documentation appears to be telling us</a> to repeat ourselves.</p>

<p>If I do nothing, the output file is like so:</p>

<pre><code>mystuff-0.1.1-Linux.tar.gz
</code></pre>

<p>Let's say the version number should be 1.2.3.  </p>

<p>I would think that this is the minimalistic CPACK settings to cause all the version numbers to be changed -- and I placed these lines in my CMakeLists.txt file:</p>

<pre><code>SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "My app is great")
SET(CPACK_PACKAGE_VENDOR "My Name")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")

SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "3")
SET(CPACK_PACKAGE_VERSION_PATCH "2")
</code></pre>

<p>When I build, the output file is still <code>mystuff-0.1.1-Linux.tar.gz</code> </p>

<p>If I repeat myself and do this:</p>

<pre><code>SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
</code></pre>

<p>Now that variable is set, but the file is still <code>mystuff-0.1.1-Linux.tar.gz</code></p>

<p>It seems that I must also change <code>CPACK_PACKAGE_FILE_NAME</code></p>

<p>What other places do I have to re-state the version number?</p>

<p>This doesn't feel idiomatic. I must be missing something to make this automatic.  Am I supposed to specify the variable at an earlier point in time?  I also see some projects on the internet containing a CPackConfig.cmake file -- the file contains overrides, but I still see some repeating oneself going on in those as well.</p>

<p><a href="http://public.kitware.com/Bug/print_bug_page.php?bug_id=15516" rel="nofollow noreferrer">This bug</a> also mentions the same thing.  Apparently, they do want us to repeat ourselves. (as of 2015)  However, even if that is the case, I was wondering if anyone has found a work-around?</p>

<p>If no work around, how about a way to re-state all the variables so that they end up automatically set correctly?  For instance, doing the following is a way to compose the version number by using the variables</p>

<pre><code>SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
</code></pre>

<p><a href="https://cmake.org/cmake/help/v3.0/module/CPack.html" rel="nofollow noreferrer">According to the documentation</a>, the file name is composed like this:</p>

<p>SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")</p>

<p>There are probably other variables that need re-setting.  If I have to restate everything, then exactly what do I need to restate to be complete?</p>