带有不支持“-o”的嵌入式 C 编译器的 CMake

CMake with an embedded C compiler that doesn't support "-o"

我正在使用名为 HC12 的旧 C 编译器编写固件。目前我使用 GNU Make 作为构建系统。我希望开始使用 CMake,但 运行 遇到了问题: 编译器不支持一些标准的 C 编译器语法,即“-o”标志。

我制作了一个自定义工具链文件并添加了我所有的 c 标志,但 CMake 似乎在生成的 GNU Makefile 中隐式添加了“-o”来编译源文件。

HC12 编译器允许我使用 -objn="name_of_file" 来指定输出文件名。

我的问题:有没有办法让 CMake 停止放置隐式“-o”以便我可以使用此编译器?

我知道这个处理器有一个 GCC 端口,但现在不能更改编译器。

您可以将 Modules/Compiler/ti.cmake 之类的文件作为参考,并为您的 HC12 编译器创建一个文件,并更改其中定义的这些宏:


# the input file options from TI, change to what your compiler needs
# They are used below in the command where ${lang} is either C, CXX or ASM
set(__COMPILER_HC12C_SOURCE_FLAG_C   "--c_file")
set(__COMPILER_HC12C_SOURCE_FLAG_CXX "--cpp_file")
set(__COMPILER_HC12C_SOURCE_FLAG_ASM "--asm_file")
# add output file option
set(__COMPILER_HC12C_OUTPUT_FLAG_C   "--objn")

macro(__compiler_HC12C lang)

  # ...

  set(CMAKE_${lang}_COMPILE_OBJECT  "<CMAKE_${lang}_COMPILER> --compile_only ${__COMPILER_HC12C_SOURCE_FLAG_${lang}}=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> ${__COMPILER_HC12C_OUTPUT_FLAG_${lang}}=<OBJECT>")
  #                                                                          ---------------------------------------                                       ---------------------------------------

  # ...

endmacro()

希望这会有所帮助。