Main Content

setOption

Class: coder.make.BuildConfiguration
Package: coder.make

Set value of option

Syntax

h.setOption(OptionName, OptionValue)

Description

h.setOption(OptionName, OptionValue) updates the values within a coder.make.BuildConfiguration object.

Input Arguments

expand all

BuildConfiguration handle, specified as a coder.make.BuildConfiguration object.

Example: h

Name of option, specified as a character vector. Choose a new option name.

Example: 'faster2'

Data Types: char

Value of option, specified as a character vector, or as the handle of a coder.make.BuildItem object that contains an option value.

Example: linkerOpts

Examples

The setOption method in intel_tc

The intel_tc.m file from Add Custom Toolchains to MATLAB® Coder™ Build Process, gets a default BuildConfiguration object and then uses setOption to update the values in that object:

% --------------------------------------------
% BUILD CONFIGURATIONS
% --------------------------------------------

optimsOffOpts = {'/c /Od'};
optimsOnOpts = {'/c /O2'};
cCompilerOpts    = '$(cflags) $(CVARSFLAG) $(CFLAGS_ADDITIONAL)';
cppCompilerOpts  = '$(cflags) $(CVARSFLAG) $(CPPFLAGS_ADDITIONAL)';
linkerOpts       = {'$(ldebug) $(conflags) $(LIBS_TOOLCHAIN)'};
sharedLinkerOpts = horzcat(linkerOpts,'-dll -def:$(DEF_FILE)');
archiverOpts     = {'/nologo'};

% Get the debug flag per build tool
debugFlag.CCompiler   = '$(CDEBUG)';   
debugFlag.CppCompiler = '$(CPPDEBUG)';
debugFlag.Linker      = '$(LDDEBUG)';  
debugFlag.Archiver    = '$(ARDEBUG)';  

cfg = tc.getBuildConfiguration('Faster Builds');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOffOpts));
cfg.setOption('C++ Compiler',horzcat(cppCompilerOpts,optimsOffOpts));
cfg.setOption('Linker',linkerOpts);
cfg.setOption('Shared Library Linker',sharedLinkerOpts);
cfg.setOption('Archiver',archiverOpts);

cfg = tc.getBuildConfiguration('Faster Runs');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOnOpts));
cfg.setOption('C++ Compiler',horzcat(cppCompilerOpts,optimsOnOpts));
cfg.setOption('Linker',linkerOpts);
cfg.setOption('Shared Library Linker',sharedLinkerOpts);
cfg.setOption('Archiver',archiverOpts);

cfg = tc.getBuildConfiguration('Debug');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOffOpts,debugFlag.CCompiler));
cfg.setOption ...
('C++ Compiler',horzcat(cppCompilerOpts,optimsOffOpts,debugFlag.CppCompiler));
cfg.setOption('Linker',horzcat(linkerOpts,debugFlag.Linker));
cfg.setOption('Shared Library Linker',horzcat(sharedLinkerOpts,debugFlag.Linker));
cfg.setOption('Archiver',horzcat(archiverOpts,debugFlag.Archiver));

tc.setBuildConfigurationOption('all','Make Tool','-f $(MAKEFILE)');

Using the Option-related methods interactively

tc = coder.make.ToolchainInfo;
cfg = tc.getBuildConfiguration('Faster Builds');
cfg.isOption('X Compiler')
ans  = 

     0
bi = coder.make.BuildItem('WV','wrongvalue')
bi = 

	Macro  : WV
	Value : wrongvalue
cfg.addOption('X Compiler',bi);
value = cfg.getOption('X Compiler')
value = 

	Macro  : WV
	Value : wrongvalue
cfg.setOption('X Compiler','rightvalue');
value = cfg.getOption('X Compiler')
value = 

	Macro  : WV
	Value : rightvalue