mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-23 00:48:55 +08:00
cmVisualStudio10TargetGenerator: Factor out helper for classic MSBuild project
In preparation for generating .Net SDK style project, refactor cmVisualStudio10TargetGenerato::Generate to split the functionality to write classic MSBuild project file. This commit only introduces a helper function and moves the functionality there. A later commit will add WriteSdkStyleProjectFile, the call to it, and the rest of the .Net SDK-style changes.
This commit is contained in:

committed by
Brad King

parent
029c8f5065
commit
fa76e5d194
@@ -405,6 +405,20 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
// Write the encoding header into the file
|
// Write the encoding header into the file
|
||||||
char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
|
char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
|
||||||
BuildFileStream.write(magic, 3);
|
BuildFileStream.write(magic, 3);
|
||||||
|
|
||||||
|
this->WriteClassicMsBuildProjectFile(BuildFileStream);
|
||||||
|
|
||||||
|
if (BuildFileStream.Close()) {
|
||||||
|
this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The groups are stored in a separate file for VS 10
|
||||||
|
this->WriteGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile(
|
||||||
|
cmGeneratedFileStream& BuildFileStream)
|
||||||
|
{
|
||||||
BuildFileStream << "<?xml version=\"1.0\" encoding=\""
|
BuildFileStream << "<?xml version=\"1.0\" encoding=\""
|
||||||
<< this->GlobalGenerator->Encoding() << "\"?>";
|
<< this->GlobalGenerator->Encoding() << "\"?>";
|
||||||
{
|
{
|
||||||
@@ -453,8 +467,7 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
|
|
||||||
{
|
{
|
||||||
Elem e1(e0, "PropertyGroup");
|
Elem e1(e0, "PropertyGroup");
|
||||||
e1.Attribute("Label", "Globals");
|
this->WriteCommonPropertyGroupGlobals(e1);
|
||||||
e1.Element("ProjectGuid", "{" + this->GUID + "}");
|
|
||||||
|
|
||||||
if ((this->MSTools || this->Android) &&
|
if ((this->MSTools || this->Android) &&
|
||||||
this->GeneratorTarget->IsInBuildSystem()) {
|
this->GeneratorTarget->IsInBuildSystem()) {
|
||||||
@@ -462,16 +475,6 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
this->VerifyNecessaryFiles();
|
this->VerifyNecessaryFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmValue vsProjectTypes =
|
|
||||||
this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
|
|
||||||
if (vsProjectTypes) {
|
|
||||||
const char* tagName = "ProjectTypes";
|
|
||||||
if (this->ProjectType == VsProjectType::csproj) {
|
|
||||||
tagName = "ProjectTypeGuids";
|
|
||||||
}
|
|
||||||
e1.Element(tagName, *vsProjectTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmValue vsProjectName =
|
cmValue vsProjectName =
|
||||||
this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
|
this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
|
||||||
cmValue vsLocalPath =
|
cmValue vsLocalPath =
|
||||||
@@ -495,24 +498,6 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
e1.Element("WinMDAssembly", "true");
|
e1.Element("WinMDAssembly", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
cmValue vsGlobalKeyword =
|
|
||||||
this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
|
|
||||||
if (!vsGlobalKeyword) {
|
|
||||||
if (this->GlobalGenerator->TargetsAndroid()) {
|
|
||||||
e1.Element("Keyword", "Android");
|
|
||||||
} else {
|
|
||||||
e1.Element("Keyword", "Win32Proj");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
e1.Element("Keyword", *vsGlobalKeyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmValue vsGlobalRootNamespace =
|
|
||||||
this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
|
|
||||||
if (vsGlobalRootNamespace) {
|
|
||||||
e1.Element("RootNamespace", *vsGlobalRootNamespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
e1.Element("Platform", this->Platform);
|
e1.Element("Platform", this->Platform);
|
||||||
cmValue projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL");
|
cmValue projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL");
|
||||||
e1.Element("ProjectName", projLabel ? projLabel : this->Name);
|
e1.Element("ProjectName", projLabel ? projLabel : this->Name);
|
||||||
@@ -602,24 +587,6 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
e1.Element("VCTargetsPath", vcTargetsPath);
|
e1.Element("VCTargetsPath", vcTargetsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
|
|
||||||
for (std::string const& keyIt : keys) {
|
|
||||||
static const cm::string_view prefix = "VS_GLOBAL_";
|
|
||||||
if (!cmHasPrefix(keyIt, prefix))
|
|
||||||
continue;
|
|
||||||
cm::string_view globalKey =
|
|
||||||
cm::string_view(keyIt).substr(prefix.length());
|
|
||||||
// Skip invalid or separately-handled properties.
|
|
||||||
if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
|
|
||||||
globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cmValue value = this->GeneratorTarget->GetProperty(keyIt);
|
|
||||||
if (!value)
|
|
||||||
continue;
|
|
||||||
e1.Element(globalKey, *value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->Managed) {
|
if (this->Managed) {
|
||||||
if (this->LocalGenerator->GetVersion() >=
|
if (this->LocalGenerator->GetVersion() >=
|
||||||
cmGlobalVisualStudioGenerator::VS17) {
|
cmGlobalVisualStudioGenerator::VS17) {
|
||||||
@@ -839,13 +806,57 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (BuildFileStream.Close()) {
|
void cmVisualStudio10TargetGenerator::WriteCommonPropertyGroupGlobals(Elem& e1)
|
||||||
this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
|
{
|
||||||
|
e1.Attribute("Label", "Globals");
|
||||||
|
e1.Element("ProjectGuid", "{" + this->GUID + "}");
|
||||||
|
|
||||||
|
cmValue vsProjectTypes =
|
||||||
|
this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
|
||||||
|
if (vsProjectTypes) {
|
||||||
|
const char* tagName = "ProjectTypes";
|
||||||
|
if (this->ProjectType == VsProjectType::csproj) {
|
||||||
|
tagName = "ProjectTypeGuids";
|
||||||
|
}
|
||||||
|
e1.Element(tagName, *vsProjectTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The groups are stored in a separate file for VS 10
|
cmValue vsGlobalKeyword =
|
||||||
this->WriteGroups();
|
this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
|
||||||
|
if (!vsGlobalKeyword) {
|
||||||
|
if (this->GlobalGenerator->TargetsAndroid()) {
|
||||||
|
e1.Element("Keyword", "Android");
|
||||||
|
} else {
|
||||||
|
e1.Element("Keyword", "Win32Proj");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e1.Element("Keyword", *vsGlobalKeyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmValue vsGlobalRootNamespace =
|
||||||
|
this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
|
||||||
|
if (vsGlobalRootNamespace) {
|
||||||
|
e1.Element("RootNamespace", *vsGlobalRootNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
|
||||||
|
for (std::string const& keyIt : keys) {
|
||||||
|
static const cm::string_view prefix = "VS_GLOBAL_";
|
||||||
|
if (!cmHasPrefix(keyIt, prefix))
|
||||||
|
continue;
|
||||||
|
cm::string_view globalKey = cm::string_view(keyIt).substr(prefix.length());
|
||||||
|
// Skip invalid or separately-handled properties.
|
||||||
|
if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
|
||||||
|
globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cmValue value = this->GeneratorTarget->GetProperty(keyIt);
|
||||||
|
if (!value)
|
||||||
|
continue;
|
||||||
|
e1.Element(globalKey, *value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
|
void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
class cmComputeLinkInformation;
|
class cmComputeLinkInformation;
|
||||||
class cmCustomCommand;
|
class cmCustomCommand;
|
||||||
class cmCustomCommandGenerator;
|
class cmCustomCommandGenerator;
|
||||||
|
class cmGeneratedFileStream;
|
||||||
class cmGlobalVisualStudio10Generator;
|
class cmGlobalVisualStudio10Generator;
|
||||||
class cmLocalVisualStudio10Generator;
|
class cmLocalVisualStudio10Generator;
|
||||||
class cmMakefile;
|
class cmMakefile;
|
||||||
@@ -260,6 +261,12 @@ private:
|
|||||||
void ClassifyAllConfigSources();
|
void ClassifyAllConfigSources();
|
||||||
void ClassifyAllConfigSource(cmGeneratorTarget::AllConfigSource const& acs);
|
void ClassifyAllConfigSource(cmGeneratorTarget::AllConfigSource const& acs);
|
||||||
|
|
||||||
|
// .Net SDK-stype project variable and helper functions
|
||||||
|
void WriteClassicMsBuildProjectFile(cmGeneratedFileStream& BuildFileStream);
|
||||||
|
|
||||||
|
void WriteCommonPropertyGroupGlobals(
|
||||||
|
cmVisualStudio10TargetGenerator::Elem& e1);
|
||||||
|
|
||||||
std::unordered_map<std::string, ConfigToSettings> ParsedToolTargetSettings;
|
std::unordered_map<std::string, ConfigToSettings> ParsedToolTargetSettings;
|
||||||
bool PropertyIsSameInAllConfigs(const ConfigToSettings& toolSettings,
|
bool PropertyIsSameInAllConfigs(const ConfigToSettings& toolSettings,
|
||||||
const std::string& propName);
|
const std::string& propName);
|
||||||
|
Reference in New Issue
Block a user