I need to create a RPM of my software expecting the following output: <my_sw_name>-<version>-<release>.rpm.
The default for <release> shall be 0.
In my CMakeLists.txt I am using the following command:
cmake_minimum_required(VERSION 3.20)
...
set(SW_RELEASE 0)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_RELEASE ${SW_RELEASE})
set(CPACK_RPM_PACKAGE_RELEASE_DIST OFF)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
...
Nevertheless, the generated RPM filename is <my_sw_name>-<version>-1.rpm, and the Release:
field in the RPM file is set to 1
.
Is this a bug in CPack or did I miss something?
To any future users who aren't aware, It's conventional to start the release number for RPM packages at 1
and not at 0
. And here's a link to the CPackRPM docs in case anyone needs it.
Reading through :/Modules/Internal/CPack/CPackRPM.cmake
for CMake version 3.24.1, I think the culprit is the following code at line 965 inside the function cpack_rpm_generate_package
:
if(NOT CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_PACKAGE_RELEASE "1")
endif()
The string 0
in CMake is falsy. Ex,
if(NOT 0)
message("zero is falsy") # this will be reached and printed
endif()
Ie. your 0
causes the expression NOT CPACK_RPM_PACKAGE_RELEASE
to evaluate to FALSE
, and then your 0
gets clobbered to a 1
.
If you want the value 0
to be supported, you could file an issue on the CMake gitlab repo requesting it. It would probably look like changing it to this:
if(NOT DEFINED CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_PACKAGE_RELEASE "1")
endif()
If this is truly the cause and you do file an issue to kitware, please either add a link to it as a comment under this answer, or to the end of the body of your question so future readers can find it.