1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-20 04:24:36 +08:00

VS: Model a default target framework

Add fields to the VS generator to select a target framework.
Migrate the existing default for VS 12 .NET CF for Windows CE.

Report the values in `CMAKE_VS_*` variables and use them for
the CSharp compiler id project too.

Issue: #22849
This commit is contained in:
Brad King
2021-11-03 14:31:04 -04:00
parent e40cedddc0
commit f97f8537f3
10 changed files with 122 additions and 10 deletions

View File

@@ -125,6 +125,9 @@ Variables that Provide Information
/variable/CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR /variable/CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR
/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE /variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE
/variable/CMAKE_VS_PLATFORM_TOOLSET_VERSION /variable/CMAKE_VS_PLATFORM_TOOLSET_VERSION
/variable/CMAKE_VS_TARGET_FRAMEWORK_VERSION
/variable/CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER
/variable/CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION /variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM /variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM
/variable/CMAKE_XCODE_BUILD_SYSTEM /variable/CMAKE_XCODE_BUILD_SYSTEM

View File

@@ -0,0 +1,13 @@
CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER
------------------------------------
.. versionadded:: 3.22
Visual Studio target framework identifier.
In some cases, the :ref:`Visual Studio Generators` may use an explicit value
for the MSBuild ``TargetFrameworkIdentifier`` setting in ``.csproj`` files.
CMake provides the chosen value in this variable.
See also :variable:`CMAKE_VS_TARGET_FRAMEWORK_VERSION` and
:variable:`CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION`.

View File

@@ -0,0 +1,13 @@
CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION
-----------------------------------------
.. versionadded:: 3.22
Visual Studio target framework targets version.
In some cases, the :ref:`Visual Studio Generators` may use an explicit value
for the MSBuild ``TargetFrameworkTargetsVersion`` setting in ``.csproj`` files.
CMake provides the chosen value in this variable.
See also :variable:`CMAKE_VS_TARGET_FRAMEWORK_VERSION` and
:variable:`CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER`.

View File

@@ -0,0 +1,17 @@
CMAKE_VS_TARGET_FRAMEWORK_VERSION
---------------------------------
.. versionadded:: 3.22
Visual Studio target framework version.
In some cases, the :ref:`Visual Studio Generators` may use an explicit value
for the MSBuild ``TargetFrameworkVersion`` setting in ``.csproj`` files.
CMake provides the chosen value in this variable.
See the :variable:`CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION` variable
and :prop_tgt:`DOTNET_TARGET_FRAMEWORK_VERSION` target property to
specify custom ``TargetFrameworkVersion`` values for project targets.
See also :variable:`CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER` and
:variable:`CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION`.

View File

@@ -421,6 +421,15 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
if(CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR) if(CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR)
set(id_ToolsetVCTargetsDir "<VCTargetsPath>${CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR}</VCTargetsPath>") set(id_ToolsetVCTargetsDir "<VCTargetsPath>${CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR}</VCTargetsPath>")
endif() endif()
if(CMAKE_VS_TARGET_FRAMEWORK_VERSION)
set(id_TargetFrameworkVersion "<TargetFrameworkVersion>${CMAKE_VS_TARGET_FRAMEWORK_VERSION}</TargetFrameworkVersion>")
endif()
if(CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER)
set(id_TargetFrameworkIdentifier "<TargetFrameworkIdentifier>${CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER}</TargetFrameworkIdentifier>")
endif()
if(CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION)
set(id_TargetFrameworkTargetsVersion "<TargetFrameworkTargetsVersion>${CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION}</TargetFrameworkTargetsVersion>")
endif()
set(id_CustomGlobals "") set(id_CustomGlobals "")
foreach(pair IN LISTS CMAKE_VS_GLOBALS) foreach(pair IN LISTS CMAKE_VS_GLOBALS)
if("${pair}" MATCHES "([^=]+)=(.*)$") if("${pair}" MATCHES "([^=]+)=(.*)$")

View File

@@ -6,6 +6,9 @@
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
@id_system@ @id_system@
@id_system_version@ @id_system_version@
@id_TargetFrameworkVersion@
@id_TargetFrameworkIdentifier@
@id_TargetFrameworkTargetsVersion@
@id_WindowsTargetPlatformVersion@ @id_WindowsTargetPlatformVersion@
@id_WindowsSDKDesktopARMSupport@ @id_WindowsSDKDesktopARMSupport@
</PropertyGroup> </PropertyGroup>

View File

@@ -580,6 +580,13 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
this->DefaultPlatformToolset = this->SelectWindowsCEToolset(); this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
if (this->GetVersion() == cmGlobalVisualStudioGenerator::VS12) {
// VS 12 .NET CF defaults to .NET framework 3.9 for Windows CE.
this->DefaultTargetFrameworkVersion = "v3.9";
this->DefaultTargetFrameworkIdentifier = "WindowsEmbeddedCompact";
this->DefaultTargetFrameworkTargetsVersion = "v8.0";
}
return true; return true;
} }

View File

@@ -76,12 +76,48 @@ bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
this->GeneratorPlatform = p; this->GeneratorPlatform = p;
// FIXME: Add CMAKE_GENERATOR_PLATFORM field to set the framework.
// For now, just report the generator's default, if any.
if (cm::optional<std::string> const& targetFrameworkVersion =
this->GetTargetFrameworkVersion()) {
mf->AddDefinition("CMAKE_VS_TARGET_FRAMEWORK_VERSION",
*targetFrameworkVersion);
}
if (cm::optional<std::string> const& targetFrameworkIdentifier =
this->GetTargetFrameworkIdentifier()) {
mf->AddDefinition("CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER",
*targetFrameworkIdentifier);
}
if (cm::optional<std::string> const& targetFrameworkTargetsVersion =
this->GetTargetFrameworkTargetsVersion()) {
mf->AddDefinition("CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION",
*targetFrameworkTargetsVersion);
}
// The generator name does not contain the platform name, and so supports // The generator name does not contain the platform name, and so supports
// explicit platform specification. We handled that above, so pass an // explicit platform specification. We handled that above, so pass an
// empty platform name to our base class implementation so it does not error. // empty platform name to our base class implementation so it does not error.
return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf); return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf);
} }
cm::optional<std::string> const&
cmGlobalVisualStudio8Generator::GetTargetFrameworkVersion() const
{
return this->DefaultTargetFrameworkVersion;
}
cm::optional<std::string> const&
cmGlobalVisualStudio8Generator::GetTargetFrameworkIdentifier() const
{
return this->DefaultTargetFrameworkIdentifier;
}
cm::optional<std::string> const&
cmGlobalVisualStudio8Generator::GetTargetFrameworkTargetsVersion() const
{
return this->DefaultTargetFrameworkTargetsVersion;
}
std::string cmGlobalVisualStudio8Generator::GetGenerateStampList() std::string cmGlobalVisualStudio8Generator::GetGenerateStampList()
{ {
return "generate.stamp.list"; return "generate.stamp.list";

View File

@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once #pragma once
#include <cm/optional>
#include "cmGlobalVisualStudio71Generator.h" #include "cmGlobalVisualStudio71Generator.h"
/** \class cmGlobalVisualStudio8Generator /** \class cmGlobalVisualStudio8Generator
@@ -24,6 +26,10 @@ public:
bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override; bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
cm::optional<std::string> const& GetTargetFrameworkVersion() const;
cm::optional<std::string> const& GetTargetFrameworkIdentifier() const;
cm::optional<std::string> const& GetTargetFrameworkTargetsVersion() const;
/** /**
* Override Configure and Generate to add the build-system check * Override Configure and Generate to add the build-system check
* target. * target.
@@ -76,4 +82,8 @@ protected:
std::string Name; std::string Name;
std::string WindowsCEVersion; std::string WindowsCEVersion;
cm::optional<std::string> DefaultTargetFrameworkVersion;
cm::optional<std::string> DefaultTargetFrameworkIdentifier;
cm::optional<std::string> DefaultTargetFrameworkTargetsVersion;
}; };

View File

@@ -507,12 +507,9 @@ void cmVisualStudio10TargetGenerator::Generate()
} else if (cmValue tfVer = this->GeneratorTarget->GetProperty( } else if (cmValue tfVer = this->GeneratorTarget->GetProperty(
"DOTNET_TARGET_FRAMEWORK_VERSION")) { "DOTNET_TARGET_FRAMEWORK_VERSION")) {
targetFrameworkVersion = *tfVer; targetFrameworkVersion = *tfVer;
} else if (this->ProjectType == csproj && } else if (this->ProjectType == csproj) {
this->GlobalGenerator->TargetsWindowsCE() && targetFrameworkVersion =
this->GlobalGenerator->GetVersion() == this->GlobalGenerator->GetTargetFrameworkVersion();
cmGlobalVisualStudioGenerator::VS12) {
// VS12 .NETCF default to .NET framework 3.9
targetFrameworkVersion = "v3.9";
} }
if (this->ProjectType == vcxproj && if (this->ProjectType == vcxproj &&
this->GlobalGenerator->TargetsWindowsCE()) { this->GlobalGenerator->TargetsWindowsCE()) {
@@ -527,16 +524,20 @@ void cmVisualStudio10TargetGenerator::Generate()
if (cmValue tfId = this->GeneratorTarget->GetProperty( if (cmValue tfId = this->GeneratorTarget->GetProperty(
"VS_TARGET_FRAMEWORK_IDENTIFIER")) { "VS_TARGET_FRAMEWORK_IDENTIFIER")) {
targetFrameworkIdentifier = *tfId; targetFrameworkIdentifier = *tfId;
} else {
targetFrameworkIdentifier = "WindowsEmbeddedCompact";
} }
if (cmValue tfTargetsVer = this->GeneratorTarget->GetProperty( if (cmValue tfTargetsVer = this->GeneratorTarget->GetProperty(
"VS_TARGET_FRAMEWORKS_TARGET_VERSION")) { "VS_TARGET_FRAMEWORKS_TARGET_VERSION")) {
targetFrameworkTargetsVersion = *tfTargetsVer; targetFrameworkTargetsVersion = *tfTargetsVer;
} else {
targetFrameworkTargetsVersion = "v8.0";
} }
} }
if (!targetFrameworkIdentifier) {
targetFrameworkIdentifier =
this->GlobalGenerator->GetTargetFrameworkIdentifier();
}
if (!targetFrameworkTargetsVersion) {
targetFrameworkTargetsVersion =
this->GlobalGenerator->GetTargetFrameworkTargetsVersion();
}
} }
if (targetFramework) { if (targetFramework) {
if (targetFramework->find(';') != std::string::npos) { if (targetFramework->find(';') != std::string::npos) {