diff options
author | Brad King <brad.king@kitware.com> | 2016-10-07 19:57:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-10-14 13:22:26 (GMT) |
commit | d079e71c290c3c55a2db5180953daf014a964c25 (patch) | |
tree | a2b7f24b599049e22e21fedca8fd9955e5c0d616 /Source | |
parent | 779939a00ebc21419404737f2fc2b34e7775f086 (diff) | |
download | CMake-d079e71c290c3c55a2db5180953daf014a964c25.zip CMake-d079e71c290c3c55a2db5180953daf014a964c25.tar.gz CMake-d079e71c290c3c55a2db5180953daf014a964c25.tar.bz2 |
VS: Provide an option to use x64 host tools
Visual Studio provides toolchains that are themselves built for 32-bit
or 64-bit host architectures. By default it uses the 32-bit tools, but
it can be told to prefer the 64-bit tools on 64-bit hosts. Extend the
`CMAKE_GENERATOR_TOOLSET` specification to provide a way to request
use of the 64-bit host tools.
Closes: #15622
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalVisualStudio10Generator.cxx | 37 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio10Generator.h | 5 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio12Generator.cxx | 15 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio12Generator.h | 3 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 9 |
6 files changed, 81 insertions, 1 deletions
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index caaac87..02ffa41 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -145,10 +145,36 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( return false; } - this->GeneratorToolset = ts; + if (!this->ParseGeneratorToolset(ts, mf)) { + return false; + } if (const char* toolset = this->GetPlatformToolset()) { mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset); } + if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) { + mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch); + } + return true; +} + +bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( + std::string const& ts, cmMakefile* mf) +{ + if (ts.find_first_of(",=") != ts.npos) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "does not recognize the toolset\n" + " " << ts << "\n" + "that was specified."; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + + this->GeneratorToolset = ts; return true; } @@ -322,6 +348,15 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const return 0; } +const char* +cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const +{ + if (!this->GeneratorToolsetHostArchitecture.empty()) { + return this->GeneratorToolsetHostArchitecture.c_str(); + } + return CM_NULLPTR; +} + void cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf) { this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf); diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 19c60aa..f8a50ac 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -22,6 +22,7 @@ public: virtual bool SetSystemName(std::string const& s, cmMakefile* mf); virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf); virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf); + virtual bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf); virtual void GenerateBuildCommand( std::vector<std::string>& makeCommand, const std::string& makeProgram, @@ -48,6 +49,9 @@ public: /** The toolset name for the target platform. */ const char* GetPlatformToolset() const; + /** The toolset host architecture name (e.g. x64 for 64-bit host tools). */ + const char* GetPlatformToolsetHostArchitecture() const; + /** Return the CMAKE_SYSTEM_NAME. */ std::string const& GetSystemName() const { return this->SystemName; } @@ -101,6 +105,7 @@ protected: std::string const& GetMSBuildCommand(); std::string GeneratorToolset; + std::string GeneratorToolsetHostArchitecture; std::string DefaultPlatformToolset; std::string WindowsTargetPlatformVersion; std::string SystemName; diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index 5fdeec7..ec7916c 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -96,6 +96,21 @@ bool cmGlobalVisualStudio12Generator::MatchesGeneratorName( return false; } +bool cmGlobalVisualStudio12Generator::ParseGeneratorToolset( + std::string const& ts, cmMakefile* mf) +{ + std::string::size_type ts_end = ts.size(); + if (cmHasLiteralSuffix(ts, ",host=x64")) { + this->GeneratorToolsetHostArchitecture = "x64"; + ts_end -= 9; + } else if (ts == "host=x64") { + this->GeneratorToolsetHostArchitecture = "x64"; + ts_end = 0; + } + return this->cmGlobalVisualStudio11Generator::ParseGeneratorToolset( + ts.substr(0, ts_end), mf); +} + bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf) { if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) { diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index 78bb637..cdda512 100644 --- a/Source/cmGlobalVisualStudio12Generator.h +++ b/Source/cmGlobalVisualStudio12Generator.h @@ -22,6 +22,9 @@ public: // version number virtual const char* GetToolsVersion() { return "12.0"; } protected: + bool ParseGeneratorToolset(std::string const& ts, + cmMakefile* mf) CM_OVERRIDE; + virtual bool InitializeWindowsPhone(cmMakefile* mf); virtual bool InitializeWindowsStore(cmMakefile* mf); virtual bool SelectWindowsPhoneToolset(std::string& toolset) const; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 75fc2e4..0ddfc9a 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -220,6 +220,19 @@ bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, cmMakefile* mf) { if (this->XcodeVersion >= 30) { + if (ts.find_first_of(",=") != ts.npos) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "does not recognize the toolset\n" + " " << ts << "\n" + "that was specified."; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } this->GeneratorToolset = ts; if (!this->GeneratorToolset.empty()) { mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET", diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 6690bfa..4a9df04 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -322,6 +322,15 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString("</PropertyGroup>\n", 1); } + if (const char* hostArch = + this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) { + this->WriteString("<PropertyGroup>\n", 1); + this->WriteString("<PreferredToolArchitecture>", 2); + (*this->BuildFileStream) << cmVS10EscapeXML(hostArch) + << "</PreferredToolArchitecture>\n"; + this->WriteString("</PropertyGroup>\n", 1); + } + this->WriteProjectConfigurations(); this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1); this->WriteString("<ProjectGUID>", 2); |