Commit d8786bfa authored by Thomas Vaughan's avatar Thomas Vaughan
Browse files

VS: Add support for per-config C# sources

Fixes: #22108
parent 95afd879
...@@ -2277,6 +2277,20 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) ...@@ -2277,6 +2277,20 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
std::back_inserter(exclude_configs)); std::back_inserter(exclude_configs));
Elem e2(e1, tool); 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); this->WriteSource(e2, si.Source);
bool useNativeUnityBuild = false; bool useNativeUnityBuild = false;
...@@ -2321,7 +2335,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) ...@@ -2321,7 +2335,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) {
e2.Element("PrecompiledHeader", "NotUsing"); e2.Element("PrecompiledHeader", "NotUsing");
} }
if (!exclude_configs.empty()) { if (!isCSharp && !exclude_configs.empty()) {
this->WriteExcludeFromBuild(e2, exclude_configs); this->WriteExcludeFromBuild(e2, exclude_configs);
} }
} }
......
...@@ -9,8 +9,13 @@ source_group(nested FILES nested/lib1.cs) ...@@ -9,8 +9,13 @@ source_group(nested FILES nested/lib1.cs)
add_library(lib2 SHARED lib2.cs) add_library(lib2 SHARED lib2.cs)
add_executable(CSharpOnly csharponly.cs) add_executable(CSharpOnly csharponly.cs)
target_link_libraries(CSharpOnly lib1 lib2) target_link_libraries(CSharpOnly lib1 lib2)
add_executable(CSharpConfigSpecific
$<$<CONFIG:Debug>:config_specific_main_debug.cs>
$<$<NOT:$<CONFIG:Debug>>:config_specific_main_not_debug.cs>
$<$<CONFIG:NotAConfig>:config_specific_main_no_exist.cs>
)
add_custom_target(CSharpCustom ALL SOURCES empty.cs) add_custom_target(CSharpCustom ALL SOURCES empty.cs)
add_custom_target(custom.cs ALL DEPENDS empty.txt) add_custom_target(custom.cs ALL DEPENDS empty.txt)
namespace CSharpConfigSpecific
{
class CSharpConfigSpecific
{
public static void Main(string[] args)
{
return;
}
}
}
namespace CSharpConfigSpecific
{
class CSharpConfigSpecific
{
public static void Main(string[] args)
{
return;
}
}
}
namespace CSharpConfigSpecific
{
class CSharpConfigSpecific
{
public static void Main(string[] args)
{
return;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment