cmake/Source/cmScriptGenerator.h

92 lines
2.8 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <ostream>
#include <string>
#include <vector>
2009-10-04 10:30:41 +03:00
class cmScriptGeneratorIndent
{
public:
2019-11-11 23:01:05 +01:00
cmScriptGeneratorIndent() = default;
2016-07-09 11:21:54 +02:00
cmScriptGeneratorIndent(int level)
: Level(level)
{
}
2009-10-04 10:30:41 +03:00
void Write(std::ostream& os) const
2016-07-09 11:21:54 +02:00
{
for (int i = 0; i < this->Level; ++i) {
2009-10-04 10:30:41 +03:00
os << " ";
}
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
cmScriptGeneratorIndent Next(int step = 2) const
2016-07-09 11:21:54 +02:00
{
2020-02-01 23:06:01 +01:00
return { this->Level + step };
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
private:
2019-11-11 23:01:05 +01:00
int Level = 0;
2009-10-04 10:30:41 +03:00
};
inline std::ostream& operator<<(std::ostream& os,
2017-07-20 19:35:53 +02:00
cmScriptGeneratorIndent indent)
2009-10-04 10:30:41 +03:00
{
indent.Write(os);
return os;
}
/** \class cmScriptGenerator
* \brief Support class for generating install and test scripts.
*
*/
class cmScriptGenerator
{
public:
2019-11-11 23:01:05 +01:00
cmScriptGenerator(std::string config_var,
std::vector<std::string> configurations);
2009-10-04 10:30:41 +03:00
virtual ~cmScriptGenerator();
2019-11-11 23:01:05 +01:00
cmScriptGenerator(cmScriptGenerator const&) = delete;
cmScriptGenerator& operator=(cmScriptGenerator const&) = delete;
2015-04-27 22:25:09 +02:00
void Generate(std::ostream& os, const std::string& config,
2009-10-04 10:30:41 +03:00
std::vector<std::string> const& configurationTypes);
protected:
2020-02-01 23:06:01 +01:00
using Indent = cmScriptGeneratorIndent;
2009-10-04 10:30:41 +03:00
virtual void GenerateScript(std::ostream& os);
2017-07-20 19:35:53 +02:00
virtual void GenerateScriptConfigs(std::ostream& os, Indent indent);
virtual void GenerateScriptActions(std::ostream& os, Indent indent);
2009-10-04 10:30:41 +03:00
virtual void GenerateScriptForConfig(std::ostream& os,
2015-04-27 22:25:09 +02:00
const std::string& config,
2017-07-20 19:35:53 +02:00
Indent indent);
virtual void GenerateScriptNoConfig(std::ostream&, Indent) {}
2011-06-19 15:41:06 +03:00
virtual bool NeedsScriptNoConfig() const { return false; }
2009-10-04 10:30:41 +03:00
// Test if this generator does something for a given configuration.
2015-04-27 22:25:09 +02:00
bool GeneratesForConfig(const std::string&);
2009-10-04 10:30:41 +03:00
2015-04-27 22:25:09 +02:00
std::string CreateConfigTest(const std::string& config);
2009-10-04 10:30:41 +03:00
std::string CreateConfigTest(std::vector<std::string> const& configs);
2020-08-30 11:54:41 +02:00
std::string CreateComponentTest(const std::string& component);
2009-10-04 10:30:41 +03:00
// Information shared by most generator types.
std::string RuntimeConfigVariable;
std::vector<std::string> const Configurations;
// Information used during generation.
2015-04-27 22:25:09 +02:00
std::string ConfigurationName;
2022-08-04 22:12:04 +02:00
std::vector<std::string> const* ConfigurationTypes = nullptr;
2009-10-04 10:30:41 +03:00
// True if the subclass needs to generate an explicit rule for each
// configuration. False if the subclass only generates one rule for
// all enabled configurations.
2022-08-04 22:12:04 +02:00
bool ActionsPerConfig = false;
2009-10-04 10:30:41 +03:00
private:
2017-07-20 19:35:53 +02:00
void GenerateScriptActionsOnce(std::ostream& os, Indent indent);
void GenerateScriptActionsPerConfig(std::ostream& os, Indent indent);
2009-10-04 10:30:41 +03:00
};