Newer
Older
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmVisualStudio10TargetGenerator.h"
#include "cmGeneratorTarget.h"
#include "cmTarget.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratedFileStream.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmVisualStudioGeneratorOptions.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmCustomCommandGenerator.h"
#include "cmVS10CLFlagTable.h"
#include "cmVS10RCFlagTable.h"
#include "cmVS10LinkFlagTable.h"
#include "cmVS11CLFlagTable.h"
#include "cmVS11RCFlagTable.h"
#include "cmVS11LinkFlagTable.h"
#include "cmVS11LibFlagTable.h"
#include "cmVS12CLFlagTable.h"
#include "cmVS12RCFlagTable.h"
#include "cmVS12LinkFlagTable.h"
#include "cmVS12LibFlagTable.h"
#include "cmVS14CLFlagTable.h"
#include "cmVS14RCFlagTable.h"
#include "cmVS14LinkFlagTable.h"
#include "cmVS14LibFlagTable.h"
#include <cmsys/auto_ptr.hxx>
cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
if(this->MSTools)
{
cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS14)
{ return cmVS14CLFlagTable; }
else if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12CLFlagTable; }
else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11CLFlagTable; }
else
{ return cmVS10CLFlagTable; }
}
return 0;
cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetRcFlagTable() const
{
if(this->MSTools)
{
cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS14)
{ return cmVS14RCFlagTable; }
else if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12RCFlagTable; }
else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11RCFlagTable; }
else
{ return cmVS10RCFlagTable; }
}
return 0;
cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
if(this->MSTools)
{
cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS14)
{ return cmVS14LibFlagTable; }
else if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12LibFlagTable; }
else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11LibFlagTable; }
else
{ return cmVS10LibFlagTable; }
}
return 0;
cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
if(this->MSTools)
{
cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS14)
{ return cmVS14LinkFlagTable; }
else if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12LinkFlagTable; }
else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11LinkFlagTable; }
else
{ return cmVS10LinkFlagTable; }
}
return 0;
static std::string cmVS10EscapeXML(std::string arg)
{
cmSystemTools::ReplaceString(arg, "&", "&");
cmSystemTools::ReplaceString(arg, "<", "<");
cmSystemTools::ReplaceString(arg, ">", ">");
return arg;
}
static std::string cmVS10EscapeComment(std::string comment)
{
// MSBuild takes the CDATA of a <Message></Message> element and just
// does "echo $CDATA" with no escapes. We must encode the string.
// http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
std::string echoable;
for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
{
switch (*c)
{
case '\r': break;
case '\n': echoable += '\t'; break;
case '"': /* no break */
case '|': /* no break */
case '&': /* no break */
case '<': /* no break */
case '>': /* no break */
case '^': echoable += '^'; /* no break */
default: echoable += *c; break;
}
}
return echoable;
}
cmVisualStudio10TargetGenerator::
cmVisualStudio10TargetGenerator(cmTarget* target,
{
this->GlobalGenerator = gg;
this->Target = target;
this->GeneratorTarget = gg->GetGeneratorTarget(target);
this->Makefile = target->GetMakefile();
this->LocalGenerator =
(cmLocalVisualStudio7Generator*)
this->Makefile->GetLocalGenerator();

Bill Hoffman
committed
this->Name = this->Target->GetName();
this->GlobalGenerator->CreateGUID(this->Name.c_str());
this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());

Bill Hoffman
committed
this->BuildFileStream = 0;
this->IsMissingFiles = false;
this->DefaultArtifactDir =
this->Makefile->GetStartOutputDirectory() + std::string("/") +
this->LocalGenerator->GetTargetDirectory(*this->Target);
}
cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
{
for(OptionsMap::iterator i = this->ClOptions.begin();
i != this->ClOptions.end(); ++i)
{
delete i->second;
}
for(OptionsMap::iterator i = this->LinkOptions.begin();
i != this->LinkOptions.end(); ++i)
{
delete i->second;
}

Bill Hoffman
committed
if(!this->BuildFileStream)
{
return;
}
if (this->BuildFileStream->Close())
{
this->GlobalGenerator
->FileReplacedDuringGenerate(this->PathToVcxproj);
}
delete this->BuildFileStream;
}
void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
const char* tag,
int indentLevel,
const char* attribute,
const char* end,
std::ostream* stream)
{
if(!stream)
{
stream = this->BuildFileStream;
}
stream->fill(' ');
stream->width(indentLevel*2 );
(*stream ) << "";
(*stream ) << "<" << tag
<< " Condition=\"'$(Configuration)|$(Platform)'=='";
(*stream ) << config << "|" << this->Platform << "'\"";
if(attribute)
{
(*stream ) << attribute;
}
// close the tag
(*stream ) << ">";
if(end)
{
(*stream ) << end;
}
}
void cmVisualStudio10TargetGenerator::WriteString(const char* line,
int indentLevel)
{
this->BuildFileStream->fill(' ');
this->BuildFileStream->width(indentLevel*2 );
// write an empty string to get the fill level indent to print
(*this->BuildFileStream ) << "";
(*this->BuildFileStream ) << line;
}
#define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"

Bill Hoffman
committed
void cmVisualStudio10TargetGenerator::Generate()

Bill Hoffman
committed
{
// do not generate external ms projects
if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|| this->Target->GetProperty("EXTERNAL_MSPROJECT"))

Bill Hoffman
committed
{
return;
}
// Tell the global generator the name of the project file

Bill Hoffman
committed
this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
".vcxproj");
if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
if(!this->ComputeClOptions())
{
return;
}
if(!this->ComputeRcOptions())
{
return;
}
if(!this->ComputeLinkOptions())
{
return;
}
cmMakefile* mf = this->Target->GetMakefile();
std::string path = mf->GetStartOutputDirectory();
path += "/";

Bill Hoffman
committed
path += this->Name;
path += ".vcxproj";
this->BuildFileStream =
new cmGeneratedFileStream(path.c_str());
this->BuildFileStream->SetCopyIfDifferent(true);
// Write the encoding header into the file
char magic[] = {0xEF,0xBB, 0xBF};
this->BuildFileStream->write(magic, 3);
//get the tools version to use
const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
std::string project_defaults=
"<?xml version=\"1.0\" encoding=\"" +
this->GlobalGenerator->Encoding() + "\"?>\n";
project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
project_defaults.append(toolsVer +"\" ");
project_defaults.append(
"xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
this->WriteString(project_defaults.c_str(),0);
this->WriteProjectConfigurations();
this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
this->WriteString("<ProjectGUID>", 2);
(*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
{
this->WriteApplicationTypeSettings();
this->VerifyNecessaryFiles();
const char* vsProjectTypes =
this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
if(vsProjectTypes)
{
this->WriteString("<ProjectTypes>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
"</ProjectTypes>\n";
}
const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
if( vsProjectName && vsLocalPath && vsProvider )
{
this->WriteString("<SccProjectName>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
"</SccProjectName>\n";
this->WriteString("<SccLocalPath>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
"</SccLocalPath>\n";
this->WriteString("<SccProvider>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
"</SccProvider>\n";
const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
if( vsAuxPath )
{
this->WriteString("<SccAuxPath>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
"</SccAuxPath>\n";
}
if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
{
this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
}
const char* vsGlobalKeyword =
this->Target->GetProperty("VS_GLOBAL_KEYWORD");
if(!vsGlobalKeyword)
{
this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
}
else
{
this->WriteString("<Keyword>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
"</Keyword>\n";
}
const char* vsGlobalRootNamespace =
this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
if(vsGlobalRootNamespace)
{
this->WriteString("<RootNamespace>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
"</RootNamespace>\n";
}
(*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
<< "</Platform>\n";
const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
if(!projLabel)
{
projLabel = this->Name.c_str();
}
this->WriteString("<ProjectName>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
if(const char* targetFrameworkVersion = this->Target->GetProperty(
"VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
{
this->WriteString("<TargetFrameworkVersion>", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
<< "</TargetFrameworkVersion>\n";
}
this->WriteString("</PropertyGroup>\n", 1);
this->WriteString("<Import Project="
"\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
1);
this->WriteProjectConfigurationValues();
this->WriteString(
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
if (this->GlobalGenerator->IsMasmEnabled())
{
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
"BuildCustomizations\\masm.props\" />\n", 2);
}
this->WriteString("</ImportGroup>\n", 1);
this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
" Condition=\"exists('" VS10_USER_PROPS "')\""
" Label=\"LocalAppDataPlatform\" />\n", 2);
this->WriteString("</ImportGroup>\n", 1);
this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
this->WriteWinRTPackageCertificateKeyFile();
this->WritePathAndIncrementalLinkOptions();
this->WriteItemDefinitionGroups();
this->WriteCustomCommands();
this->WriteAllSources();
this->WriteDotNetReferences();
this->WriteEmbeddedResourceGroup();
this->WriteWinRTReferences();
this->WriteProjectReferences();
this->WriteString(
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
" />\n", 1);
this->WriteTargetSpecificReferences();
this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
if (this->GlobalGenerator->IsMasmEnabled())
{
this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
"BuildCustomizations\\masm.targets\" />\n", 2);
}
this->WriteString("</ImportGroup>\n", 1);
this->WriteString("</Project>", 0);
// The groups are stored in a separate file for VS 10
this->WriteGroups();
}
void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
{
std::vector<std::string> references;
if(const char* vsDotNetReferences =
this->Target->GetProperty("VS_DOTNET_REFERENCES"))
{
cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
}
if(!references.empty())
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<std::string>::iterator ri = references.begin();
ri != references.end(); ++ri)
{
this->WriteString("<Reference Include=\"", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
this->WriteString("<CopyLocalSatelliteAssemblies>true"
"</CopyLocalSatelliteAssemblies>\n", 3);
this->WriteString("<ReferenceOutputAssembly>true"
"</ReferenceOutputAssembly>\n", 3);
this->WriteString("</Reference>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
}
void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
{
std::vector<cmSourceFile const*> resxObjs;
this->GeneratorTarget->GetResxSources(resxObjs, "");
if(!resxObjs.empty())
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
oi != resxObjs.end(); ++oi)
{
std::string obj = (*oi)->GetFullPath();
this->WriteString("<EmbeddedResource Include=\"", 2);
this->ConvertToWindowsSlash(obj);
(*this->BuildFileStream ) << obj << "\">\n";
this->WriteString("<DependentUpon>", 3);
std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
(*this->BuildFileStream ) << hFileName;
this->WriteString("</DependentUpon>\n", 3);
std::vector<std::string> const * configs =
this->GlobalGenerator->GetConfigurations();
for(std::vector<std::string>::const_iterator i = configs->begin();
i != configs->end(); ++i)
{
this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
{
(*this->BuildFileStream ) << "$(RootNamespace).";
}
(*this->BuildFileStream ) << "%(Filename)";
(*this->BuildFileStream ) << ".resources";
(*this->BuildFileStream ) << "</LogicalName>\n";
}
this->WriteString("</EmbeddedResource>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
}
void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
{
if(this->MSTools)
{
if(this->GlobalGenerator->TargetsWindowsPhone() &&
this->GlobalGenerator->GetSystemVersion() == "8.0")
{
this->WriteString(
"<Import Project=\""
"$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
"$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
"$(TargetPlatformVersion).targets\" />\n", 1);
}
}
}
void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
{
std::vector<std::string> references;
if(const char* vsWinRTReferences =
this->Target->GetProperty("VS_WINRT_REFERENCES"))
{
cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
}
if(this->GlobalGenerator->TargetsWindowsPhone() &&
this->GlobalGenerator->GetSystemVersion() == "8.0" &&
references.empty())
{
references.push_back("platform.winmd");
}
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<std::string>::iterator ri = references.begin();
ri != references.end(); ++ri)
{
this->WriteString("<Reference Include=\"", 2);
(*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
this->WriteString("</Reference>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
}
// ConfigurationType Application, Utility StaticLibrary DynamicLibrary
void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
{
this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
std::vector<std::string> *configs =
static_cast<cmGlobalVisualStudio7Generator *>
(this->GlobalGenerator)->GetConfigurations();
for(std::vector<std::string>::iterator i = configs->begin();
i != configs->end(); ++i)
{
this->WriteString("<ProjectConfiguration Include=\"", 2);
(*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
this->WriteString("<Configuration>", 3);
(*this->BuildFileStream ) << *i << "</Configuration>\n";
(*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
<< "</Platform>\n";
this->WriteString("</ProjectConfiguration>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
{
std::vector<std::string> *configs =
static_cast<cmGlobalVisualStudio7Generator *>
(this->GlobalGenerator)->GetConfigurations();
for(std::vector<std::string>::iterator i = configs->begin();
i != configs->end(); ++i)
{
this->WritePlatformConfigTag("PropertyGroup",
i->c_str(),
1, " Label=\"Configuration\"", "\n");
std::string configType = "<ConfigurationType>";
switch(this->Target->GetType())
{
case cmTarget::SHARED_LIBRARY:
case cmTarget::MODULE_LIBRARY:
configType += "DynamicLibrary";
break;
case cmTarget::STATIC_LIBRARY:
configType += "StaticLibrary";
break;
case cmTarget::EXECUTABLE:
configType += "Application";
break;
case cmTarget::UTILITY:
case cmTarget::GLOBAL_TARGET:
configType += "Utility";
break;
case cmTarget::UNKNOWN_LIBRARY:
case cmTarget::INTERFACE_LIBRARY:
}
configType += "</ConfigurationType>\n";
this->WriteString(configType.c_str(), 2);
if(this->MSTools)
{
this->WriteMSToolConfigurationValues(*i);
}
this->WriteString("</PropertyGroup>\n", 1);
}
}
//----------------------------------------------------------------------------
void cmVisualStudio10TargetGenerator
::WriteMSToolConfigurationValues(std::string const& config)
{
cmGlobalVisualStudio10Generator* gg =
static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
const char* mfcFlag =
this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
std::string useOfMfcValue = "false";
if(mfcFlagValue == "1")
{
useOfMfcValue = "Static";
}
else if(mfcFlagValue == "2")
{
useOfMfcValue = "Dynamic";
}
std::string mfcLine = "<UseOfMfc>";
mfcLine += useOfMfcValue + "</UseOfMfc>\n";
this->WriteString(mfcLine.c_str(), 2);
if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
this->ClOptions[config]->UsingUnicode()) ||
this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
this->GlobalGenerator->TargetsWindowsPhone() ||
this->GlobalGenerator->TargetsWindowsStore() ||
this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
{
this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
}
else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
this->ClOptions[config]->UsingSBCS())
{
this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
}
else
{
this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
}
if(const char* toolset = gg->GetPlatformToolset())
{
std::string pts = "<PlatformToolset>";
pts += toolset;
pts += "</PlatformToolset>\n";
this->WriteString(pts.c_str(), 2);
}
if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
{
this->WriteString("<WindowsAppContainer>true"
"</WindowsAppContainer>\n", 2);
}
}
void cmVisualStudio10TargetGenerator::WriteCustomCommands()
{
this->SourcesVisited.clear();
std::vector<cmSourceFile const*> customCommands;
this->GeneratorTarget->GetCustomCommands(customCommands, "");
for(std::vector<cmSourceFile const*>::const_iterator
si = customCommands.begin();
si != customCommands.end(); ++si)
{
this->WriteCustomCommand(*si);
}
}
//----------------------------------------------------------------------------
void cmVisualStudio10TargetGenerator
::WriteCustomCommand(cmSourceFile const* sf)
{
if(this->SourcesVisited.insert(sf).second)
{
if(std::vector<cmSourceFile*> const* depends =
this->GeneratorTarget->GetSourceDepends(sf))
{
for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
di != depends->end(); ++di)
{
this->WriteCustomCommand(*di);
}
}
if(cmCustomCommand const* command = sf->GetCustomCommand())
{
this->WriteString("<ItemGroup>\n", 1);
this->WriteCustomRule(sf, *command);
this->WriteString("</ItemGroup>\n", 1);
}
}
}
cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
cmCustomCommand const &
command)
{
std::string sourcePath = source->GetFullPath();
// VS 10 will always rebuild a custom command attached to a .rule
// file that doesn't exist so create the file explicitly.
if (source->GetPropertyAsBool("__CMAKE_RULE"))
{
if(!cmSystemTools::FileExists(sourcePath.c_str()))
{
// Make sure the path exists for the file
std::string path = cmSystemTools::GetFilenamePath(sourcePath);
cmSystemTools::MakeDirectory(path.c_str());
cmsys::ofstream fout(sourcePath.c_str());
if(fout)
{
fout << "# generated from CMake\n";
fout.flush();
fout.close();
}
else
{
std::string error = "Could not create file: [";
error += sourcePath;
error += "] ";
cmSystemTools::Error
(error.c_str(), cmSystemTools::GetLastSystemError().c_str());
}
}
}
cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
std::vector<std::string> *configs =
static_cast<cmGlobalVisualStudio7Generator *>
(this->GlobalGenerator)->GetConfigurations();
this->WriteSource("CustomBuild", source, ">\n");
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);
cmVS10EscapeXML(lg->ConstructScript(ccg));
this->WritePlatformConfigTag("Message",i->c_str(), 3);
(*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
this->WritePlatformConfigTag("Command", i->c_str(), 3);
(*this->BuildFileStream ) << script << "</Command>\n";
this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
(*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
for(std::vector<std::string>::const_iterator d =
ccg.GetDepends().begin();
d != ccg.GetDepends().end();
++d)
{
std::string dep;
if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
{
this->ConvertToWindowsSlash(dep);
(*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
}
(*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
const char* sep = "";
for(std::vector<std::string>::const_iterator o =
ccg.GetOutputs().begin();
o != ccg.GetOutputs().end();
++o)
{
std::string out = *o;
this->ConvertToWindowsSlash(out);
(*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
sep = ";";
}
(*this->BuildFileStream ) << "</Outputs>\n";
if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
{
// VS >= 11 let us turn off linking of custom command outputs.
this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
(*this->BuildFileStream ) << "false</LinkObjects>\n";
}
}
this->WriteString("</CustomBuild>\n", 2);
}
std::string
cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
bool forceRelative)
{
return forceRelative
? cmSystemTools::RelativePath(
this->Makefile->GetCurrentOutputDirectory(), path.c_str())
: this->LocalGenerator->Convert(path.c_str(),
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED,
/* optional = */ true);
void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
{
// first convert all of the slashes
std::string::size_type pos = 0;
while((pos = s.find('/', pos)) != std::string::npos)
{
s[pos] = '\\';
pos++;
}
}
void cmVisualStudio10TargetGenerator::WriteGroups()
// collect up group information
std::vector<cmSourceGroup> sourceGroups =
this->Makefile->GetSourceGroups();
std::vector<cmSourceFile*> classes;
if (!this->Target->GetConfigCommonSourceFiles(classes))
{
return;
}
std::set<cmSourceGroup*> groupsUsed;
for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
s != classes.end(); s++)
{
cmSourceFile* sf = *s;
std::string const& source = sf->GetFullPath();
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
this->AddMissingSourceGroups(groupsUsed, sourceGroups);
// Write out group file
std::string path = this->Makefile->GetStartOutputDirectory();
path += "/";

Bill Hoffman
committed
path += this->Name;
path += ".vcxproj.filters";
cmGeneratedFileStream fout(path.c_str());
fout.SetCopyIfDifferent(true);
char magic[] = {0xEF,0xBB, 0xBF};
fout.write(magic, 3);
cmGeneratedFileStream* save = this->BuildFileStream;
this->BuildFileStream = & fout;
//get the tools version to use
const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
std::string project_defaults=
"<?xml version=\"1.0\" encoding=\"" +
this->GlobalGenerator->Encoding() + "\"?>\n";
project_defaults.append("<Project ToolsVersion=\"");
project_defaults.append(toolsVer +"\" ");
project_defaults.append(
"xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
this->WriteString(project_defaults.c_str(),0);
for(ToolSourceMap::const_iterator ti = this->Tools.begin();
ti != this->Tools.end(); ++ti)
{
this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
}
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
// Added files are images and the manifest.
if (!this->AddedFiles.empty())
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<std::string>::const_iterator
oi = this->AddedFiles.begin(); oi != this->AddedFiles.end(); ++oi)
{
std::string fileName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameName(*oi));
if (fileName == "wmappmanifest.xml")
{
this->WriteString("<XML Include=\"", 2);
(*this->BuildFileStream) << *oi << "\">\n";
this->WriteString("<Filter>Resource Files</Filter>\n", 3);
this->WriteString("</XML>\n", 2);
}
else if(cmSystemTools::GetFilenameExtension(fileName) ==
".appxmanifest")
{
this->WriteString("<AppxManifest Include=\"", 2);
(*this->BuildFileStream) << *oi << "\">\n";
this->WriteString("<Filter>Resource Files</Filter>\n", 3);
this->WriteString("</AppxManifest>\n", 2);
}
else if(cmSystemTools::GetFilenameExtension(fileName) ==
".pfx")
{
this->WriteString("<None Include=\"", 2);
(*this->BuildFileStream) << *oi << "\">\n";
this->WriteString("<Filter>Resource Files</Filter>\n", 3);
this->WriteString("</None>\n", 2);
}
else
{
this->WriteString("<Image Include=\"", 2);
(*this->BuildFileStream) << *oi << "\">\n";
this->WriteString("<Filter>Resource Files</Filter>\n", 3);
this->WriteString("</Image>\n", 2);
}
}
this->WriteString("</ItemGroup>\n", 1);
}
std::vector<cmSourceFile const*> resxObjs;
this->GeneratorTarget->GetResxSources(resxObjs, "");
if(!resxObjs.empty())
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
oi != resxObjs.end(); ++oi)
{
std::string obj = (*oi)->GetFullPath();
this->WriteString("<EmbeddedResource Include=\"", 2);
this->ConvertToWindowsSlash(obj);
(*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
this->WriteString("<Filter>Resource Files</Filter>\n", 3);
this->WriteString("</EmbeddedResource>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
// Add object library contents as external objects.
std::vector<std::string> objs;
this->GeneratorTarget->UseObjectLibraries(objs, "");
if(!objs.empty())
{
this->WriteString("<ItemGroup>\n", 1);
for(std::vector<std::string>::const_iterator
oi = objs.begin(); oi != objs.end(); ++oi)
{
std::string obj = *oi;
this->WriteString("<Object Include=\"", 2);
this->ConvertToWindowsSlash(obj);
(*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
this->WriteString("</Object>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
}
this->WriteString("<ItemGroup>\n", 1);
for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
g != groupsUsed.end(); ++g)
{
cmSourceGroup* sg = *g;
const char* name = sg->GetFullName();
if(strlen(name) != 0)
{
this->WriteString("<Filter Include=\"", 2);
(*this->BuildFileStream) << name << "\">\n";
std::string guidName = "SG_Filter_";
guidName += name;
this->GlobalGenerator->CreateGUID(guidName.c_str());
this->WriteString("<UniqueIdentifier>", 3);
std::string guid
= this->GlobalGenerator->GetGUID(guidName.c_str());
(*this->BuildFileStream)
<< "{"
<< guid << "}"
<< "</UniqueIdentifier>\n";
this->WriteString("</Filter>\n", 2);
}
}
if(!objs.empty())
{
this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
std::string guidName = "SG_Filter_Object Libraries";
this->GlobalGenerator->CreateGUID(guidName.c_str());
this->WriteString("<UniqueIdentifier>", 3);
std::string guid =
this->GlobalGenerator->GetGUID(guidName.c_str());
(*this->BuildFileStream) << "{" << guid << "}"
<< "</UniqueIdentifier>\n";
this->WriteString("</Filter>\n", 2);
}
if(!resxObjs.empty() || !this->AddedFiles.empty())
{
this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
std::string guidName = "SG_Filter_Resource Files";
this->GlobalGenerator->CreateGUID(guidName.c_str());
this->WriteString("<UniqueIdentifier>", 3);
std::string guid =
this->GlobalGenerator->GetGUID(guidName.c_str());
(*this->BuildFileStream) << "{" << guid << "}"
<< "</UniqueIdentifier>\n";
this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
(*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
(*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
this->WriteString("</Filter>\n", 2);
}
this->WriteString("</ItemGroup>\n", 1);
this->WriteString("</Project>\n", 0);
// restore stream pointer
this->BuildFileStream = save;
if (fout.Close())
{