For certain applications, you might want to control aspects of the build process that occur after code generation but before compilation. For example, you might want to specify compiler or linker options. You can customize build processing that occurs after code generation using MATLAB® Coder™ for MEX functions, C/C++ libraries and C/C++ executables.
You can customize your build using:
The coder.updateBuildInfo
function
in your MATLAB code
A post-code-generation command
To customize the post-code-generation build from your MATLAB code:
In your MATLAB code, call coder.updateBuildInfo
to
update the build information object. You specify a build information
object method and the input arguments for the method. See coder.updateBuildInfo
and Build Information Methods.
Generate code from your MATLAB code using the codegen
command or from the project interface.
To customize your build using the post-code-generation command:
Write Post-Code-Generation Command. Typically, you use this command to get the project name and build information or to add data to the build information object.
At the start of a build, the MATLAB Coder build process
logs the following project, build option, and dependency information
to a build information object, RTW.BuildInfo
:
Compiler options
Preprocessor identifier definitions
Linker options
Source files and paths
Include files and paths
Precompiled external libraries
Use the Build Information Methods to access this information in the build information object. Write Post-Code-Generation Command explains how to use the functions to control a post-code-generation build.
When code generation is complete, MATLAB Coder creates a buildInfo.mat
file
in the build folder.
Use these methods to access or write data to the build information object. The syntax is:
buildInfo.method_name(input_arg1, ..., input_argn)
Purpose: Add compiler options to build information.
Syntax: addCompileFlags(
buildinfo
, options
, groups
)
groups
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
options
A character array or cell array of character arrays that specifies
the compiler options to be added to the build information. The function
adds each option to the end of a compiler option vector. If you specify
multiple options within a single character array, for example '-Zi
-Wall'
, the function adds the options to the vector as a
single element. For example, if you add '-Zi -Wall'
and
then '-O3'
, the vector consists of two elements,
as shown below.
'-Zi -Wall' '-O3'
groups
(optional)A character array or cell array of character arrays that groups specified compiler options. You can use groups to
Document the use of specific compiler options
Retrieve or apply collections of compiler options
You can apply
A single group name to one or more compiler options
Multiple group names to collections of compiler options (available for nonmakefile build environments only)
To... | Specify groups as
a... |
---|---|
Apply one group name to compiler options | Character array. |
Apply different group names to compiler options | Cell array of character arrays such that the number of group
names matches the number of elements you specify for options . |
Description:
The addCompileFlags
function adds specified
compiler options to the project's build information. MATLAB Coder stores
the compiler options in a vector. The function adds options to the
end of the vector based on the order in which you specify them.
In addition to the required buildinfo
and options
arguments,
you can use an optional groups
argument
to group your options.
Purpose: Add preprocessor macro definitions to build information.
Syntax: addDefines(
buildinfo
, macrodefs
, groups
)
groups
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
macrodefs
A character array or cell array of character arrays that specifies
the preprocessor macro definitions to be added to the object. The
function adds each definition to the end of a compiler option vector.
If you specify multiple definitions within a single character array,
for example '-DRT -DDEBUG'
, the function adds the
options to the vector as a single element. For example, if you add '-DPROTO
-DDEBUG'
and then '-DPRODUCTION'
, the
vector consists of two elements, as shown below.
'-DPROTO -DDEBUG' '-DPRODUCTION'
groups
(optional)A character array or cell array of character arrays that groups specified definitions. You can use groups to
Document the use of specific macro definitions
Retrieve or apply groups of macro definitions
You can apply
A single group name to one or more macro definitions
Multiple group names to collections of macro definitions (available for nonmakefile build environments only)
To... | Specify groups as
a... |
---|---|
Apply one group name to macro definitions | Character array. |
Apply different group names to macro definitions | Cell array of character arrays such that the number of group
names matches the number elements you specify for macrodefs . |
Description:
The addDefines
function adds specified
preprocessor macro definitions to the project's build information.
The MATLAB Coder software stores the definitions in a vector.
The function adds definitions to the end of the vector based on the
order in which you specify them.
In addition to the required buildinfo
and macrodefs
arguments,
you can use an optional groups
argument
to group your options.
Purpose: Add include files to build information.
Syntax: addIncludeFiles(
buildinfo
, filenames
, paths
, groups
)
paths
and groups
are
optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
filenames
A character array or cell array of character arrays that specifies names of include files to be added to the build information.
The filename can include wildcard characters, provided that
the dot delimiter (.
) is present. Examples are '*.*'
, '*.h'
,
and '*.h*'
.
The function adds the filenames to the end of a vector in the order that you specify them.
The function removes duplicate include file entries that
You specify as input
Already exist in the include file vector
Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path and corresponding filename.
paths
(optional)A character array or cell array of character arrays that specifies paths to the include files. The function adds the paths to the end of a vector in the order that you specify them. If you specify a single path as a character array, the function uses that path for all files.
groups
(optional)A character array or cell array of character arrays that groups specified include files. You can use groups to
Document the use of specific include files
Retrieve or apply groups of include files
You can apply
A single group name to an include file
A single group name to multiple include files
Multiple group names to collections of multiple include files
To... | Specify groups as
a... |
---|---|
Apply one group name to include files | Character array. |
Apply different group names to include files | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for filenames . |
Description:
The addIncludeFiles
function adds specified
include files to the project's build information. The MATLAB Coder software
stores the include files in a vector. The function adds the filenames
to the end of the vector in the order that you specify them.
In addition to the required buildinfo
and filenames
arguments,
you can specify optional paths
and groups
arguments.
You can specify each optional argument as a character array or a cell
array of character arrays.
If You Specify an Optional Argument as a... | The Function... |
---|---|
Character array | Applies the character array to the include files it adds to the build information |
Cell array of character arrays | Pairs each character array with a specified include file. Thus,
the length of the cell array must match the length of the cell array
you specify for filenames . |
If you choose to specify groups
,
but omit paths
, specify a null character
vector (''
) for paths
.
Purpose: Add include paths to build information.
Syntax: addIncludePaths(
buildinfo
, paths
, groups
)
groups
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
paths
A character array or cell array of character arrays that specifies include file paths to be added to the build information. The function adds the paths to the end of a vector in the order that you specify them.
The function removes duplicate include file entries that
You specify as input
Already exist in the include path vector
Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path and corresponding filename.
groups
(optional)A character array or cell array of character arrays that groups specified include paths. You can use groups to
Document the use of specific include paths
Retrieve or apply groups of include paths
You can apply
A single group name to an include path
A single group name to multiple include paths
Multiple group names to collections of multiple include paths
To | Specify groups as
a |
---|---|
Apply one group name to include paths | Character array. |
Apply different group names to include paths | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for paths . |
Description:
The addIncludePaths
function adds specified
include paths to the project's build information. The MATLAB Coder software
stores the include paths in a vector. The function adds the paths
to the end of the vector in the order that you specify them.
In addition to the required buildinfo
and paths
arguments,
you can specify an optional groups
argument.
You can specify groups
as a character array
or a cell array of character arrays.
If You Specify an Optional Argument as a | The Function |
---|---|
Character array | Applies the character array to the include paths it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified include path. Thus,
the length of the cell array must match the length of the cell array
you specify for paths . |
Purpose: Add link options to build information.
Syntax: addLinkFlags(
buildinfo
, options
, groups
)
groups
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
options
A character array or cell array of character arrays that specifies
the linker options to be added to the build information. The function
adds each option to the end of a linker option vector. If you specify
multiple options within a single character array, for example '-MD
-Gy'
, the function adds the options to the vector as a single
element. For example, if you add '-MD -Gy'
and
then '-T'
, the vector consists of two elements,
as shown below.
'-MD -Gy' '-T'
groups
(optional)A character array or cell array of character arrays that groups specified linker options. You can use groups to
Document the use of specific linker options
Retrieve or apply groups of linker options
You can apply
A single group name to one or more linker options
Multiple group names to collections of linker options (available for nonmakefile build environments only)
To | Specify groups as
a. |
---|---|
Apply one group name to linker options | Character array. |
Apply different group names to linker options | Cell array of character arrays such that the number of group
names matches the number of elements you specify for options . |
Description:
The addLinkFlags
function adds specified
linker options to the project's build information. The MATLAB Coder software
stores the linker options in a vector. The function adds options to
the end of the vector based on the order in which you specify them.
In addition to the required buildinfo
and options
arguments,
you can use an optional groups
argument
to group your options.
Purpose: Add link objects to build information.
Syntax: addLinkObjects(
buildinfo
, linkobjs
, paths
, priority
, precompiled
, linkonly
, groups
)
The arguments except buildinfo
, linkobjs
,
and paths
are optional. If you specify
an optional argument, you must specify the optional arguments preceding
it.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
linkobjs
A character array or cell array of character arrays that specifies
the filenames of linkable objects to be added to the build information.
The function adds the filenames that you specify in the function call
to a vector that stores the object filenames in priority order. If
you specify multiple objects that have the same priority (see priority
below),
the function adds them to the vector based on the order in which you
specify the object filenames in the cell array.
The function removes duplicate link objects that
You specify as input
Already exist in the linkable object filename vector
Have a path that matches the path of a matching linkable object filename
A duplicate entry consists of an exact match of a path and corresponding linkable object filename.
paths
A character array or cell array of character arrays that specifies paths to the linkable objects. If you specify a character array, the path applies to all linkable objects.
priority
(optional)A numeric value or vector of numeric values that indicates the relative priority of each specified link object. Lower values have higher priority. The default priority is 1000.
precompiled
(optional)The logical value true
or false
or
a vector of logical values that indicates whether each specified link
object is precompiled.
Specify true
if the link object has been
prebuilt for faster compiling and linking and exists in a specified
location.
If precompiled is false
(the default), the MATLAB Coder build
process creates the link object in the build folder.
This argument is ignored if linkonly
equals true
.
linkonly
(optional)The logical value true
or false
or
a vector of logical values that indicates whether each specified link
object is to be used only for linking.
Specify true
if the MATLAB Coder build
process should not build, nor generate rules in the makefile for building,
the specified link object, but should include it when linking the
final executable. For example, you can use this to incorporate link
objects for which source files are not available. If linkonly
is
true, the value of precompiled
is ignored.
If linkonly
is false
(the
default), rules for building the link objects are added to the makefile.
In this case, the value of precompiled
determines
which subsection of the added rules is expanded, START_PRECOMP_LIBRARIES
(true
)
or START_EXPAND_LIBRARIES
(false
).
The software performs the expansion of the START_PRECOMP_LIBRARIES
or START_EXPAND_LIBRARIES
macro
only if your code generation target uses the template makefile approach
for building code.
groups
(optional)A character array or cell array of character arrays that groups specified link objects. You can use groups to
Document the use of specific link objects
Retrieve or apply groups of link objects
You can apply
A single group name to a linkable object
A single group name to multiple linkable objects
Multiple group name to collections of multiple linkable objects
To. | Specify groups as
a |
---|---|
Apply one group name to link objects | Character array. |
Apply different group names to link objects | Cell array of character arrays such that the number of group
names matches the number elements you specify for linkobjs . |
The default value of groups
is {''}
.
Description:
The addLinkObjects
function adds specified
link objects to the project's build information. The MATLAB Coder software
stores the link objects in a vector in relative priority order. If
multiple objects have the same priority or you do not specify priorities,
the function adds the objects to the vector based on the order in
which you specify them.
In addition to the required buildinfo
, linkobjs
,
and paths
arguments, you can specify the
optional arguments priority
, precompiled
, linkonly
,
and groups
. You can specify paths
and groups
as
a character array or a cell array of character arrays.
If You Specify paths or groups as
a... | The Function... |
---|---|
Character array | Applies the character array to the objects it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified object. Thus, the
length of the cell array must match the length of the cell array you
specify for linkobjs . |
Similarly, you can specify priority
, precompiled
,
and linkonly
as a value or vector of values.
If You Specify priority , precompiled ,
or linkonly as a | The Function |
---|---|
Value | Applies the value to the objects it adds to the build information. |
Vector of values | Pairs each value with a specified object. Thus, the length
of the vector must match the length of the cell array you specify
for linkobjs . |
If you choose to specify an optional argument, you must specify
the optional arguments preceding it. For example, to specify that
objects are precompiled using the precompiled
argument,
you must specify the priority
argument
that precedes precompiled
. You could pass
the default priority value 1000, as shown below.
addLinkObjects(myBuildInfo, 'test1', '/proj/lib/lib1', 1000, true);
Purpose: Add nonbuild-related files to build information.
Syntax: addNonBuildFiles(
buildinfo
, filenames
, paths
, groups
)
paths
and groups
are
optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
filenames
A character array or cell array of character arrays that specifies names of nonbuild-related files to be added to the build information.
The filename can include wildcard characters, provided that
the dot delimiter (.
) is present. Examples are '*.*'
, '*.DLL'
,
and '*.D*'
.
The function adds the filenames to the end of a vector in the order that you specify them.
The function removes duplicate nonbuild file entries that
Already exist in the nonbuild file vector
Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path and corresponding filename.
paths
(optional)A character array or cell array of character arrays that specifies paths to the nonbuild files. The function adds the paths to the end of a vector in the order that you specify them. If you specify a single path as a character array, the function uses that path for all files.
groups
(optional)A character array or cell array of character arrays that groups specified nonbuild files. You can use groups to
Document the use of specific nonbuild files
Retrieve or apply groups of nonbuild files
You can apply
A single group name to a nonbuild file
A single group name to multiple nonbuild files
Multiple group names to collections of multiple nonbuild files
To | Specify groups as
a. |
---|---|
Apply one group name to nonbuild files | Character array. |
Apply different group names to nonbuild files | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for filenames . |
Description:
The addNonBuildFiles
function adds specified
nonbuild-related files, such as DLL files required for a final executable,
or a README file, to the project's build information. The MATLAB Coder software
stores the nonbuild files in a vector. The function adds the filenames
to the end of the vector in the order that you specify them.
In addition to the required buildinfo
and filenames
arguments,
you can specify optional paths
and groups
arguments.
You can specify each optional argument as a character array or a cell
array of character arrays.
If You Specify an Optional Argument as a | The Function |
---|---|
Character array | Applies the character array to the nonbuild files it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified nonbuild file.
Thus, the length of the cell array must match the length of the cell
array you specify for filenames . |
If you choose to specify groups
,
but omit paths
, specify a null character
vector (''
) for paths
.
Purpose: Add source files to build information.
Syntax: addSourceFiles(
buildinfo
, filenames
, paths
, groups
)
paths
and groups
are
optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
filenames
A character array or cell array of character arrays that specifies names of the source files to be added to the build information.
The filename can include wildcard characters, provided that
the dot delimiter (.
) is present. Examples are '*.*'
, '*.c'
,
and '*.c*'
.
The function adds the filenames to the end of a vector in the order that you specify them.
The function removes duplicate source file entries that
You specify as input
Already exist in the source file vector
Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path and corresponding filename.
paths
(optional)A character array or cell array of character arrays that specifies paths to the source files. The function adds the paths to the end of a vector in the order that you specify them. If you specify a single path as a character array, the function uses that path for all files.
groups
(optional)A character array or cell array of character arrays that groups specified source files. You can use groups to
Document the use of specific source files
Retrieve or apply groups of source files
You can apply
A single group name to a source file
A single group name to multiple source files
Multiple group names to collections of multiple source files
To | Specify group as
a |
---|---|
Apply one group name to source files | Character array. |
Apply different group names to source files | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for filenames . |
Description:
The addSourceFiles
function adds specified
source files to the project's build information. The MATLAB Coder software
stores the source files in a vector. The function adds the filenames
to the end of the vector in the order that you specify them.
In addition to the required buildinfo
and filenames
arguments,
you can specify optional paths
and groups
arguments.
You can specify each optional argument as a character array or a cell
array of character arrays.
If You Specify an Optional Argument as a. | The Function |
---|---|
Character array | Applies the character array to the source files it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified source file. Thus,
the length of the cell array must match the length of the cell array
you specify for filenames . |
If you choose to specify groups
,
but omit paths
, specify a null character
vector (''
) for paths
.
Purpose: Add source paths to build information.
Syntax: addSourcePaths(
buildinfo
, paths
, groups
)
groups
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
paths
A character array or cell array of character arrays that specifies source file paths to be added to the build information. The function adds the paths to the end of a vector in the order that you specify them.
The function removes duplicate source file entries that
You specify as input
Already exist in the source path vector
Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path and corresponding filename.
Note: The MATLAB Coder software does not check whether a specified path is valid. |
groups
(optional)A character array or cell array of character arrays that groups specified source paths. You can use groups to
Document the use of specific source paths
Retrieve or apply groups of source paths
You can apply
A single group name to a source path
A single group name to multiple source paths
Multiple group names to collections of multiple source paths
To | Specify groups as
a |
---|---|
Apply one group name to source paths | Character array. |
Apply different group names to source paths | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for paths . |
Description:
The addSourcePaths
function adds specified
source paths to the project's build information. The MATLAB Coder software
stores the source paths in a vector. The function adds the paths to
the end of the vector in the order that you specify them.
In addition to the required buildinfo
and paths
arguments,
you can specify an optional groups
argument
. You can specify groups
as a character
array or a cell array of character arrays.
If You Specify an Optional Argument as a | The Function |
---|---|
Character array | Applies the character array to the source paths it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified source path. Thus,
the length of the character array or cell array must match the length
of the cell array you specify for paths . |
Note: The MATLAB Coder software does not check whether a specified path is valid. |
Purpose: Add template makefile (TMF) tokens that provide build-time information for makefile generation.
Syntax: addTMFTokens(
buildinfo
, tokennames
, tokenvalues
, groups
)
is optional.groups
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
tokennames
A character array or cell array of character arrays that specifies
names of TMF tokens (for example, '|>CUSTOM_OUTNAME<|'
)
to be added to the build information. The function adds the token
names to the end of a vector in the order that you specify them.
If you specify a token name that already exists in the vector, the first instance takes precedence and its value used for replacement.
tokenvalues
A character array or cell array of character arrays that specifies TMF token values corresponding to the previously-specified TMF token names. The function adds the token values to the end of a vector in the order that you specify them.
groups
(optional)A character array or cell array of character arrays that groups specified TMF tokens. You can use groups to
Document the use of specific TMF tokens
Retrieve or apply groups of TMF tokens
You can apply
A single group name to a TMF token
A single group name to multiple TMF tokens
Multiple group names to collections of multiple TMF tokens
To | Specify groups as
a |
---|---|
Apply one group name to TMF tokens | Character array. |
Apply different group names to TMF tokens | Cell array of character arrays such that the number of group
names that you specify matches the number of elements you specify
for . |
Description:
Call the addTMFTokens
function inside a
post code generation command to provide build-time information to
help customize makefile generation. The tokens specified in the addTMFTokens
function
call must be handled appropriately in the template makefile (TMF)
for the target selected for your project. For example, if your post
code generation command calls addTMFTokens
to
add a TMF token named |>CUSTOM_OUTNAME<|
that
specifies an output file name for the build, the TMF must act on the
value of |>CUSTOM_OUTNAME<|
to achieve the
desired result.
The addTMFTokens
function adds specified
TMF token names and values to the project's build information. The MATLAB Coder software
stores the TMF tokens in a vector. The function adds the tokens to
the end of the vector in the order that you specify them.
In addition to the required
, buildinfo
,
and tokennames
arguments,
you can specify an optional tokenvalues
argument.
You can specify groups
as
a character array or a cell array of character arrays.groups
If You Specify an Optional Argument as a | The Function |
---|---|
Character array | Applies the character array to the TMF tokens it adds to the build information. |
Cell array of character arrays | Pairs each character array with a specified TMF token. Thus,
the length of the cell array must match the length of the cell array
you specify for . |
Purpose: Find and add include (header) files to build information.
Syntax: findIncludeFiles(
buildinfo
, extPatterns
)
extPatterns
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
extPatterns
(optional)A cell array of character arrays that specify patterns of file name extensions for which the function is to search. Each pattern
Must start with *.
Can include a combination of alphanumeric and underscore (_) characters
The default pattern is *.h
.
Examples of valid patterns include
*.h |
*.hpp |
*.x* |
Description:
The findIncludeFiles
function
Searches for include files, based on specified file name extension patterns, in the source and include paths recorded in a project's build information object
Adds the files found, along with their full paths, to the build information object
Deletes duplicate entries
Purpose: Get compiler options from build information.
Syntax: options
=
getCompileFlags(buildinfo
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of compiler flags you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of compiler flags you do not want the function to return.
Output arguments:
Compiler options stored in the project's build information.
Description:
The getCompileFlags
function returns compiler
options stored in the project's build information. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of options the function
returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get preprocessor macro definitions from build information.
Syntax: [
macrodefs
, identifiers
, values
]
= getDefines(buildinfo
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of macro definitions you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of macro definitions you do not want the function to return.
Output arguments:
Preprocessor macro definitions stored in the project's build information. The function returns the macro definitions in three vectors.
Vector | Description |
---|---|
| Complete macro definitions with -D prefix |
| Names of the macros |
| Values assigned to the macros (anything specified to the right
of the first equals sign) ; the default is an empty character vector
('' ) |
Description:
The getDefines
function returns preprocessor
macro definitions stored in the project's build information. When
the function returns a definition, it automatically
Prepends a -D
to the definition
if the -D
was not specified when the definition
was added to the build information
Changes a lowercase -d
to -D
Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of definitions the function
is to return.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get All files from project's build information.
Syntax: [
fPathNames
, names
]
= getFullFileList(buildinfo
, fcase
)
fcase
is optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
fcase
(optional)The character vector 'source'
, 'include'
,
or 'nonbuild'
. If the argument is omitted, the
function returns all the files from
the build information object.
If You Specify | The Function |
---|---|
'source' | Returns source files from the build information object. |
'include' | Returns include files from the build information object. |
'nonbuild' | Returns nonbuild files from the build information object. |
Output arguments:
Fully-qualified file paths and file names for files stored in the project's build information.
Note:
Usually it is unnecessary to resolve the path of every file
in the project build information, because the makefile for the project
build will resolve file locations based on source paths and rules.
Therefore, |
Description:
The getFullFileList
function returns the
fully-qualified paths and names of all
files, or files of a selected type (source, include, or nonbuild),
stored in the project's build information.
Purpose: Get include files from build information.
Syntax: files
=
getIncludeFiles(buildinfo
, concatenatePaths
, replaceMatlabroot
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
concatenatePaths
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Concatenates and returns each filename with its corresponding path. |
false | Returns only filenames. |
replaceMatlabroot
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Replaces the token $(MATLAB_ROOT) with the
absolute path for your MATLAB installation folder. |
false | Does not replace the token $(MATLAB_ROOT) . |
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of include files you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of include files you do not want the function to return.
Output arguments:
Names of include files stored in the project's build information.
Description:
The getIncludeFiles
function returns the
names of include files stored in the project's build information.
Use the concatenatePaths
and replaceMatlabroot
arguments
to control whether the function includes paths and your MATLAB root
definition in the output it returns. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of include files the
function returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get include paths from build information.
Syntax: files
=getIncludePaths(buildinfo
, replaceMatlabroot
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
replaceMatlabroot
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Replaces the token $(MATLAB_ROOT) with the
absolute path for your MATLAB installation folder. |
false | Does not replace the token $(MATLAB_ROOT) . |
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of include paths you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of include paths you do not want the function to return.
Output arguments:
Paths of include files stored in the build information object.
Description:
The getIncludePaths
function returns the
names of include file paths stored in the project's build information.
Use the replaceMatlabroot
argument to control
whether the function includes your MATLAB root definition in
the output it returns. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of include file paths
the function returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get link options from build information.
Syntax: options
=getLinkFlags(buildinfo
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
includeGroups
(optional)A character array or cell array that specifies groups of linker flags you want the function to return.
excludeGroups
(optional)A character array or cell array that specifies groups of linker
flags you do not want the function to return. To exclude groups and
not include specific groups, specify an empty cell array (''
)
for includeGroups
.
Output arguments:
Linker options stored in the project's build information.
Description:
The getLinkFlags
function returns linker
options stored in the project's build information. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of options the function
returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get nonbuild-related files from build information.
Syntax: files
=getNonBuildFiles(buildinfo
, concatenatePaths
, replaceMatlabroot
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
concatenatePaths
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Concatenates and returns each filename with its corresponding path. |
false | Returns only filenames. |
replaceMatlabroot
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Replaces the token $(MATLAB_ROOT) with the
absolute path for your MATLAB installation folder. |
false | Does not replace the token $(MATLAB_ROOT) . |
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of nonbuild files you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of nonbuild files you do not want the function to return.
Output arguments:
Names of nonbuild files stored in the project's build information.
Description:
The getNonBuildFiles
function returns the
names of nonbuild-related files, such as DLL files required for a
final executable, or a README file, stored in the project's build
information. Use the concatenatePaths
and replaceMatlabroot
arguments
to control whether the function includes paths and your MATLAB root
definition in the output it returns. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of nonbuild files the
function returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get source files from project's build information.
Syntax: srcfiles
=getSourceFiles(buildinfo
, concatenatePaths
, replaceMatlabroot
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
concatenatePaths
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Concatenates and returns each filename with its corresponding path. |
false | Returns only filenames. |
Note:
Usually it is unnecessary to resolve the path of every file
in the project build information, because the makefile for the project
build will resolve file locations based on source paths and rules.
Therefore, specifying true for |
replaceMatlabroot
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Replaces the token $(MATLAB_ROOT) with the
absolute path for your MATLAB installation folder. |
false | Does not replace the token $(MATLAB_ROOT) . |
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of source files you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of source files you do not want the function to return.
Output arguments:
Names of source files stored in the project's build information.
Description:
The getSourceFiles
function returns the
names of source files stored in the project's build information. Use
the concatenatePaths
and replaceMatlabroot
arguments
to control whether the function includes paths and your MATLAB root
definition in the output it returns. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of source files the
function returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Get source paths from build information.
Syntax: files
=getSourcePaths(buildinfo
, replaceMatlabroot
, includeGroups
, excludeGroups
)
includeGroups
and excludeGroups
are
optional.
Input arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
replaceMatlabroot
The logical value true
or false
.
If You Specify | The Function |
---|---|
true | Replaces the token $(MATLAB_ROOT) with the
absolute path for your MATLAB installation folder. |
false | Does not replace the token $(MATLAB_ROOT) . |
includeGroups
(optional)A character array or cell array of character arrays that specifies groups of source paths you want the function to return.
excludeGroups
(optional)A character array or cell array of character arrays that specifies groups of source paths you do not want the function to return.
Output arguments:
Paths of source files stored in the project's build information.
Description:
The getSourcePaths
function returns the
names of source file paths stored in the project build information.
Use the replaceMatlabroot
argument to control
whether the function includes your MATLAB root definition in
the output it returns. Using optional includeGroups
and excludeGroups
arguments,
you can selectively include or exclude groups of source file paths
that the function returns.
If you choose to specify excludeGroups
and
omit includeGroups
, specify a null character
vector (''
) for includeGroups
.
Purpose: Package generated code in zip file for relocation.
Syntax: packNGo(
buildinfo
, propVals
...)
propVals
is optional.
Arguments:
buildinfo
Build information loaded from the build folder.
propVals
(optional)A cell array of property-value pairs that specify packaging details.
To | Specify Property | With Value |
---|---|---|
Package generated code files in a zip file as a single, flat folder. | 'packType' | 'flat' (default) |
Package generated code files hierarchically in a primary zip
file. The value of the | 'packType' | 'hierarchical' |
Create a primary zip file that contains three secondary zip
files:
Paths for files in the secondary zip files are relative to the root folder of the primary zip file. | 'nestedZipFiles' | true (default) |
Create a primary zip file that contains folders, for example,
your build folder and matlabroot . | 'nestedZipFiles' | false |
Specify a file name for the primary zip file. | 'fileName' | ' Default: |
Include only the minimal header files required to build the code in the zip file. | 'minimalHeaders' | true (default) |
Include header files found on the include path in the zip file. | 'minimalHeaders' | false |
Include the html folder for your code generation
report. | 'includeReport' | true (default is false ) |
Direct packNGo not to error out on parse
errors. | 'ignoreParseError' | true (default is false ) |
Direct packNGo not to error out if files
are missing. | 'ignoreFileMissing' | true (default is false ) |
Description:
The packNGo
function packages the following
code files in a compressed zip file so you can relocate, unpack, and
rebuild them in another development environment.
Source files (for example, .c
and .cpp
files)
Header files (for example, .h
and .hpp
files)
Nonbuild-related files (for example, .dll
files
required for a final executable file and .txt
informational
files)
MAT-file that contains the build information object
(.mat
file)
Use this function to relocate files so that they can be recompiled for a specific target environment, or rebuilt in a development environment in which MATLAB is not installed.
By default, the packNGo
function packages
the files as a flat folder structure in a zip file, foo.zip
.
The zip file is located in the current working folder.
You can customize the output by specifying property name and value pairs as previously described.
After relocating the zip file, use a standard zip utility to unpack the compressed file.
Limitations:
The following limitations apply to use of the packNGo
function:
The function operates on source files only, such as *.c
, *.cpp
,
and *.h
files. The function does not support compile
flags, defines, or makefiles.
The function does not package example main source and header files that you generate using the default configuration settings. To package the example main files, configure code generation to generate and compile the example main function, generate your code, and then package the build files.
Unnecessary files might be included. The function might find additional files from source paths and include paths recorded in the build information, even if they are not used.
packNGo
does not package the
code generated for MEX targets.
See Also:
Purpose: Update files in project build information with missing paths and file extensions.
Syntax: updateFilePathsAndExtensions(
buildinfo
, extensions
)
extensions
is optional.
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
extensions
(optional)A cell array of character arrays that specifies the extensions
(file types) of files for which to search and include in the update
processing. By default, the function searches for files with a .c
extension.
The function checks files and updates paths and extensions based on
the order in which you list the extensions in the cell array. For
example, if you specify {'.c' '.cpp'}
, and a folder
contains myfile.c
and myfile.cpp
,
an instance of myfile
is updated to myfile.c
.
Description:
Using paths that already exist in a project's build information,
the updateFilePathsAndExtensions
function checks
whether file references in the build information need to be updated
with a path or file extension. This function can be particularly useful
for
Maintaining build information for a toolchain that requires the use of file extensions
Updating multiple customized instances of build information for a given project
Purpose: Change file separator used in project's build information.
Syntax: updateFileSeparator(
buildinfo
, separator
)
Arguments:
buildinfo
Build information stored in RTW.BuildInfo
.
separator
A character array that specifies the file separator \ (Windows®) or / (UNIX®) to be applied to file path specifications.
Description:
The updateFileSeparator
function changes
instances of the current file separator (/ or \) in a project's build
information to the specified file separator.
The default value for the file separator matches the value returned
by the MATLAB command filesep
. For makefile
based builds, you can override the default by defining a separator
with the MAKEFILE_FILESEP
macro in the template
makefile. If the GenerateMakefile
parameter is
set, the MATLAB Coder software overrides the default separator
and updates the build information after evaluating the PostCodeGenCommand
configuration
parameter.
A post-code-generation command is a MATLAB file that typically
calls functions that get data from or add data to the build information
object. For example, you can access the project name in the variable projectName
and
the RTW.BuildInfo
object in the variable buildInfo
.
You can write the command as a script or a function.
If You Write the Command as a | Then the |
---|---|
Script | Script can gain access to the project (top-level function) name and the build information directly. |
Function | Function can receive the project name and the build information as arguments. |
If your post-code-generation command calls user-defined functions, make sure that the functions are on the MATLAB path. If the build process cannot find a function that you use in your command, the process fails.
You can call combinations of build information functions to customize the post-code-generation build. See Write and Use Post-Code-Generation Command at the Command Line
Set PostCodeGenCommand
to the script name.
At the command line, enter:
cfg = coder.config('lib'); cfg.PostCodeGenCommand = 'ScriptName';
Set PostCodeGenCommand
to the function signature.
When you define the command as a function, you can specify an arbitrary
number of input arguments. If you want to access the project name,
include projectName
as an argument. If you want
to modify or access build information, add buildInfo
as
an argument.
At the command line, enter:
cfg = coder.config('lib'); cfg.PostCodeGenCommand = 'FunctionName(projectName, buildInfo)';
After you have written a post-code-generation command, you must include this command in the build processing. You can include the command from the project settings dialog box or the command line.
To open the Generate dialog
box, on the Generate Code page, click the Generate arrow
.
Click More Settings.
On the Custom Code tab, set the Post-code-generation command parameter.
How you use the PostCodeGenCommand
option
depends on whether you write the command as a script or a function.
See Use Post-Code-Generation Command at the Command Line and Use Post-Code-Generation Command in the MATLAB Coder App..
Set the PostCodeGenCommand
option for the
code generation configuration object (coder.MexCodeConfig
, coder.CodeConfig
or coder.EmbeddedCodeConfig
).
How you use the PostCodeGenCommand
option
depends on whether you write the command as a script or a function.
See Use Post-Code-Generation Command at the Command Line and Use Post-Code-Generation Command in the MATLAB Coder App..
The following example shows how to write and use a post-code-generation
command as a function. The setbuildargs
function
takes the build information object as a parameter, sets up link options,
and adds them to the build information object.
Create a post-code-generation command as a function, setbuildargs
,
which takes the buildInfo
object as a parameter:
function setbuildargs(buildInfo) % The example being compiled requires pthread support. % The -lpthread flag requests that the pthread library be included % in the build linkFlags = {'-lpthread'}; buildInfo.addLinkFlags(linkFlags);
Create a code generation configuration object. Set
the PostCodeGenCommand
option to 'setbuildargs(buildInfo)'
so
that this command is included in the build processing:
cfg = coder.config('mex'); cfg.PostCodeGenCommand = 'setbuildargs(buildInfo)';
Using the -config
option, generate
a MEX function passing the configuration object to codegen
.
For example, for the function foo
that has no
input parameters:
codegen -config cfg foo