VS: Model target framework in CMAKE_GENERATOR_PLATFORM
See the Visual Studio documentation on Framework targeting. Generated project files need to specify a target framework somehow.
CMake has some support for this already. See the CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION variable and DOTNET_TARGET_FRAMEWORK target property to control the TargetFrameworkVersion
. However, that only works for project targets, and not for try_compile
or similar. Issue #22835 (closed) raises a case where we need to generate an explicit TargetFrameworkVersion
even in the tiny project CMake creates during compiler identification.
In principle, the target framework is just as fundamental to generation as the target platform. See the VS documentation on MSBuild target framework and target platform and Target frameworks in SDK-style projects. Therefore we should support specifying the target framework as part of CMAKE_GENERATOR_PLATFORM, and also select a default explicitly when needed (e.g. VS 2022 for #22835 (closed)).
In CMAKE_GENERATOR_TOOLSET we already support comma-separated fields with additional settings. We could do the same for CMAKE_GENERATOR_PLATFORM
, and then add a framework=
field for the target framework. We may need to offer controls for:
-
TargetFrameworkVersion
/TargetFrameworkIdentifier
/TargetFrameworkTargetsVersion
TargetFramework
depending on the style of the project.
This capability may become important to help users update their target framework version after .NET Framework 4.5.2, 4.6, 4.6.1 reach End of Support.