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

William A. Hoffman billlist at nycap.rr.com
Thu Sep 7 19:35:35 EDT 2006


At 06:42 PM 9/7/2006, Michael Casadevall wrote:
>1. Never seen that. autotools should only enter cross-compiling mode  
>if --host is set, and its different the current platform, or if both  
>build and host are set with different values.
If you look in a configure script..

rm -f a.out a.exe conftest$ac_cv_exeext b.out
ac_clean_files=$ac_clean_files_save
# Check the compiler produces executables we can run.  If not, either
# the compiler is broken, or we cross compile.
echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
echo "$as_me:$LINENO: result: $cross_compiling" >&5
echo "${ECHO_T}$cross_compiling" >&6

That is from the configure script of gnu make 3.8.1.
Looking at the other cross-compile stuff in that configure script.
It seems that all the try-run stuff is automatically set to No, if
it is in cross compile mode.  That would not be hard to do in cmake.

>2. In an earlier email which got disconnected from this one stated  
>there would be a configuration question CROSS_COMPILE. I'll attach  
>that email to the bottom of this one

I found it:

>TARGET_CC
>...


>LOCAL_CC
>LOCAL_CXX
>LOCAL_LD
>LOCAL_*etc*
>
>*CMAKE_SSH=ssh
>*CMAKE_SCP=scp
>TARGET_REMOTE_PATH=~

I am thinking that the normal variables could be used.   One idea
I had was to run cmake twice, once for local and once for target.
If we marked the targets with LOCAL or TARGET we would know which ones
to put in which build tree.   A toplevel makefile could be created that
walks into both trees in the correct order.

>I am aware of that method of cross-compiling, and its horrible. You  
>also need to add lines for RANLIB, AR, and usually some other  
>utilities and then remove TRY_RUN. I still won't call that cross- compiler support, CMake should undersatnd if its cross-compiling, and  
>it should be, in theory, as easy as compiling natively. Also, it  
>mucks the filenames and such. Try cross-compiling in CMake from Mac  
>OS X to Windows. Do-able with minigw, and autotools, but it would be  
>a nightmare for CMake based projects.

You do not have to remove the TRY_RUN calls.  TRY_RUN only runs once.
So, if the variable is pre-loaded in the cache, then it will not run.
I still don't think it would be a nightmare, things like exe extension
are all cmake variables at this point.  It would again require setting
them correctly in an initial cache.

Could you post an example of how the Mac OS X compiler can be used to
create windows executables?   I can give it a try and see how bad it really
is.


>Anyway, looking through the source of CMake, this is going to a bit  
>messy. Right now, it doesn't have a concept of multiple platforms,  
>and the Makefile generator isn't written in a way that it would be  
>easy to add it. I'm poking through the Module code now, and seeing  
>how it all comes together and see specifically what needs  
>modification now. I'm deciding if a new generator is needed, or the  
>Unix one can be recycled with a lot of hack and slashing.
>Michael

At the end of the day, I don't think we want two makefile generators.
I don't think it will require that much hacking and slashing... It may
require some refactoring. It runs the compiler with some flags and produces 
files, it is not that much different.

-Bill



More information about the CMake mailing list