Exlude files from build based on variable?


#1

Hi, all

I need to exclude certain files from the build and I would like to make it conditional on a #define variable.
Basically, I am building same code for two different platforms – one has smaller flash footprint and some features have to be compiled out. Changes are scattered across multiple projects, so modifying each one for a build is not practical.
Is there a way to automate that in M2M?
One option is to put #ifdef xxxx in each file to be taken out. Unfortunately, for one of the project this is not practical as it contains hundreds of files.

Another option that will be helpful is ability to create multiple targets from a project. For example, I have 2 files in a project that is built as a library. Would be very nice to have the build result as 2 separate libraries + library that combines the two. Then, at link stage, I can select what to link. It is still manual process, but it will be easier to manage.

Any help is appreciated.
Thanks,
Rudolf


#2

Yes, you can create separate builds (Eclipse calls them “Configurations”) - that’s exactly how DS does the [Target] and [RTE] builds!

I’m not sure if you can conditionally include a source file in one target, but not another. But what you can do is have the build define a symbol, and then use that to effectively “comment-out” the entire file content:

#if defined SOME_OPTION
    :
    :
    // all code here
    :
    :
#endif

This has the (potential) advantage of being portable across all environments - and not dependent on any particular feature of DS…

See also: https://forum.sierrawireless.com/t/different-configurations-different-output-names/4303/5


#3

And for the Eclipse-specific answer, you can (for each build config) specify which file you want to exclude from build.
Go to file right-click menu -> resource configuration -> exclude from build
From there you can choose the configs in which you don’t want to build the file.


#4

Hi,
That would be ideal, but the problem with that approach – you can not create your own custom configurations!

Rudolf