我需要编写一个工具链文件来在我的构建系统上配置特殊的编译器前缀和 CFLAGS。我正在尝试使用 CMake 来实现,但我遇到了困难。
这是我的 toolchain.cmake 文件的示例:
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")
但我在编译器检查期间收到此错误:
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'
在 CMakeCache.txt 上,我可以看到以下变量:
//Flags used by the compiler during all build types.
CMAKE_C_FLAGS:STRING=
如您所见,它没有在 sh4gcc 调用中使用 CMAKE_C_FLAGS 变量。我在这里想念什么?