1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

VS: Provide the default platform name to project code

The value of `CMAKE_VS_PLATFORM_NAME` is computed by Visual Studio
generators based on `CMAKE_GENERATOR_PLATFORM` or some default.
Prior to the VS 2019 generator, the default was always `Win32`.
However, for the `Visual Studio 16 2019` generator, the default is
based on the host platform.

Store the default in a new `CMAKE_VS_PLATFORM_NAME_DEFAULT` variable for
use by project code.  This is particularly useful in toolchain files
because they are allowed to set `CMAKE_GENERATOR_PLATFORM` and so
`CMAKE_VS_PLATFORM_NAME` is not yet known.  Of course the toolchain file
author knows whether it will set `CMAKE_GENERATOR_PLATFORM`, and if not
then `CMAKE_VS_PLATFORM_NAME_DEFAULT` provides the platform name that
will be used.

Fixes: #19177
This commit is contained in:
Brad King
2019-04-19 07:40:14 -04:00
parent 5e98111643
commit db02be85a0
10 changed files with 40 additions and 3 deletions

View File

@@ -28,7 +28,8 @@ by default.
Platform Selection Platform Selection
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
The default target platform name (architecture) is that of the host. The default target platform name (architecture) is that of the host
and is provided in the :variable:`CMAKE_VS_PLATFORM_NAME_DEFAULT` variable.
The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
via the :manual:`cmake(1)` ``-A`` option, to specify a target platform via the :manual:`cmake(1)` ``-A`` option, to specify a target platform

View File

@@ -105,6 +105,7 @@ Variables that Provide Information
/variable/CMAKE_VS_MSBUILD_COMMAND /variable/CMAKE_VS_MSBUILD_COMMAND
/variable/CMAKE_VS_NsightTegra_VERSION /variable/CMAKE_VS_NsightTegra_VERSION
/variable/CMAKE_VS_PLATFORM_NAME /variable/CMAKE_VS_PLATFORM_NAME
/variable/CMAKE_VS_PLATFORM_NAME_DEFAULT
/variable/CMAKE_VS_PLATFORM_TOOLSET /variable/CMAKE_VS_PLATFORM_TOOLSET
/variable/CMAKE_VS_PLATFORM_TOOLSET_CUDA /variable/CMAKE_VS_PLATFORM_TOOLSET_CUDA
/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE /variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE

View File

@@ -137,6 +137,10 @@ Variables
relocatable and reproducible builds that are invariant of the build relocatable and reproducible builds that are invariant of the build
directory. directory.
* A :variable:`CMAKE_VS_PLATFORM_NAME_DEFAULT` variable was added for
:ref:`Visual Studio Generators` to report their default platform used
when :variable:`CMAKE_GENERATOR_PLATFORM` is not set explicitly.
Properties Properties
---------- ----------
@@ -391,3 +395,10 @@ Changes made since CMake 3.14.0 include the following.
our conventions. 3.14.1 revises the module to use ``Fontconfig_*`` our conventions. 3.14.1 revises the module to use ``Fontconfig_*``
variable names. This is incompatible with 3.14.0 but since the variable names. This is incompatible with 3.14.0 but since the
module is new in the 3.14 series usage should not yet be widespread. module is new in the 3.14 series usage should not yet be widespread.
3.14.3
------
* The :variable:`CMAKE_VS_PLATFORM_NAME_DEFAULT` variable was added
to help toolchain files work with the :generator:`Visual Studio 16 2019`
generator where the default platform now depends on the host platform.

View File

@@ -1,8 +1,10 @@
CMAKE_VS_PLATFORM_NAME CMAKE_VS_PLATFORM_NAME
---------------------- ----------------------
Visual Studio target platform name. Visual Studio target platform name used by the current generator.
VS 8 and above allow project files to specify a target platform. VS 8 and above allow project files to specify a target platform.
CMake provides the name of the chosen platform in this variable. CMake provides the name of the chosen platform in this variable.
See the :variable:`CMAKE_GENERATOR_PLATFORM` variable for details. See the :variable:`CMAKE_GENERATOR_PLATFORM` variable for details.
See also the :variable:`CMAKE_VS_PLATFORM_NAME_DEFAULT` variable.

View File

@@ -0,0 +1,9 @@
CMAKE_VS_PLATFORM_NAME_DEFAULT
------------------------------
Default for the Visual Studio target platform name for the current generator
without considering the value of the :variable:`CMAKE_GENERATOR_PLATFORM`
variable. For :ref:`Visual Studio Generators` for VS 2017 and below this is
always ``Win32``. For VS 2019 and above this is based on the host platform.
See also the :variable:`CMAKE_VS_PLATFORM_NAME` variable.

View File

@@ -101,7 +101,7 @@ void cmGlobalVisualStudio7Generator::EnableLanguage(
} }
// Create list of configurations requested by user's cache, if any. // Create list of configurations requested by user's cache, if any.
this->cmGlobalGenerator::EnableLanguage(lang, mf, optional); this->cmGlobalVisualStudioGenerator::EnableLanguage(lang, mf, optional);
// if this environment variable is set, then copy it to // if this environment variable is set, then copy it to
// a static cache entry. It will be used by // a static cache entry. It will be used by

View File

@@ -52,6 +52,14 @@ void cmGlobalVisualStudioGenerator::SetVersion(VSVersion v)
this->Version = v; this->Version = v;
} }
void cmGlobalVisualStudioGenerator::EnableLanguage(
std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
{
mf->AddDefinition("CMAKE_VS_PLATFORM_NAME_DEFAULT",
this->DefaultPlatformName.c_str());
this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
}
bool cmGlobalVisualStudioGenerator::SetGeneratorPlatform(std::string const& p, bool cmGlobalVisualStudioGenerator::SetGeneratorPlatform(std::string const& p,
cmMakefile* mf) cmMakefile* mf)
{ {

View File

@@ -50,6 +50,9 @@ public:
/** Is the installed VS an Express edition? */ /** Is the installed VS an Express edition? */
bool IsExpressEdition() const { return this->ExpressEdition; } bool IsExpressEdition() const { return this->ExpressEdition; }
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
bool optional) override;
bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override; bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
/** /**

View File

@@ -1 +1,2 @@
message("CMAKE_VS_PLATFORM_NAME_DEFAULT is \"${CMAKE_VS_PLATFORM_NAME_DEFAULT}\"")
set(CMAKE_GENERATOR_PLATFORM "Test Platform") set(CMAKE_GENERATOR_PLATFORM "Test Platform")

View File

@@ -1,3 +1,4 @@
CMAKE_VS_PLATFORM_NAME_DEFAULT is "[^"]+"
CMake Error at TestPlatformToolchain.cmake:[0-9]+ \(message\): CMake Error at TestPlatformToolchain.cmake:[0-9]+ \(message\):
CMAKE_GENERATOR_PLATFORM is "Test Platform" as expected. CMAKE_GENERATOR_PLATFORM is "Test Platform" as expected.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):