[CMake] Adding cross-compiler support to CMake ...

Michael Casadevall sonicmctails at aol.com
Wed Sep 6 02:19:04 EDT 2006


I wish to add support for cross-compiling to CMake since its a tool I  
use a lot, and I can finally kill the last few of my projects using  
autotools. To my knowledge, autotools is the only system that  
provides cross-compiling, and poorly at that, and I've been thinking  
on ways to add it to CMake. Here's what I got so far:

Add a standard flag when the language is c, or c++ (or some other  
language that can be cross-compiled): CROSS_COMPILE?

If its yes, remove the normal fields for compilers (from the advanced  
view), and have the following (I'm open to suggestions for TARGET  
(the machine being built for) and LOCAL:
TARGET_CC
TARGET_CXX
TARGET_LD
TARGET_*etc*
TARGET_PLATFORM

LOCAL_CC
LOCAL_CXX
LOCAL_LD
LOCAL_*etc*


*CMAKE_SSH=ssh
*CMAKE_SCP=scp
TARGET_REMOTE_PATH=~

* = should probably be environment varriables
Anyone who's cross-compiled anything with autotools will notice that  
I chose to use different terminology, and omit the equivalent of -- 
target that autotools use for a few reasons:

--target is only used in VERY rare cases when doing a canadian cross,  
or when creating an actual cross-compiler. In years of using cross- 
compilers, I've never seen the need to do it. Beside gcc and  
binutils, to my knowledge, no package uses --target. (for those of  
you curious, --target is used to set the target output of code from a  
compiler, hence why its not used very often - I don't believe general  
projects will ever need this functionality, and if they do, they can  
simply write a custom macro to mimic its functionality).

Next, you'll see that I specfic CMAKE_SSH/SCP and TARGET_REMTOE_PATH.  
autotools cross-compiler support is VERY clunky, and it is very poor  
in running remote platform tests. When autotoos needs to determine if  
something is true on the target machine, it bombs with "Unable to  
test due to cross-compiling", and doesn't give you any alternative  
but to dig into the configure script, find the variable it's  
referring and manually set it. It also "helpfully" deletes any test  
code it would have used to determine it on a local platform. In  
addition, this can be extended to CTest to properly run tests on both  
the remote and building systems.

Also, since GCC is the only open-source and free cross-compiler  
(OpenWatcom can't be built as a crosscompiler, and Borland and  
Microsoft don't offer them (expect for Windows CE, and VERY old  
versions of Windows NT)), it will be a requirement for CMake to test  
for GCC as the cross-compiler, but have support for different native  
compilers.

Finally, a special generator will have to be written that can handle  
the generation of a makefile that will properly do the cross-compiling.

I am interested in any support or ideas before I attempt to take this  
project on.
Michael


More information about the CMake mailing list