mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 19:43:23 +08:00
VS: Teach VS 2019 generator to select host tools matching host arch
This generator is new so we can introduce the long-desired behavior of selecting ``host=x64`` tools by default on x64 hosts.
This commit is contained in:
@@ -47,6 +47,7 @@ default. The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps
|
|||||||
via the :manual:`cmake(1)` ``-T`` option, to specify another toolset.
|
via the :manual:`cmake(1)` ``-T`` option, to specify another toolset.
|
||||||
|
|
||||||
.. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace::
|
.. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace::
|
||||||
By default this generator uses the 32-bit variant even on a 64-bit host.
|
By default this generator uses the 64-bit variant on x64 hosts and
|
||||||
|
the 32-bit variant otherwise.
|
||||||
|
|
||||||
.. include:: VS_TOOLSET_HOST_ARCH.txt
|
.. include:: VS_TOOLSET_HOST_ARCH.txt
|
||||||
|
@@ -10,4 +10,5 @@ vs2019
|
|||||||
in the generator name. Instead :variable:`CMAKE_GENERATOR_PLATFORM`
|
in the generator name. Instead :variable:`CMAKE_GENERATOR_PLATFORM`
|
||||||
must be used, e.g. through the ``-A`` command-line option. Furthermore,
|
must be used, e.g. through the ``-A`` command-line option. Furthermore,
|
||||||
the default target platform (architecture) is now based on the *host*
|
the default target platform (architecture) is now based on the *host*
|
||||||
platform.
|
platform. The VS host toolset selection is now based on the host
|
||||||
|
architecture as well.
|
||||||
|
@@ -607,10 +607,26 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionString() const
|
|||||||
const char*
|
const char*
|
||||||
cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
|
cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
|
||||||
{
|
{
|
||||||
if (!this->GeneratorToolsetHostArchitecture.empty()) {
|
std::string const& hostArch =
|
||||||
return this->GeneratorToolsetHostArchitecture.c_str();
|
this->GetPlatformToolsetHostArchitectureString();
|
||||||
|
if (hostArch.empty()) {
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return hostArch.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string const&
|
||||||
|
cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
if (!this->GeneratorToolsetHostArchitecture.empty()) {
|
||||||
|
return this->GeneratorToolsetHostArchitecture;
|
||||||
|
}
|
||||||
|
if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
|
||||||
|
return this->DefaultPlatformToolsetHostArchitecture;
|
||||||
|
}
|
||||||
|
static std::string const empty;
|
||||||
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
|
const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
|
||||||
|
@@ -58,6 +58,7 @@ public:
|
|||||||
|
|
||||||
/** The toolset host architecture name (e.g. x64 for 64-bit host tools). */
|
/** The toolset host architecture name (e.g. x64 for 64-bit host tools). */
|
||||||
const char* GetPlatformToolsetHostArchitecture() const;
|
const char* GetPlatformToolsetHostArchitecture() const;
|
||||||
|
std::string const& GetPlatformToolsetHostArchitectureString() const;
|
||||||
|
|
||||||
/** The cuda toolset version. */
|
/** The cuda toolset version. */
|
||||||
const char* GetPlatformToolsetCuda() const;
|
const char* GetPlatformToolsetCuda() const;
|
||||||
@@ -152,6 +153,7 @@ protected:
|
|||||||
std::string GeneratorToolsetHostArchitecture;
|
std::string GeneratorToolsetHostArchitecture;
|
||||||
std::string GeneratorToolsetCuda;
|
std::string GeneratorToolsetCuda;
|
||||||
std::string DefaultPlatformToolset;
|
std::string DefaultPlatformToolset;
|
||||||
|
std::string DefaultPlatformToolsetHostArchitecture;
|
||||||
std::string WindowsTargetPlatformVersion;
|
std::string WindowsTargetPlatformVersion;
|
||||||
std::string SystemName;
|
std::string SystemName;
|
||||||
std::string SystemVersion;
|
std::string SystemVersion;
|
||||||
|
@@ -11,10 +11,13 @@
|
|||||||
|
|
||||||
#if defined(_M_ARM64)
|
#if defined(_M_ARM64)
|
||||||
# define HOST_PLATFORM_NAME "ARM64"
|
# define HOST_PLATFORM_NAME "ARM64"
|
||||||
|
# define HOST_TOOLS_ARCH ""
|
||||||
#elif defined(_M_ARM)
|
#elif defined(_M_ARM)
|
||||||
# define HOST_PLATFORM_NAME "ARM"
|
# define HOST_PLATFORM_NAME "ARM"
|
||||||
|
# define HOST_TOOLS_ARCH ""
|
||||||
#elif defined(_M_IA64)
|
#elif defined(_M_IA64)
|
||||||
# define HOST_PLATFORM_NAME "Itanium"
|
# define HOST_PLATFORM_NAME "Itanium"
|
||||||
|
# define HOST_TOOLS_ARCH ""
|
||||||
#else
|
#else
|
||||||
# include "cmsys/SystemInformation.hxx"
|
# include "cmsys/SystemInformation.hxx"
|
||||||
#endif
|
#endif
|
||||||
@@ -33,6 +36,20 @@ static std::string VSHostPlatformName()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string VSHostArchitecture()
|
||||||
|
{
|
||||||
|
#ifdef HOST_TOOLS_ARCH
|
||||||
|
return HOST_TOOLS_ARCH;
|
||||||
|
#else
|
||||||
|
cmsys::SystemInformation info;
|
||||||
|
if (info.Is64Bits()) {
|
||||||
|
return "x64";
|
||||||
|
} else {
|
||||||
|
return "x86";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned int VSVersionToMajor(
|
static unsigned int VSVersionToMajor(
|
||||||
cmGlobalVisualStudioGenerator::VSVersion v)
|
cmGlobalVisualStudioGenerator::VSVersion v)
|
||||||
{
|
{
|
||||||
@@ -262,6 +279,7 @@ cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator(
|
|||||||
this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version);
|
this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version);
|
||||||
if (this->Version >= cmGlobalVisualStudioGenerator::VS16) {
|
if (this->Version >= cmGlobalVisualStudioGenerator::VS16) {
|
||||||
this->DefaultPlatformName = VSHostPlatformName();
|
this->DefaultPlatformName = VSHostPlatformName();
|
||||||
|
this->DefaultPlatformToolsetHostArchitecture = VSHostArchitecture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
-- CMAKE_VS_PLATFORM_TOOLSET='Test Toolset'
|
-- CMAKE_VS_PLATFORM_TOOLSET='Test Toolset'
|
||||||
-- CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=''
|
-- CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE='.*'
|
||||||
|
@@ -1,2 +1,15 @@
|
|||||||
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET='${CMAKE_VS_PLATFORM_TOOLSET}'")
|
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET='${CMAKE_VS_PLATFORM_TOOLSET}'")
|
||||||
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE='${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}'")
|
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE='${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}'")
|
||||||
|
|
||||||
|
if(CMAKE_GENERATOR MATCHES "Visual Studio 1[6]")
|
||||||
|
cmake_host_system_information(RESULT is_64_bit QUERY IS_64BIT)
|
||||||
|
if(is_64_bit)
|
||||||
|
if(NOT "${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}" STREQUAL "x64")
|
||||||
|
message(FATAL_ERROR "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE is not 'x64' as expected.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(NOT "${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE is not empty as expected.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
Reference in New Issue
Block a user