[CMake] Automatically add a revision number to the CPack installer name

Glenn Ramsey gr at componic.co.nz
Thu Mar 8 16:41:26 EST 2012


On 09/03/12 10:13, David Cole wrote:
> On Thu, Mar 8, 2012 at 3:57 PM, Glenn Ramsey<gr at componic.co.nz>  wrote:
>> Is it possible to add, at build time, a revision number to the installer
>> file name produced by CPack? I understand that to get the revision number at
>> build time one must run a command and I have used that technique to generate
>> a source code header, but I cannot figure out how to apply it to the package
>> file name. The simplest method would appear to be to add a post-build
>> command that renames the file to the package target, but it appears that
>> this cannot be currently done [1].
>>
>> A previous list message [1] suggests the following:
>>
>>> If you want to hook it up automatically, you could write your own
>>> version of the package target that just calls cpack itself in
>>> ${CMAKE_BINARY_DIR}. That target could have a post-build rule that
>>> does the rename.
>>
>>
>> When I tried that. It created an infinite loop with cpack calling make and
>> make calling cpack.
>>
>> What would I need to do to correctly implement this solution? Is there
>> another way to do it?
>>
>> Glenn
>>
>> [1]<http://www.cmake.org/pipermail/cmake/2011-May/044440.html>
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
> Set CPACK_PACKAGE_FILE_NAME before including CPack.
>
>  From Modules/CPack.cmake:
>
> #  CPACK_PACKAGE_FILE_NAME - The name of the package file to generate,
> #  not including the extension. For example, cmake-2.6.1-Linux-i686.
> #  The default value is
> #  ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}.
>
> The default should already include the version number. Perhaps you
> could simply encode your build number into your CPACK_PACKAGE_VERSION
> value, and it then the rest would be automatic.
>
>
> HTH,
> David

Hi David,

I think what you are suggesting is something like this:

cmake_minimum_required(VERSION 2.8)
project(myapp)

add_executable(main main.cpp)
install(TARGETS main DESTINATION .)

include(FindSubversion)
Subversion_WC_INFO(${CMAKE_SOURCE_DIR} myapp)

set(CPACK_PACKAGE_VERSION ${myapp_WC_REVISION})
include(CPack)

This includes a revision number in the package file name and it demonstrates the 
problem I am trying to solve. The revision number in the package file name does 
not change if the repository revision number changes, unless you run cmake 
manually. What I am after is a way to have the revision number update to the 
most recent revision.

Glenn



More information about the CMake mailing list