conditional build based on platform

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
NaFi_2915566
Level 3
Level 3
First like received First like given

I am trying to build based on platform and having a hard time finding what to check.

For now it is the BlinkLed example but we will need it later when we create the platform for our own board.

ideally I'd like to

#ifdef CYW943907AEVAL1F

   #define WICED_LEDG WICED_GPIO_5

   #define WICED_LEDR WICED_GPIO_16

#elif defined(Quicksilver_EVL)

   #define WICED_LEDG WICED_GPIO_28

   #define WICED_LEDR WICED_GPIO_29

#else

   #error "must choose a platform"

#endif

but the only define I can find is in config.mk

PLATFORM                  := CYW943907AEVAL1F

which is almost impossible to check in a preprocessor directive.

Does anybody know a better define or way to check which platform we're building for?

0 Likes
1 Solution

Kindly follow the MACRO based approach as explained in the earlier response. You will have to define the MACRO in your application .c/.h file. If the MACRO is defined at multiple locations, the compiler will throw a warning regarding the locations where the MACRO is defined. 

View solution in original post

3 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Do you want this based on the build string that in specified in make target? Or we can explore an easier option to define a MACRO based on platform.

Defining a MACRO as:

#define PLATFORM_1

Taking decision based on this MACRO

#if PLATFORM_1

//do something for platform1

#else

//do something else

#endif /*PLATFORM_1*/

0 Likes

riya

This: "Do you want this based on the build string that in specified in make target?"

I'd like to automate this as much as possible and not change my code for the platforms.

I am not sure of the order of execution. 

I could add a new macro into each platform (in board.h or in one of the MK files) if it will propagate to my code.

It would require some care when doing SDK updates.

0 Likes

Kindly follow the MACRO based approach as explained in the earlier response. You will have to define the MACRO in your application .c/.h file. If the MACRO is defined at multiple locations, the compiler will throw a warning regarding the locations where the MACRO is defined.