From 73ee599a8203271245ab7a55095eb92843768b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Mon, 23 Apr 2018 07:16:04 +0200 Subject: cmGeneratorTarget: make GetManagedType() return 'Native' for static targets --- Source/cmGeneratorTarget.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bf5ff65..799ae95 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5510,12 +5510,14 @@ cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType( const std::string& config) const { // Only libraries and executables can be managed targets. - if (this->GetType() != cmStateEnums::SHARED_LIBRARY && - this->GetType() != cmStateEnums::STATIC_LIBRARY && - this->GetType() != cmStateEnums::EXECUTABLE) { + if (this->GetType() > cmStateEnums::SHARED_LIBRARY) { return ManagedType::Undefined; } + if (this->GetType() == cmStateEnums::STATIC_LIBRARY) { + return ManagedType::Native; + } + // Check imported target. if (this->IsImported()) { if (cmGeneratorTarget::ImportInfo const* info = -- cgit v0.12 From 8d7ffed04819669ebc9fb365ade6bffaab443a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Fri, 27 Apr 2018 07:24:47 +0200 Subject: cmVisualStudio10TargetGenerator: issue warning when adding static C# lib --- Source/cmVisualStudio10TargetGenerator.cxx | 8 ++++++++ Tests/RunCMake/VS10Project/VsCSharpCustomTags-stderr.txt | 3 +++ Tests/RunCMake/VS10Project/VsCSharpReferenceProps-stderr.txt | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 Tests/RunCMake/VS10Project/VsCSharpCustomTags-stderr.txt create mode 100644 Tests/RunCMake/VS10Project/VsCSharpReferenceProps-stderr.txt diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7a7c647..da00f5c 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -333,6 +333,14 @@ void cmVisualStudio10TargetGenerator::Generate() this->ProjectType = vcxproj; this->Managed = false; } else if (this->ProjectFileExtension == ".csproj") { + if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { + std::string message = "The C# target \"" + + this->GeneratorTarget->GetName() + + "\" is of type STATIC_LIBRARY. This is discouraged (and may be " + "disabled in future). Make it a SHARED library instead."; + this->Makefile->IssueMessage(cmake::MessageType::DEPRECATION_WARNING, + message); + } this->ProjectType = csproj; this->Managed = true; } diff --git a/Tests/RunCMake/VS10Project/VsCSharpCustomTags-stderr.txt b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-stderr.txt new file mode 100644 index 0000000..1ea3b51 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-stderr.txt @@ -0,0 +1,3 @@ +^CMake Deprecation Warning in CMakeLists.txt: + The C# target "foo" is of type STATIC_LIBRARY. This is discouraged \(and + may be disabled in future\). Make it a SHARED library instead.$ diff --git a/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-stderr.txt b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-stderr.txt new file mode 100644 index 0000000..4402b8f --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-stderr.txt @@ -0,0 +1,8 @@ +^CMake Deprecation Warning in CMakeLists.txt: + The C# target "foo2" is of type STATIC_LIBRARY. This is discouraged \(and + may be disabled in future\). Make it a SHARED library instead. + + +CMake Deprecation Warning in CMakeLists.txt: + The C# target "foo" is of type STATIC_LIBRARY. This is discouraged \(and + may be disabled in future\). Make it a SHARED library instead.$ -- cgit v0.12 From 1e5a8f882f36648a74c54ebda1d2480bb99c29b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Fri, 27 Apr 2018 07:29:57 +0200 Subject: cmVisualStudio10TargetGenerator: fix checking for managed target --- Source/cmVisualStudio10TargetGenerator.cxx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index da00f5c..95e52e6 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3811,18 +3811,9 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) // If the dependency target is not managed (compiled with /clr or // C# target) we cannot reference it and have to set // 'ReferenceOutputAssembly' to false. - cmGeneratorTarget::ManagedType check = - cmGeneratorTarget::ManagedType::Mixed; - // FIXME: These (5) lines should be removed. They are here to allow - // manual setting of the /clr flag in compiler options. Setting - // /clr manually makes cmGeneratorTarget::GetManagedType() return - // 'Native' instead of 'Mixed' or 'Managed'. - check = cmGeneratorTarget::ManagedType::Native; - bool unmanagedStatic = false; - if (dt->GetType() == cmStateEnums::STATIC_LIBRARY) { - unmanagedStatic = !dt->HasLanguage("CSharp", ""); - } - if (dt->GetManagedType("") < check || unmanagedStatic) { + auto referenceNotManaged = + dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed; + if (referenceNotManaged) { e2.Element("ReferenceOutputAssembly", "false"); } } -- cgit v0.12 From d244f2cad3fea2884eb706e2761189ea9644b70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Fri, 27 Apr 2018 07:31:03 +0200 Subject: cmVisualStudio10TargetGenerator: add handling of manual /clr setting --- Source/cmVisualStudio10TargetGenerator.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 95e52e6..3fb0e10 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3813,6 +3813,16 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) // 'ReferenceOutputAssembly' to false. auto referenceNotManaged = dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed; + // Workaround to check for manually set /clr flags. + if (referenceNotManaged) { + if (const auto* flags = dt->GetProperty("COMPILE_OPTIONS")) { + std::string flagsStr = flags; + if (flagsStr.find("clr") != std::string::npos) { + // There is a warning already issued when building the flags. + referenceNotManaged = false; + } + } + } if (referenceNotManaged) { e2.Element("ReferenceOutputAssembly", "false"); } -- cgit v0.12 From b7c2b2cd78a8bc16cd7e294c2ae9d5d45f029e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20St=C3=BCrmer?= Date: Fri, 27 Apr 2018 07:31:45 +0200 Subject: cmVisualStudio10TargetGenerator: add handling of static C# targets --- Source/cmVisualStudio10TargetGenerator.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 3fb0e10..f4911c9 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3823,6 +3823,11 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) } } } + // Workaround for static library C# targets + if (referenceNotManaged && + dt->GetType() == cmStateEnums::STATIC_LIBRARY) { + referenceNotManaged = !dt->HasLanguage("CSharp", ""); + } if (referenceNotManaged) { e2.Element("ReferenceOutputAssembly", "false"); } -- cgit v0.12