MATLAB: Is it possible to include “defines” in the rtwmakecfg.m file in Real-Time Workshop 7.1 (R2008a)

simulink coder

I am using a custom template make file (TMF) in order to add a "define" parameter. A snippet of the custom makefile is provided below:
CPP_REQ_DEFINES = -DMODEL=$(MODEL) -DRT -DNUMST=$(NUMST) \
-DTID01EQ=$(TID01EQ) -DNCSTATES=$(NCSTATES) \
-DMT=$(MULTITASKING) -DHAVESTDIO -DXPCMSVISUALC \
-DXPCCALLCONV=__cdecl -DUSE_RTMODEL -DERT_CORE \
-DLEGACY_CODE_NOT_UNICODE_COMPLIANT
I added the last line to make some of the legacy code compile properly for xPC target. I would like to avoid using our own files in place of default MATLAB files because this practice takes us away from any updates that are made in future MATLAB releases, and the "rtwmakecfg.m" file seems to be the perfect place to put "defines" that only affect a certain S-function.

Best Answer

It is not possible to specify "defines" in the rtwmakecfg.m file.
To work around the issue, add defines to buildInfo in the PostCodeGenCommand as shown below:
set_param(model,'PostCodeGenCommand','addDefines(buildInfo,{''-DLEGACY_CODE_NOT_UNICODE_COMPLIANT'' ''-DMY_DEFINE=1''},''OPTS'');')
The defines must be put in the group 'OPTS', which is the last argument to addDefines.
For more information on using the PostCodeGenCommand, refer to the documentation titled "Programming a Post Code Generation Command" in the Help Documentation (for R2008a) linked below:
web([docroot,'/toolbox/rtw/ug/bqobjt8.html#bqobjzq'])
This section describes how to use the PostCodeGenCommand, as well as points to the list of functions available for manipulating buildInfo, which is the source of information put into the generated makefile.