mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
VS: Fix SLNs for DOTNET_SDK targets with VS_GLOBAL_PlatformTarget
By default, .NET SDK-style projects build for "Any CPU", so we generate solution files accordingly. Although CMake does not model per-target architectures, some projects set the `VS_GLOBAL_PlatformTarget` property on `DOTNET_SDK` targets in order to compile for a specific architecture. Fix generated solution files to account for the architecture override. Issue: #23513
This commit is contained in:
@@ -977,12 +977,19 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
|
|||||||
project->TypeId = Solution::Project::TypeIdDefault;
|
project->TypeId = Solution::Project::TypeIdDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
project->Platform =
|
if (gt->IsDotNetSdkTarget() &&
|
||||||
// On VS 19 and above, always map .NET SDK projects to "Any CPU".
|
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName())) {
|
||||||
(gt->IsDotNetSdkTarget() && this->Version >= VSVersion::VS16 &&
|
cmValue platformTarget = gt->GetProperty("VS_GLOBAL_PlatformTarget");
|
||||||
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName()))
|
if (!platformTarget.IsEmpty()) {
|
||||||
? "Any CPU"
|
project->Platform = *platformTarget;
|
||||||
: solution.Platform;
|
} else {
|
||||||
|
project->Platform =
|
||||||
|
// On VS 16 and above, always map .NET SDK projects to "Any CPU".
|
||||||
|
this->Version >= VSVersion::VS16 ? "Any CPU" : solution.Platform;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
project->Platform = solution.Platform;
|
||||||
|
}
|
||||||
|
|
||||||
// Add solution-level dependencies.
|
// Add solution-level dependencies.
|
||||||
TargetDependSet const& depends = this->GetTargetDirectDepends(gt);
|
TargetDependSet const& depends = this->GetTargetDirectDepends(gt);
|
||||||
|
@@ -1,11 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 4.0)
|
||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
|
if(RunCMake_GENERATOR MATCHES "Visual Studio 1[4-7]")
|
||||||
|
set(sln_ext "sln")
|
||||||
|
else()
|
||||||
|
set(sln_ext "slnx")
|
||||||
|
endif()
|
||||||
|
|
||||||
run_cmake(VsDotnetSdkStartupObject)
|
run_cmake(VsDotnetSdkStartupObject)
|
||||||
run_cmake(VsDotnetSdkDefines)
|
run_cmake(VsDotnetSdkDefines)
|
||||||
run_cmake(DotnetSdkVariables)
|
run_cmake(DotnetSdkVariables)
|
||||||
run_cmake(VsDotnetSdkXamlFiles)
|
run_cmake(VsDotnetSdkXamlFiles)
|
||||||
run_cmake(VsDotnetSdkAssemblyName)
|
run_cmake(VsDotnetSdkAssemblyName)
|
||||||
run_cmake(VsDotnetSdkConfigurations)
|
run_cmake(VsDotnetSdkConfigurations)
|
||||||
|
run_cmake(VsDotnetSdkTargetPlatform)
|
||||||
|
|
||||||
function(run_VsDotnetSdk)
|
function(run_VsDotnetSdk)
|
||||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build)
|
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build)
|
||||||
|
@@ -0,0 +1,27 @@
|
|||||||
|
set(slnFile ${RunCMake_TEST_BINARY_DIR}/VsDotnetSdkTargetPlatform.sln)
|
||||||
|
|
||||||
|
if(NOT EXISTS "${slnFile}")
|
||||||
|
string(APPEND RunCMake_TEST_FAILED
|
||||||
|
"Solution file:\n"
|
||||||
|
" ${slnFile}\n"
|
||||||
|
"does not exist."
|
||||||
|
)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(STRINGS "${slnFile}" lines)
|
||||||
|
|
||||||
|
set(haveAnyCPU 0)
|
||||||
|
foreach(line IN LISTS lines)
|
||||||
|
if(line MATCHES [[\.(ActiveCfg|Build\.0) = (Debug|Release|MinSizeRel|RelWithDebInfo)\|Any CPU]])
|
||||||
|
set(haveAnyCPU 1)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(haveAnyCPU)
|
||||||
|
string(APPEND RunCMake_TEST_FAILED
|
||||||
|
"Solution file:\n"
|
||||||
|
" ${slnFile}\n"
|
||||||
|
"incorrectly maps to Any CPU."
|
||||||
|
)
|
||||||
|
endif()
|
@@ -0,0 +1,23 @@
|
|||||||
|
RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/VsDotnetSdkTargetPlatform.slnx" [[
|
||||||
|
^<\?xml version="1\.0" encoding="UTF-8"\?>
|
||||||
|
<Solution>
|
||||||
|
<Configurations>
|
||||||
|
<BuildType Name="Debug"/>
|
||||||
|
<BuildType Name="Release"/>
|
||||||
|
<BuildType Name="MinSizeRel"/>
|
||||||
|
<BuildType Name="RelWithDebInfo"/>
|
||||||
|
<Platform Name="[^"]+"/>
|
||||||
|
</Configurations>
|
||||||
|
<Project Path="ALL_BUILD\.vcxproj" Id="[0-9a-f-]+">
|
||||||
|
<BuildDependency Project="ZERO_CHECK\.vcxproj"/>
|
||||||
|
<BuildDependency Project="foo\.csproj"/>
|
||||||
|
<Build Solution="Debug\|\*" Project="false"/>
|
||||||
|
<Build Solution="Release\|\*" Project="false"/>
|
||||||
|
<Build Solution="MinSizeRel\|\*" Project="false"/>
|
||||||
|
<Build Solution="RelWithDebInfo\|\*" Project="false"/>
|
||||||
|
</Project>
|
||||||
|
<Project Path="ZERO_CHECK\.vcxproj" Id="[0-9a-f-]+"/>
|
||||||
|
<Project Path="foo\.csproj" Id="[0-9a-f-]+">
|
||||||
|
<BuildDependency Project="ZERO_CHECK\.vcxproj"/>
|
||||||
|
</Project>
|
||||||
|
</Solution>$]])
|
@@ -0,0 +1 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/VsDotnetSdkTargetPlatform-check-${sln_ext}.cmake)
|
10
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform.cmake
Normal file
10
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform.cmake
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
enable_language(CSharp)
|
||||||
|
|
||||||
|
set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
|
||||||
|
|
||||||
|
add_executable(foo csharponly.cs lib1.cs)
|
||||||
|
|
||||||
|
set_target_properties(foo PROPERTIES
|
||||||
|
VS_GLOBAL_Platforms "${CMAKE_VS_PLATFORM_NAME}"
|
||||||
|
VS_GLOBAL_PlatformTarget "${CMAKE_VS_PLATFORM_NAME}"
|
||||||
|
)
|
Reference in New Issue
Block a user