[PATCH] Fix LLVM target triple computation with MSVC

Zachary Turner zturner at google.com
Tue Jul 29 18:38:32 PDT 2014


Hi chandlerc,

CMake tries to determine the host target triple for the build by checking the value of CMAKE_CL_64.  The value of this variable is tied to the CMake generator, and not the toolchain in use.  In particular, it is only set to 1 when a generator of the form "Visual Studio <n> Win64" is used.  This means that it doesn't work for the Ninja generator, and will always give you a host triple of i686-pc-win32 even when compiling with a 64-bit toolchain.

This patch addresses this by running ${CMAKE_CXX_COMPILER} when MSVC is detected, and parsing its output to determine the architecture that it claims it targets, and then choosing the target triple accordingly.

http://reviews.llvm.org/D4715

Files:
  cmake/modules/GetHostTriple.cmake

Index: cmake/modules/GetHostTriple.cmake
===================================================================
--- cmake/modules/GetHostTriple.cmake
+++ cmake/modules/GetHostTriple.cmake
@@ -3,9 +3,19 @@
 
 function( get_host_triple var )
   if( MSVC )
-    if( CMAKE_CL_64 )
+    execute_process(
+      COMMAND ${CMAKE_CXX_COMPILER}
+      OUTPUT_VARIABLE CL_OUTPUT
+      ERROR_VARIABLE CL_ERROR)
+    STRING(REGEX REPLACE "Microsoft \\(R\\).* for (x64|x86|ARM).*"
+                         "\\1" 
+                         CL_TARGET_ARCHITECTURE
+                         ${CL_ERROR})
+    if ( "${CL_TARGET_ARCHITECTURE}" STREQUAL "x64" )
       set( value "x86_64-pc-win32" )
-    else()
+    elseif ( "${CL_TARGET_ARCHITECTURE}" STREQUAL "ARM" )
+      set( value "arm-pc-win32" )
+    else ()
       set( value "i686-pc-win32" )
     endif()
   elseif( MINGW AND NOT MSYS )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4715.12005.patch
Type: text/x-patch
Size: 880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140730/92cc679a/attachment.bin>


More information about the llvm-commits mailing list