From 2655605261fc3cbf3e951b0f17f137bddf2dcaac Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 5 Jul 2022 16:00:43 +0200 Subject: FreeBSD: follow CPACK_PACKAGE_FILE_NAME, if set The underlying pkg library always produces a -.pkg file, so to follow CPACK_PACKAGE_FILE_NAME we need to detect that and rename appropriately. FIXES #23034 --- Source/CPack/cmCPackFreeBSDGenerator.cxx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx index 4f07ad4..162dfc7 100644 --- a/Source/CPack/cmCPackFreeBSDGenerator.cxx +++ b/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 -., + // 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; } -- cgit v0.12