[CMake] CMake 2.6.0 cross-compile: 1st time failed, 2nd time passed

ning mailxiening at gmail.com
Tue Aug 5 21:04:16 EDT 2008


Hi, Alex

2008/8/6 Alexander Neundorf <a.neundorf-work at gmx.net>:
> On Tuesday 05 August 2008, ning wrote:
>> Hi, all
>>
>> Just for other cmake newbies, like me, who run into cross-compiler that
>> is not able to build a simple program by default without special flags.
>> When I go on reading the wiki
>> http://www.cmake.org/Wiki/CMake_Cross_Compiling
>> I found that I should use CMakeForceCompiler module to bypass build
>> of cmTryCompileExec. It works for me now.
>
> You need two special flags, if I see correctly ?
>> > SET(CMAKE_C_FLAGS       "--sysroot=${SYSROOT_PATH} -mfloat-abi=softfp")
>> > SET(CMAKE_C_COMPILER    "arm-wrs-linux-gnueabi-gcc")
Actually, I just use flags as told by administrator of the build server.
We could pass on one server with only "--sysroot=${SYSROOT_PATH}",
but need to add "-mfloat-abi=softfp" on another server.

>
> And these both are really required for building just the most basic
> executable ?
> Currently cmake supports 1 additional extra argument, then you could do it
> like this:
> SET(CMAKE_C_COMPILER  arm-wrs-linux-gnueabi-gcc "--sysroot=${SYSROOT_PATH}")
>
> You can try if you get this working for you.
I removed force compiler inclusion from CMAKE_TOOLCHAIN_FILE and
"if (CMAKE_CROSSCOMPILING)" clause from CMakeLists.txt to try
set(CMAKE_C_COMPILER
        "arm-wrs-linux-gnueabi-gcc"
        "--sysroot=${SYSROOT_PATH} -mfloat-abi=softfp")
It works well.
>
>
>
>> One note: It looks like CMAKE_C_FLAGS should not be set in
>> cross-tools.cmake which is assigned to -DCMAKE_TOOLCHAIN_FILE
>> in command line. CMAKE_C_FLAGS for cross compiler should
>> be surrounded by "if (CMAKE_CROSSCOMPILING)...endif" in
>> CMakeLists.txt.
>
> Yes, if you set compiler flags or similar things in CMakeLists.txt you should
> always put this in appropriate IF() statements, so they are only executed for
> the compiler they are intended for (not only when cross compiling, e.g. you
> also need different flags whether you are using gcc or msvc).
Actually I would like to put cross-compiler specific flags in
CMAKE_TOOLCHAIN_FILE,
and leave CMakeLists.txt with only flags that are common to native and
cross compilers.

>
> Alex
>

BTW, I was using CMake2.6.0 when I initiated this question, and I have
upgraded to
CMake2.6.1 before I tried your method.
Thank you.

Best regards
ning


More information about the CMake mailing list