فهرست منبع

CPack/productbuild: Add option to customize product identifier

This adds a new option, CPACK_PRODUCTBUILD_IDENTIFIER, which allows
for customization of the productbuild product identifier within the
CPack productbuild generator.

Fixes: #20830
Greg Fiumara 4 سال پیش
والد
کامیت
7213ceb869

+ 8 - 0
Help/cpack_gen/productbuild.rst

@@ -18,6 +18,14 @@ macOS using ProductBuild:
  the automatically detected command (or specify its location if the
  auto-detection fails to find it).
 
+.. variable:: CPACK_PRODUCTBUILD_IDENTIFIER
+
+ .. versionadded:: 3.23
+
+ Set the unique (non-localized) product identifier to be associated with the
+ product (i.e., ``com.kitware.cmake``). Any component product names will be
+ appended to this value.
+
 .. variable:: CPACK_PRODUCTBUILD_IDENTITY_NAME
 
  .. versionadded:: 3.8

+ 6 - 0
Help/release/dev/cpack-productbuild-identifier.rst

@@ -0,0 +1,6 @@
+cpack-productbuild-identifier
+-----------------------------
+
+* The :cpack_gen:`CPack productbuild Generator` gained a new variable,
+  :variable:`CPACK_PRODUCTBUILD_IDENTIFIER`, used to customize the unique
+  product identifier associated with the product.

+ 8 - 3
Source/CPack/cmCPackPKGGenerator.cxx

@@ -210,9 +210,14 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponentGroup& group,
 void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component,
                                        cmXMLWriter& xout)
 {
-  std::string packageId =
-    cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"), '.',
-             this->GetOption("CPACK_PACKAGE_NAME"), '.', component.Name);
+  std::string packageId;
+  if (cmValue i = this->GetOption("CPACK_PRODUCTBUILD_IDENTIFIER")) {
+    packageId = cmStrCat(i, '.', component.Name);
+  } else {
+    packageId =
+      cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"), '.',
+               this->GetOption("CPACK_PACKAGE_NAME"), '.', component.Name);
+  }
 
   xout.StartElement("choice");
   xout.Attribute("id", component.Name + "Choice");

+ 12 - 2
Source/CPack/cmCPackProductBuildGenerator.cxx

@@ -95,6 +95,10 @@ int cmCPackProductBuildGenerator::PackageFiles()
   if (cmValue p = this->GetOption("CPACK_PRODUCTBUILD_KEYCHAIN_PATH")) {
     keychainPath = p;
   }
+  std::string identifier;
+  if (cmValue i = this->GetOption("CPACK_PRODUCTBUILD_IDENTIFIER")) {
+    identifier = i;
+  }
 
   pkgCmd << productbuild << " --distribution \"" << packageDirFileName
          << "/Contents/distribution.dist\""
@@ -102,6 +106,7 @@ int cmCPackProductBuildGenerator::PackageFiles()
          << "\""
          << " --resources \"" << resDir << "\""
          << " --version \"" << version << "\""
+         << (identifier.empty() ? "" : " --identifier \"" + identifier + "\"")
          << (identityName.empty() ? "" : " --sign \"" + identityName + "\"")
          << (keychainPath.empty() ? ""
                                   : " --keychain \"" + keychainPath + "\"")
@@ -204,8 +209,13 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
   // The command that will be used to run ProductBuild
   std::ostringstream pkgCmd;
 
-  std::string pkgId = cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"),
-                               '.', this->GetOption("CPACK_PACKAGE_NAME"));
+  std::string pkgId;
+  if (cmValue n = this->GetOption("CPACK_PRODUCTBUILD_IDENTIFIER")) {
+    pkgId = n;
+  } else {
+    pkgId = cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"), '.',
+                     this->GetOption("CPACK_PACKAGE_NAME"));
+  }
   if (component) {
     pkgId += '.';
     pkgId += component->Name;