From 7c825fd15ffc5f4de5e32c46bc015e802cb70c79 Mon Sep 17 00:00:00 2001 From: Nikita Nemkin Date: Tue, 4 Feb 2025 17:55:48 +0500 Subject: [PATCH] cpack: Respect CPACK_ARCHIVE_FILE_NAME for non-component packages The variable CPACK_ARCHIVE_FILE_NAME (added in 9e06e97d30faf0916bec) 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 --- Help/cpack_gen/archive.rst | 42 ++++++++++++++++-------- Help/release/dev/cpack-archive-name.rst | 6 ++++ Source/CPack/cmCPackArchiveGenerator.cxx | 28 +++++++++------- Source/CPack/cmCPackArchiveGenerator.h | 1 + 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 Help/release/dev/cpack-archive-name.rst diff --git a/Help/cpack_gen/archive.rst b/Help/cpack_gen/archive.rst index 379e6f5828..81da98b2ee 100644 --- a/Help/cpack_gen/archive.rst +++ b/Help/cpack_gen/archive.rst @@ -55,25 +55,39 @@ Variables specific to CPack Archive generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. variable:: CPACK_ARCHIVE_FILE_NAME - CPACK_ARCHIVE__FILE_NAME - - Package file name without extension. - - :Default: The default is ``[-]``, with spaces - replaced by '-'. - - The extension is determined from the archive format (see list above) and - automatically appended to the file name. Note that ```` is all - uppercase in the variable name. .. versionadded:: 3.9 - Per-component :variable:`!CPACK_ARCHIVE__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__FILE_NAME + + .. versionadded:: 3.9 + + Component archive name without extension. + + :Default: ``-``, with spaces replaced + by ``'-'``. + + The extension is appended automatically. Note that ```` 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. diff --git a/Help/release/dev/cpack-archive-name.rst b/Help/release/dev/cpack-archive-name.rst new file mode 100644 index 0000000000..8e9c00befc --- /dev/null +++ b/Help/release/dev/cpack-archive-name.rst @@ -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. diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 75475cee6e..6052e1310a 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -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()) { diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h index b0a7160612..2e62d1779c 100644 --- a/Source/CPack/cmCPackArchiveGenerator.h +++ b/Source/CPack/cmCPackArchiveGenerator.h @@ -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);