Conditional compiling depending on platform type?

04 Nov 2014

Hello,

is there a solution for conditional compiling, depending on the chosen platform type?

I'm developing for LPC1114, but for easier testing I'm using normal mbed device. So I have to change platform type and many defines to match the appropriate processor type.

Sure I can use #define in combination with #ifdef / #else / #ifndef, but I'm asking if there might already be a directive to have the compiler decide which part of code has to be taken automatically (like MBED_BUILD_TIMESTAMP for example)?

Michael

04 Nov 2014

You should be able to use

#ifdef TARGET_LPC11XX

These are basically the directory names for target specific code in the mbed SDK for example the code specific to LPC11XX lives in libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX.

All of the capitalised directories in that path are passed to the compiler as defines, so you could have #ifdefs for

  • TARGET_NXP
  • TARGET_LPC11XX_11CXX
  • TARGET_LPC11XX

Which you could choose depending on how specific your code is.

04 Nov 2014

Hello Stephen,

thanks for the fast reply - I'll test this at once, that's exactly what I was looking for!

Best regards,

Michael