cross compiling with cmake picking up host rather than target definitions

Viewed 29

I'm having problems cross compiling with cmake under linux.

cmake is generating a makefile with -isystem /usr... clauses when of course /usr is the host system so it's picking up all the wrong definitions. Particularly annoying is that cmake knows it is wrong because the compile command spews out lots of errors/warnings like ...

aarch64-linux-c++: WARNING: unsafe header/library path used in cross-compilation: '-isystem' '/usr/local/include'

Now, I'm no expert on cmake, but I know I have to specify a find path in a toolchain file something like ...

set(CMAKE_SYSTEM_NAME Linux)
set(BR_PATH "/home/mike/work/v3")
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_CROSSCOMPILING 1)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER ${BR_PATH}/output/host/bin/aarch64-buildroot-linux-gnu-gcc.br_real)
set(CMAKE_CXX_COMPILER ${BR_PATH}/output/host/bin/aarch64-linux-c++)

set(CMAKE_FIND_ROOT_PATH "${BR_PATH}/output/host/lib; ${BR_PATH}/output/host/aarch64-buildroot-linux-gnu/sysroot")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Now, it is clearly picking up this toolchain file OK, because it is using the correct compiler. I don't understand why it is ignoring my CMAKE_FIND_ROOT_PATH.

I tried forcing its' hand by doing set(CMAKE_IGNORE_PATH /usr), but it still included "-isystem /usr/include" in the generated makefile.

What am I doing wrong ?

1 Answers
Related