summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-10-30 13:37:07 (GMT)
committerBrad King <brad.king@kitware.com>2018-10-31 13:13:19 (GMT)
commita56edad6d61268204af8228b8d58fa26d8f72269 (patch)
tree0d3fb5b71f8f83db49b7eed811defe2902f48c44 /Source/cmGeneratorTarget.cxx
parentf87d5f13c29a961238ccf623d4954d2d0636adaa (diff)
downloadCMake-a56edad6d61268204af8228b8d58fa26d8f72269.zip
CMake-a56edad6d61268204af8228b8d58fa26d8f72269.tar.gz
CMake-a56edad6d61268204af8228b8d58fa26d8f72269.tar.bz2
CSharp: Fix regression in VS project type selection for custom target
A target created by `add_custom_target` should always be a `.vcxproj` file even if it has `.cs` sources involved in custom commands and such. The latter case was broken by refactoring in commit v3.12.0-rc1~160^2~7 (remove TargetIsCSharpOnly() and use methods from cmGeneratorTarget, 2018-03-19). The reason is that the `HasLanguage` method added by commit v3.12.0-rc1~239^2~6 (cmGeneratorTarget: add HasLanguage() as wrapper for GetLanguages(), 2018-03-19) does not check the target type and so is not a suitable check for deciding the project file extension. The `HasLanguage` method was an attempt at an abstraction that turns out not to work very well. Replace it with a dedicated `IsCSharpOnly` method that considers the target type, sources, and non-transitive `LINKER_LANGUAGE`. Fixes: #18515
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx28
1 files changed, 15 insertions, 13 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 80fb621..5c294f8 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -5594,20 +5594,23 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
}
}
-bool cmGeneratorTarget::HasLanguage(std::string const& language,
- std::string const& config,
- bool exclusive) const
+bool cmGeneratorTarget::IsCSharpOnly() const
{
- std::set<std::string> languages;
- this->GetLanguages(languages, config);
- // The "exclusive" check applies only to source files and not
- // the linker language which may be affected by dependencies.
- if (exclusive && languages.size() > 1) {
+ // Only certain target types may compile CSharp.
+ if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::STATIC_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
return false;
}
- // add linker language (if it is different from compiler languages)
- languages.insert(this->GetLinkerLanguage(config));
- return languages.count(language) > 0;
+ std::set<std::string> languages;
+ this->GetLanguages(languages, "");
+ // Consider an explicit linker language property, but *not* the
+ // computed linker language that may depend on linked targets.
+ const char* linkLang = this->GetProperty("LINKER_LANGUAGE");
+ if (linkLang && *linkLang) {
+ languages.insert(linkLang);
+ }
+ return languages.size() == 1 && languages.count("CSharp") > 0;
}
void cmGeneratorTarget::ComputeLinkImplementationLanguages(
@@ -5971,6 +5974,5 @@ cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
// C# targets are always managed. This language specific check
// is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
// has to be set manually for C# targets.
- return this->HasLanguage("CSharp", config) ? ManagedType::Managed
- : ManagedType::Native;
+ return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
}