Main Content

Support Compiler Optimization Level Control

This section describes how to configure a custom embedded target to support compiler optimization level control. Without the described modifications, you cannot use model configuration parameter Compiler optimization level to control the compiler optimization level for building generated code. For more information about compiler optimization level control, see Compiler optimization level.

About Compiler Optimization Level Control and Custom Targets

The requirements for supporting compiler optimization level control are as follows:

For an example that shows how to configure custom target optional features, see Customize System Target Files.

Declaring Compiler Optimization Level Control Compliance

To declare compiler optimization level control compliance for your target, you must implement a callback function that sets the CompOptLevelCompliant flag, and then install the callback function in the SelectCallback field of the rtwgensettings structure in your system target file. The callback function is triggered whenever the user selects the target in the System Target File Browser. For example, the following system target file code installs a SelectCallback function named custom_select_callback_handler:

rtwgensettings.SelectCallback = 'custom_select_callback_handler(hDlg,hSrc)';

The arguments to the SelectCallback function (hDlg, hSrc) are handles to private data used by the callback API functions. These handles are restricted to use in system target file callback functions. They should be passed in without alteration.

Your callback function should set the CompOptLevelCompliant flag as follows:

slConfigUISetVal(hDlg,hSrc,'CompOptLevelCompliant','on');
slConfigUISetEnabled(hDlg,hSrc,'CompOptLevelCompliant',false);
hSrc.getConfigSet.refreshDialog;

For more information about the system target file callback API, see the slConfigUIGetVal, slConfigUISetEnabled, and slConfigUISetVal function reference pages.

When the CompOptLevelCompliant target configuration parameter is set to on, the Compiler optimization level parameter is displayed in the Code Generation pane of the Configuration Parameters dialog box for your model.

Providing Compiler Optimization Level Control Support in the Target Makefile

As part of supporting compiler optimization level control for your target, you must modify the target makefile to honor the setting for model configuration parameter Compiler optimization level. Use a GRT or ERT target provided by MathWorks as a model for making the modifications.

Related Topics