summaryrefslogtreecommitdiffstats
path: root/Source/CPack
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CPack')
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.cxx12
-rw-r--r--Source/CPack/cmCPackConfigure.h.in5
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.cxx7
-rw-r--r--Source/CPack/cmCPackFreeBSDGenerator.cxx54
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.cxx8
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.h2
-rw-r--r--Source/CPack/cmCPackNSISGenerator.cxx34
-rw-r--r--Source/CPack/cpack.cxx171
8 files changed, 253 insertions, 40 deletions
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();
}
diff --git a/Source/CPack/cmCPackConfigure.h.in b/Source/CPack/cmCPackConfigure.h.in
index 8ac1661..2c1302d 100644
--- a/Source/CPack/cmCPackConfigure.h.in
+++ b/Source/CPack/cmCPackConfigure.h.in
@@ -1,2 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#cmakedefine01 ENABLE_BUILD_WIX_GENERATOR
+#cmakedefine01 ENABLE_BUILD_FREEBSD_PKG
+#cmakedefine01 HAVE_CoreServices
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
index 0f7acfb..0579066 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.cxx
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -14,6 +14,7 @@
#include "cmsys/FStream.hxx"
#include "cmsys/RegularExpression.hxx"
+#include "cmCPackConfigure.h"
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
#include "cmDuration.h"
@@ -23,7 +24,7 @@
#include "cmValue.h"
#include "cmXMLWriter.h"
-#ifdef HAVE_CoreServices
+#if HAVE_CoreServices
// For the old LocaleStringToLangAndRegionCodes() function, to convert
// to the old Script Manager RegionCode values needed for the 'LPic' data
// structure used for generating multi-lingual SLAs.
@@ -590,7 +591,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
kCFStringEncodingMacRoman);
LangCode lang = 0;
RegionCode region = 0;
-#ifdef HAVE_CoreServices
+#if HAVE_CoreServices
OSStatus err =
LocaleStringToLangAndRegionCodes(iso_language_cstr, &lang, &region);
if (err != noErr)
@@ -601,7 +602,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
<< iso_language_cstr << std::endl);
return 0;
}
-#ifdef HAVE_CoreServices
+#if HAVE_CoreServices
header_data.push_back(region);
header_data.push_back(i);
header_data.push_back(0);
diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx
index 607d797..162dfc7 100644
--- a/Source/CPack/cmCPackFreeBSDGenerator.cxx
+++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx
@@ -23,8 +23,6 @@
// Suffix used to tell libpkg what compression to use
static const char FreeBSDPackageCompression[] = "txz";
-// Resulting package file-suffix, for < 1.17 and >= 1.17 versions of libpkg
-static const char FreeBSDPackageSuffix_10[] = ".txz";
static const char FreeBSDPackageSuffix_17[] = ".pkg";
cmCPackFreeBSDGenerator::cmCPackFreeBSDGenerator()
@@ -83,6 +81,14 @@ public:
{
if (!isValid())
return false;
+ // The API in the FreeBSD sources (the header has no documentation),
+ // is as follows:
+ //
+ // int pkg_create(struct pkg_create *pc, const char *metadata, const char
+ // *plist, bool hash)
+ //
+ // We let the plist be determined from what is installed, and all
+ // the rest comes from the manifest data.
int r = pkg_create(d, manifest.c_str(), nullptr, false);
return r == 0;
}
@@ -402,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()) {
@@ -416,40 +423,33 @@ int cmCPackFreeBSDGenerator::PackageFiles()
return 0;
}
- // Specifically looking for packages suffixed with the TAG, either extension
- std::string broken_suffix_10 =
- cmStrCat('-', var_lookup("CPACK_TOPLEVEL_TAG"), FreeBSDPackageSuffix_10);
+ // Specifically looking for packages suffixed with the TAG
std::string broken_suffix_17 =
cmStrCat('-', var_lookup("CPACK_TOPLEVEL_TAG"), FreeBSDPackageSuffix_17);
for (std::string& name : packageFileNames) {
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Packagefile " << name << std::endl);
- if (cmHasSuffix(name, broken_suffix_10)) {
- name.replace(name.size() - broken_suffix_10.size(), std::string::npos,
- FreeBSDPackageSuffix_10);
- break;
- }
if (cmHasSuffix(name, broken_suffix_17)) {
name.replace(name.size() - broken_suffix_17.size(), std::string::npos,
FreeBSDPackageSuffix_17);
break;
}
}
- // If the name uses a *new* style name, which doesn't exist, but there
- // is an *old* style name, then use that instead. This indicates we used
- // an older libpkg, which still creates .txz instead of .pkg files.
- for (std::string& name : packageFileNames) {
- if (cmHasSuffix(name, FreeBSDPackageSuffix_17) &&
- !cmSystemTools::FileExists(name)) {
- const std::string badSuffix(FreeBSDPackageSuffix_17);
- const std::string goodSuffix(FreeBSDPackageSuffix_10);
- std::string repairedName(name);
- repairedName.replace(repairedName.size() - badSuffix.size(),
- std::string::npos, goodSuffix);
- if (cmSystemTools::FileExists(repairedName)) {
- name = repairedName;
- cmCPackLogger(cmCPackLog::LOG_DEBUG,
- "Repaired packagefile " << name << std::endl);
- }
+
+ 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);
}
}
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
index 725ea8a..efb94b9 100644
--- a/Source/CPack/cmCPackGeneratorFactory.cxx
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -6,7 +6,7 @@
#include <utility>
#include "IFW/cmCPackIFWGenerator.h"
-#ifdef HAVE_FREEBSD_PKG
+#if ENABLE_BUILD_FREEBSD_PKG
# include "cmCPackFreeBSDGenerator.h"
#endif
#include "cmCPackArchiveGenerator.h"
@@ -34,7 +34,7 @@
# include "cmCPackRPMGenerator.h"
#endif
-#if defined(_WIN32) || (defined(__CYGWIN__) && defined(HAVE_LIBUUID))
+#if ENABLE_BUILD_WIX_GENERATOR
# include "WiX/cmCPackWIXGenerator.h"
#endif
@@ -80,7 +80,7 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
cmCPackCygwinSourceGenerator::CreateGenerator);
}
#endif
-#if defined(_WIN32) || (defined(__CYGWIN__) && defined(HAVE_LIBUUID))
+#if ENABLE_BUILD_WIX_GENERATOR
if (cmCPackWIXGenerator::CanGenerate()) {
this->RegisterGenerator("WIX", "MSI file format via WiX tools",
cmCPackWIXGenerator::CreateGenerator);
@@ -119,7 +119,7 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
cmCPackRPMGenerator::CreateGenerator);
}
#endif
-#ifdef HAVE_FREEBSD_PKG
+#if ENABLE_BUILD_FREEBSD_PKG
if (cmCPackFreeBSDGenerator::CanGenerate()) {
this->RegisterGenerator("FREEBSD", "FreeBSD pkg(8) packages",
cmCPackFreeBSDGenerator::CreateGenerator);
diff --git a/Source/CPack/cmCPackGeneratorFactory.h b/Source/CPack/cmCPackGeneratorFactory.h
index f3e25a6..52c1b5c 100644
--- a/Source/CPack/cmCPackGeneratorFactory.h
+++ b/Source/CPack/cmCPackGeneratorFactory.h
@@ -8,6 +8,8 @@
#include <memory>
#include <string>
+#include "cmCPackConfigure.h" // IWYU pragma: keep
+
class cmCPackGenerator;
class cmCPackLog;
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index 217f716..6ca5783 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -242,6 +242,33 @@ int cmCPackNSISGenerator::PackageFiles()
this->SetOptionIfNotSet("CPACK_NSIS_LICENSE_PAGE", licenceCode);
}
+ std::string nsisPreArguments;
+ if (cmValue nsisArguments =
+ this->GetOption("CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS")) {
+ std::vector<std::string> expandedArguments;
+ cmExpandList(nsisArguments, expandedArguments);
+
+ for (auto& arg : expandedArguments) {
+ if (!cmHasPrefix(arg, NSIS_OPT)) {
+ nsisPreArguments = cmStrCat(nsisPreArguments, NSIS_OPT);
+ }
+ nsisPreArguments = cmStrCat(nsisPreArguments, arg, ' ');
+ }
+ }
+
+ std::string nsisPostArguments;
+ if (cmValue nsisArguments =
+ this->GetOption("CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS")) {
+ std::vector<std::string> expandedArguments;
+ cmExpandList(nsisArguments, expandedArguments);
+ for (auto& arg : expandedArguments) {
+ if (!cmHasPrefix(arg, NSIS_OPT)) {
+ nsisPostArguments = cmStrCat(nsisPostArguments, NSIS_OPT);
+ }
+ nsisPostArguments = cmStrCat(nsisPostArguments, arg, ' ');
+ }
+ }
+
// Setup all of the component sections
if (this->Components.empty()) {
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", "");
@@ -358,8 +385,11 @@ int cmCPackNSISGenerator::PackageFiles()
this->ConfigureFile(nsisInInstallOptions, nsisInstallOptions);
this->ConfigureFile(nsisInFileName, nsisFileName);
std::string nsisCmd =
- cmStrCat('"', this->GetOption("CPACK_INSTALLER_PROGRAM"), "\" \"",
- nsisFileName, '"');
+ cmStrCat('"', this->GetOption("CPACK_INSTALLER_PROGRAM"), "\" ",
+ nsisPreArguments, " \"", nsisFileName, '"');
+ if (!nsisPostArguments.empty()) {
+ nsisCmd = cmStrCat(nsisCmd, " ", nsisPostArguments);
+ }
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd << std::endl);
std::string output;
int retVal = 1;
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index 221f7dd..631bfd9 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -1,6 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
+#include <algorithm>
#include <cstddef>
#include <functional>
#include <iostream>
@@ -11,10 +12,12 @@
#include <utility>
#include <vector>
+#include <cm/optional>
#include <cmext/algorithm>
#include "cmsys/Encoding.hxx"
+#include "cmCMakePresetsGraph.h"
#include "cmCPackGenerator.h"
#include "cmCPackGeneratorFactory.h"
#include "cmCPackLog.h"
@@ -50,7 +53,7 @@ const char* cmDocumentationOptions[][2] = {
{ "-C <Configuration>", "Specify the project configuration" },
{ "-D <var>=<value>", "Set a CPack variable." },
{ "--config <configFile>", "Specify the config file." },
- { "--verbose,-V", "Enable verbose output" },
+ { "-V,--verbose", "Enable verbose output" },
{ "--trace", "Put underlying cmake scripts in trace mode." },
{ "--trace-expand", "Put underlying cmake scripts in expanded trace mode." },
{ "--debug", "Enable debug output (for CPack developers)" },
@@ -58,6 +61,8 @@ const char* cmDocumentationOptions[][2] = {
{ "-R <packageVersion>", "Override/define CPACK_PACKAGE_VERSION" },
{ "-B <packageDirectory>", "Override/define CPACK_PACKAGE_DIRECTORY" },
{ "--vendor <vendorName>", "Override/define CPACK_PACKAGE_VENDOR" },
+ { "--preset", "Read arguments from a package preset" },
+ { "--list-presets", "List available package presets" },
{ nullptr, nullptr }
};
@@ -116,6 +121,9 @@ int main(int argc, char const* const* argv)
std::string cpackProjectVendor;
std::string cpackConfigFile;
+ std::string preset;
+ bool listPresets = false;
+
std::map<std::string, std::string> definitions;
auto const verboseLambda = [&log](const std::string&, cmake*,
@@ -182,6 +190,10 @@ int main(int argc, char const* const* argv)
CommandArgument::setToValue(cpackProjectPatch) },
CommandArgument{ "--vendor", CommandArgument::Values::One,
CommandArgument::setToValue(cpackProjectVendor) },
+ CommandArgument{ "--preset", CommandArgument::Values::One,
+ CommandArgument::setToValue(preset) },
+ CommandArgument{ "--list-presets", CommandArgument::Values::Zero,
+ CommandArgument::setToTrue(listPresets) },
CommandArgument{
"-D", CommandArgument::Values::One,
[&log, &definitions](const std::string& arg, cmake*,
@@ -228,6 +240,160 @@ int main(int argc, char const* const* argv)
}
}
+ cmCPackGeneratorFactory generators;
+ generators.SetLogger(&log);
+
+ // Set up presets
+ if (!preset.empty() || listPresets) {
+ const auto workingDirectory = cmSystemTools::GetCurrentWorkingDirectory();
+
+ auto const presetGeneratorsPresent =
+ [&generators](const cmCMakePresetsGraph::PackagePreset& p) {
+ return std::all_of(p.Generators.begin(), p.Generators.end(),
+ [&generators](const std::string& gen) {
+ return generators.GetGeneratorsList().count(
+ gen) != 0;
+ });
+ };
+
+ cmCMakePresetsGraph presetsGraph;
+ auto result = presetsGraph.ReadProjectPresets(workingDirectory);
+ if (result != cmCMakePresetsGraph::ReadFileResult::READ_OK) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Could not read presets from "
+ << workingDirectory << ": "
+ << cmCMakePresetsGraph::ResultToString(result)
+ << std::endl);
+ return 1;
+ }
+
+ if (listPresets) {
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 0;
+ }
+
+ auto presetPair = presetsGraph.PackagePresets.find(preset);
+ if (presetPair == presetsGraph.PackagePresets.end()) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "No such package preset in " << workingDirectory << ": \""
+ << preset << '"' << std::endl);
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 1;
+ }
+
+ if (presetPair->second.Unexpanded.Hidden) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot use hidden package preset in "
+ << workingDirectory << ": \"" << preset << '"'
+ << std::endl);
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 1;
+ }
+
+ auto const& expandedPreset = presetPair->second.Expanded;
+ if (!expandedPreset) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Could not evaluate package preset \""
+ << preset << "\": Invalid macro expansion" << std::endl);
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 1;
+ }
+
+ if (!expandedPreset->ConditionResult) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot use disabled package preset in "
+ << workingDirectory << ": \"" << preset << '"'
+ << std::endl);
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 1;
+ }
+
+ if (!presetGeneratorsPresent(presetPair->second.Unexpanded)) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot use preset");
+ presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
+ return 1;
+ }
+
+ auto configurePresetPair =
+ presetsGraph.ConfigurePresets.find(expandedPreset->ConfigurePreset);
+ if (configurePresetPair == presetsGraph.ConfigurePresets.end()) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "No such configure preset in "
+ << workingDirectory << ": \""
+ << expandedPreset->ConfigurePreset << '"' << std::endl);
+ presetsGraph.PrintConfigurePresetList();
+ return 1;
+ }
+
+ if (configurePresetPair->second.Unexpanded.Hidden) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Cannot use hidden configure preset in "
+ << workingDirectory << ": \""
+ << expandedPreset->ConfigurePreset << '"' << std::endl);
+ presetsGraph.PrintConfigurePresetList();
+ return 1;
+ }
+
+ auto const& expandedConfigurePreset = configurePresetPair->second.Expanded;
+ if (!expandedConfigurePreset) {
+ cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+ "Could not evaluate configure preset \""
+ << expandedPreset->ConfigurePreset
+ << "\": Invalid macro expansion" << std::endl);
+ return 1;
+ }
+
+ cmSystemTools::ChangeDirectory(expandedConfigurePreset->BinaryDir);
+
+ auto presetEnvironment = expandedPreset->Environment;
+ for (auto const& var : presetEnvironment) {
+ if (var.second) {
+ cmSystemTools::PutEnv(cmStrCat(var.first, '=', *var.second));
+ }
+ }
+
+ if (!expandedPreset->ConfigFile.empty() && cpackConfigFile.empty()) {
+ cpackConfigFile = expandedPreset->ConfigFile;
+ }
+
+ if (!expandedPreset->Generators.empty() && generator.empty()) {
+ generator = cmJoin(expandedPreset->Generators, ";");
+ }
+
+ if (!expandedPreset->Configurations.empty() && cpackBuildConfig.empty()) {
+ cpackBuildConfig = cmJoin(expandedPreset->Configurations, ";");
+ }
+
+ definitions.insert(expandedPreset->Variables.begin(),
+ expandedPreset->Variables.end());
+
+ if (expandedPreset->DebugOutput == true) {
+ debugLambda("", &cminst, &globalMF);
+ }
+
+ if (expandedPreset->VerboseOutput == true) {
+ verboseLambda("", &cminst, &globalMF);
+ }
+
+ if (!expandedPreset->PackageName.empty() && cpackProjectName.empty()) {
+ cpackProjectName = expandedPreset->PackageName;
+ }
+
+ if (!expandedPreset->PackageVersion.empty() &&
+ cpackProjectVersion.empty()) {
+ cpackProjectVersion = expandedPreset->PackageVersion;
+ }
+
+ if (!expandedPreset->PackageDirectory.empty() &&
+ cpackProjectDirectory.empty()) {
+ cpackProjectDirectory = expandedPreset->PackageDirectory;
+ }
+
+ if (!expandedPreset->VendorName.empty() && cpackProjectVendor.empty()) {
+ cpackProjectVendor = expandedPreset->VendorName;
+ }
+ }
+
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Read CPack config file: " << cpackConfigFile << std::endl);
@@ -238,9 +404,6 @@ int main(int argc, char const* const* argv)
cpackConfigFileSpecified = false;
}
- cmCPackGeneratorFactory generators;
- generators.SetLogger(&log);
-
cmDocumentation doc;
doc.addCPackStandardDocSections();
/* Were we invoked to display doc or to do some work ?