This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

Parents
  • 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

Reply
  • 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

Children