For certain applications, you might want to control aspects of the build process that occur after C/C++ source code generation but before compilation. For example, you can specify compiler or linker options. You can get and modify all the generated source files to add a copyright disclaimer. You can control the build process in a variety of ways. Customize the build process by:
Using the function coder.updateBuildInfo
.
Modifying the build information by using a coder.ExternalDependency
class.
Modifying the build information with a script or function executed by the
PostCodeGenCommand
configuration property. This script or
function is called a post-code-generation command.
All three of these approaches work by altering the
makefile that is generated and used to build your code. As a best practice, it is
recommended to use the first two approaches, coder.updateBuildInfo
and
coder.ExternalDependency
. These approaches enable you to preconfigure
your MATLAB® code with the build information that you require. Alternatively, the post-code
generation command can provide an additional, highly customizable approach, based around an
independent function or script.
The coder.ExternalDependency
class and the post-code-generation command
provide access to the build information object, buildInfo
. You can use
build information methods on buildInfo
to configure project, build, and
dependency information. MATLAB
Coder™ creates buildInfo
from the class
RTW.BuildInfo
at the start of the build. This object is stored in a
MAT-file buildInfo.mat
and saved in the build folder.
After code generation, you can access the build information object by loading it from
buildInfo.mat
. Do not confuse the build information object with the
build configuration object, coder.BuildConfig
, which provides specific
functionality for configuring build within a coder.ExternalDependency
class.
To access or write data to the build information object, use build information methods. Using these methods you can modify:
Compiler options
Linker options
Preprocessor identifier definitions
Source files and paths
Include files and paths
Precompiled external libraries
Packaging options.
To call the methods, use the syntax:
method_name(buildInfo,input_arg1,...,input_argN)
Alternatively, you can enter:
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 vector, an array of character vectors, or a
string 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 vector, an array of character vectors, or a string 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)
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.
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 vector, an array of character vectors, or a
string 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 vector, an array of character vectors, or a string 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)
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.
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vector, an array of character vectors, or a string
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 vector, an array of character vectors, or a string 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)
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.
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 vector, an array of character vectors, or a string
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
Note
The MATLAB Coder software does not check whether a specified path is valid.
Note
Support for template makefiles (TMF) will be removed in a future release. Instead, use the toolchain approach for building the generated code.
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 vector, an array of character vectors, or a string
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 vector, an array of character vectors, or a string 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 vector, an array of character vectors, or a string 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
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.
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 vectors or string array that specifies 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 cell array of character vectors or a string that specifies groups of compiler flags you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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 cell array of character vectors or a string that specifies groups of macro definitions you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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,
getFullFileList
returns the path for each file
only if a path was explicitly associated with the file when it was
added, or if you called
updateFilePathsAndExtensions
to resolve file
paths and extensions before calling
getFullFileList
.
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 cell array of character vectors or a string that specifies groups of include files you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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 cell array of character vectors or a string that specifies groups of include paths you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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 cell array of character vectors or a string that specifies groups of linker flags you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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 cell array of character vectors or a string that specifies groups of nonbuild files you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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
concatenatePaths
returns the path for
each file only if a path was explicitly associated with the
file when it was added, or if you called
updateFilePathsAndExtensions
to
resolve file paths and extensions before calling
getSourceFiles
.
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 cell array of character vectors or a string that specifies groups of source files you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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 cell array of character vectors or a string that specifies groups of source paths you want the function to return.
excludeGroups
(optional)A cell array of character vectors or a string 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
.
See packNGo
.
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 vectors or a string 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 vector 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.
To use the build information object after code generation is complete, load the
buildInfo.mat
file from your generated code. For example:
load(fullfile('.','raspberrypi_generated_code','buildInfo.mat')); packNGo(buildInfo, 'fileName','copy_to_raspberrypi');
coder.updateBuildInfo
FunctionThe coder.updateBuildInfo
function provides a convenient way to
customize the build process from within your MATLAB code. For more information and examples, see the coder.updateBuildInfo
reference page.
coder.ExternalDependency
ClassWhen you are working with external code integration or you have multiple functions
that use the same build information, customize the build process by using the
coder.ExternalDependency
class. The
coder.ExternalDependency
class provides access to the build
information object and methods. For more information and examples, see Develop Interface for External C/C++ Code and the coder.ExternalDependency
reference page.
As a best practice, customize your build process by using the first two approaches,
coder.updateBuildInfo
and
coder.ExternalDependency
. A third approach that provides
additional flexibility is a post-code-generation command. A post-code-generation command
is a function or script executed by the PostCodeGenCommand
configuration object property. Set the command by using your code generation
configuration object (coder.MexCodeConfig
, coder.CodeConfig
or coder.EmbeddedCodeConfig
).
Command Format | Result |
---|---|
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. |
To write the post code-generation command as a script, set
PostCodeGenCommand
to the script name. You can access the project
name in the variable projectName
and the
RTW.BuildInfo
object in the variable
buildInfo
. At the command line, enter:
cfg = coder.config('lib'); cfg.PostCodeGenCommand = 'ScriptName';
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)';
For example, consider the function setbuildargs
that takes the
build information object as a parameter and adds linker options by using the
addLinkFlags
method.
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);
To use this function as a post-code-generation command, create a configuration object. Use this configuration object when you generate code. For example:
cfg = coder.config('dll'); cfg.PostCodeGenCommand = 'setbuildargs(buildInfo)'; codegen -config cfg foo
To set a post-code-generation command from the MATLAB Coder app:
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.
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.
coder.CodeConfig
| coder.EmbeddedCodeConfig
| coder.ExternalDependency
| coder.MexCodeConfig
| coder.updateBuildInfo