How to enable iterative builds for C projects with precompiler switches?

97 Views Asked by At

I am developing C code for five different embedded controllers. In the past, I used to have a separate project for each of those controllers, yet the amount of shared code is around 98%. Therefore, I merged the all projects and abstracted the hardware access by preprocessor macros. Example:

Compiler:

gcc ... -D FS_CONTROLLER_A=STD_ON

Code:

#if FS_CONTROLLER_A == STD_ON
int8_t accessPin = 0;
#else
int8_t accessPin = 1; 
#endif

This solutions saves a lot of time and works like a charm. Unfortunately, iterative builds do not work. If I build controller A, the decider of my build environment 'sCons' creates an MD5 Checksum of each file it builds. When I switch to controller B, only the preprocessor macros are changed. Therefore, the MD5 checksum stays the same and the decider does not detect any changes and refuses to rebuild the file.

I could implement and register a custom decider in sCons, yet this sounds like a lot of dirty hustle. Is there a solution to this problem already? I wouldn't hesistate to switch to cMake or Gradle if they offer a native solution. From my point of view, any solution would needs to run the preprocessor before calling a decider.

PS: I know that the Keil Arm IDE comes with this functionality, yet I want and need to use my own build environment.

0

There are 0 best solutions below