MATLAB: How to change the code generation directory depending on the selection of the System Target File in Real-Time Workshop 6.5 (R2006b)

simulink coder

I created a custom target and I have used the header comments in my System Target File (STF) to define multiple targets in just one STF. I want to generate my code into different directories depending on my target selection.

Best Answer

The advantage of using the header comments in a System Target File to define multiple targets is to have only one tlc file for the most options. This makes maintenance easier. On the other hand you usually have one line defining the BuildDirSuffix for all cases.
If you want to use different directories based on your selection of the System Target File you could use the getActiveConfigSet function to get the description of the System Target File which was selected. Then you can create different BuildDirSuffix for different descriptions, as shown in the following example:
cs = getActiveConfigSet(gcs);
tmp = cs.Components(7).Description;
switch tmp
case 'my_grt1'
rtwgensettings.BuildDirSuffix = '_mygrt1_rtw';
otherwise
rtwgensettings.BuildDirSuffix = '_mygrt2_rtw';
end
Attached you can find the example System Target File and the VDP demo model.