Configure CMake Build Process
CMake is a third-party, open-source tool for build process management. To build code generated from MATLAB® code or Simulink® models, the code generator provides CMake toolchain definitions for Microsoft® Visual C++® on Windows® and GCC on Linux® computers, that use Ninja and makefile generators.
If a supported toolchain is installed on your development computer, you can specify
the corresponding CMake toolchain definition during code generation. When you run
codegen
at the command line or click the
Generate Code button in the GPU Coder™ app, CMake:
Uses the configuration file
CMakeLists.txt
to generate standard the build filesRuns the compiler and other build tools to create executable code
Specify CMake Toolchain Definition
You can specify the CMake toolchain using the GPU Coder app, the MATLAB command line, or the Simulink Configuration Parameters dialog.
Using the GPU Coder App
In the Generate Code step, on the More Settings > Hardware tab:
Specify your hardware board and, optionally, the hardware implementation parameters. This information determines the available toolchain definitions. Use the default value,
MATLAB Host Computer
, to deploy the generated code to the computer where MATLAB is running. For more information, see Available CMake Toolchain Definitions.Specify these build process parameters:
Toolchain — From the drop-down list, select a CMake toolchain definition.
Build configuration — Select one of these values:
Release
— Enable optimizationsDebug
— Disable optimizations and generate debug symbolsRelWithDebInfo
— Enable optimizations and generate debug symbolsMinSizeRel
— Optimize for size and do not generate debug symbolsSpecify
— Specify toolchain details using the CMake Configure and CMake Build fields
Toolchain details — If Build configuration is
Specify
, populate these fields:CMake Configure — Additional command-line arguments to pass to CMake when generating the project build system builder artifacts for the downstream tools
CMake Build — Additional command-line arguments to pass to CMake when using it in build mode
At the Command Line
In a coder.CodeConfig
or coder.EmbeddedCodeConfig
object:
If necessary, configure the target hardware by assigning a
coder.hardware
object to theHardware
property or modifying theHardwareImplementation
property by assigning acoder.HardwareImplementation
object. This information determines the available toolchain definitions. For more information, see Available CMake Toolchain Definitions.Specify the build process by assigning the
Toolchain
and theBuildConfiguration
properties. If you setBuildConfiguration
to"Specify"
, use theCustomToolchainOptions
property to customize tool settings in the selected toolchain. For more information on the availableBuildConfiguration
options, see the previous section.
Using the Simulink Configuration Parameters Dialog
In the Configuration Parameters dialog box:
On the Hardware Implementation pane, specify parameter values for your target device. These values determine the available toolchains. For more information, see Available CMake Toolchain Definitions.
On the Code Generation pane, specify these parameters:
Toolchain — From the drop-down list, select a CMake toolchain definition.
Build configuration — Select one of these values:
Release
— Enable optimizationsDebug
— Disable optimizations and generate debug symbolsRelWithDebInfo
— Enable optimizations and generate debug symbolsMinSizeRel
— Optimize for size and do not generate debug symbolsSpecify
— Specify toolchain details using the CMake Configure and CMake Build fields
Toolchain details — If Build configuration is
Specify
, populate these fields:CMake Configure — Additional command-line arguments to pass to CMake when generating the project build system builder artifacts for the downstream tools.
CMake Build — Additional command-line arguments to pass to CMake when using it in build mode.
For more information, see the cmake(1) page on the CMake website.
Available CMake Toolchain Definitions
Platform | Shipped Toolchain Definition |
---|---|
Windows | Microsoft Visual C++ 2017 v15.0 |
CMake/nmake (64-bit Windows)
|
Microsoft Visual C++ 2017 v15.0 |
CMake/Ninja (64-bit Windows) | |
Microsoft Visual C++ 2019 v16.0 |
CMake/nmake (64-bit Windows) | |
Microsoft Visual C++ 2019 v16.0 |
CMake/Ninja (64-bit Windows) | |
Microsoft Visual C++ 2022 v17.0 |
CMake/nmake (64-bit Windows) | |
Microsoft Visual C++ 2022 v17.0 |
CMake/Ninja (64-bit Windows) | |
Linux | GNU gcc/g++ | CMake/gmake (64-bit
Linux) |
GNU gcc/g++ | CMake/Ninja (64-bit
Linux) |
See Also
slbuild
(Simulink) | packNGo
| codegen
| coder.CodeConfig
| coder.EmbeddedCodeConfig