cpack: Respect CPACK_ARCHIVE_FILE_NAME for non-component packages

The variable CPACK_ARCHIVE_FILE_NAME (added in 9e06e97d30)
only works if per-component packaging is enabled. This isn't obvious
from the documentation.

Make it also work for non-component packages and adjust documentation.

Fixes: #8769
This commit is contained in:
Nikita Nemkin 2025-02-04 17:55:48 +05:00
parent c10cb0fde9
commit 7c825fd15f
4 changed files with 52 additions and 25 deletions

View File

@ -55,25 +55,39 @@ Variables specific to CPack Archive generator
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. variable:: CPACK_ARCHIVE_FILE_NAME
CPACK_ARCHIVE_<component>_FILE_NAME
Package file name without extension.
:Default: The default is ``<CPACK_PACKAGE_FILE_NAME>[-<component>]``, with spaces
replaced by '-'.
The extension is determined from the archive format (see list above) and
automatically appended to the file name. Note that ``<component>`` is all
uppercase in the variable name.
.. versionadded:: 3.9
Per-component :variable:`!CPACK_ARCHIVE_<component>_FILE_NAME` variables.
Archive name for component-based packages, without extension.
:Default: :variable:`CPACK_PACKAGE_FILE_NAME`
The extension is appended automatically.
If :variable:`CPACK_COMPONENTS_GROUPING` is set to ``ALL_COMPONENTS_IN_ONE``,
this will be the name of the one output archive.
.. versionchanged:: 4.0
This variable also works for non-component packages.
.. variable:: CPACK_ARCHIVE_<component>_FILE_NAME
.. versionadded:: 3.9
Component archive name without extension.
:Default: ``<CPACK_ARCHIVE_FILE_NAME>-<component>``, with spaces replaced
by ``'-'``.
The extension is appended automatically. Note that ``<component>`` is all
uppercase in the variable name.
.. variable:: CPACK_ARCHIVE_FILE_EXTENSION
.. versionadded:: 3.25
Package file extension.
Archive file extension.
:Default: Default values are given in the list above.
@ -97,10 +111,10 @@ CPack generators which are essentially archives at their core. These include:
.. variable:: CPACK_ARCHIVE_THREADS
The number of threads to use when performing the compression.
.. versionadded:: 3.18
The number of threads to use when performing the compression.
:Default: value of :variable:`CPACK_THREADS`
If set to ``0``, the number of available cores on the machine will be used instead.

View File

@ -0,0 +1,6 @@
cpack-archive-name
------------------
* When using the :cpack_gen:`CPack Archive Generator`, the output archive
name can be overridden with the :variable:`CPACK_ARCHIVE_FILE_NAME` variable.
Previously, this variable worked only for component-based packages.

View File

@ -191,6 +191,19 @@ cmCPackArchiveGenerator::cmCPackArchiveGenerator(
cmCPackArchiveGenerator::~cmCPackArchiveGenerator() = default;
std::string cmCPackArchiveGenerator::GetArchiveFileName()
{
std::string packageFileName = this->toplevel + "/";
if (cmValue v = this->GetOptionIfSet("CPACK_ARCHIVE_FILE_NAME")) {
packageFileName += *v;
} else {
v = this->GetOption("CPACK_PACKAGE_FILE_NAME");
packageFileName += *v;
}
packageFileName += this->GetOutputExtension();
return packageFileName;
}
std::string cmCPackArchiveGenerator::GetArchiveComponentFileName(
std::string const& component, bool isGroupName)
{
@ -398,17 +411,7 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne()
{
// reset the package file names
this->packageFileNames.clear();
this->packageFileNames.emplace_back(this->toplevel);
this->packageFileNames[0] += "/";
if (cmValue v = this->GetOptionIfSet("CPACK_ARCHIVE_FILE_NAME")) {
this->packageFileNames[0] += *v;
} else {
v = this->GetOption("CPACK_PACKAGE_FILE_NAME");
this->packageFileNames[0] += *v;
}
this->packageFileNames[0] += this->GetOutputExtension();
this->packageFileNames.emplace_back(this->GetArchiveFileName());
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Packaging all groups in one package..."
@ -449,6 +452,9 @@ int cmCPackArchiveGenerator::PackageFiles()
}
// CASE 3 : NON COMPONENT package.
this->packageFileNames.clear();
this->packageFileNames.emplace_back(this->GetArchiveFileName());
DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive);
cmWorkingDirectory workdir(this->toplevel);
if (workdir.Failed()) {

View File

@ -44,6 +44,7 @@ public:
bool SupportsComponentInstallation() const override;
private:
std::string GetArchiveFileName();
// get archive component filename
std::string GetArchiveComponentFileName(std::string const& component,
bool isGroupName);