[CMake] Changed behavior of CPACK_PACKAGE_VERSION generation?

Björn Blissing bjorn.blissing at vti.se
Wed Dec 12 13:31:58 EST 2018


Hi,

Today we discovered that our generated CPACK_PACKAGE_VERSION variables were broken.
This is probably related to us updating to a newer version of CMake.

Previously we generated this variable by setting the CPACK_PACKAGE_VERSION_MAJOR and CPACK_PACKAGE_VERSION_MINOR to fixed values, while CPACK_PACKAGE_VERSION_PATCH was set to variable name.
This name was then replaced by running a custom target just before building. In this target the variable name got replaced with the current SVN revision number. This have worked the last years, but now the variable name just gets omitted when we run "generate" in CMake.

A short example:
================
cmake_minimum_required(VERSION 2.8.9)
project (hello)
add_executable(hello helloworld.cpp)
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "REPLACEME")
include(CPack)

Would result in the following strings in CPackConfig.cmake:
-----------------------------------------------------------
set(CPACK_PACKAGE_VERSION "1.0.REPLACEME") 
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "REPLACEME")


But with the CMake 3.12.2 this will be:
---------------------------------------
set(CPACK_PACKAGE_VERSION "1.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "REPLACEME")


So our CPACK_PACKAGE_VERSION will omit the variable name, which in turn makes our custom target to fail.

Our quick fix was to add the following line to our CMakeList.txt file:
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

My question is: Is this change of behavior intended? Are only numbers allowed to be part of the CPack version variable?

Regards
Björn Blissing





More information about the CMake mailing list