Overriding CPack version from command line not working

According to the docs, using cpack -R <version> should override whatever CPACK_PACKAGE_VERSION has been previously deduced/configured. Except as far as I can tell, it doesn’t…

-R <packageVersion>
Override/define the value of the CPACK_PACKAGE_VERSION variable used for packaging. It will override a value set in the CPackConfig.cmake file or one automatically computed from CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR and CPACK_PACKAGE_VERSION_PATCH.

Am I missing something? :smiley:

Minimal reproducer

CMakeLists.txt

cmake_minimum_required(VERSION 3.25)
project(HELLO VERSION 1.2.3)

set(HELLO_SOURCE [[
#include <iostream>
int main()
{
  std::cout << "Hello, World!" << std::endl;
  return 0;
}
]])
file(WRITE "${CMAKE_BINARY_DIR}/hello.cpp" "${HELLO_SOURCE}")

add_executable(hello "${CMAKE_BINARY_DIR}/hello.cpp")
install(TARGETS hello)

include(CPack)

Then:

$ cmake --version
cmake version 3.25.0
$ cmake -S . -B build
...
-- Generating done
-- Build files have been written to: /Users/rcoup/tmp/cpack-ver/build
$ cmake --build build/
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello

$ cd build
$ cpack -G ZIP
CPack: Create package using ZIP
CPack: Install projects
CPack: - Run preinstall target for: HELLO
CPack: - Install project: HELLO []
CPack: Create package
CPack: - package: /Users/rcoup/tmp/cpack-ver/build/HELLO-1.2.3-Darwin.zip generated.

$ cpack -G ZIP -R 2.3.4
CPack: Create package using ZIP
CPack: Install projects
CPack: - Run preinstall target for: HELLO
CPack: - Install project: HELLO []
CPack: Create package
CPack: - package: /Users/rcoup/tmp/cpack-ver/build/HELLO-1.2.3-Darwin.zip generated.
1 Like

I have the same issue and I think something broke in CPack. The OpenCL-SDK does something very similar, it overrides CPACK_SOURCE_IGNORE_FILES on the CLI, and this used to work for the v2022.05.18 release, but in the v2023.02.06 release the ignored files started showing up again in the source ZIP files. I tried reverting to older versions on my local box, but that’s not the issue. I don’t know what is, but the override effect clearly doesn’t work.

(This is one of the very annoying aspects of the Windows runners in GitHub Actions, is that there’s no way to containerize the builds and we’re constantly subject to tool versions changing under us breaking builds/releases.)

FWIW, I also tried whether:

  • CMake/CPack being on the PATH makes a difference
  • using CPACK_PROPERTIES_FILE

The only thing that seems to work is to hang CPack-related commands onto CMake configuration, before including CPack.cmake. Nothing overrides the contents of the generated files.