# Overriding CPack version from command line not working

**URL:** https://discourse.cmake.org/t/overriding-cpack-version-from-command-line-not-working/7008
**Category:** Usage
**Tags:** tool:cpack
**Created:** [December 2, 2022, 1:12pm UTC](https://discourse.cmake.org/t/overriding-cpack-version-from-command-line-not-working/7008 "2022-12-02T13:12:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rcoup](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rcoup/32/2091_2.png) [@rcoup](https://discourse.cmake.org/u/rcoup)
#### Post date: [December 2, 2022, 1:12pm UTC](https://discourse.cmake.org/t/overriding-cpack-version-from-command-line-not-working/7008/1 "2022-12-02T13:12:44Z")

</div>

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? 😃

**Minimal reproducer**

`CMakeLists.txt`

```cmake
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:

```console
$ 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.

```

---

<div class="post-metadata">

### Author: ![MathiasMagnus](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathiasmagnus/32/431_2.png) [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)
#### Post date: [April 16, 2023, 3:04pm UTC](https://discourse.cmake.org/t/overriding-cpack-version-from-command-line-not-working/7008/2 "2023-04-16T15:04:40Z")

</div>

I have the same issue and I think something broke in CPack. The [OpenCL-SDK](https://github.com/KhronosGroup/OpenCL-SDK) does something very similar, it [overrides](https://github.com/KhronosGroup/OpenCL-SDK/blob/3c1010133ceb0e8ef4e4774b870f5ae17ef04a75/.github/workflows/release.yml) `CPACK_SOURCE_IGNORE_FILES` on the CLI, and this used to work for the [v2022.05.18](https://github.com/KhronosGroup/OpenCL-SDK/releases/tag/v2022.05.18) release, but in the [v2023.02.06](https://github.com/KhronosGroup/OpenCL-SDK/releases/tag/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.
