Cross compile LLVM

Hi;

I am trying to cross compile LLVM for Android-NDK;
I am using CMake as a build system; hence, i have defined CMAKE_SYSTEM_NAME variable so to turn on CMAKE_CROSSCOMPILING flag, being used by LLVM.

As far as i understand from the LLVM structure; when cross compiling, executable are generated with two versions; one goes under the target build directory ${CMAKE_BINARY_DIR} and the other goes into ${CMAKE_BINARY_DIR}/native/…

We i do that, i get all the tblgen + clang executable generated like that.

however, the tools under TOOLS don’t; and they aren’t runnable on the host-build system.

why is that? any ideas are appreciated.

Thanks

Rami Jiossy <sramij@gmail.com> writes:

I am trying to cross compile LLVM for Android-NDK;
I am using CMake as a build system; hence, i have defined CMAKE_SYSTEM_NAME
variable so to turn on CMAKE_CROSSCOMPILING flag, being used by LLVM.

As far as i understand from the LLVM structure; when cross compiling,
executable are generated with two versions; one goes under the target build
directory ${CMAKE_BINARY_DIR} and the other goes into
${CMAKE_BINARY_DIR}/native/....

We i do that, i get all the tblgen + clang executable generated like that.

however, the tools under TOOLS don't; and they aren't runnable on the
host-build system.

why is that? any ideas are appreciated.

First of all, setting CMAKE_SYSTEM_NAME is not enough for
cross-compiling. Please see

http://www.llvm.org/docs/CMake.html#cross-compiling

for pointers to specific instructions about how to cross-compile with
CMake.

When LLVM is cross-compiled, a native tlbgen executable is generated for
using on the build process. Tools for the target platform are generated
in ${CMAKE_BINARY_DIR}. Dunno about clang.

If, after following the instructions linked above, you don't obtain the
tools for the target platform in ${CMAKE_BINARY_DIR}, there is a bug in
the LLVM CMake scripts.

I’m assuming you mean “with” Android NDK “for” an ARM/MIPS/X86 Android device. Otherwise, there’s no need to cross-compile.

That said, this is what I would expect the build to do. You’re cross-compiling, so you want a version of LLVM built for a different system. Everything in tools/ will be built to be used on the target system, not the host system. If you want tools for the host system, you can compile LLVM normally. Tablegen will be built for the host system because it is needed during the build process. I’m not sure about clang, it seems like a bug if you compile for Android/ARM and get a Linux/X86 version of clang.