1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-21 06:10:16 +08:00

cmVisualStudio10TargetGenerator: store managed reference information in maps

This commit is contained in:
Michael Stürmer
2018-03-20 12:59:02 +01:00
parent 16fec7e2fc
commit 43571073e0
2 changed files with 60 additions and 7 deletions

View File

@@ -319,6 +319,8 @@ void cmVisualStudio10TargetGenerator::Generate()
this->Name.c_str()); this->Name.c_str());
this->GeneratorTarget->Target->SetProperty( this->GeneratorTarget->Target->SetProperty(
"GENERATOR_FILE_NAME_EXT", this->ProjectFileExtension.c_str()); "GENERATOR_FILE_NAME_EXT", this->ProjectFileExtension.c_str());
this->DotNetHintReferences.clear();
this->AdditionalUsingDirectories.clear();
if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
if (!this->ComputeClOptions()) { if (!this->ComputeClOptions()) {
return; return;
@@ -679,8 +681,6 @@ void cmVisualStudio10TargetGenerator::Generate()
void cmVisualStudio10TargetGenerator::WriteDotNetReferences() void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
{ {
std::vector<std::string> references; std::vector<std::string> references;
typedef std::pair<std::string, std::string> HintReference;
std::vector<HintReference> hintReferences;
if (const char* vsDotNetReferences = if (const char* vsDotNetReferences =
this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) { this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) {
cmSystemTools::ExpandListArgument(vsDotNetReferences, references); cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
@@ -696,11 +696,12 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
"/" + path; "/" + path;
} }
ConvertToWindowsSlash(path); ConvertToWindowsSlash(path);
hintReferences.push_back(HintReference(name, path)); this->DotNetHintReferences[""].push_back(
DotNetHintReference(name, path));
} }
} }
} }
if (!references.empty() || !hintReferences.empty()) { if (!references.empty() || !this->DotNetHintReferences.empty()) {
this->WriteString("<ItemGroup>\n", 1); this->WriteString("<ItemGroup>\n", 1);
for (std::string const& ri : references) { for (std::string const& ri : references) {
// if the entry from VS_DOTNET_REFERENCES is an existing file, generate // if the entry from VS_DOTNET_REFERENCES is an existing file, generate
@@ -709,13 +710,18 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
std::string name = cmsys::SystemTools::GetFilenameWithoutExtension(ri); std::string name = cmsys::SystemTools::GetFilenameWithoutExtension(ri);
std::string path = ri; std::string path = ri;
ConvertToWindowsSlash(path); ConvertToWindowsSlash(path);
hintReferences.push_back(HintReference(name, path)); this->DotNetHintReferences[""].push_back(
DotNetHintReference(name, path));
} else { } else {
this->WriteDotNetReference(ri, "", ""); this->WriteDotNetReference(ri, "", "");
} }
} }
for (const auto& i : hintReferences) { for (const auto& h : this->DotNetHintReferences) {
this->WriteDotNetReference(i.first, i.second, ""); // DotNetHintReferences is also populated from AddLibraries().
// The configuration specific hint references are added there.
for (const auto& i : h.second) {
this->WriteDotNetReference(i.first, i.second, h.first);
}
} }
this->WriteString("</ItemGroup>\n", 1); this->WriteString("</ItemGroup>\n", 1);
} }
@@ -2625,6 +2631,18 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
ConvertToWindowsSlash(pdb); ConvertToWindowsSlash(pdb);
this->WriteElemEscapeXML("ProgramDataBaseFileName", pdb, 3); this->WriteElemEscapeXML("ProgramDataBaseFileName", pdb, 3);
} }
// add AdditionalUsingDirectories
if (this->AdditionalUsingDirectories.count(configName) > 0) {
std::string dirs;
for (auto u : this->AdditionalUsingDirectories[configName]) {
if (!dirs.empty()) {
dirs.append(";");
}
dirs.append(u);
}
this->WriteElemEscapeXML("AdditionalUsingDirectories", dirs, 3);
}
} }
this->WriteString("</ClCompile>\n", 2); this->WriteString("</ClCompile>\n", 2);
@@ -3496,6 +3514,32 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
for (cmComputeLinkInformation::Item const& l : libs) { for (cmComputeLinkInformation::Item const& l : libs) {
if (l.Target) { if (l.Target) {
auto managedType = l.Target->GetManagedType(config); auto managedType = l.Target->GetManagedType(config);
if (managedType != cmGeneratorTarget::ManagedType::Native &&
this->GeneratorTarget->GetManagedType(config) !=
cmGeneratorTarget::ManagedType::Native &&
l.Target->IsImported()) {
auto location = l.Target->GetFullPath(config);
if (!location.empty()) {
ConvertToWindowsSlash(location);
switch (this->ProjectType) {
case csproj:
// If the target we want to "link" to is an imported managed
// target and this is a C# project, we add a hint reference. This
// reference is written to project file in
// WriteDotNetReferences().
this->DotNetHintReferences[config].push_back(
DotNetHintReference(l.Target->GetName(), location));
break;
case vcxproj:
// Add path of assembly to list of using-directories, so the
// managed assembly can be used by '#using <assembly.dll>' in
// code.
this->AdditionalUsingDirectories[config].insert(
cmSystemTools::GetFilenamePath(location));
break;
}
}
}
// Do not allow C# targets to be added to the LIB listing. LIB files are // Do not allow C# targets to be added to the LIB listing. LIB files are
// used for linking C++ dependencies. C# libraries do not have lib files. // used for linking C++ dependencies. C# libraries do not have lib files.
// Instead, they compile down to C# reference libraries (DLL files). The // Instead, they compile down to C# reference libraries (DLL files). The

View File

@@ -216,6 +216,15 @@ private:
bool IsMissingFiles; bool IsMissingFiles;
std::vector<std::string> AddedFiles; std::vector<std::string> AddedFiles;
std::string DefaultArtifactDir; std::string DefaultArtifactDir;
// managed C++/C# relevant members
typedef std::pair<std::string, std::string> DotNetHintReference;
typedef std::vector<DotNetHintReference> DotNetHintReferenceList;
typedef std::map<std::string, DotNetHintReferenceList>
DotNetHintReferenceMap;
DotNetHintReferenceMap DotNetHintReferences;
typedef std::set<std::string> UsingDirectories;
typedef std::map<std::string, UsingDirectories> UsingDirectoriesMap;
UsingDirectoriesMap AdditionalUsingDirectories;
typedef std::map<std::string, ToolSources> ToolSourceMap; typedef std::map<std::string, ToolSources> ToolSourceMap;
ToolSourceMap Tools; ToolSourceMap Tools;