cmake/Source/cmScriptGenerator.h

97 lines
2.7 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. */
2009-10-04 10:30:41 +03:00
#ifndef cmScriptGenerator_h
#define cmScriptGenerator_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h"
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:
2016-07-09 11:21:54 +02:00
cmScriptGeneratorIndent()
: Level(0)
{
}
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
{
2009-10-04 10:30:41 +03:00
return cmScriptGeneratorIndent(this->Level + step);
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
private:
int Level;
};
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
{
2017-07-20 19:35:53 +02:00
CM_DISABLE_COPY(cmScriptGenerator)
2009-10-04 10:30:41 +03:00
public:
2015-04-27 22:25:09 +02:00
cmScriptGenerator(const std::string& config_var,
2009-10-04 10:30:41 +03:00
std::vector<std::string> const& configurations);
virtual ~cmScriptGenerator();
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:
typedef cmScriptGeneratorIndent Indent;
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);
std::string CreateComponentTest(const char* component);
// 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;
2009-10-04 10:30:41 +03:00
std::vector<std::string> const* ConfigurationTypes;
// 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.
bool ActionsPerConfig;
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
};
#endif