[CMake] cross compiler flags

Dave Milter davemilter at gmail.com
Tue Nov 20 01:53:57 EST 2007


>cat CMakeLists.txt
PROJECT(arm_test)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")

ADD_EXECUTABLE(arm_test arm_test.cpp)

>cat Toolchain-arm-gcc-4.1.1.cmake
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /usr/local/arm/4.1.1-920t/bin/arm-linux-cc -march=armv4)
SET(CMAKE_CXX_COMPILER /usr/local/arm/4.1.1-920t/bin/arm-linux-c++ -march=armv4)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /usr/local/arm/4.1.1-920t/bin
/home/user/projects/arm/linux-2.6/linux-crater_1-0-3/build/root/)

# 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_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")

>cat arm_test.cpp
#include <cstdio>
#include <cstdlib>

int main()
{
        printf("hi from cirrus!\n");
        return EXIT_SUCCESS;
}

I build project in such way:
>mkdir build-arm/ && cd build-arm && cmake
-DCMAKE_TOOLCHAIN_FILE=../Toolchain-arm-gcc-4.1.1.cmake .. && make
VERBOSE=1

The command, which run arm-linux-gcc looks like:
  /usr/local/arm/4.1.1-920t/bin/arm-linux-c++ -march=armv4   -o
CMakeFiles/arm_test.dir/arm_test.o -c
/home/user/projects/tests/cmake-cross-compile/arm_test.cpp

As you see there is no "-Wall".

The toolchain if it is important you can find here:
http://arm.cirrus.com/files/tools/arm-linux-gcc-4.1.1-920t.tar.bz2

it is just binary files of gcc x86->arm cross compiler,
untar it to /usr/local/arm and all will just work, if you have x86 and Linux.

On 11/19/07, Alexander Neundorf <a.neundorf-work at gmx.net> wrote:
> On Monday 19 November 2007, Dave Milter wrote:
> > Usually, I use such construction to set cmake flags:
> > SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall
> >
> > but when I use "-DCMAKE_TOOLCHAIN_FILE" option this construction for
> > some reason does not work,
> > actually, if I run "make VERBOSE=1" compiler comand does not contain
> > flags at all, except "-c" "-o" and so on.
>
> Hmm, it should work.
> Can you create a testcase ?
>
> Alex
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list