cmVisualStudio10TargetGenerator: Adopt Windows Store and Phone infrastructure

Move support for Resx, Xaml, Certificate, and AppManifest file handling
out of cmGeneratorTarget.
This commit is contained in:
Brad King
2020-05-15 07:33:08 -04:00
parent 3fa3b7a402
commit 65fe58a4b4
4 changed files with 119 additions and 147 deletions
+12 -63
View File
@@ -976,51 +976,12 @@ void cmGeneratorTarget::GetExternalObjects(
IMPLEMENT_VISIT(SourceKindExternalObject); IMPLEMENT_VISIT(SourceKindExternalObject);
} }
void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& headers,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
headers = kinded.ExpectedResxHeaders;
}
void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindResx);
}
void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindAppManifest);
}
void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data, void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
const std::string& config) const const std::string& config) const
{ {
IMPLEMENT_VISIT(SourceKindManifest); IMPLEMENT_VISIT(SourceKindManifest);
} }
void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindCertificate);
}
void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
headers = kinded.ExpectedXamlHeaders;
}
void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
srcs = kinded.ExpectedXamlSources;
}
std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
{ {
if (!this->UtilityItemsDone) { if (!this->UtilityItemsDone) {
@@ -1040,12 +1001,6 @@ std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
return this->UtilityItems; return this->UtilityItems;
} }
void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindXaml);
}
const std::string& cmGeneratorTarget::GetLocation( const std::string& cmGeneratorTarget::GetLocation(
const std::string& config) const const std::string& config) const
{ {
@@ -1728,14 +1683,6 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
} }
} else if (ext == "resx") { } else if (ext == "resx") {
kind = SourceKindResx; kind = SourceKindResx;
// Build and save the name of the corresponding .h file
// This relationship will be used later when building the project files.
// Both names would have been auto generated from Visual Studio
// where the user supplied the file name and Visual Studio
// appended the suffix.
std::string resx = sf->ResolveFullPath();
std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
files.ExpectedResxHeaders.insert(hFileName);
} else if (ext == "appxmanifest") { } else if (ext == "appxmanifest") {
kind = SourceKindAppManifest; kind = SourceKindAppManifest;
} else if (ext == "manifest") { } else if (ext == "manifest") {
@@ -1744,16 +1691,6 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
kind = SourceKindCertificate; kind = SourceKindCertificate;
} else if (ext == "xaml") { } else if (ext == "xaml") {
kind = SourceKindXaml; kind = SourceKindXaml;
// Build and save the name of the corresponding .h and .cpp file
// This relationship will be used later when building the project files.
// Both names would have been auto generated from Visual Studio
// where the user supplied the file name and Visual Studio
// appended the suffix.
std::string xaml = sf->ResolveFullPath();
std::string hFileName = xaml + ".h";
std::string cppFileName = xaml + ".cpp";
files.ExpectedXamlHeaders.insert(hFileName);
files.ExpectedXamlSources.insert(cppFileName);
} else if (header_regex.find(sf->ResolveFullPath())) { } else if (header_regex.find(sf->ResolveFullPath())) {
kind = SourceKindHeader; kind = SourceKindHeader;
} else { } else {
@@ -1811,6 +1748,18 @@ void cmGeneratorTarget::ComputeAllConfigSources() const
} }
} }
std::vector<cmGeneratorTarget::AllConfigSource>
cmGeneratorTarget::GetAllConfigSources(SourceKind kind) const
{
std::vector<AllConfigSource> result;
for (AllConfigSource const& source : this->GetAllConfigSources()) {
if (source.Kind == kind) {
result.push_back(source);
}
}
return result;
}
std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const
{ {
std::set<std::string> languages; std::set<std::string> languages;
+3 -17
View File
@@ -117,9 +117,6 @@ public:
struct KindedSources struct KindedSources
{ {
std::vector<SourceAndKind> Sources; std::vector<SourceAndKind> Sources;
std::set<std::string> ExpectedResxHeaders;
std::set<std::string> ExpectedXamlHeaders;
std::set<std::string> ExpectedXamlSources;
bool Initialized = false; bool Initialized = false;
}; };
@@ -137,6 +134,9 @@ public:
per-source configurations assigned. */ per-source configurations assigned. */
std::vector<AllConfigSource> const& GetAllConfigSources() const; std::vector<AllConfigSource> const& GetAllConfigSources() const;
/** Get all sources needed for all configurations with given kind. */
std::vector<AllConfigSource> GetAllConfigSources(SourceKind kind) const;
/** Get all languages used to compile sources in any configuration. /** Get all languages used to compile sources in any configuration.
This excludes the languages of objects from object libraries. */ This excludes the languages of objects from object libraries. */
std::set<std::string> GetAllConfigCompileLanguages() const; std::set<std::string> GetAllConfigCompileLanguages() const;
@@ -151,8 +151,6 @@ public:
void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&, void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&,
const std::string& config) const; const std::string& config) const;
void GetResxSources(std::vector<cmSourceFile const*>&,
const std::string& config) const;
void GetExternalObjects(std::vector<cmSourceFile const*>&, void GetExternalObjects(std::vector<cmSourceFile const*>&,
const std::string& config) const; const std::string& config) const;
void GetHeaderSources(std::vector<cmSourceFile const*>&, void GetHeaderSources(std::vector<cmSourceFile const*>&,
@@ -161,20 +159,8 @@ public:
const std::string& config) const; const std::string& config) const;
void GetCustomCommands(std::vector<cmSourceFile const*>&, void GetCustomCommands(std::vector<cmSourceFile const*>&,
const std::string& config) const; const std::string& config) const;
void GetExpectedResxHeaders(std::set<std::string>&,
const std::string& config) const;
void GetAppManifest(std::vector<cmSourceFile const*>&,
const std::string& config) const;
void GetManifests(std::vector<cmSourceFile const*>&, void GetManifests(std::vector<cmSourceFile const*>&,
const std::string& config) const; const std::string& config) const;
void GetCertificates(std::vector<cmSourceFile const*>&,
const std::string& config) const;
void GetXamlSources(std::vector<cmSourceFile const*>&,
const std::string& config) const;
void GetExpectedXamlHeaders(std::set<std::string>&,
const std::string& config) const;
void GetExpectedXamlSources(std::set<std::string>&,
const std::string& config) const;
std::set<cmLinkItem> const& GetUtilityItems() const; std::set<cmLinkItem> const& GetUtilityItems() const;
+94 -66
View File
@@ -248,6 +248,7 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() == this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
this->Makefile->GetCurrentBinaryDirectory()); this->Makefile->GetCurrentBinaryDirectory());
this->ClassifyAllConfigSources();
} }
cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
@@ -921,13 +922,11 @@ void cmVisualStudio10TargetGenerator::WriteDotNetDocumentationFile(Elem& e0)
void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
{ {
std::vector<cmSourceFile const*> resxObjs; if (!this->ResxObjs.empty()) {
this->GeneratorTarget->GetResxSources(resxObjs, "");
if (!resxObjs.empty()) {
Elem e1(e0, "ItemGroup"); Elem e1(e0, "ItemGroup");
std::string srcDir = this->Makefile->GetCurrentSourceDirectory(); std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
ConvertToWindowsSlash(srcDir); ConvertToWindowsSlash(srcDir);
for (cmSourceFile const* oi : resxObjs) { for (cmSourceFile const* oi : this->ResxObjs) {
std::string obj = oi->GetFullPath(); std::string obj = oi->GetFullPath();
ConvertToWindowsSlash(obj); ConvertToWindowsSlash(obj);
bool useRelativePath = false; bool useRelativePath = false;
@@ -1016,11 +1015,9 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0) void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
{ {
std::vector<cmSourceFile const*> xamlObjs; if (!this->XamlObjs.empty()) {
this->GeneratorTarget->GetXamlSources(xamlObjs, "");
if (!xamlObjs.empty()) {
Elem e1(e0, "ItemGroup"); Elem e1(e0, "ItemGroup");
for (cmSourceFile const* oi : xamlObjs) { for (cmSourceFile const* oi : this->XamlObjs) {
std::string obj = oi->GetFullPath(); std::string obj = oi->GetFullPath();
std::string xamlType; std::string xamlType;
cmProp xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE"); cmProp xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE");
@@ -1624,11 +1621,9 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
} }
} }
std::vector<cmSourceFile const*> resxObjs; if (!this->ResxObjs.empty()) {
this->GeneratorTarget->GetResxSources(resxObjs, "");
if (!resxObjs.empty()) {
Elem e1(e0, "ItemGroup"); Elem e1(e0, "ItemGroup");
for (cmSourceFile const* oi : resxObjs) { for (cmSourceFile const* oi : this->ResxObjs) {
std::string obj = oi->GetFullPath(); std::string obj = oi->GetFullPath();
ConvertToWindowsSlash(obj); ConvertToWindowsSlash(obj);
Elem e2(e1, "EmbeddedResource"); Elem e2(e1, "EmbeddedResource");
@@ -1656,7 +1651,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
} }
} }
if (!resxObjs.empty() || !this->AddedFiles.empty()) { if (!this->ResxObjs.empty() || !this->AddedFiles.empty()) {
std::string guidName = "SG_Filter_Resource Files"; std::string guidName = "SG_Filter_Resource Files";
std::string guid = this->GlobalGenerator->GetGUID(guidName); std::string guid = this->GlobalGenerator->GetGUID(guidName);
Elem e2(e1, "Filter"); Elem e2(e1, "Filter");
@@ -2209,10 +2204,10 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
} }
} break; } break;
case cmGeneratorTarget::SourceKindResx: case cmGeneratorTarget::SourceKindResx:
// Handled elsewhere. this->ResxObjs.push_back(si.Source);
break; break;
case cmGeneratorTarget::SourceKindXaml: case cmGeneratorTarget::SourceKindXaml:
// Handled elsewhere. this->XamlObjs.push_back(si.Source);
break; break;
} }
@@ -3493,12 +3488,12 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
// its location as the root source directory. // its location as the root source directory.
std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory(); std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
{ {
std::vector<cmSourceFile const*> extraSources; for (cmGeneratorTarget::AllConfigSource const& source :
this->GeneratorTarget->GetExtraSources(extraSources, ""); this->GeneratorTarget->GetAllConfigSources()) {
for (cmSourceFile const* si : extraSources) { if (source.Kind == cmGeneratorTarget::SourceKindExtra &&
if ("androidmanifest.xml" == "androidmanifest.xml" ==
cmSystemTools::LowerCase(si->GetLocation().GetName())) { cmSystemTools::LowerCase(source.Source->GetLocation().GetName())) {
rootDir = si->GetLocation().GetDirectory(); rootDir = source.Source->GetLocation().GetDirectory();
break; break;
} }
} }
@@ -4234,12 +4229,13 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
this->GlobalGenerator->TargetsWindowsPhone()) && this->GlobalGenerator->TargetsWindowsPhone()) &&
(cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) { (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
std::string pfxFile; std::string pfxFile;
std::vector<cmSourceFile const*> certificates; for (cmGeneratorTarget::AllConfigSource const& source :
this->GeneratorTarget->GetCertificates(certificates, ""); this->GeneratorTarget->GetAllConfigSources()) {
for (cmSourceFile const* si : certificates) { if (source.Kind == cmGeneratorTarget::SourceKindCertificate) {
pfxFile = this->ConvertPath(si->GetFullPath(), false); pfxFile = this->ConvertPath(source.Source->GetFullPath(), false);
ConvertToWindowsSlash(pfxFile); ConvertToWindowsSlash(pfxFile);
break; break;
}
} }
if (this->IsMissingFiles && if (this->IsMissingFiles &&
@@ -4285,28 +4281,61 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
} }
} }
void cmVisualStudio10TargetGenerator::ClassifyAllConfigSources()
{
for (cmGeneratorTarget::AllConfigSource const& source :
this->GeneratorTarget->GetAllConfigSources()) {
this->ClassifyAllConfigSource(source);
}
}
void cmVisualStudio10TargetGenerator::ClassifyAllConfigSource(
cmGeneratorTarget::AllConfigSource const& acs)
{
switch (acs.Kind) {
case cmGeneratorTarget::SourceKindResx: {
// Build and save the name of the corresponding .h file
// This relationship will be used later when building the project files.
// Both names would have been auto generated from Visual Studio
// where the user supplied the file name and Visual Studio
// appended the suffix.
std::string resx = acs.Source->ResolveFullPath();
std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
this->ExpectedResxHeaders.insert(hFileName);
} break;
case cmGeneratorTarget::SourceKindXaml: {
// Build and save the name of the corresponding .h and .cpp file
// This relationship will be used later when building the project files.
// Both names would have been auto generated from Visual Studio
// where the user supplied the file name and Visual Studio
// appended the suffix.
std::string xaml = acs.Source->ResolveFullPath();
std::string hFileName = xaml + ".h";
std::string cppFileName = xaml + ".cpp";
this->ExpectedXamlHeaders.insert(hFileName);
this->ExpectedXamlSources.insert(cppFileName);
} break;
default:
break;
}
}
bool cmVisualStudio10TargetGenerator::IsResxHeader( bool cmVisualStudio10TargetGenerator::IsResxHeader(
const std::string& headerFile) const std::string& headerFile)
{ {
std::set<std::string> expectedResxHeaders; return this->ExpectedResxHeaders.count(headerFile) > 0;
this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
return expectedResxHeaders.count(headerFile) > 0;
} }
bool cmVisualStudio10TargetGenerator::IsXamlHeader( bool cmVisualStudio10TargetGenerator::IsXamlHeader(
const std::string& headerFile) const std::string& headerFile)
{ {
std::set<std::string> expectedXamlHeaders; return this->ExpectedXamlHeaders.count(headerFile) > 0;
this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
return expectedXamlHeaders.count(headerFile) > 0;
} }
bool cmVisualStudio10TargetGenerator::IsXamlSource( bool cmVisualStudio10TargetGenerator::IsXamlSource(
const std::string& sourceFile) const std::string& sourceFile)
{ {
std::set<std::string> expectedXamlSources; return this->ExpectedXamlSources.count(sourceFile) > 0;
this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
return expectedXamlSources.count(sourceFile) > 0;
} }
void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1) void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1)
@@ -4387,39 +4416,38 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
// For Windows and Windows Phone executables, we will assume that if a // For Windows and Windows Phone executables, we will assume that if a
// manifest is not present that we need to add all the necessary files // manifest is not present that we need to add all the necessary files
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
std::vector<cmSourceFile const*> manifestSources; std::vector<cmGeneratorTarget::AllConfigSource> manifestSources =
this->GeneratorTarget->GetAppManifest(manifestSources, ""); this->GeneratorTarget->GetAllConfigSources(
{ cmGeneratorTarget::SourceKindAppManifest);
std::string const& v = this->GlobalGenerator->GetSystemVersion(); std::string const& v = this->GlobalGenerator->GetSystemVersion();
if (this->GlobalGenerator->TargetsWindowsPhone()) { if (this->GlobalGenerator->TargetsWindowsPhone()) {
if (v == "8.0") { if (v == "8.0") {
// Look through the sources for WMAppManifest.xml // Look through the sources for WMAppManifest.xml
std::vector<cmSourceFile const*> extraSources; bool foundManifest = false;
this->GeneratorTarget->GetExtraSources(extraSources, ""); for (cmGeneratorTarget::AllConfigSource const& source :
bool foundManifest = false; this->GeneratorTarget->GetAllConfigSources()) {
for (cmSourceFile const* si : extraSources) { if (source.Kind == cmGeneratorTarget::SourceKindExtra &&
// Need to do a lowercase comparison on the filename "wmappmanifest.xml" ==
if ("wmappmanifest.xml" == cmSystemTools::LowerCase(
cmSystemTools::LowerCase(si->GetLocation().GetName())) { source.Source->GetLocation().GetName())) {
foundManifest = true; foundManifest = true;
break; break;
}
}
if (!foundManifest) {
this->IsMissingFiles = true;
}
} else if (v == "8.1") {
if (manifestSources.empty()) {
this->IsMissingFiles = true;
} }
} }
} else if (this->GlobalGenerator->TargetsWindowsStore()) { if (!foundManifest) {
this->IsMissingFiles = true;
}
} else if (v == "8.1") {
if (manifestSources.empty()) { if (manifestSources.empty()) {
if (v == "8.0") { this->IsMissingFiles = true;
this->IsMissingFiles = true; }
} else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) { }
this->IsMissingFiles = true; } else if (this->GlobalGenerator->TargetsWindowsStore()) {
} if (manifestSources.empty()) {
if (v == "8.0") {
this->IsMissingFiles = true;
} else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
this->IsMissingFiles = true;
} }
} }
} }
+10 -1
View File
@@ -13,10 +13,11 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "cmGeneratorTarget.h"
class cmComputeLinkInformation; class cmComputeLinkInformation;
class cmCustomCommand; class cmCustomCommand;
class cmGeneratedFileStream; class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmGlobalVisualStudio10Generator; class cmGlobalVisualStudio10Generator;
class cmLocalVisualStudio10Generator; class cmLocalVisualStudio10Generator;
class cmMakefile; class cmMakefile;
@@ -238,6 +239,14 @@ private:
using ToolSourceMap = std::map<std::string, ToolSources>; using ToolSourceMap = std::map<std::string, ToolSources>;
ToolSourceMap Tools; ToolSourceMap Tools;
std::set<std::string> ExpectedResxHeaders;
std::set<std::string> ExpectedXamlHeaders;
std::set<std::string> ExpectedXamlSources;
std::vector<cmSourceFile const*> ResxObjs;
std::vector<cmSourceFile const*> XamlObjs;
void ClassifyAllConfigSources();
void ClassifyAllConfigSource(cmGeneratorTarget::AllConfigSource const& acs);
using ConfigToSettings = using ConfigToSettings =
std::unordered_map<std::string, std::unordered_map<std::string,
std::unordered_map<std::string, std::string>>; std::unordered_map<std::string, std::string>>;