summaryrefslogtreecommitdiff
path: root/Source/cmVisualStudio10TargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx267
1 files changed, 208 insertions, 59 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 9cfb3703e..6376376a0 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -216,12 +216,16 @@ void cmVisualStudio10TargetGenerator::Generate()
// Write the encoding header into the file
char magic[] = {0xEF,0xBB, 0xBF};
this->BuildFileStream->write(magic, 3);
- this->WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",0);
- this->WriteString("<Project DefaultTargets=\"Build\" "
- "ToolsVersion=\"4.0\" "
- "xmlns=\"http://schemas.microsoft.com/"
- "developer/msbuild/2003\">\n",
- 0);
+
+ //get the tools version to use
+ const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
+ std::string project_defaults="<?xml version=\"1.0\" encoding=\"utf-8\"?>\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);
@@ -274,6 +278,15 @@ void cmVisualStudio10TargetGenerator::Generate()
"</Keyword>\n";
}
+ const char* vsGlobalRootNamespace =
+ this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
+ if(vsGlobalRootNamespace)
+ {
+ this->WriteString("<RootNamespace>", 2);
+ (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
+ "</RootNamespace>\n";
+ }
+
this->WriteString("<Platform>", 2);
(*this->BuildFileStream) << this->Platform << "</Platform>\n";
const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
@@ -283,6 +296,13 @@ void cmVisualStudio10TargetGenerator::Generate()
}
this->WriteString("<ProjectName>", 2);
(*this->BuildFileStream) << projLabel << "</ProjectName>\n";
+ if(const char* targetFrameworkVersion = this->Target->GetProperty(
+ "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
+ {
+ this->WriteString("<TargetFrameworkVersion>", 2);
+ (*this->BuildFileStream) << targetFrameworkVersion
+ << "</TargetFrameworkVersion>\n";
+ }
this->WriteString("</PropertyGroup>\n", 1);
this->WriteString("<Import Project="
"\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
@@ -291,6 +311,11 @@ void cmVisualStudio10TargetGenerator::Generate()
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 "\""
@@ -303,12 +328,18 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WriteCustomCommands();
this->WriteAllSources();
this->WriteDotNetReferences();
+ this->WriteEmbeddedResourceGroup();
this->WriteWinRTReferences();
this->WriteProjectReferences();
this->WriteString(
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
" />\n", 1);
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
@@ -341,6 +372,47 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
}
}
+void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
+{
+ std::vector<cmSourceFile*> const& resxObjs =
+ this->GeneratorTarget->ResxSources;
+ if(!resxObjs.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<cmSourceFile*>::const_iterator oi = resxObjs.begin();
+ 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::WriteWinRTReferences()
{
std::vector<std::string> references;
@@ -467,6 +539,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
this->WriteString("<WindowsAppContainer>true"
"</WindowsAppContainer>\n", 2);
}
+
this->WriteString("</PropertyGroup>\n", 1);
}
}
@@ -647,18 +720,40 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
fout.write(magic, 3);
cmGeneratedFileStream* save = this->BuildFileStream;
this->BuildFileStream = & fout;
- this->WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<Project "
- "ToolsVersion=\"4.0\" "
- "xmlns=\"http://schemas.microsoft.com/"
- "developer/msbuild/2003\">\n",
- 0);
+
+ //get the tools version to use
+ const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
+ std::string project_defaults="<?xml version=\"1.0\" encoding=\"utf-8\"?>\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);
}
+ std::vector<cmSourceFile*> const& resxObjs =
+ this->GeneratorTarget->ResxSources;
+ if(!resxObjs.empty())
+ {
+ this->WriteString("<ItemGroup>\n", 1);
+ for(std::vector<cmSourceFile*>::const_iterator oi = resxObjs.begin();
+ oi != resxObjs.end(); ++oi)
+ {
+ std::string obj = (*oi)->GetFullPath();
+ this->WriteString("<EmbeddedResource Include=\"", 2);
+ this->ConvertToWindowsSlash(obj);
+ (*this->BuildFileStream ) << 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);
@@ -713,6 +808,23 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
<< "</UniqueIdentifier>\n";
this->WriteString("</Filter>\n", 2);
}
+
+ if(!this->GeneratorTarget->ResxSources.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
@@ -844,8 +956,20 @@ void cmVisualStudio10TargetGenerator::WriteSource(
}
this->ConvertToWindowsSlash(sourceFile);
this->WriteString("<", 2);
- (*this->BuildFileStream ) << tool <<
- " Include=\"" << sourceFile << "\"" << (end? end : " />\n");
+ (*this->BuildFileStream ) << tool << " Include=\"" << sourceFile << "\"";
+
+ if(sf->GetExtension() == "h" &&
+ this->IsResxHeader(sf->GetFullPath()))
+ {
+ (*this->BuildFileStream ) << ">\n";
+ this->WriteString("<FileType>CppForm</FileType>\n", 3);
+ this->WriteString("</ClInclude>\n", 2);
+ }
+ else
+ {
+ (*this->BuildFileStream ) << (end? end : " />\n");
+ }
+
ToolSource toolSource = {sf, forceRelative};
this->Tools[tool].push_back(toolSource);
}
@@ -876,24 +1000,37 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
si != this->GeneratorTarget->ObjectSources.end(); ++si)
{
const char* lang = (*si)->GetLanguage();
- bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0;
- bool rc = strcmp(lang, "RC") == 0;
- const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None");
- this->WriteSource(tool, *si, " ");
- // ouput any flags specific to this source file
- if(cl && this->OutputSourceSpecificFlags(*si))
+ const char* tool = NULL;
+ if (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0)
{
- // if the source file has specific flags the tag
- // is ended on a new line
- this->WriteString("</ClCompile>\n", 2);
+ tool = "ClCompile";
}
- else if(rc && this->OutputSourceSpecificFlags(*si))
+ else if (strcmp(lang, "ASM_MASM") == 0 &&
+ this->GlobalGenerator->IsMasmEnabled())
{
- this->WriteString("</ResourceCompile>\n", 2);
+ tool = "MASM";
+ }
+ else if (strcmp(lang, "RC") == 0)
+ {
+ tool = "ResourceCompile";
+ }
+
+ if (tool)
+ {
+ this->WriteSource(tool, *si, " ");
+ if (this->OutputSourceSpecificFlags(*si))
+ {
+ this->WriteString("</", 2);
+ (*this->BuildFileStream ) << tool << ">\n";
+ }
+ else
+ {
+ (*this->BuildFileStream ) << " />\n";
+ }
}
else
{
- (*this->BuildFileStream ) << " />\n";
+ this->WriteSource("None", *si);
}
}
@@ -1192,7 +1329,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
if(!linkLanguage)
{
cmSystemTools::Error
- ("CMake can not determine linker language for target:",
+ ("CMake can not determine linker language for target: ",
this->Name.c_str());
return false;
}
@@ -1219,21 +1356,21 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
{
flags += " /TP ";
}
+ this->LocalGenerator->AddCompileOptions(flags, this->Target,
+ linkLanguage, configName.c_str());
}
- // Add the target-specific flags.
- if(const char* targetFlags = this->Target->GetProperty("COMPILE_FLAGS"))
- {
- flags += " ";
- flags += targetFlags;
- }
+
// Get preprocessor definitions for this directory.
std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
clOptions.FixExceptionHandlingDefault();
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
+ std::string asmLocation = configName + "/";
+ clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
clOptions.Parse(flags.c_str());
clOptions.Parse(defineFlags.c_str());
- clOptions.AddDefines(this->Target->GetCompileDefinitions(
- configName.c_str()).c_str());
+ std::vector<std::string> targetDefines;
+ this->Target->GetCompileDefinitions(targetDefines, configName.c_str());
+ clOptions.AddDefines(targetDefines);
clOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
@@ -1272,18 +1409,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
"\n", "CXX");
- this->WriteString("<AssemblerListingLocation>", 3);
- *this->BuildFileStream << configName
- << "</AssemblerListingLocation>\n";
this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
- if(this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
- {
- this->WriteString("<ProgramDataBaseFileName>", 3);
- *this->BuildFileStream << this->Target->GetPDBDirectory(configName.c_str())
- << "/"
- << this->Target->GetPDBName(configName.c_str())
- << "</ProgramDataBaseFileName>\n";
- }
this->WriteString("</ClCompile>\n", 2);
}
@@ -1294,7 +1420,9 @@ OutputIncludes(std::vector<std::string> const & includes)
for(std::vector<std::string>::const_iterator i = includes.begin();
i != includes.end(); ++i)
{
- *this->BuildFileStream << *i << ";";
+ std::string incDir = *i;
+ this->ConvertToWindowsSlash(incDir);
+ *this->BuildFileStream << cmVS10EscapeXML(incDir) << ";";
}
this->WriteString("%(AdditionalIncludeDirectories)"
"</AdditionalIncludeDirectories>\n", 0);
@@ -1322,20 +1450,17 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
{
return;
}
- const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS");
- std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_";
- flagsConfigVar += cmSystemTools::UpperCase(config);
- const char* libflagsConfig =
- this->Target->GetProperty(flagsConfigVar.c_str());
- if(libflags || libflagsConfig)
+ std::string libflags;
+ this->LocalGenerator->GetStaticLibraryFlags(libflags,
+ cmSystemTools::UpperCase(config), this->Target);
+ if(!libflags.empty())
{
this->WriteString("<Lib>\n", 2);
cmVisualStudioGeneratorOptions
libOptions(this->LocalGenerator,
cmVisualStudioGeneratorOptions::Linker,
cmVSGetLibFlagTable(this->LocalGenerator), 0, this);
- libOptions.Parse(libflags?libflags:"");
- libOptions.Parse(libflagsConfig?libflagsConfig:"");
+ libOptions.Parse(libflags.c_str());
libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
libOptions.OutputFlagMap(*this->BuildFileStream, " ");
this->WriteString("</Lib>\n", 2);
@@ -1377,7 +1502,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
if(!linkLanguage)
{
cmSystemTools::Error
- ("CMake can not determine linker language for target:",
+ ("CMake can not determine linker language for target: ",
this->Name.c_str());
return false;
}
@@ -1428,11 +1553,11 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
}
if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
{
- flags += " /SUBSYSTEM:WINDOWS";
+ linkOptions.AddFlag("SubSystem", "Windows");
}
else
{
- flags += " /SUBSYSTEM:CONSOLE";
+ linkOptions.AddFlag("SubSystem", "Console");
}
std::string standardLibsVar = "CMAKE_";
standardLibsVar += linkLanguage;
@@ -1459,7 +1584,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
if(!pcli)
{
cmSystemTools::Error
- ("CMake can not compute cmComputeLinkInformation for target:",
+ ("CMake can not compute cmComputeLinkInformation for target: ",
this->Name.c_str());
return false;
}
@@ -1591,6 +1716,21 @@ void cmVisualStudio10TargetGenerator::
WriteMidlOptions(std::string const& /*config*/,
std::vector<std::string> const & includes)
{
+ // This processes *any* of the .idl files specified in the project's file
+ // list (and passed as the item metadata %(Filename) expressing the rule
+ // input filename) into output files at the per-config *build* dir
+ // ($(IntDir)) each.
+ //
+ // IOW, this MIDL section is intended to provide a fully generic syntax
+ // content suitable for most cases (read: if you get errors, then it's quite
+ // probable that the error is on your side of the .idl setup).
+ //
+ // Also, note that the marked-as-generated _i.c file in the Visual Studio
+ // generator case needs to be referred to as $(IntDir)\foo_i.c at the
+ // project's file list, otherwise the compiler-side processing won't pick it
+ // up (for non-directory form, it ends up looking in project binary dir
+ // only). Perhaps there's something to be done to make this more automatic
+ // on the CMake side?
this->WriteString("<Midl>\n", 2);
this->OutputIncludes(includes);
this->WriteString("<OutputDirectory>$(IntDir)</OutputDirectory>\n", 3);
@@ -1730,3 +1870,12 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
}
this->WriteString("</ItemGroup>\n", 1);
}
+
+bool cmVisualStudio10TargetGenerator::
+ IsResxHeader(const std::string& headerFile)
+{
+ std::set<std::string>::iterator it =
+ this->GeneratorTarget->ExpectedResxHeaders.find(headerFile);
+
+ return it != this->GeneratorTarget->ExpectedResxHeaders.end();
+}