Keil Logo Arm Logo

Conditional compiling in Keil MDK-ARM

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
blueshift Girish
Posted
24-Feb-2017 04:13 GMT
Toolset
ARM
New! Conditional compiling in Keil MDK-ARM

Hi,

We are using LPC2478 in our system with Keil RTX OS. We use Keil uVision v474. Our code is C based with above 300 files segregated in different folders.

Currently, our project is such that we have different features that we enable once on runtime based on configuration file. These features amount to a lot of code but in final application only few features are used.

So, we would like to have some mechanism where we read the configuration first and based on that only selectively compile that feature.

Based on what we learned one way would be to add pre-processor directives in code. But we do not want to change anything in code. Also this may need a lot of pre-processor directives to be added in code based on features.

The other way that we intend to do is create a mapping of features with files, read the configuration, and then have some sort of compilation/linker script that will enable/disable these files during building.

I need help on starting point for creating such script that will allow us to selectively compile files or even may discard some variables declared. Our project needs optimization level to be set to 0 only.

Any existing script or starting point on this could be much helpful.

Thanks,
blueshift

Author
Zack Havens
Posted
24-Feb-2017 16:19 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Hello blueshift,

An alternative to macros, without changing the code base, is to create other targets. You can create another target from Project => Manage => Project Items.
Click on the white outline symbol with a yellow star, next to Project Targets.

Then in the new target, you can right click on the source file in the Project Window, and go to "Options for File...".
In this dialog, there is an option that says "Include in Target Build". You can edit this per file. Right clicking on a source group's folder will give you a similar dialog called "Options for Source Group...", to include or uninclude entire groups of files.

You can build different targets on the command line:
http://www.keil.com/support/man/docs/uv4/uv4_commandline.htm
and use the drop-down list, shown in the following picture, to navigate between targets:
http://www.keil.com/support/man/docs/uv4/uv4_ca_projtargfilegr.htm

Another alternative (that gives complete control) is to write your own batch files. If you go to Options for Target => Output, and enable "Create batch file", then this will give you a template to work with for your specific project, after a successful compile. One *.bat file, probably one *.__ia file, and many *.__i files will be generated. Note that this option forces a rebuild of the target's source every time in the IDE, and the output will replace the original batch file, if it already existed. Renaming the batch file is the easiest way to save user modifications.

Thanks,
Zack

Author
blueshift Girish
Posted
27-Feb-2017 06:18 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Thanks Zack. The second option to use an auto-created batch file seems to be a good start on conditional compiling.
Probably can add conditions in that batch file and then do final compilations through that batch file.

Will post more on this.

Regards,
blueshift

Author
Zack Havens
Posted
27-Feb-2017 15:12 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Sounds good. Our device family pack tutorials for MDKv5 include some example batch files with conditional statements:
http://www.keil.com/pack/doc/CMSIS/Pack/html/createPackBoard.html
within a file called "gen_pack.bat".

I gotta make one correction. The batch file is generated after a successful link, rather than a successful compile.

Author
Girish Thavai
Posted
14-Mar-2017 10:35 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Hi,
I have another approach in my mind not sure if its supported in our current ARM environment. I m thinking of dynamic loading of code the way we see how DLLs or Libs are handled for higher architecture applications.

We have SD-Card already interfaced with our controller. Was thinking that we might put modules as bin files on SD-Card. When configuration changes, specific modules will be flashed at particular location on Flash ROM.

For this, not sure how the bin will generated only with module related information.

Author
Zack Havens
Posted
14-Mar-2017 15:46 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Hello Girish,

This topic is worth starting another thread.

Thanks,
Zack

Author
Girish Thavai
Posted
15-Mar-2017 04:28 GMT
Toolset
ARM
New! RE: Conditional compiling in Keil MDK-ARM

Ok Zack. Will do.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

ARM’s Privacy Policy has been updated. By continuing to use our site, you consent to ARM’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.