1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Merge topic 'vs-sdk-style-platform-override'

4ebedf246d VS: Fix SLNs for DOTNET_SDK targets with VS_GLOBAL_PlatformTarget

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Steven Boswell <ulatekh@yahoo.com>
Merge-request: !11247
This commit is contained in:
Brad King
2025-09-30 13:56:43 +00:00
committed by Kitware Robot
6 changed files with 82 additions and 6 deletions

View File

@@ -1009,12 +1009,19 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
project->TypeId = Solution::Project::TypeIdDefault;
}
project->Platform =
// On VS 19 and above, always map .NET SDK projects to "Any CPU".
(gt->IsDotNetSdkTarget() && this->Version >= VSVersion::VS16 &&
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName()))
? "Any CPU"
: solution.Platform;
if (gt->IsDotNetSdkTarget() &&
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName())) {
cmValue platformTarget = gt->GetProperty("VS_GLOBAL_PlatformTarget");
if (!platformTarget.IsEmpty()) {
project->Platform = *platformTarget;
} 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.
TargetDependSet const& depends = this->GetTargetDirectDepends(gt);

View File

@@ -1,11 +1,19 @@
cmake_minimum_required(VERSION 4.0)
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(VsDotnetSdkDefines)
run_cmake(DotnetSdkVariables)
run_cmake(VsDotnetSdkXamlFiles)
run_cmake(VsDotnetSdkAssemblyName)
run_cmake(VsDotnetSdkConfigurations)
run_cmake(VsDotnetSdkTargetPlatform)
function(run_VsDotnetSdk)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build)

View File

@@ -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()

View File

@@ -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>$]])

View File

@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/VsDotnetSdkTargetPlatform-check-${sln_ext}.cmake)

View 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}"
)