From d8786bfa16889f445a37bee7e665948e7a134c13 Mon Sep 17 00:00:00 2001 From: Thomas Vaughan Date: Mon, 3 May 2021 08:53:09 -0400 Subject: VS: Add support for per-config C# sources Fixes: #22108 --- Source/cmVisualStudio10TargetGenerator.cxx | 16 +++++++++++++++- Tests/CSharpOnly/CMakeLists.txt | 7 ++++++- Tests/CSharpOnly/config_specific_main_debug.cs | 10 ++++++++++ Tests/CSharpOnly/config_specific_main_no_exist.cs | 10 ++++++++++ Tests/CSharpOnly/config_specific_main_not_debug.cs | 10 ++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Tests/CSharpOnly/config_specific_main_debug.cs create mode 100644 Tests/CSharpOnly/config_specific_main_no_exist.cs create mode 100644 Tests/CSharpOnly/config_specific_main_not_debug.cs diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 0255d60..42c3a68 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2277,6 +2277,20 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) std::back_inserter(exclude_configs)); Elem e2(e1, tool); + bool isCSharp = (si.Source->GetLanguage() == "CSharp"); + if (isCSharp && exclude_configs.size() > 0) { + std::stringstream conditions; + bool firstConditionSet{ false }; + for (const auto& ci : include_configs) { + if (firstConditionSet) { + conditions << " Or "; + } + conditions << "('$(Configuration)|$(Platform)'=='" + + this->Configurations[ci] + "|" + this->Platform + "')"; + firstConditionSet = true; + } + e2.Attribute("Condition", conditions.str()); + } this->WriteSource(e2, si.Source); bool useNativeUnityBuild = false; @@ -2321,7 +2335,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { e2.Element("PrecompiledHeader", "NotUsing"); } - if (!exclude_configs.empty()) { + if (!isCSharp && !exclude_configs.empty()) { this->WriteExcludeFromBuild(e2, exclude_configs); } } diff --git a/Tests/CSharpOnly/CMakeLists.txt b/Tests/CSharpOnly/CMakeLists.txt index 195af05..f7928b6 100644 --- a/Tests/CSharpOnly/CMakeLists.txt +++ b/Tests/CSharpOnly/CMakeLists.txt @@ -9,8 +9,13 @@ source_group(nested FILES nested/lib1.cs) add_library(lib2 SHARED lib2.cs) add_executable(CSharpOnly csharponly.cs) - target_link_libraries(CSharpOnly lib1 lib2) +add_executable(CSharpConfigSpecific + $<$:config_specific_main_debug.cs> + $<$>:config_specific_main_not_debug.cs> + $<$:config_specific_main_no_exist.cs> + ) + add_custom_target(CSharpCustom ALL SOURCES empty.cs) add_custom_target(custom.cs ALL DEPENDS empty.txt) diff --git a/Tests/CSharpOnly/config_specific_main_debug.cs b/Tests/CSharpOnly/config_specific_main_debug.cs new file mode 100644 index 0000000..b62524b --- /dev/null +++ b/Tests/CSharpOnly/config_specific_main_debug.cs @@ -0,0 +1,10 @@ +namespace CSharpConfigSpecific +{ + class CSharpConfigSpecific + { + public static void Main(string[] args) + { + return; + } + } +} diff --git a/Tests/CSharpOnly/config_specific_main_no_exist.cs b/Tests/CSharpOnly/config_specific_main_no_exist.cs new file mode 100644 index 0000000..b62524b --- /dev/null +++ b/Tests/CSharpOnly/config_specific_main_no_exist.cs @@ -0,0 +1,10 @@ +namespace CSharpConfigSpecific +{ + class CSharpConfigSpecific + { + public static void Main(string[] args) + { + return; + } + } +} diff --git a/Tests/CSharpOnly/config_specific_main_not_debug.cs b/Tests/CSharpOnly/config_specific_main_not_debug.cs new file mode 100644 index 0000000..b62524b --- /dev/null +++ b/Tests/CSharpOnly/config_specific_main_not_debug.cs @@ -0,0 +1,10 @@ +namespace CSharpConfigSpecific +{ + class CSharpConfigSpecific + { + public static void Main(string[] args) + { + return; + } + } +} -- cgit v0.12