This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CODECOMPOSER: Exclude files from build conditionally

Part Number: CODECOMPOSER
Other Parts Discussed in Thread: MSPM0G3507

Tool/software:

Hi,

I'm currently working on a project where i'd like to be able to manage drivers files conditionally. What i'm trying to achieve is to be able to exclude or not some

files from the build based on variables. The goal is to be able to quickly enable or not some C files if they are un-needed depending on which board the

project is compiled for. For this reason, manually excluding files with "right click -> exclude file from build" is not satisfying, as the configuration may be shared on git, through CCS variables

or an external config file for example.

Is there a way to achieve this behaviour with CCS ? I've been trying with pre-build steps, by creating a python script that reads a config file and should somehow decide which files will be included or not in the compilation, but unsuccessfully for now.

I'm using Code composer studio 9 for now but may eventually upgrade.

Thanks in advance,

Regards

  • Hello,

    Is there a way to achieve this behaviour with CCS ? I've been trying with pre-build steps, by creating a python script that reads a config file and should somehow decide which files will be included or not in the compilation, but unsuccessfully for now.

    Not for specific files. At least not easily. It *might* be possible if you are willing to manually edit the .ccsproject in the project folder (which we typically do not recommend), then your script can add something like:

    <sourceEntries>
    <entry excluding="empty_mspm0g3507.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
    </sourceEntries>

    inside the <configuration> tag. If you decided to try this, I would first recommend manually excluding the file via the IDE and see the changes made to your .ccsproject so that you know where and how to make the change.

    One concern I have is that doing this as a project pre-build step may not work since I think CCS will generate the makefiles (which will define which file are part of the build) prior to calling the pre-build step. Hence modifying the .ccsproject as a pre-build step will be too late. If this is the case then you will need to not rely on a pre-build step. If you are building project using the project CLI commands, then you can just call your script manually first.

    Hope this helps

    ki

  • Hello,

    Thanks for the reply. Yeah modifying the ccsproject looks like a "dangerous" thing to do. I think i won't exclude the files from compilation but rather remove the file content with #ifdef directives based on defines in a header generated by my pre-build step, a bit ugly but it should work.

    Thanks again,

    Maxence

  • The is another option to consider. If you can move all the conditional files to a separate folder, you can have your script generate an empty file called ".exclude" inside the same folder. This .exclude file will cause all files in the folder to excluded from the build.