summaryrefslogtreecommitdiffstats
path: root/Source/cmVisualStudio10TargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx130
1 files changed, 72 insertions, 58 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index ed7e243..bb76b7f 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -19,6 +19,7 @@
#include "cmSourceFile.h"
#include "cmVisualStudioGeneratorOptions.h"
#include "cmLocalVisualStudio7Generator.h"
+#include "cmCustomCommandGenerator.h"
#include "cmVS10CLFlagTable.h"
#include "cmVS10LinkFlagTable.h"
#include "cmVS10LibFlagTable.h"
@@ -140,7 +141,7 @@ cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
const char* tag,
- const char* config,
+ const std::string& config,
int indentLevel,
const char* attribute,
const char* end,
@@ -221,7 +222,8 @@ void cmVisualStudio10TargetGenerator::Generate()
//get the tools version to use
const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
std::string project_defaults=
- "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n";
+ "<?xml version=\"1.0\" encoding=\"" +
+ this->GlobalGenerator->Encoding() + "\"?>\n";
project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
project_defaults.append(toolsVer +"\" ");
project_defaults.append(
@@ -376,12 +378,12 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
{
- std::vector<cmSourceFile*> resxObjs;
+ std::vector<cmSourceFile const*> resxObjs;
this->GeneratorTarget->GetResxSources(resxObjs);
if(!resxObjs.empty())
{
this->WriteString("<ItemGroup>\n", 1);
- for(std::vector<cmSourceFile*>::const_iterator oi = resxObjs.begin();
+ for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
oi != resxObjs.end(); ++oi)
{
std::string obj = (*oi)->GetFullPath();
@@ -550,9 +552,9 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
void cmVisualStudio10TargetGenerator::WriteCustomCommands()
{
this->SourcesVisited.clear();
- std::vector<cmSourceFile*> customCommands;
+ std::vector<cmSourceFile const*> customCommands;
this->GeneratorTarget->GetCustomCommands(customCommands);
- for(std::vector<cmSourceFile*>::const_iterator
+ for(std::vector<cmSourceFile const*>::const_iterator
si = customCommands.begin();
si != customCommands.end(); ++si)
{
@@ -561,7 +563,8 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommands()
}
//----------------------------------------------------------------------------
-void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf)
+void cmVisualStudio10TargetGenerator
+::WriteCustomCommand(cmSourceFile const* sf)
{
if(this->SourcesVisited.insert(sf).second)
{
@@ -584,7 +587,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf)
}
void
-cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
+cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
cmCustomCommand const &
command)
{
@@ -616,8 +619,6 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
}
}
cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
- std::string comment = lg->ConstructComment(command);
- comment = cmVS10EscapeComment(comment);
std::vector<std::string> *configs =
static_cast<cmGlobalVisualStudio7Generator *>
(this->GlobalGenerator)->GetConfigurations();
@@ -627,8 +628,11 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
for(std::vector<std::string>::iterator i = configs->begin();
i != configs->end(); ++i)
{
+ cmCustomCommandGenerator ccg(command, *i, this->Makefile);
+ std::string comment = lg->ConstructComment(ccg);
+ comment = cmVS10EscapeComment(comment);
std::string script =
- cmVS10EscapeXML(lg->ConstructScript(command, i->c_str()));
+ cmVS10EscapeXML(lg->ConstructScript(ccg));
this->WritePlatformConfigTag("Message",i->c_str(), 3);
(*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
this->WritePlatformConfigTag("Command", i->c_str(), 3);
@@ -637,8 +641,8 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
(*this->BuildFileStream ) << source->GetFullPath();
for(std::vector<std::string>::const_iterator d =
- command.GetDepends().begin();
- d != command.GetDepends().end();
+ ccg.GetDepends().begin();
+ d != ccg.GetDepends().end();
++d)
{
std::string dep;
@@ -652,8 +656,8 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
const char* sep = "";
for(std::vector<std::string>::const_iterator o =
- command.GetOutputs().begin();
- o != command.GetOutputs().end();
+ ccg.GetOutputs().begin();
+ o != ccg.GetOutputs().end();
++o)
{
std::string out = *o;
@@ -730,7 +734,8 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
//get the tools version to use
const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
std::string project_defaults=
- "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n";
+ "<?xml version=\"1.0\" encoding=\"" +
+ this->GlobalGenerator->Encoding() + "\"?>\n";
project_defaults.append("<Project ToolsVersion=\"");
project_defaults.append(toolsVer +"\" ");
project_defaults.append(
@@ -743,12 +748,12 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
}
- std::vector<cmSourceFile*> resxObjs;
+ std::vector<cmSourceFile const*> resxObjs;
this->GeneratorTarget->GetResxSources(resxObjs);
if(!resxObjs.empty())
{
this->WriteString("<ItemGroup>\n", 1);
- for(std::vector<cmSourceFile*>::const_iterator oi = resxObjs.begin();
+ for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
oi != resxObjs.end(); ++oi)
{
std::string obj = (*oi)->GetFullPath();
@@ -899,7 +904,7 @@ WriteGroupSources(const char* name,
for(ToolSources::const_iterator s = sources.begin();
s != sources.end(); ++s)
{
- cmSourceFile* sf = s->SourceFile;
+ cmSourceFile const* sf = s->SourceFile;
std::string const& source = sf->GetFullPath();
cmSourceGroup* sourceGroup =
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
@@ -926,7 +931,7 @@ WriteGroupSources(const char* name,
}
void cmVisualStudio10TargetGenerator::WriteSource(
- const char* tool, cmSourceFile* sf, const char* end)
+ const char* tool, cmSourceFile const* sf, const char* end)
{
// Visual Studio tools append relative paths to the current dir, as in:
//
@@ -982,9 +987,9 @@ void cmVisualStudio10TargetGenerator::WriteSource(
}
void cmVisualStudio10TargetGenerator::WriteSources(
- const char* tool, std::vector<cmSourceFile*> const& sources)
+ const char* tool, std::vector<cmSourceFile const*> const& sources)
{
- for(std::vector<cmSourceFile*>::const_iterator
+ for(std::vector<cmSourceFile const*>::const_iterator
si = sources.begin(); si != sources.end(); ++si)
{
this->WriteSource(tool, *si);
@@ -999,31 +1004,31 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
}
this->WriteString("<ItemGroup>\n", 1);
- std::vector<cmSourceFile*> headerSources;
+ std::vector<cmSourceFile const*> headerSources;
this->GeneratorTarget->GetHeaderSources(headerSources);
this->WriteSources("ClInclude", headerSources);
- std::vector<cmSourceFile*> idlSources;
+ std::vector<cmSourceFile const*> idlSources;
this->GeneratorTarget->GetIDLSources(idlSources);
this->WriteSources("Midl", idlSources);
- std::vector<cmSourceFile*> objectSources;
+ std::vector<cmSourceFile const*> objectSources;
this->GeneratorTarget->GetObjectSources(objectSources);
- for(std::vector<cmSourceFile*>::const_iterator
+ for(std::vector<cmSourceFile const*>::const_iterator
si = objectSources.begin();
si != objectSources.end(); ++si)
{
- const char* lang = (*si)->GetLanguage();
+ const std::string& lang = (*si)->GetLanguage();
const char* tool = NULL;
- if (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0)
+ if (lang == "C"|| lang == "CXX")
{
tool = "ClCompile";
}
- else if (strcmp(lang, "ASM_MASM") == 0 &&
+ else if (lang == "ASM_NASM" &&
this->GlobalGenerator->IsMasmEnabled())
{
tool = "MASM";
}
- else if (strcmp(lang, "RC") == 0)
+ else if (lang == "RC")
{
tool = "ResourceCompile";
}
@@ -1047,7 +1052,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
}
}
- std::vector<cmSourceFile*> externalObjects;
+ std::vector<cmSourceFile const*> externalObjects;
this->GeneratorTarget->GetExternalObjects(externalObjects);
if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
{
@@ -1059,7 +1064,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
{
// If an object file is generated in this target, then vs10 will use
// it in the build, and we have to list it as None instead of Object.
- for(std::vector<cmSourceFile*>::const_iterator
+ for(std::vector<cmSourceFile const*>::const_iterator
si = externalObjects.begin();
si != externalObjects.end(); ++si)
{
@@ -1069,7 +1074,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
}
}
- std::vector<cmSourceFile*> extraSources;
+ std::vector<cmSourceFile const*> extraSources;
this->GeneratorTarget->GetExtraSources(extraSources);
this->WriteSources("None", extraSources);
@@ -1089,9 +1094,9 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
}
bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
- cmSourceFile* source)
+ cmSourceFile const* source)
{
- cmSourceFile& sf = *source;
+ cmSourceFile const& sf = *source;
std::string objectName;
if(this->GeneratorTarget->HasExplicitObjectName(&sf))
@@ -1108,29 +1113,28 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
{
defines += cdefs;
}
- const char* lang =
+ std::string lang =
this->GlobalGenerator->GetLanguageFromExtension
(sf.GetExtension().c_str());
- const char* sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
- const char* linkLanguage = this->Target->GetLinkerLanguage();
+ std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
+ const std::string& linkLanguage = this->Target->GetLinkerLanguage();
bool needForceLang = false;
// source file does not match its extension language
- if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
+ if(lang != sourceLang)
{
needForceLang = true;
lang = sourceLang;
}
// if the source file does not match the linker language
// then force c or c++
- if(needForceLang || (linkLanguage && lang
- && strcmp(lang, linkLanguage) != 0))
+ if(needForceLang || (linkLanguage != lang))
{
- if(strcmp(lang, "CXX") == 0)
+ if(lang == "CXX")
{
// force a C++ file type
flags += " /TP ";
}
- else if(strcmp(lang, "C") == 0)
+ else if(lang == "C")
{
// force to c
flags += " /TC ";
@@ -1341,17 +1345,17 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
// collect up flags for
if(this->Target->GetType() < cmTarget::UTILITY)
{
- const char* linkLanguage =
+ const std::string& linkLanguage =
this->Target->GetLinkerLanguage(configName.c_str());
- if(!linkLanguage)
+ if(linkLanguage.empty())
{
cmSystemTools::Error
("CMake can not determine linker language for target: ",
this->Name.c_str());
return false;
}
- if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
- || strcmp(linkLanguage, "Fortran") == 0)
+ if(linkLanguage == "C" || linkLanguage == "CXX"
+ || linkLanguage == "Fortran")
{
std::string baseFlagVar = "CMAKE_";
baseFlagVar += linkLanguage;
@@ -1365,11 +1369,11 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
}
// set the correct language
- if(strcmp(linkLanguage, "C") == 0)
+ if(linkLanguage == "C")
{
flags += " /TC ";
}
- if(strcmp(linkLanguage, "CXX") == 0)
+ if(linkLanguage == "CXX")
{
flags += " /TP ";
}
@@ -1427,6 +1431,17 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
"\n", "CXX");
this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
+
+ // Specify the compiler program database file if configured.
+ std::string pdb = this->Target->GetCompilePDBPath(configName.c_str());
+ if(!pdb.empty())
+ {
+ this->ConvertToWindowsSlash(pdb);
+ this->WriteString("<ProgramDataBaseFileName>", 3);
+ *this->BuildFileStream << cmVS10EscapeXML(pdb)
+ << "</ProgramDataBaseFileName>\n";
+ }
+
this->WriteString("</ClCompile>\n", 2);
}
@@ -1514,9 +1529,9 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
cmVSGetLinkFlagTable(this->LocalGenerator), 0, this));
Options& linkOptions = *pOptions;
- const char* linkLanguage =
+ const std::string& linkLanguage =
this->Target->GetLinkerLanguage(config.c_str());
- if(!linkLanguage)
+ if(linkLanguage.empty())
{
cmSystemTools::Error
("CMake can not determine linker language for target: ",
@@ -1666,10 +1681,10 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
linkOptions.AddFlag("ImportLibrary", imLib.c_str());
linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
linkOptions.Parse(flags.c_str());
- if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
+ std::string def = this->GeneratorTarget->GetModuleDefinitionFile();
+ if(!def.empty())
{
- linkOptions.AddFlag("ModuleDefinitionFile",
- this->GeneratorTarget->ModuleDefinitionFile.c_str());
+ linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
}
this->LinkOptions[config] = pOptions.release();
@@ -1825,13 +1840,12 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
i != commands.end(); ++i)
{
- const cmCustomCommand& command = *i;
+ cmCustomCommandGenerator ccg(*i, configName, this->Makefile);
comment += pre;
- comment += lg->ConstructComment(command);
+ comment += lg->ConstructComment(ccg);
script += pre;
pre = "\n";
- script +=
- cmVS10EscapeXML(lg->ConstructScript(command, configName.c_str()));
+ script += cmVS10EscapeXML(lg->ConstructScript(ccg));
}
comment = cmVS10EscapeComment(comment);
this->WriteString("<Message>",3);