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
--
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to