A short guide to CMakeLists.txt for building STM8 projects with SDCC.
The goal is to produce two output files: .elf for debugging and .ihx for flashing the chip.
The overall workflow is as follows:
* configure CMake to use SDCC as the build tool
* set the correct compiler and linker options
* build the *.elf
* convert the *.elf into binary data in *.ihx
Next, I go through the key parts in more detail, and at the end you’ll find the complete CMakeLists.txt file. I’ll note upfront: I’m using CMake version 4.2.3, but the solution should also work on relatively newer versions, I haven’t tested older releases.