[CMake] [HOWTO] Easily Cross-Compile CMake (with xstatic)
Rolf Eike Beer
eike at sf-mail.de
Fri Oct 26 05:09:22 EDT 2018
Am 2018-10-26 10:04, schrieb Zach van Rijn:
> Hi Friends,
>
>
> I have, until recently, been under the impression that CMake is
> rather difficult (or impossible?) to cross-compile correctly. I
> believe I have devised a sane method of doing so. In addition to
> being simple, the output binaries are fully static, so they may
> be transferred to any compatible system without dependencies. It
> has been tested on CMake version 3.12.3, on 48 platforms, of
> which 19 do not build without patches (contribs welcome!)
Hi Zach,
as someone who does crosscompiling for a living I have read your post,
even if I have never seen a need for what you are doing. It's an
interesting approach, although it looks pretty brute force. Not that I
have not done things like that myself (has anyone tried to compile a
recent udev without all the systemd things around it and without
packaging the dependencies only needed for the systemd parts before? you
know what I mean.).
I had an old cross-build recipe for CMake around and decided to clean
the dust away and see if it still works. Well, it did not, but that was
just because the embedded curl tries to do some try_run() things that do
not work. Since I already have a cross-curl library at hand I decided to
just use that, and things worked.
So, the 2 things that I do not understand why you need them at all:
-why do the bootstrap thing and move compilers? Just build a recent
CMake with your host toolchain, package that, and drop it into the build
container. The need for the host compiler should be gone at this point
-why do you need to overwrite the compiler with the target compiler?
Just drop it anywhere and tell CMake with CC and CXX variables where it
is. Or better, pass it a toolchain file like mine:
=== toolchain.cmake ===
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
# specify the cross compiler
set(CMAKE_C_COMPILER /opt/emlix/test/bin/arm-unknown-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER
/opt/emlix/test/bin/arm-unknown-linux-gnueabi-g++)
# where is the target environment
set(CMAKE_FIND_ROOT_PATH /opt/emlix/test/sysroot)
set(CMAKE_SYSROOT /opt/emlix/test/sysroot)
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
===
I'm pretty sure you may find some rough edges, especially if you do not
want to have the dependencies pre-build but use the embedded copies and
do static builds with them. But otherwise you should hopefully be able
to simplify your setup a lot.
Eike
--
More information about the CMake
mailing list