Hi all,
I’m struggling with the correct way to structure my project using CMake. I have a large chunk of shared code which includes the entrypoint for all targets. The main
function, as well as other portions of the shared code, have their behavior modified by various compile definitions via #ifdef
’s. The value of these compile definitions, as well as the implementation for a few functions that are called in the shared code, vary depending on which executable is being compiled.
At the moment the shared code is an interface library in CMake that’s linked by the executable targets, but I’m not really sure that’s correct, since it isn’t really a standalone library. I’ve tried a bunch of approaches and gone back and forth with CMake docs, ChatGPT and googling, but haven’t been able to get compilation to succeed without a ton of warnings about the compile definitions being redefined.
I’d really appreciate any help, whether just general guidance on setting up this type of project with CMake or notes specific to the repository below:
The current state of my CMake setup is here: https://github.com/ZadenRB/OpenGCC_Firmware/tree/zr/cmake-help. The opengcc
folder is the shared code, with the different targets living under controllers
subfolders.
Previously, instead of using compile definitions, I had a header file for each target that was included in the relevant shared files (with the path to include set via a compile definition). This seemed to work. However, I noticed that if I set these values via compile definitions, then I’d get a ton of warnings about redefinitions of those constants, which makes me suspect there was something wrong with that approach too. Plus, I’d prefer to use compile definitions, as it would simplify things for me. In any case, that approach is on the master branch of the repository linked above.