[Custom Component] Conditional souce file inclusion depending on a component option.

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

cross mob
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

So i have a custom component with several source files (.h and .c), i would like to limit the inclusion of some of this files on the projects depending of one of the component parameters.

   

It's similar to how the SCB component work, depending on the chosen option (SPI, I2C, UART, etc.) the header and source files of the chosen option are included and the others header and source files are not included.

   

I had read the custom component author documentation but could not find information on how to do this. Does anyone know if it's possible?

   

 

   

I'm using Creator 4.1 if that helps.

   

Thanks in advance

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You will just need to enter some #if in your component API files to control the including of the required .h files.

   

 

   

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You will just need to enter some #if in your component API files to control the including of the required .h files.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

No doubt the #if logic will for sure work with the .h files, but can something similar be done to selectively make a .c file part of the project ?  

0 Likes

Hi, thats a good idea for including .h files, actually it is how the header files for different peripherals of the SCB block are included. From the SCB.h file:

   
    

#if (`$INSTANCE_NAME`_SCB_MODE_I2C_INC)
    #include "`$INSTANCE_NAME`_I2C_PVT.h"
#endif /* (`$INSTANCE_NAME`_SCB_MODE_I2C_INC) */

    

#if (`$INSTANCE_NAME`_SCB_MODE_EZI2C_INC)
    #include "`$INSTANCE_NAME`_EZI2C_PVT.h"
#endif /* (`$INSTANCE_NAME`_SCB_MODE_EZI2C_INC) */

    

#if (`$INSTANCE_NAME`_SCB_MODE_SPI_INC || `$INSTANCE_NAME`_SCB_MODE_UART_INC)
    #include "`$INSTANCE_NAME`_SPI_UART_PVT.h"
#endif /* (`$INSTANCE_NAME`_SCB_MODE_SPI_INC || `$INSTANCE_NAME`_SCB_MODE_UART_INC) */

   
   

 

   

but as tonyL says it doesn't seem help for .c  files.

0 Likes