[PATCH] D53073: With CMake 3.8+ force Visual Studio generator builds to use the x64 host toolchain if the user is on a 64-bit system

Greg Bedwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 10 04:51:00 PDT 2018


gbedwell created this revision.
gbedwell added reviewers: zturner, rnk, aaron.ballman, MikeStump.
Herald added a subscriber: mgorny.

  With older CMake versions, or if the user is on a 32-bit system we'll still output a warning suggesting using the 64-bit host toolchain.

Hopefully this will alleviate some of the teething problems new developers may run into using the Visual Studio generators (assuming the workflow is to go and grab the latest version of CMake.  The "Getting Started with the LLVM System using Microsoft Visual Studio" documentation suggests a CMake 3.8.0 requirement anyway.  See https://cmake.org/cmake/help/latest/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.html

On my 64-bit Windows system, I get the following behaviour:

| CMake version | Generator                   | warning (CMakeLists.txt:31) produced | CMAKE_CPP_COMPILER                                                                                                   |
| 3.4.3         | Visual Studio 14 2015       | yes                                  | C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe                                                    |
| 3.4.3         | Visual Studio 14 2015 Win64 | yes                                  | C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe                                          |
| 3.8.2         | Visual Studio 14 2015       | no                                   | C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64_x86/cl.exe                                          |
| 3.8.2         | Visual Studio 14 2015 Win64 | no                                   | C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe                                              |
| 3.8.2         | Visual Studio 15 2017       | no                                   | C:/Program Files (x86)/Microsoft Visual Studio/Preview/Professional/VC/Tools/MSVC/14.16.26926/bin/Hostx64/x86/cl.exe |
| 3.8.2         | Visual Studio 15 2017 Win64 | no                                   | C:/Program Files (x86)/Microsoft Visual Studio/Preview/Professional/VC/Tools/MSVC/14.16.26926/bin/Hostx64/x64/cl.exe |
|




https://reviews.llvm.org/D53073

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -26,10 +26,19 @@
 endif()
 
 if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
-  message(WARNING "Visual Studio generators use the x86 host compiler by "
-                  "default, even for 64-bit targets. This can result in linker "
-                  "instability and out of memory errors. To use the 64-bit "
-                  "host compiler, pass -Thost=x64 on the CMake command line.")
+
+  if ((CMAKE_VERSION VERSION_LESS 3.8) OR (NOT "$ENV{PROCESSOR_ARCHITECTURE}" STREQUAL "AMD64"))
+    message(WARNING "Visual Studio generators use the x86 host compiler by "
+                    "default, even for 64-bit targets. This can result in "
+                    "linker instability and out of memory errors. To use the "
+                    "64-bit host compiler, pass -Thost=x64 on the CMake "
+                    "command line.")
+  else()
+    # CMake 3.8 introduces the following variable to allow us to select the
+    # 64-bit host Visual Studio toolchain.
+    set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64")
+  endif()
+
 endif()
 
 project(LLVM


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53073.168981.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181010/e915eeb1/attachment.bin>


More information about the llvm-commits mailing list