arm-none-eabi-gcc won't pass compiler tests

I’m running an arm-none-eabi-gcc cross-compiler, version 5.4.1 20160919, on two different systems and, on setting up my CMake configuration, the compiler checks fail.

The workaround I’m currently resorting to is manually set the CMAKE_C_COMPILER_WORKS variable

set(CMAKE_C_COMPILER_WORKS 1)

which I’m not quite happy with. My CMake setup relies on three distinct files, CMakeLists.txt, toolchains/uarm.cmake and uarm.cmake, which you can find here (if you allow me, I’ll upload the archive directly on discourse).

Once you download the archive, you can build a sample program with

make build
cd build
cmake -D CMAKE_TOOLCHAIN_FILE=../toolchains/uarm.cmake ..
make kernel.uarm

Is the problem I’m dealing with inherent to the compiler (version) or to my CMake setup? If the latter, can I solve it?

I’m relatively new to CMake, and if you point out any other defect about my setup other than the primary one I’ll be more than happy to hear!

Particularly, I’m not quite sure if setting CMakeLists.txt:15 like so

# This avoids the -rdynamic flag
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

is “correct”, nor whether I’m doing a good use of the toolchain file(s).

I’m not particularly aware of the consequences, but it looks like modifying toolchains/uarm.cmake:3 to

set(CMAKE_SYSTEM_NAME Generic)

does the trick, plausibly better than faking successful tests. Any observation is welcomed.

https://cmake.org/cmake/help/v3.17/variable/CMAKE_CROSSCOMPILING.html#variable:CMAKE_CROSSCOMPILING

I’m going to say that this is the easiest method as part of cross compiling. Setting a toolchain file doesn’t trigger cross compiling mode by itself.

If you don’t set CMAKE_SYSTEM_NAME then CMake assumes you are building for the host, and will set various language and compiler settings to be compatible with the host. You don’t want this if you are using arm-none-eabi-gcc. The Generic System is appropriate and has worked for me for other cross compilers.