[CMake] Cross-compiling a static library (CMake 2.8.3)

Alexander Neundorf a.neundorf-work at gmx.net
Tue Feb 8 15:52:44 EST 2011


On Monday 07 February 2011, Emmanuel Blot wrote:
> >> FWIW: I found why I use CMAKE_FORCE_C_COMPILER rather than the simpler
> >> CMAKE_C_COMPILER command:
> >> I build projects for eCos from outside the eCos tree directory, and
> >> CMake has some trouble finding the eCos header files when simply using
> >> CMAKE_C_COMPILER. It complains about CMAKE_FIND_ROOT_PATH which is
> >> nevertheless defined as expected.
>
> Sorry to get back so late on this topic
>
> > You should not need to use CMAKE_FORCE_C_COMPILER() for eCos.
> > Can you please post some more details on your setup ?
>
> I build eCos-based projects for ARM. The compiler prefix is "arm-eabi-"
>
> The basic directory layout is as follows:
>
> ecos/ : contains the std eCos "packages" subdir, etc.
> sdk/  : contains our base code, that builds against eCos
>
> build/ : where all the code is built (out-of-source build), that is:
>   build/ecos_build
>   build/ecos_install
>   build/sdk ...
>
> > Where is the eCos tree with libtarget.a etc. ?
>
>   build/ecos_install/lib/libtarget.a
>   build/ecos_install/include/pkgconf/system.h
>
> > How does your toolchain file look like ?
>
> arm-eabi-gcc-4.5.2 (on Linux, Mac OS X), arm-eabi-gcc-4.5.2.exe (on Cygwin)
> all other toolchain tools are prefixed with arm-eabi- as well
>
> > How do you call cmake ?
>
> From a shell script. A simplified version of the command line would be
> (TOPDIR does not exist, TOPDIR is actually the absolute path to the
> startup directory)
>
> TOPDIR=$PWD
> (cd build/sdk &&
>  cmake -DCMAKE_FIND_ROOT_PATH=$TOPDIR/build/ecos_install \
>        -DSDK_PATH=$TOPDIR/build/sdk/install -DCMAKE_BUILD_TYPE=DEBUG \
>        -DPYTHON=/usr/bin/python2.6 ../../sdk && /usr/bin/make install)


Where do you set the toolchain file ?
I would have expected it in the command line.

> I also define:
>
>   SET (CMAKE_SYSTEM_NAME eCos)
>   SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
>   SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY LAST)
>   SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE LAST)
>
> (again, I can't remember why I selected "LAST" at some point in the
> past, but "ONLY" led to some other issues)
>
> When I drop CMAKE_FORCE_C_COMPILER and replace it with
> CMAKE_C_COMPILER, I get the following error message
>
> Building sdk in DEBUG
> -- The C compiler identification is GNU
> -- The CXX compiler identification is GNU
> -- Check for working C compiler: /usr/local/homebrew/bin/arm-eabi-gcc-4.5.2
> CMake Error at
> /usr/local/homebrew/Cellar/cmake/2.8.4-rc2/share/cmake/Modules/Platform/eCo
>s.cmake:36 (MESSAGE):
>   Could not find eCos pkgconf/system.h.  Build eCos first and set up
>   CMAKE_FIND_ROOT_PATH correctly.


Ok, found it.
CMAKE_FIND_ROOT_PATH must be set in the toolchain file.

The error comes from within a try_compile() call.
For this, a tiny new cmake project is created. There, the toolchain file is 
included, so stuff set in the toolchain file works there too.
Now you set CMAKE_FIND_ROOT_PATH via -D, so it is not known to the test 
project created by try_compile(), so the find_path() fails.

In which directory is the toolchain file located ? Is it in TOPDIR/ ?

Alex


More information about the CMake mailing list