diff options
author | Michael Stürmer <michael.stuermer@schaeffler.com> | 2017-08-29 08:46:54 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-09-05 13:41:40 (GMT) |
commit | 7e57e6ae123439d5101ae1fc3ce593652b408b0c (patch) | |
tree | a587f76c38814a49ceb1a4580b1ca2a4d4d1c598 /Source | |
parent | 29907992277e0145a83368f3e8674b0608d745c5 (diff) | |
download | CMake-7e57e6ae123439d5101ae1fc3ce593652b408b0c.zip CMake-7e57e6ae123439d5101ae1fc3ce593652b408b0c.tar.gz CMake-7e57e6ae123439d5101ae1fc3ce593652b408b0c.tar.bz2 |
VS: Do not reference output assemblies if not possible for CSharp target
Since commit v3.9.0-rc4~4^2 (Vs: allow CSharp targets to be linked to
CXX targets, 2017-06-20) CSharp targets get `ProjectReference` entries
to their dependencies. This causes VS to also reference the
dependency's output assembly by default, which is incorrect for
non-managed targets.
Fix this by setting `ReferenceOutputAssembly` to `false` for targets
that can't provide output assemblies. Unmanaged C++ targets (shared
libs & executables) can still be referenced and a warning will be shown
in the IDE but the build will not break anymore.
Fixes: #17172
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 7 |
3 files changed, 23 insertions, 0 deletions
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 87a22d1..bbff48e 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -778,6 +778,19 @@ bool cmGlobalVisualStudioGenerator::TargetIsCSharpOnly( return false; } +bool cmGlobalVisualStudioGenerator::TargetCanBeReferenced( + cmGeneratorTarget const* gt) +{ + if (this->TargetIsCSharpOnly(gt)) { + return true; + } + if (gt->GetType() != cmStateEnums::SHARED_LIBRARY && + gt->GetType() != cmStateEnums::EXECUTABLE) { + return false; + } + return true; +} + bool cmGlobalVisualStudioGenerator::TargetCompare::operator()( cmGeneratorTarget const* l, cmGeneratorTarget const* r) const { diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index c12a933..3c43ccd 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -85,6 +85,9 @@ public: // return true if target is C# only static bool TargetIsCSharpOnly(cmGeneratorTarget const* gt); + // return true if target can be referenced by C# targets + bool TargetCanBeReferenced(cmGeneratorTarget const* gt); + /** Get the top-level registry key for this VS version. */ std::string GetRegistryBase(); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 88fa19c..dee153f 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3502,6 +3502,13 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() (*this->BuildFileStream) << "</Project>\n"; this->WriteString("<Name>", 3); (*this->BuildFileStream) << name << "</Name>\n"; + if (csproj == this->ProjectType) { + if (!static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator) + ->TargetCanBeReferenced(dt)) { + this->WriteString( + "<ReferenceOutputAssembly>false</ReferenceOutputAssembly>\n", 3); + } + } this->WriteString("</ProjectReference>\n", 2); } this->WriteString("</ItemGroup>\n", 1); |