[LLVMdev] Host target triple on Windows

Zachary Turner zturner at google.com
Tue Jul 29 17:38:27 PDT 2014


I'm trying to figure out how to get, from CMake, the architecture of the
platform that I'm compiling LLVM for.  If I'm building LLVM on x86, I want
x86.  On x64 I want x86_64.  On arm arm.  etc.

The best I can figure out so far is that I should use LLVM_HOST_TRIPLE, and
extract the first component of this.  At least if my understanding is
correct, I should have the following behavior:

Compiling using 32-bit toolchain on Windows: LLVM_HOST_TRIPLE =
i686-pc-win32
Compiling using 64-bit toolchain on Windows: LLVM_HOST_TRIPLE
= x86_64-pc-win32

This doesn't currently seem to work.  See, for example, the following
output from when I run CMake twice from the command line, once with an x86
toolchain and once with an x64 toolchain:

D:\src\llvm\build\ninja>"c:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\vcvarsall.bat" x86

D:\src\llvm\build\ninja>where cl
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\cl.exe

D:\src\llvm\build\ninja>cmake ..\..
-- Target triple: i686-pc-win32
-- Native target architecture is X86

D:\src\llvm\build\ninja>"c:\Program Files (x86)\Microsoft Visual Studio
12.0\VC\vcvarsall.bat" x86_amd64

D:\src\llvm\build\ninja>where cl
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\cl.exe
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe

D:\src\llvm\build\ninja>cmake ..\..
-- Target triple: i686-pc-win32
-- Native target architecture is X86


In both cases my triple is the same.  This seems to boil down to some code
in llvm\cmake\modules\GetHostTriple.cmake.  It uses the variable
CMAKE_CL_64.  From what I can tell, the value of this variable depends on
your CMake generator, and not on your toolchain. Some googling suggests
that CMAKE_CL_64 will be set to 1 if you run cmake -G "Visual Studio 12
Win64".  I can't even get this to work, however, as it just says that
generator doesn't exist.  Furthermore, it won't work with other generators,
such as the ninja generator.

Ultimately, it would be nice if there were a way to just ask the compiler
what architecture it's going to generate code for.  Luckily, it seems like
there might be a solution.  If you run cl  with no arguments it is always
prefaced with a header such as the following:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_arm>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for ARM
Copyright (C) Microsoft Corporation.  All rights reserved.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Note at the end it says "for ARM", or "for x86", etc.  So, I think a better
solution for the GetHostTriple() function might be to run cl.exe and use
STRING(REGEX MATCH ...) to figure out what cl reports.

Disagreements?  Suggestions?

If there's no objections I'd like to make this change.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140729/ec8266ea/attachment.html>


More information about the llvm-dev mailing list