From cc3cd8bc2a7510db9eaee5a160c80e338273af57 Mon Sep 17 00:00:00 2001
From: Andrey Filipenkov <decapitator@ukr.net>
Date: Thu, 11 Aug 2022 15:35:45 +0300
Subject: CPack: allow custom file extension in archive generator

---
 Help/cpack_gen/archive.rst                          |  6 ++++++
 Help/release/dev/cpack-archive-custom-extension.rst |  6 ++++++
 Source/CPack/cmCPackArchiveGenerator.cxx            | 12 ++++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 Help/release/dev/cpack-archive-custom-extension.rst

diff --git a/Help/cpack_gen/archive.rst b/Help/cpack_gen/archive.rst
index a77b615..9df3cc4 100644
--- a/Help/cpack_gen/archive.rst
+++ b/Help/cpack_gen/archive.rst
@@ -57,6 +57,12 @@ Variables specific to CPack Archive generator
   .. versionadded:: 3.9
     Per-component ``CPACK_ARCHIVE_<component>_FILE_NAME`` variables.
 
+.. variable:: CPACK_ARCHIVE_FILE_EXTENSION
+
+  .. versionadded:: 3.25
+
+  Package file extension. Default values are given in the list above.
+
 .. variable:: CPACK_ARCHIVE_COMPONENT_INSTALL
 
   Enable component packaging. If enabled (ON), then the archive generator
diff --git a/Help/release/dev/cpack-archive-custom-extension.rst b/Help/release/dev/cpack-archive-custom-extension.rst
new file mode 100644
index 0000000..38ad36f
--- /dev/null
+++ b/Help/release/dev/cpack-archive-custom-extension.rst
@@ -0,0 +1,6 @@
+cpack-archive-custom-extension
+------------------------------
+
+* The :cpack_gen:`CPack Archive Generator` gained a new
+  :variable:`CPACK_ARCHIVE_FILE_EXTENSION` variable to control
+  the package file name extension.
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 56e8463..894c24b 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -94,6 +94,18 @@ std::string cmCPackArchiveGenerator::GetArchiveComponentFileName(
 int cmCPackArchiveGenerator::InitializeInternal()
 {
   this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
+  cmValue newExtensionValue = this->GetOption("CPACK_ARCHIVE_FILE_EXTENSION");
+  if (!newExtensionValue.IsEmpty()) {
+    std::string newExtension = *newExtensionValue;
+    if (!cmHasLiteralPrefix(newExtension, ".")) {
+      newExtension = cmStrCat('.', newExtension);
+    }
+    cmCPackLogger(cmCPackLog::LOG_DEBUG,
+                  "Using user-provided file extension "
+                    << newExtension << " instead of the default "
+                    << this->OutputExtension << std::endl);
+    this->OutputExtension = std::move(newExtension);
+  }
   return this->Superclass::InitializeInternal();
 }
 
-- 
cgit v0.12