summaryrefslogtreecommitdiff
path: root/Source/cmExtraCodeBlocksGenerator.cxx
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2015-07-16 21:52:35 +0200
committerBrad King <brad.king@kitware.com>2016-03-21 10:11:53 -0400
commit27e097645350fc07dadc79a8944b47a97e5ecdc3 (patch)
tree300746dea4a5a215cda999d6a2e9c2425b196d0d /Source/cmExtraCodeBlocksGenerator.cxx
parentd740762181976834df32bc9baaf273e5278313b0 (diff)
downloadcmake-27e097645350fc07dadc79a8944b47a97e5ecdc3.tar.gz
cmExtraCodeBlocksGenerator: port to cmXMLWriter
Diffstat (limited to 'Source/cmExtraCodeBlocksGenerator.cxx')
-rw-r--r--Source/cmExtraCodeBlocksGenerator.cxx234
1 files changed, 145 insertions, 89 deletions
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx
index 476d3ac410..52512a811c 100644
--- a/Source/cmExtraCodeBlocksGenerator.cxx
+++ b/Source/cmExtraCodeBlocksGenerator.cxx
@@ -18,7 +18,7 @@
#include "cmSourceFile.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
#include <cmsys/SystemTools.hxx>
@@ -101,11 +101,11 @@ struct Tree
void InsertPath(const std::vector<std::string>& splitted,
std::vector<std::string>::size_type start,
const std::string& fileName);
- void BuildVirtualFolder(std::string& virtualFolders) const;
+ void BuildVirtualFolder(cmXMLWriter& xml) const;
void BuildVirtualFolderImpl(std::string& virtualFolders,
const std::string& prefix) const;
- void BuildUnit(std::string& unitString, const std::string& fsPath) const;
- void BuildUnitImpl(std::string& unitString,
+ void BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const;
+ void BuildUnitImpl(cmXMLWriter& xml,
const std::string& virtualFolderPath,
const std::string& fsPath) const;
};
@@ -159,16 +159,18 @@ void Tree::InsertPath(const std::vector<std::string>& splitted,
}
-void Tree::BuildVirtualFolder(std::string& virtualFolders) const
+void Tree::BuildVirtualFolder(cmXMLWriter& xml) const
{
- virtualFolders += "<Option virtualFolders=\"CMake Files\\;";
+ xml.StartElement("Option");
+ std::string virtualFolders = "CMake Files\\;";
for (std::vector<Tree>::const_iterator it = folders.begin();
it != folders.end();
++it)
{
it->BuildVirtualFolderImpl(virtualFolders, "");
}
- virtualFolders += "\" />";
+ xml.Attribute("virtualFolders", virtualFolders);
+ xml.EndElement();
}
@@ -185,26 +187,31 @@ void Tree::BuildVirtualFolderImpl(std::string& virtualFolders,
}
-void Tree::BuildUnit(std::string& unitString, const std::string& fsPath) const
+void Tree::BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const
{
for (std::vector<std::string>::const_iterator it = files.begin();
it != files.end();
++it)
{
- unitString += " <Unit filename=\"" + fsPath + *it + "\">\n";
- unitString += " <Option virtualFolder=\"CMake Files\\\" />\n";
- unitString += " </Unit>\n";
+ xml.StartElement("Unit");
+ xml.Attribute("filename", fsPath + *it);
+
+ xml.StartElement("Option");
+ xml.Attribute("virtualFolder", "CMake Files\\");
+ xml.EndElement();
+
+ xml.EndElement();
}
for (std::vector<Tree>::const_iterator it = folders.begin();
it != folders.end();
++it)
{
- it->BuildUnitImpl(unitString, "", fsPath);
+ it->BuildUnitImpl(xml, "", fsPath);
}
}
-void Tree::BuildUnitImpl(std::string& unitString,
+void Tree::BuildUnitImpl(cmXMLWriter& xml,
const std::string& virtualFolderPath,
const std::string& fsPath) const
{
@@ -212,16 +219,21 @@ void Tree::BuildUnitImpl(std::string& unitString,
it != files.end();
++it)
{
- unitString += " <Unit filename=\"" +fsPath+path+ "/" + *it + "\">\n";
- unitString += " <Option virtualFolder=\"CMake Files\\"
- + virtualFolderPath + path + "\\\" />\n";
- unitString += " </Unit>\n";
+ xml.StartElement("Unit");
+ xml.Attribute("filename", fsPath + path + "/" + *it);
+
+ xml.StartElement("Option");
+ xml.Attribute("virtualFolder",
+ "CMake Files\\" + virtualFolderPath + path + "\\");
+ xml.EndElement();
+
+ xml.EndElement();
}
for (std::vector<Tree>::const_iterator it = folders.begin();
it != folders.end();
++it)
{
- it->BuildUnitImpl(unitString,
+ it->BuildUnitImpl(xml,
virtualFolderPath + path + "\\", fsPath + path + "/");
}
}
@@ -289,30 +301,41 @@ void cmExtraCodeBlocksGenerator
}
}
- // Now build a virtual tree string
- std::string virtualFolders;
- tree.BuildVirtualFolder(virtualFolders);
- // And one for <Unit>
- std::string unitFiles;
- tree.BuildUnit(unitFiles, std::string(lgs[0]->GetSourceDirectory()) + "/");
-
// figure out the compiler
std::string compiler = this->GetCBCompilerId(mf);
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
const std::string makeArgs = mf->GetSafeDefinition(
"CMAKE_CODEBLOCKS_MAKE_ARGUMENTS");
- fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
- "<CodeBlocks_project_file>\n"
- " <FileVersion major=\"1\" minor=\"6\" />\n"
- " <Project>\n"
- " <Option title=\"" << lgs[0]->GetProjectName()<<"\" />\n"
- " <Option makefile_is_custom=\"1\" />\n"
- " <Option compiler=\"" << compiler << "\" />\n"
- " "<<virtualFolders<<"\n"
- " <Build>\n";
-
- this->AppendTarget(fout, "all", 0, make.c_str(), lgs[0], compiler.c_str(),
+ cmXMLWriter xml(fout);
+ xml.StartDocument();
+ xml.StartElement("CodeBlocks_project_file");
+
+ xml.StartElement("FileVersion");
+ xml.Attribute("major", 1);
+ xml.Attribute("minor", 6);
+ xml.EndElement();
+
+ xml.StartElement("Project");
+
+ xml.StartElement("Option");
+ xml.Attribute("title", lgs[0]->GetProjectName());
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("makefile_is_custom", 1);
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("compiler", compiler);
+ xml.EndElement();
+
+ // Now build a virtual tree
+ tree.BuildVirtualFolder(xml);
+
+ xml.StartElement("Build");
+
+ this->AppendTarget(xml, "all", 0, make.c_str(), lgs[0], compiler.c_str(),
makeArgs);
// add all executable and library targets and some of the GLOBAL
@@ -334,7 +357,7 @@ void cmExtraCodeBlocksGenerator
if (strcmp((*lg)->GetCurrentBinaryDirectory(),
(*lg)->GetBinaryDirectory())==0)
{
- this->AppendTarget(fout, targetName, 0,
+ this->AppendTarget(xml, targetName, 0,
make.c_str(), *lg, compiler.c_str(),
makeArgs);
}
@@ -352,7 +375,7 @@ void cmExtraCodeBlocksGenerator
break;
}
- this->AppendTarget(fout, targetName, 0,
+ this->AppendTarget(xml, targetName, 0,
make.c_str(), *lg, compiler.c_str(),makeArgs);
break;
case cmState::EXECUTABLE:
@@ -362,11 +385,11 @@ void cmExtraCodeBlocksGenerator
case cmState::OBJECT_LIBRARY:
{
cmGeneratorTarget* gt = *ti;
- this->AppendTarget(fout, targetName, gt,
+ this->AppendTarget(xml, targetName, gt,
make.c_str(), *lg, compiler.c_str(), makeArgs);
std::string fastTarget = targetName;
fastTarget += "/fast";
- this->AppendTarget(fout, fastTarget, gt,
+ this->AppendTarget(xml, fastTarget, gt,
make.c_str(), *lg, compiler.c_str(), makeArgs);
}
break;
@@ -376,8 +399,7 @@ void cmExtraCodeBlocksGenerator
}
}
- fout<<" </Build>\n";
-
+ xml.EndElement(); // Build
// Collect all used source files in the project.
// Keep a list of C/C++ source files which might have an acompanying header
@@ -505,24 +527,27 @@ void cmExtraCodeBlocksGenerator
std::string const& unitFilename = sit->first;
CbpUnit const& unit = sit->second;
- fout<<" <Unit filename=\""<< cmXMLSafe(unitFilename) <<"\">\n";
+ xml.StartElement("Unit");
+ xml.Attribute("filename", unitFilename);
for(std::vector<const cmGeneratorTarget*>::const_iterator ti =
unit.Targets.begin();
ti != unit.Targets.end(); ++ti)
{
- std::string const& targetName = (*ti)->GetName();
- fout<<" <Option target=\""<< cmXMLSafe(targetName) <<"\"/>\n";
+ xml.StartElement("Option");
+ xml.Attribute("target", (*ti)->GetName());
+ xml.EndElement();
}
- fout<<" </Unit>\n";
+ xml.EndElement();
}
// Add CMakeLists.txt
- fout<<unitFiles;
+ tree.BuildUnit(xml, std::string(mf->GetHomeDirectory()) + "/");
- fout<<" </Project>\n"
- "</CodeBlocks_project_file>\n";
+ xml.EndElement(); // Project
+ xml.EndElement(); // CodeBlocks_project_file
+ xml.EndDocument();
}
@@ -553,7 +578,7 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
// Generate the xml code for one target.
-void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
+void cmExtraCodeBlocksGenerator::AppendTarget(cmXMLWriter& xml,
const std::string& targetName,
cmGeneratorTarget* target,
const char* make,
@@ -565,7 +590,9 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
std::string makefileName = lg->GetCurrentBinaryDirectory();
makefileName += "/Makefile";
- fout<<" <Target title=\"" << targetName << "\">\n";
+ xml.StartElement("Target");
+ xml.Attribute("title", targetName);
+
if (target!=0)
{
int cbTargetType = this->GetCBTargetType(target);
@@ -603,13 +630,29 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
location = target->GetLocation(buildType);
}
- fout<<" <Option output=\"" << location
- << "\" prefix_auto=\"0\" extension_auto=\"0\" />\n"
- " <Option working_dir=\"" << workingDir << "\" />\n"
- " <Option object_output=\"./\" />\n"
- " <Option type=\"" << cbTargetType << "\" />\n"
- " <Option compiler=\"" << compiler << "\" />\n"
- " <Compiler>\n";
+ xml.StartElement("Option");
+ xml.Attribute("output", location);
+ xml.Attribute("prefix_auto", 0);
+ xml.Attribute("extension_auto", 0);
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("working_dir", workingDir);
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("object_output", "./");
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("type", cbTargetType);
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("compiler", compiler);
+ xml.EndElement();
+
+ xml.StartElement("Compiler");
// the compilerdefines for this target
std::vector<std::string> cdefs;
@@ -619,8 +662,9 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
for(std::vector<std::string>::const_iterator di = cdefs.begin();
di != cdefs.end(); ++di)
{
- cmXMLSafe safedef(di->c_str());
- fout <<" <Add option=\"-D" << safedef.str() << "\" />\n";
+ xml.StartElement("Add");
+ xml.Attribute("option", "-D" + *di);
+ xml.EndElement();
}
// the include directories for this target
@@ -653,36 +697,48 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
dirIt != uniqIncludeDirs.end();
++dirIt)
{
- fout <<" <Add directory=\"" << *dirIt << "\" />\n";
+ xml.StartElement("Add");
+ xml.Attribute("directory", *dirIt);
+ xml.EndElement();
}
- fout<<" </Compiler>\n";
+ xml.EndElement(); // Compiler
}
else // e.g. all and the GLOBAL and UTILITY targets
{
- fout<<" <Option working_dir=\""
- << lg->GetCurrentBinaryDirectory() << "\" />\n"
- <<" <Option type=\"" << 4 << "\" />\n";
- }
-
- fout<<" <MakeCommands>\n"
- " <Build command=\""
- << this->BuildMakeCommand(make, makefileName.c_str(), targetName,
- makeFlags)
- << "\" />\n"
- " <CompileFile command=\""
- << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;",
- makeFlags)
- << "\" />\n"
- " <Clean command=\""
- << this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)
- << "\" />\n"
- " <DistClean command=\""
- << this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)
- << "\" />\n"
- " </MakeCommands>\n"
- " </Target>\n";
+ xml.StartElement("Option");
+ xml.Attribute("working_dir", lg->GetCurrentBinaryDirectory());
+ xml.EndElement();
+
+ xml.StartElement("Option");
+ xml.Attribute("type", 4);
+ xml.EndElement();
+ }
+
+ xml.StartElement("MakeCommands");
+
+ xml.StartElement("Build");
+ xml.Attribute("command",
+ this->BuildMakeCommand(make, makefileName.c_str(), targetName, makeFlags));
+ xml.EndElement();
+
+ xml.StartElement("CompileFile");
+ xml.Attribute("command",
+ this->BuildMakeCommand(make, makefileName.c_str(),"\"$file\"", makeFlags));
+ xml.EndElement();
+ xml.StartElement("Clean");
+ xml.Attribute("command",
+ this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags));
+ xml.EndElement();
+
+ xml.StartElement("DistClean");
+ xml.Attribute("command",
+ this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags));
+ xml.EndElement();
+
+ xml.EndElement(); //MakeCommands
+ xml.EndElement(); //Target
}
@@ -825,7 +881,7 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
// http://public.kitware.com/Bug/view.php?id=13952
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += " /NOLOGO /f ";
- command += cmXMLSafe(makefileName).str();
+ command += makefileName;
command += " VERBOSE=1 ";
command += target;
}
@@ -834,9 +890,9 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
// no escaping of spaces in this case, see
// http://public.kitware.com/Bug/view.php?id=10014
std::string makefileName = makefile;
- command += " -f &quot;";
+ command += " -f \"";
command += makefileName;
- command += "&quot; ";
+ command += "\" ";
command += " VERBOSE=1 ";
command += target;
}
@@ -848,9 +904,9 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
else
{
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
- command += " -f &quot;";
+ command += " -f \"";
command += makefileName;
- command += "&quot; ";
+ command += "\" ";
command += " VERBOSE=1 ";
command += target;
}