diff options
author | Brad King <brad.king@kitware.com> | 2017-09-01 19:17:01 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-09-05 13:42:16 (GMT) |
commit | 94e70e5329e54754820008514a08614577d2f201 (patch) | |
tree | 1fb75acad7d57c755bc14210fc8ab515b43e0f18 | |
parent | 671cc7490ca1dd732cbb3671d4732eb1ee1e180e (diff) | |
parent | 7e57e6ae123439d5101ae1fc3ce593652b408b0c (diff) | |
download | CMake-94e70e5329e54754820008514a08614577d2f201.zip CMake-94e70e5329e54754820008514a08614577d2f201.tar.gz CMake-94e70e5329e54754820008514a08614577d2f201.tar.bz2 |
Merge branch 'backport-vs-csharp-ref-no-asm' into vs-csharp-ref-no-asm
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 7 | ||||
-rw-r--r-- | Tests/CSharpLinkToCxx/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/CSharpLinkToCxx/cpp_native.cpp | 10 | ||||
-rw-r--r-- | Tests/CSharpLinkToCxx/cpp_native.hpp | 9 |
6 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index d7ea35a..ece2a77 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -782,6 +782,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 04d97c5..399b6e0 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 86099eb..7fe2f2a 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3607,6 +3607,13 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() this->WriteString("<Name>", 3); (*this->BuildFileStream) << name << "</Name>\n"; this->WriteDotNetReferenceCustomTags(name); + 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); diff --git a/Tests/CSharpLinkToCxx/CMakeLists.txt b/Tests/CSharpLinkToCxx/CMakeLists.txt index c4269e0..153c57c 100644 --- a/Tests/CSharpLinkToCxx/CMakeLists.txt +++ b/Tests/CSharpLinkToCxx/CMakeLists.txt @@ -15,3 +15,9 @@ target_compile_options(CLIApp PRIVATE "/clr") add_executable(CSharpLinkToCxx csharp.cs) target_link_libraries(CSharpLinkToCxx CLIApp) + +# this unmanaged C++ library will be added to the C#/.NET +# references of CSharpLinkToCxx but it will show a warning +# because it is unmanaged +add_library(CppNativeApp SHARED cpp_native.hpp cpp_native.cpp) +target_link_libraries(CSharpLinkToCxx CppNativeApp) diff --git a/Tests/CSharpLinkToCxx/cpp_native.cpp b/Tests/CSharpLinkToCxx/cpp_native.cpp new file mode 100644 index 0000000..dc7670f --- /dev/null +++ b/Tests/CSharpLinkToCxx/cpp_native.cpp @@ -0,0 +1,10 @@ +#include "cpp_native.hpp" + +#include <iostream> + +namespace CppApp { +void MyCpp::testMyCpp() +{ + std::cout << "#message from CppApp" << std::endl; +} +} diff --git a/Tests/CSharpLinkToCxx/cpp_native.hpp b/Tests/CSharpLinkToCxx/cpp_native.hpp new file mode 100644 index 0000000..0fa1a3b --- /dev/null +++ b/Tests/CSharpLinkToCxx/cpp_native.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace CppApp { +class MyCpp +{ +public: + void testMyCpp(); +}; +} |