Переглянути джерело

Merge topic 'cpack-archive-name'

7c825fd15f cpack: Respect CPACK_ARCHIVE_FILE_NAME for non-component packages

Acked-by: Kitware Robot <[email protected]>
Acked-by: Alex Turbov <[email protected]>
Merge-request: !10287
Brad King 8 місяців тому
батько
коміт
0a17f39596

+ 25 - 11
Help/cpack_gen/archive.rst

@@ -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.
+  .. versionadded:: 3.9
 
-  :Default: The default is ``<CPACK_PACKAGE_FILE_NAME>[-<component>]``, with spaces
-   replaced by '-'.
+  Archive name for component-based packages, without extension.
 
-  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.
+  :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
-    Per-component :variable:`!CPACK_ARCHIVE_<component>_FILE_NAME` variables.
+
+  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.

+ 6 - 0
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.

+ 17 - 11
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()) {

+ 1 - 0
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);