<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Title" content="">
<meta name="Keywords" content="">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.msoIns
{mso-style-type:export-only;
mso-style-name:"";
text-decoration:underline;
color:teal;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">That will work well for me. Thank you!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Pirama Arumuga Nainar <pirama@google.com><br>
<b>Date: </b>Friday, October 20, 2017 at 11:09 AM<br>
<b>To: </b>Shoaib Meenai <smeenai@fb.com><br>
<b>Cc: </b>"llvm-dev@lists.llvm.org" <llvm-dev@lists.llvm.org><br>
<b>Subject: </b>Re: [llvm-dev] LLVM cross-compilation cmake issues<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">CROSS_TOOLCHAIN_FLAGS_NATIVE can be used to pass CMake variables when building the native tools. What I do is set up a toolchain file:
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">set(CMAKE_C_COMPILER {host-cc})<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">set(CMAKE_CXX_COMPILER {host-cxx})<o:p></o:p></p>
</div>
</blockquote>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">... <o:p></o:p></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">And pass this to the top level CMake:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">-DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_TOOLCHAIN_FILE=<path-to-above-file>" <o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">CMAKE_C_COMPILER etc can instead be directly set in this flag (instead of a toolchain file):<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">-DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_C_COMPILER=<host-cc> ..." <o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Oct 17, 2017 at 5:11 PM, Shoaib Meenai via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">I'm an idiot and sent to llvm-commits instead of llvm-dev. Fixing.<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
On 10/17/17, 5:09 PM, "llvm-commits on behalf of Shoaib Meenai via llvm-commits" <<a href="mailto:llvm-commits-bounces@lists.llvm.org">llvm-commits-bounces@lists.llvm.org</a> on behalf of
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
<br>
Hi all (CC beanz for cmake advice),<br>
<br>
<br>
<br>
I'm running into a cmake problem when I try to cross-compile a Windows-hosted<br>
<br>
toolchain (building on Linux). I'm using clang-cl as my cross-compiler, and I<br>
<br>
set up the compiler paths in a cmake toolchain file. Unfortunately, as part of<br>
<br>
setting up the compiler, cmake sets the environment variables ASM, CC, CXX,<br>
<br>
etc. to the paths it found. It's easy enough to reproduce this; just configure<br>
<br>
the following CMakeLists.txt:<br>
<br>
<br>
<br>
message(STATUS "CC is $ENV{CC}")<br>
<br>
project(null C)<br>
<br>
message(STATUS "CC is $ENV{CC}")<br>
<br>
<br>
<br>
The first printout should be empty (assuming you don't have CC set in your<br>
<br>
environment already, of course), and the second value should be the full path<br>
<br>
the compiler found by cmake. Note that this will only occur on the initial<br>
<br>
configure; subsequent configures should have the compiler setup cached, and<br>
<br>
will therefore not set the environment variable. I've confirmed this behavior<br>
<br>
on cmake 3.5, 3.6, and 3.9, so I'm fairly sure it's universal.<br>
<br>
<br>
<br>
This causes problems for me because when I'm running the initial cmake<br>
<br>
configure for my cross-compile, ASM, CC, and CXX get set to the values for my<br>
<br>
cross-compiler (clang-cl). LLVM's build then launches the configure for the<br>
<br>
native portions of the build (TableGen, etc.), but this configure is launched<br>
<br>
with the aforementioned environment variables, and cmake's compiler detection<br>
<br>
picks up on those environment variables, so it then tries to compile the<br>
<br>
native portions with my cross-compiler, which goes about as well as you'd<br>
<br>
expect.<br>
<br>
<br>
<br>
My current workaround is to simply unset these environment variables before<br>
<br>
running the native configure step:<br>
<br>
<br>
<br>
--- a/cmake/modules/CrossCompile.cmake<br>
<br>
+++ b/cmake/modules/CrossCompile.cmake<br>
<br>
@@ -45,6 +45,9 @@ function(llvm_create_cross_target_internal target_name toolchain buildtype)<br>
<br>
# Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built<br>
<br>
set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}")<br>
<br>
endif()<br>
<br>
+ unset(ENV{ASM})<br>
<br>
+ unset(ENV{CC})<br>
<br>
+ unset(ENV{CXX})<br>
<br>
execute_process(COMMAND ${CMAKE_COMMAND} ${build_type_flags}<br>
<br>
-G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD}<br>
<br>
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}<br>
<br>
<br>
<br>
It would be more proper to save the values of these environment variables at<br>
<br>
the start of the configure (before any project command is run) and restore<br>
<br>
those values before starting the native configure, of course. This still feels<br>
<br>
pretty ugly though, and I'm sure I'm not the first person to run into a<br>
<br>
similar issue. What would be the best way to fix this?<br>
<br>
<br>
<br>
Thanks,<br>
<br>
Shoaib<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=8ELwXEfNVoGOamcM1LPnxtDt4B9cgcSOabVKJZexuuU&s=TewHIKn_JhBOwiDZuDz6rGWMoBaH2jNeGs5OM7LG6cY&e=" target="_blank">
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=8ELwXEfNVoGOamcM1LPnxtDt4B9cgcSOabVKJZexuuU&s=TewHIKn_JhBOwiDZuDz6rGWMoBaH2jNeGs5OM7LG6cY&e=</a><br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=qFQxRnRUC41XbKVdOpYJLdYqihp4Fx--ayW0eB7ISd4&s=w3ZRpCJ-YxoB5MoosSaF7q1kwK9i3Fg4vkyPL7PN0bk&e=" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>