[llvm-dev] Guidance on cross compiling LLVM with mingw-w64 and cmake

via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 11 12:51:28 PST 2016


Brilliant. That worked, and was apparently all I was missing. I could have sworn I tried something like this, but apparently not.

For completeness, my NATIVE.cmake toolchain file is just:



Thanks Justin!

On Thu, Feb 11, 2016 at 11:55 AM -0800, "Justin Bogner" <mail at justinbogner.com> wrote:

Tony Kelman via llvm-dev <llvm-dev at lists.llvm.org> writes:
> I need to build libLLVM (individual static libraries are fine at the
> moment) using mingw-w64 cross compilers, i686-w64-mingw32-gcc and
> (separately) x86_64-w64-mingw32-gcc. I'd like this to work from both
> Linux and Cygwin build environments. With autotools, this worked fine:
> ../configure --host=i686-w64-mingw32 and that's it (with mingw32-gcc-c++
> installed on Fedora 23, also works fine on Ubuntu, Cygwin, etc).
> I'm trying to recreate this with cmake so we don't get stuck on 3.8
> indefinitely. Here's what I've got so far:
> cmake .. -DCMAKE_C_COMPILER=/usr/bin/i686-w64-mingw32-gcc \
>   -DCMAKE_CXX_COMPILER=/usr/bin/i686-w64-mingw32-g++ \
>   -DCMAKE_RC_COMPILER=/usr/bin/i686-w64-mingw32-windres
> # (some older versions of cmake have issues if you don't
> # specify an absolute path to windres)
> When this gets to "Configuring NATIVE targets" it calls cmake again
> trying to use the same mingw compilers, but without CMAKE_SYSTEM_NAME
> set so it doesn't succeed in configuring. During the build I then get
> a "No rule to make target 'LLVMSupport'.  Stop." Full build log is at
> http://sprunge.us/bCUU
> I'd like to go with the default behavior of building a native version
> of TableGen, but the way that's currently set up in cmake isn't working
> here. I'm looking at cmake/modules/CrossCompile.cmake (and I think
> "toochain" on the first line is a typo?) and trying to figure out how
> to make its call to execute_process(COMMAND ${CMAKE_COMMAND} ...) not
> inherit the top-level settings for CMAKE_C_COMPILER etc from the cross
> build. Any ideas? I've tried moving my mingw settings from the command
> line to a toolchain file but that hasn't done anything different so far.
> I've also tried specifically creating a native toolchain file and
> tweaking the call to llvm_create_cross_target_internal at the end of
> CrossCompile.cmake to use it, but that hasn't worked either - keeps giving
> Could not find toolchain file: "/home/llvm/cmake/platforms/NATIVE.cmake"

Looks like the (unreachable due to the toochain typo) cmake code to set
the native toolchain file is buggy - it's failing to find the file
because it thinks the quotes are part of the file name. This:


should probably say this:


You could probably also try out your native toolchain file without
changing CrossCompile.cmake by setting CROSS_TOOLCHAIN_FLAGS_NATIVE on
your cmake command line:

  cmake .. -DCMAKE_C_COMPILER=/usr/bin/i686-w64-mingw32-gcc \
    -DCMAKE_CXX_COMPILER=/usr/bin/i686-w64-mingw32-g++ \
    -DCMAKE_RC_COMPILER=/usr/bin/i686-w64-mingw32-windres \

If that helps, we should probably figure out a more general way to pass
in or find the native toolchain - it's kind of haphazard right now.

Finally, if you need a workaround to get things going you can probably
configure and build tablegen in another build directory (just run cmake
like you're building for the host and build the llvm-tblgen target).
This can then be passed in with -DLLVM_NATIVE_BUILD=/path/to/builddir
and the cross build *should* pick up the tablegen from there.

> Is this a configuration anyone else has gotten working with cmake?
> Thanks,
> Tony
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160211/319556e8/attachment.html>

More information about the llvm-dev mailing list