mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 11:18:40 +08:00
cmVisualStudio10TargetGenerator: refactoring (continued)
This commit is contained in:
@@ -28,14 +28,23 @@ static std::string cmVS10EscapeXML(std::string arg)
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string cmVS10EscapeAttr(std::string arg)
|
||||||
|
{
|
||||||
|
cmSystemTools::ReplaceString(arg, "&", "&");
|
||||||
|
cmSystemTools::ReplaceString(arg, "<", "<");
|
||||||
|
cmSystemTools::ReplaceString(arg, ">", ">");
|
||||||
|
cmSystemTools::ReplaceString(arg, "\"", """);
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
struct cmVisualStudio10TargetGenerator::Elem
|
struct cmVisualStudio10TargetGenerator::Elem
|
||||||
{
|
{
|
||||||
cmGeneratedFileStream& S;
|
std::ostream& S;
|
||||||
int Indent;
|
int Indent;
|
||||||
bool HasElements = false;
|
bool HasElements = false;
|
||||||
const char* Tag = nullptr;
|
const char* Tag = nullptr;
|
||||||
|
|
||||||
Elem(cmGeneratedFileStream& s, int i)
|
Elem(std::ostream& s, int i)
|
||||||
: S(s)
|
: S(s)
|
||||||
, Indent(i)
|
, Indent(i)
|
||||||
{
|
{
|
||||||
@@ -61,7 +70,7 @@ struct cmVisualStudio10TargetGenerator::Elem
|
|||||||
HasElements = true;
|
HasElements = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmGeneratedFileStream& WriteString(const char* line);
|
std::ostream& WriteString(const char* line);
|
||||||
void StartElement(const char* tag)
|
void StartElement(const char* tag)
|
||||||
{
|
{
|
||||||
this->Tag = tag;
|
this->Tag = tag;
|
||||||
@@ -72,11 +81,20 @@ struct cmVisualStudio10TargetGenerator::Elem
|
|||||||
{
|
{
|
||||||
this->WriteString("<") << tag << ">" << val << "</" << tag << ">\n";
|
this->WriteString("<") << tag << ">" << val << "</" << tag << ">\n";
|
||||||
}
|
}
|
||||||
|
void Element(const char* tag, const std::string& val)
|
||||||
|
{
|
||||||
|
Elem(*this).WriteElem(tag, cmVS10EscapeXML(val));
|
||||||
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Attr(const char* an, const T& av)
|
void Attr(const char* an, const T& av)
|
||||||
{
|
{
|
||||||
this->S << " " << an << "=\"" << av << "\"";
|
this->S << " " << an << "=\"" << av << "\"";
|
||||||
}
|
}
|
||||||
|
Elem& Attribute(const char* an, const std::string& av)
|
||||||
|
{
|
||||||
|
Attr(an, cmVS10EscapeAttr(av));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
void WriteEndTag(const char* tag)
|
void WriteEndTag(const char* tag)
|
||||||
{
|
{
|
||||||
if (HasElements) {
|
if (HasElements) {
|
||||||
@@ -139,15 +157,6 @@ inline void cmVisualStudio10TargetGenerator::WriteElemEscapeXML(
|
|||||||
this->WriteElem(tag, cmVS10EscapeXML(val), indentLevel);
|
this->WriteElem(tag, cmVS10EscapeXML(val), indentLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string cmVS10EscapeAttr(std::string arg)
|
|
||||||
{
|
|
||||||
cmSystemTools::ReplaceString(arg, "&", "&");
|
|
||||||
cmSystemTools::ReplaceString(arg, "<", "<");
|
|
||||||
cmSystemTools::ReplaceString(arg, ">", ">");
|
|
||||||
cmSystemTools::ReplaceString(arg, "\"", """);
|
|
||||||
return arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string cmVS10EscapeComment(std::string comment)
|
static std::string cmVS10EscapeComment(std::string comment)
|
||||||
{
|
{
|
||||||
// MSBuild takes the CDATA of a <Message></Message> element and just
|
// MSBuild takes the CDATA of a <Message></Message> element and just
|
||||||
@@ -238,38 +247,46 @@ cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
|
|||||||
delete this->BuildFileStream;
|
delete this->BuildFileStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cmVisualStudio10TargetGenerator::CalcCondition(
|
||||||
|
const std::string& config) const
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "'$(Configuration)|$(Platform)'=='";
|
||||||
|
oss << config << "|" << this->Platform;
|
||||||
|
oss << "'";
|
||||||
|
// handle special case for 32 bit C# targets
|
||||||
|
if (this->ProjectType == csproj && this->Platform == "Win32") {
|
||||||
|
oss << " Or ";
|
||||||
|
oss << "'$(Configuration)|$(Platform)'=='";
|
||||||
|
oss << config << "|x86";
|
||||||
|
oss << "'";
|
||||||
|
}
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
|
void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
|
||||||
const char* tag, const std::string& config, int indentLevel,
|
const char* tag, const std::string& config, int indentLevel,
|
||||||
const char* attribute)
|
const char* attribute)
|
||||||
|
|
||||||
{
|
{
|
||||||
std::ostream* stream = this->BuildFileStream;
|
std::ostream& stream = *this->BuildFileStream;
|
||||||
stream->fill(' ');
|
stream.fill(' ');
|
||||||
stream->width(indentLevel * 2);
|
stream.width(indentLevel * 2);
|
||||||
(*stream) << ""; // applies indentation
|
stream << ""; // applies indentation
|
||||||
(*stream) << "<" << tag << " Condition=\"";
|
stream << "<" << tag << " Condition=\"";
|
||||||
(*stream) << "'$(Configuration)|$(Platform)'=='";
|
stream << this->CalcCondition(config);
|
||||||
(*stream) << config << "|" << this->Platform;
|
stream << "\"";
|
||||||
(*stream) << "'";
|
|
||||||
// handle special case for 32 bit C# targets
|
|
||||||
if (this->ProjectType == csproj && this->Platform == "Win32") {
|
|
||||||
(*stream) << " Or ";
|
|
||||||
(*stream) << "'$(Configuration)|$(Platform)'=='";
|
|
||||||
(*stream) << config << "|x86";
|
|
||||||
(*stream) << "'";
|
|
||||||
}
|
|
||||||
(*stream) << "\"";
|
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
(*stream) << attribute;
|
stream << attribute;
|
||||||
}
|
}
|
||||||
// close the tag
|
// close the tag
|
||||||
(*stream) << ">";
|
stream << ">";
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
(*stream) << "\n";
|
stream << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmGeneratedFileStream& cmVisualStudio10TargetGenerator::Elem::WriteString(
|
std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString(
|
||||||
const char* line)
|
const char* line)
|
||||||
{
|
{
|
||||||
this->S.fill(' ');
|
this->S.fill(' ');
|
||||||
|
@@ -33,6 +33,7 @@ public:
|
|||||||
~cmVisualStudio10TargetGenerator();
|
~cmVisualStudio10TargetGenerator();
|
||||||
void Generate();
|
void Generate();
|
||||||
// used by cmVisualStudioGeneratorOptions
|
// used by cmVisualStudioGeneratorOptions
|
||||||
|
std::string CalcCondition(const std::string& config) const;
|
||||||
void WritePlatformConfigTag(const char* tag, const std::string& config,
|
void WritePlatformConfigTag(const char* tag, const std::string& config,
|
||||||
int indentLevel, const char* attribute = 0);
|
int indentLevel, const char* attribute = 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user