Browse Source

FreeBSD: follow CPACK_PACKAGE_FILE_NAME, if set

The underlying pkg library always produces a <name>-<version>.pkg
file, so to follow CPACK_PACKAGE_FILE_NAME we need to detect
that and rename appropriately.

FIXES #23034
Adriaan de Groot 3 years ago
parent
commit
2655605261
1 changed files with 20 additions and 1 deletions
  1. 20 1
      Source/CPack/cmCPackFreeBSDGenerator.cxx

+ 20 - 1
Source/CPack/cmCPackFreeBSDGenerator.cxx

@@ -408,7 +408,8 @@ int cmCPackFreeBSDGenerator::PackageFiles()
     return 0;
   }
 
-  std::string output_dir = cmSystemTools::CollapseFullPath("../", toplevel);
+  const std::string output_dir =
+    cmSystemTools::CollapseFullPath("../", toplevel);
   PkgCreate package(output_dir, toplevel, manifestname);
   if (package.isValid()) {
     if (!package.Create()) {
@@ -434,5 +435,23 @@ int cmCPackFreeBSDGenerator::PackageFiles()
     }
   }
 
+  const std::string packageFileName =
+    var_lookup("CPACK_PACKAGE_FILE_NAME") + FreeBSDPackageSuffix_17;
+  if (packageFileNames.size() == 1 && !packageFileName.empty() &&
+      packageFileNames[0] != packageFileName) {
+    // Since libpkg always writes <name>-<version>.<suffix>,
+    // if there is a CPACK_PACKAGE_FILE_NAME set, we need to
+    // rename, and then re-set the name.
+    const std::string sourceFile = packageFileNames[0];
+    const std::string packageSubDirectory =
+      cmSystemTools::GetParentDirectory(sourceFile);
+    const std::string targetFileName =
+      packageSubDirectory + '/' + packageFileName;
+    if (cmSystemTools::RenameFile(sourceFile, targetFileName)) {
+      this->packageFileNames.clear();
+      this->packageFileNames.emplace_back(targetFileName);
+    }
+  }
+
   return 1;
 }