install: Implement new install(CODE|SCRIPT) option ALL_COMPONENTS

In a per-component installation the generated installation scripts
are invoked once for each component.

Per default custom installation script code added by install(CODE|SCRIPT)
only runs for one specific component in this context.

The new ALL_COMPONENTS option allows custom script code to be run once
for each component being installed.
This commit is contained in:
Nils Gladitz
2021-05-19 10:15:16 +02:00
parent 82fd8b6ba3
commit 99ff75455e
25 changed files with 133 additions and 20 deletions
+5
View File
@@ -1016,6 +1016,11 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
if (gen->GetExcludeFromAll()) {
installer["isExcludeFromAll"] = true;
}
if (gen->GetAllComponentsFlag()) {
installer["isForAllComponents"] = true;
}
this->AddBacktrace(installer, gen->GetBacktrace());
return installer;
+10 -2
View File
@@ -161,6 +161,7 @@ bool HandleScriptMode(std::vector<std::string> const& args,
bool doing_script = false;
bool doing_code = false;
bool exclude_from_all = false;
bool all_components = false;
// Scan the args once for COMPONENT. Only allow one.
//
@@ -172,6 +173,8 @@ bool HandleScriptMode(std::vector<std::string> const& args,
}
if (args[i] == "EXCLUDE_FROM_ALL") {
exclude_from_all = true;
} else if (args[i] == "ALL_COMPONENTS") {
all_components = true;
}
}
@@ -182,6 +185,11 @@ bool HandleScriptMode(std::vector<std::string> const& args,
return false;
}
if (all_components && componentCount == 1) {
status.SetError("ALL_COMPONENTS and COMPONENT are mutually exclusive");
return false;
}
// Scan the args again, this time adding install generators each time we
// encounter a SCRIPT or CODE arg:
//
@@ -208,14 +216,14 @@ bool HandleScriptMode(std::vector<std::string> const& args,
}
helper.Makefile->AddInstallGenerator(
cm::make_unique<cmInstallScriptGenerator>(
script, false, component, exclude_from_all,
script, false, component, exclude_from_all, all_components,
helper.Makefile->GetBacktrace()));
} else if (doing_code) {
doing_code = false;
std::string const& code = arg;
helper.Makefile->AddInstallGenerator(
cm::make_unique<cmInstallScriptGenerator>(
code, true, component, exclude_from_all,
code, true, component, exclude_from_all, all_components,
helper.Makefile->GetBacktrace()));
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
MessageLevel message, bool exclude_from_all, std::string literal_args,
bool optional, cmListFileBacktrace backtrace)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all, std::move(backtrace))
exclude_from_all, false, std::move(backtrace))
, LocalGenerator(nullptr)
, Directories(dirs)
, FilePermissions(std::move(file_permissions))
+1 -1
View File
@@ -26,7 +26,7 @@ cmInstallExportGenerator::cmInstallExportGenerator(
std::string filename, std::string name_space, bool exportOld, bool android,
cmListFileBacktrace backtrace)
: cmInstallGenerator(destination, configurations, component, message,
exclude_from_all, std::move(backtrace))
exclude_from_all, false, std::move(backtrace))
, ExportSet(exportSet)
, FilePermissions(std::move(file_permissions))
, FileName(std::move(filename))
+1 -1
View File
@@ -17,7 +17,7 @@ cmInstallFilesGenerator::cmInstallFilesGenerator(
MessageLevel message, bool exclude_from_all, std::string rename,
bool optional, cmListFileBacktrace backtrace)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all, std::move(backtrace))
exclude_from_all, false, std::move(backtrace))
, LocalGenerator(nullptr)
, Files(files)
, FilePermissions(std::move(file_permissions))
+12 -6
View File
@@ -11,12 +11,13 @@
cmInstallGenerator::cmInstallGenerator(
std::string destination, std::vector<std::string> const& configurations,
std::string component, MessageLevel message, bool exclude_from_all,
cmListFileBacktrace backtrace)
bool all_components, cmListFileBacktrace backtrace)
: cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations)
, Destination(std::move(destination))
, Component(std::move(component))
, Message(message)
, ExcludeFromAll(exclude_from_all)
, AllComponents(all_components)
, Backtrace(std::move(backtrace))
{
}
@@ -160,15 +161,20 @@ void cmInstallGenerator::GenerateScript(std::ostream& os)
Indent indent;
// Begin this block of installation.
std::string component_test =
this->CreateComponentTest(this->Component, this->ExcludeFromAll);
os << indent << "if(" << component_test << ")\n";
if (!this->AllComponents) {
std::string component_test =
this->CreateComponentTest(this->Component, this->ExcludeFromAll);
os << indent << "if(" << component_test << ")\n";
}
// Generate the script possibly with per-configuration code.
this->GenerateScriptConfigs(os, indent.Next());
this->GenerateScriptConfigs(os,
this->AllComponents ? indent : indent.Next());
// End this block of installation.
os << indent << "endif()\n\n";
if (!this->AllComponents) {
os << indent << "endif()\n\n";
}
}
bool cmInstallGenerator::InstallsForConfig(const std::string& config)
+4 -1
View File
@@ -33,7 +33,8 @@ public:
cmInstallGenerator(std::string destination,
std::vector<std::string> const& configurations,
std::string component, MessageLevel message,
bool exclude_from_all, cmListFileBacktrace backtrace);
bool exclude_from_all, bool all_components,
cmListFileBacktrace backtrace);
~cmInstallGenerator() override;
cmInstallGenerator(cmInstallGenerator const&) = delete;
@@ -65,6 +66,7 @@ public:
std::string const& GetComponent() const { return this->Component; }
bool GetExcludeFromAll() const { return this->ExcludeFromAll; }
bool GetAllComponentsFlag() const { return this->AllComponents; }
cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
@@ -79,5 +81,6 @@ protected:
std::string const Component;
MessageLevel const Message;
bool const ExcludeFromAll;
bool const AllComponents;
cmListFileBacktrace const Backtrace;
};
+3 -2
View File
@@ -14,9 +14,10 @@
cmInstallScriptGenerator::cmInstallScriptGenerator(
std::string script, bool code, std::string const& component,
bool exclude_from_all, cmListFileBacktrace backtrace)
bool exclude_from_all, bool all_components, cmListFileBacktrace backtrace)
: cmInstallGenerator("", std::vector<std::string>(), component,
MessageDefault, exclude_from_all, std::move(backtrace))
MessageDefault, exclude_from_all, all_components,
std::move(backtrace))
, Script(std::move(script))
, Code(code)
, AllowGenex(false)
+1 -1
View File
@@ -21,7 +21,7 @@ class cmInstallScriptGenerator : public cmInstallGenerator
public:
cmInstallScriptGenerator(
std::string script, bool code, std::string const& component,
bool exclude_from_all,
bool exclude_from_all, bool all_components,
cmListFileBacktrace backtrace = cmListFileBacktrace());
~cmInstallScriptGenerator() override;
+1 -1
View File
@@ -17,7 +17,7 @@ cmInstallSubdirectoryGenerator::cmInstallSubdirectoryGenerator(
cmMakefile* makefile, std::string binaryDirectory, bool excludeFromAll,
cmListFileBacktrace backtrace)
: cmInstallGenerator("", std::vector<std::string>(), "", MessageDefault,
excludeFromAll, std::move(backtrace))
excludeFromAll, false, std::move(backtrace))
, Makefile(makefile)
, BinaryDirectory(std::move(binaryDirectory))
{
+1 -1
View File
@@ -46,7 +46,7 @@ cmInstallTargetGenerator::cmInstallTargetGenerator(
std::string const& component, MessageLevel message, bool exclude_from_all,
bool optional, cmListFileBacktrace backtrace)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all, std::move(backtrace))
exclude_from_all, false, std::move(backtrace))
, TargetName(std::move(targetName))
, Target(nullptr)
, FilePermissions(std::move(file_permissions))
+2 -2
View File
@@ -3317,7 +3317,7 @@ void cmLocalGenerator::GenerateTargetInstallRules(
// Include the user-specified pre-install script for this target.
if (cmProp preinstall = l->GetProperty("PRE_INSTALL_SCRIPT")) {
cmInstallScriptGenerator g(*preinstall, false, "", false);
cmInstallScriptGenerator g(*preinstall, false, "", false, false);
g.Generate(os, config, configurationTypes);
}
@@ -3370,7 +3370,7 @@ void cmLocalGenerator::GenerateTargetInstallRules(
// Include the user-specified post-install script for this target.
if (cmProp postinstall = l->GetProperty("POST_INSTALL_SCRIPT")) {
cmInstallScriptGenerator g(*postinstall, false, "", false);
cmInstallScriptGenerator g(*postinstall, false, "", false, false);
g.Generate(os, config, configurationTypes);
}
}