Reputation: 2612
I need to write a toolchain file to configure special compiler prefix and CFLAGS on my build system. I'm trying to do it with CMake, but I'm having a hard time.
Here is an example of my toolchain.cmake file:
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CROSSCOMPILING TRUE)
set(COMPILER_PREFIX sh4)
set(USER_ROOT_PATH /opt/st40)
set(CMAKE_FIND_ROOT_PATH ${USER_ROOT_PATH})
find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}gcc)
find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}g++)
find_program(CMAKE_AR NAMES ${COMPILER_PREFIX}ar)
find_program(CMAKE_RANLIB NAMES ${COMPILER_PREFIX}ranlib)
set(CMAKE_C_FLAGS "-mruntime=os21 -mboard=board_custom003024_map256_se -specs=lib/custom003024_h205_board.mem")
But I get this error during the compiler checks:
Building C object
CMakeFiles/cmTryCompileExec2889774418.dir/testCCompiler.c.obj
/opt/st40/bin/sh4gcc -o
CMakeFiles/cmTryCompileExec2889774418.dir/testCCompiler.c.obj -c
/project/cmake/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec2889774418
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec2889774418.dir/link.txt --verbose=1
/opt/st40/bin/sh4gcc
CMakeFiles/cmTryCompileExec2889774418.dir/testCCompiler.c.obj -o
cmTryCompileExec2889774418
sh4gcc: -mboard undefined
gmake[1]: Leaving directory
`/project/cmake/build/CMakeFiles/CMakeTmp'
And on CMakeCache.txt, I can see the following variable:
//Flags used by the compiler during all build types.
CMAKE_C_FLAGS:STRING=
As you can see, it doesn't use the CMAKE_C_FLAGS variable in the sh4gcc call. What am I missing here?
Upvotes: 1
Views: 4619
Reputation: 2612
I've found a workaround in another question. Seems that if I set CMAKE_C_FLAGS in the toolchain file like this:
set(CMAKE_C_FLAGS "-mruntime=os21 -mboard=board_custom003024_map256_se -specs=lib/custom003024_h205_board.mem" CACHE STRING "" FORCE)
It works the way I expect it too. This doesn't seem to have any weird side effects.
Upvotes: 5