summaryrefslogtreecommitdiff
path: root/Source/CPack/cmCPackGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CPack/cmCPackGenerator.cxx')
-rw-r--r--Source/CPack/cmCPackGenerator.cxx125
1 files changed, 83 insertions, 42 deletions
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 288dc58a7..a9fe91cd1 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -20,6 +20,7 @@
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmProperty.h"
#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
@@ -216,7 +217,7 @@ int cmCPackGenerator::InstallProject()
mode_t* default_dir_mode = nullptr;
const char* default_dir_install_permissions =
this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
- if (default_dir_install_permissions && *default_dir_install_permissions) {
+ if (cmNonempty(default_dir_install_permissions)) {
std::vector<std::string> items =
cmExpandedList(default_dir_install_permissions);
for (const auto& arg : items) {
@@ -264,6 +265,23 @@ int cmCPackGenerator::InstallProject()
return 0;
}
+ // Run pre-build actions
+ const char* preBuildScripts = this->GetOption("CPACK_PRE_BUILD_SCRIPTS");
+ if (preBuildScripts) {
+ const auto scripts = cmExpandedList(preBuildScripts, false);
+ for (const auto& script : scripts) {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "Executing pre-build script: " << script << std::endl);
+
+ if (!this->MakefileMap->ReadListFile(script)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "The pre-build script not found: " << script
+ << std::endl);
+ return 0;
+ }
+ }
+ }
+
if (setDestDir) {
cmSystemTools::PutEnv("DESTDIR=");
}
@@ -276,7 +294,7 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
{
(void)setDestDir;
const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
- if (installCommands && *installCommands) {
+ if (cmNonempty(installCommands)) {
std::string tempInstallDirectoryEnv =
cmStrCat("CMAKE_INSTALL_PREFIX=", tempInstallDirectory);
cmSystemTools::PutEnv(tempInstallDirectoryEnv);
@@ -327,13 +345,14 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
}
const char* installDirectories =
this->GetOption("CPACK_INSTALLED_DIRECTORIES");
- if (installDirectories && *installDirectories) {
+ if (cmNonempty(installDirectories)) {
std::vector<std::string> installDirectoriesVector =
cmExpandedList(installDirectories);
if (installDirectoriesVector.size() % 2 != 0) {
cmCPackLogger(
cmCPackLog::LOG_ERROR,
- "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
+ "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> "
+ "and "
"<subdirectory>. The <subdirectory> can be '.' to be installed in "
"the toplevel directory of installation."
<< std::endl);
@@ -475,10 +494,10 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
"- Install script: " << installScript << std::endl);
if (setDestDir) {
- // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
- // underneath the tempInstallDirectory. The value of the project's
- // CMAKE_INSTALL_PREFIX is sent in here as the value of the
- // CPACK_INSTALL_PREFIX variable.
+ // For DESTDIR based packaging, use the *project*
+ // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
+ // value of the project's CMAKE_INSTALL_PREFIX is sent in here as the
+ // value of the CPACK_INSTALL_PREFIX variable.
std::string dir;
if (this->GetOption("CPACK_INSTALL_PREFIX")) {
@@ -523,7 +542,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
const char* cmakeProjects = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
const char* cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR");
std::string absoluteDestFiles;
- if (cmakeProjects && *cmakeProjects) {
+ if (cmNonempty(cmakeProjects)) {
if (!cmakeGenerator) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
@@ -576,7 +595,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
std::string installTypesVar = "CPACK_" +
cmSystemTools::UpperCase(project.Component) + "_INSTALL_TYPES";
const char* installTypes = this->GetOption(installTypesVar);
- if (installTypes && *installTypes) {
+ if (cmNonempty(installTypes)) {
std::vector<std::string> installTypesVector =
cmExpandedList(installTypes);
for (std::string const& installType : installTypesVector) {
@@ -589,7 +608,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
std::string componentsVar =
"CPACK_COMPONENTS_" + cmSystemTools::UpperCase(project.Component);
const char* components = this->GetOption(componentsVar);
- if (components && *components) {
+ if (cmNonempty(components)) {
cmExpandList(components, componentsVector);
for (std::string const& comp : componentsVector) {
project.Components.push_back(
@@ -753,7 +772,7 @@ int cmCPackGenerator::InstallCMakeProject(
const char* default_dir_inst_permissions =
this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
- if (default_dir_inst_permissions && *default_dir_inst_permissions) {
+ if (cmNonempty(default_dir_inst_permissions)) {
mf.AddDefinition("CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS",
default_dir_inst_permissions);
}
@@ -811,7 +830,7 @@ int cmCPackGenerator::InstallCMakeProject(
* - Because it was already used for component install
* in order to put things in subdirs...
*/
- cmSystemTools::PutEnv(std::string("DESTDIR=") + tempInstallDirectory);
+ cmSystemTools::PutEnv("DESTDIR=" + tempInstallDirectory);
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"- Creating directory: '" << dir << "'" << std::endl);
@@ -887,8 +906,8 @@ int cmCPackGenerator::InstallCMakeProject(
// forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
// to CPack (may be used by generators like CPack RPM or DEB)
// in order to transparently handle ABSOLUTE PATH
- if (const char* def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
- mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", def);
+ if (cmProp def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
+ mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", *def);
}
// Now rebuild the list of files after installation
@@ -921,11 +940,11 @@ int cmCPackGenerator::InstallCMakeProject(
}
}
- if (auto d = mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
+ if (cmProp d = mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
if (!absoluteDestFiles.empty()) {
absoluteDestFiles += ";";
}
- absoluteDestFiles += d;
+ absoluteDestFiles += *d;
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles
<< std::endl);
@@ -936,12 +955,13 @@ int cmCPackGenerator::InstallCMakeProject(
GetComponentInstallDirNameSuffix(component);
if (nullptr != this->GetOption(absoluteDestFileComponent)) {
std::string absoluteDestFilesListComponent =
- cmStrCat(this->GetOption(absoluteDestFileComponent), ';', d);
+ cmStrCat(this->GetOption(absoluteDestFileComponent), ';', *d);
this->SetOption(absoluteDestFileComponent,
absoluteDestFilesListComponent.c_str());
} else {
- this->SetOption(absoluteDestFileComponent,
- mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"));
+ this->SetOption(
+ absoluteDestFileComponent,
+ cmToCStr(mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")));
}
}
}
@@ -964,8 +984,8 @@ bool cmCPackGenerator::ReadListFile(const char* moduleName)
void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
const char* value)
{
- const char* def = this->MakefileMap->GetDefinition(op);
- if (def && *def) {
+ cmProp def = this->MakefileMap->GetDefinition(op);
+ if (cmNonempty(def)) {
return;
}
this->SetOption(op, value);
@@ -1076,6 +1096,25 @@ int cmCPackGenerator::DoPackage()
return 0;
}
}
+ // Run post-build actions
+ const char* postBuildScripts = this->GetOption("CPACK_POST_BUILD_SCRIPTS");
+ if (postBuildScripts) {
+ this->MakefileMap->AddDefinition("CPACK_PACKAGE_FILES",
+ cmJoin(this->packageFileNames, ";"));
+
+ const auto scripts = cmExpandedList(postBuildScripts, false);
+ for (const auto& script : scripts) {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "Executing post-build script: " << script << std::endl);
+
+ if (!this->MakefileMap->ReadListFile(script)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "The post-build script not found: " << script
+ << std::endl);
+ return 0;
+ }
+ }
+ }
/* Prepare checksum algorithm*/
const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
@@ -1177,30 +1216,31 @@ bool cmCPackGenerator::IsOn(const std::string& name) const
bool cmCPackGenerator::IsSetToOff(const std::string& op) const
{
- const char* ret = this->MakefileMap->GetDefinition(op);
- if (ret && *ret) {
- return cmIsOff(ret);
+ cmProp ret = this->MakefileMap->GetDefinition(op);
+ if (cmNonempty(ret)) {
+ return cmIsOff(*ret);
}
return false;
}
bool cmCPackGenerator::IsSetToEmpty(const std::string& op) const
{
- const char* ret = this->MakefileMap->GetDefinition(op);
+ cmProp ret = this->MakefileMap->GetDefinition(op);
if (ret) {
- return !*ret;
+ return ret->empty();
}
return false;
}
const char* cmCPackGenerator::GetOption(const std::string& op) const
{
- const char* ret = this->MakefileMap->GetDefinition(op);
+ cmProp ret = this->MakefileMap->GetDefinition(op);
if (!ret) {
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"Warning, GetOption return NULL for: " << op << std::endl);
+ return nullptr;
}
- return ret;
+ return ret->c_str();
}
std::vector<std::string> cmCPackGenerator::GetOptions() const
@@ -1289,7 +1329,7 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName,
bool copyOnly /* = false */)
{
return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
- false) == 1;
+ false, true) == 1;
}
int cmCPackGenerator::CleanTemporaryDirectory()
@@ -1378,7 +1418,8 @@ int cmCPackGenerator::PrepareGroupingKind()
<< std::endl);
}
- // if user specified packaging method, override the default packaging method
+ // if user specified packaging method, override the default packaging
+ // method
if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) {
componentPackageMethod = method;
}
@@ -1471,7 +1512,7 @@ cmCPackInstallationType* cmCPackGenerator::GetInstallationType(
installType->Name = name;
const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
- if (displayName && *displayName) {
+ if (cmNonempty(displayName)) {
installType->DisplayName = displayName;
} else {
installType->DisplayName = installType->Name;
@@ -1493,7 +1534,7 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
"CPACK_COMPONENT_" + cmsys::SystemTools::UpperCase(name);
component->Name = name;
const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
- if (displayName && *displayName) {
+ if (cmNonempty(displayName)) {
component->DisplayName = displayName;
} else {
component->DisplayName = component->Name;
@@ -1505,17 +1546,17 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
cmIsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
const char* archiveFile = this->GetOption(macroPrefix + "_ARCHIVE_FILE");
- if (archiveFile && *archiveFile) {
+ if (cmNonempty(archiveFile)) {
component->ArchiveFile = archiveFile;
}
const char* plist = this->GetOption(macroPrefix + "_PLIST");
- if (plist && *plist) {
+ if (cmNonempty(plist)) {
component->Plist = plist;
}
const char* groupName = this->GetOption(macroPrefix + "_GROUP");
- if (groupName && *groupName) {
+ if (cmNonempty(groupName)) {
component->Group = GetComponentGroup(projectName, groupName);
component->Group->Components.push_back(component);
} else {
@@ -1523,13 +1564,13 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
}
const char* description = this->GetOption(macroPrefix + "_DESCRIPTION");
- if (description && *description) {
+ if (cmNonempty(description)) {
component->Description = description;
}
// Determine the installation types.
const char* installTypes = this->GetOption(macroPrefix + "_INSTALL_TYPES");
- if (installTypes && *installTypes) {
+ if (cmNonempty(installTypes)) {
std::vector<std::string> installTypesVector =
cmExpandedList(installTypes);
for (std::string const& installType : installTypesVector) {
@@ -1540,7 +1581,7 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
// Determine the component dependencies.
const char* depends = this->GetOption(macroPrefix + "_DEPENDS");
- if (depends && *depends) {
+ if (cmNonempty(depends)) {
std::vector<std::string> dependsVector = cmExpandedList(depends);
for (std::string const& depend : dependsVector) {
cmCPackComponent* child = GetComponent(projectName, depend);
@@ -1564,21 +1605,21 @@ cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup(
// Define the group
group->Name = name;
const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
- if (displayName && *displayName) {
+ if (cmNonempty(displayName)) {
group->DisplayName = displayName;
} else {
group->DisplayName = group->Name;
}
const char* description = this->GetOption(macroPrefix + "_DESCRIPTION");
- if (description && *description) {
+ if (cmNonempty(description)) {
group->Description = description;
}
group->IsBold = this->IsOn(macroPrefix + "_BOLD_TITLE");
group->IsExpandedByDefault = this->IsOn(macroPrefix + "_EXPANDED");
const char* parentGroupName =
this->GetOption(macroPrefix + "_PARENT_GROUP");
- if (parentGroupName && *parentGroupName) {
+ if (cmNonempty(parentGroupName)) {
group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
group->ParentGroup->Subgroups.push_back(group);
} else {