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

193 Views Asked by At

I'm writing firmware using an older C compiler called HC12. Currently I use GNU Make for the build system. I'm hoping to start using CMake, but ran into an issue: The compiler does not support some standard C compiler syntax, namely the "-o" flag.

I've made a custom toolchain file and added all my c flags, but CMake seems to implicitly add the "-o" to compile source files, in the generated GNU Makefiles.

The HC12 compiler allows me to use -objn="name_of_file" to specify the output filename.

My question: Is there a way to get CMake to stop putting the implicit "-o" so that I can use this compiler?

I know there is a GCC port for this processor, but changing compilers at this point isn't an option.

1

There are 1 best solutions below

1
kesselhaus On BEST ANSWER

You could take a file like the Modules/Compiler/ti.cmake as a reference and create one for your HC12 compiler, and also change these macros defined there:


# 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()

Hope, this will help.