mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-28 09:59:20 -05:00
Merge topic 'install-code-script-genex'
6dad812143 install: Teach CODE,SCRIPT modes to evaluate generator expressions
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2113
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmInstallScriptGenerator.h"
|
||||
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmScriptGenerator.h"
|
||||
|
||||
#include <ostream>
|
||||
@@ -16,24 +17,47 @@ cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script,
|
||||
, Script(script)
|
||||
, Code(code)
|
||||
{
|
||||
// We need per-config actions if the script has generator expressions.
|
||||
if (cmGeneratorExpression::Find(Script) != std::string::npos) {
|
||||
this->ActionsPerConfig = true;
|
||||
}
|
||||
}
|
||||
|
||||
cmInstallScriptGenerator::~cmInstallScriptGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
void cmInstallScriptGenerator::GenerateScript(std::ostream& os)
|
||||
void cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
|
||||
{
|
||||
Indent indent;
|
||||
std::string component_test =
|
||||
this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll);
|
||||
os << indent << "if(" << component_test << ")\n";
|
||||
|
||||
if (this->Code) {
|
||||
os << indent.Next() << this->Script << "\n";
|
||||
} else {
|
||||
os << indent.Next() << "include(\"" << this->Script << "\")\n";
|
||||
}
|
||||
|
||||
os << indent << "endif()\n\n";
|
||||
this->LocalGenerator = lg;
|
||||
}
|
||||
|
||||
void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os,
|
||||
Indent indent,
|
||||
std::string const& script)
|
||||
{
|
||||
if (this->Code) {
|
||||
os << indent.Next() << script << "\n";
|
||||
} else {
|
||||
os << indent.Next() << "include(\"" << script << "\")\n";
|
||||
}
|
||||
}
|
||||
|
||||
void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os,
|
||||
Indent indent)
|
||||
{
|
||||
if (this->ActionsPerConfig) {
|
||||
this->cmInstallGenerator::GenerateScriptActions(os, indent);
|
||||
} else {
|
||||
this->AddScriptInstallRule(os, indent, this->Script);
|
||||
}
|
||||
}
|
||||
|
||||
void cmInstallScriptGenerator::GenerateScriptForConfig(
|
||||
std::ostream& os, const std::string& config, Indent indent)
|
||||
{
|
||||
cmGeneratorExpression ge;
|
||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(this->Script);
|
||||
this->AddScriptInstallRule(os, indent,
|
||||
cge->Evaluate(this->LocalGenerator, config));
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include "cmInstallGenerator.h"
|
||||
#include "cmScriptGenerator.h"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
class cmLocalGenerator;
|
||||
|
||||
/** \class cmInstallScriptGenerator
|
||||
* \brief Generate target installation rules.
|
||||
*/
|
||||
@@ -20,10 +23,18 @@ public:
|
||||
const char* component, bool exclude_from_all);
|
||||
~cmInstallScriptGenerator() override;
|
||||
|
||||
void Compute(cmLocalGenerator* lg) override;
|
||||
|
||||
protected:
|
||||
void GenerateScript(std::ostream& os) override;
|
||||
void GenerateScriptActions(std::ostream& os, Indent indent) override;
|
||||
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
|
||||
Indent indent) override;
|
||||
void AddScriptInstallRule(std::ostream& os, Indent indent,
|
||||
std::string const& script);
|
||||
|
||||
std::string Script;
|
||||
bool Code;
|
||||
cmLocalGenerator* LocalGenerator;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user