Configure CMake Build Process
CMake is a third-party, open-source tool for build process management. To build code generated from Simulink® models, the software provides CMake toolchain definitions for:
Microsoft® Visual C++® and MinGW® on Windows®, GCC on Linux®, and Xcode on Mac computers, using Ninja and makefile generators.
Microsoft Visual Studio® and Xcode project builds.
If
a supported toolchain is installed on your development computer, you can specify the
corresponding CMake toolchain definition for your model. When you run slbuild
, press Ctrl+B, or run a software-in-the-loop
(SIL), processor-in-the-loop (PIL), or external mode simulation, CMake:
Uses configuration (
CMakeLists.txt
) files to generate standard build files.Runs the compiler and other build tools to create executable code.
You can also:
Provide custom CMake toolchain definitions by using the
target
package. For more information, see Create Custom CMake Toolchain Definition.Generate only code and a configuration file for algorithm export.
Specify CMake Toolchain Definition
In the Configuration Parameters dialog box:
On the Hardware Implementation pane, specify parameter values for your target device, which determines the selection of toolchain definitions that is available. 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
— Optimizations enabled.Debug
— Optimizations disabled, debug symbols generated.RelWithDebInfo
— Optimizations enabled, debug symbols generated.MinSizeRel
— Optimized for size, debug symbols not generated.Specify — Enables you to specify toolchain details through 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 https://cmake.org/cmake/help/latest/manual/cmake.1.html.
Available CMake Toolchain Definitions
Platform | Shipped Toolchain Definition | Device Vendor and Type that Make Definition Available |
---|---|---|
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 Studio Project 2017 | CMake (64-bit Windows) | ||
Microsoft Visual Studio Project 2019 | CMake (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) | ||
MinGW64 | CMake/gmake (64-bit Windows) | ||
MinGW64 | CMake/Ninja (64-bit Windows) | ||
Microsoft Visual C++ 2017 v15.0 | CMake/nmake (32-bit Windows) |
| |
Microsoft Visual C++ 2017 v15.0 | CMake/Ninja (32-bit Windows) | ||
Microsoft Visual Studio Project 2017 | CMake (32-bit Windows) | ||
Microsoft Visual Studio Project 2019 | CMake (32-bit Windows) | ||
Microsoft Visual C++ 2019 v16.0 | CMake/nmake (32-bit Windows) | ||
Microsoft Visual C++ 2019 v16.0 | CMake/Ninja (32-bit Windows) | ||
Microsoft Visual C++ 2022 v17.0 | CMake/nmake (32-bit Windows) | ||
Microsoft Visual C++ 2022 v17.0 | CMake/Ninja (32-bit Windows) | ||
Linux | GNU gcc/g++ | CMake/gmake (64-bit Linux) |
|
GNU gcc/g++ | CMake/Ninja (64-bit Linux) | ||
Mac | Xcode with Clang | CMake/gmake (64-bit Mac) |
|
Xcode with Clang | CMake/Ninja (64-bit Mac) | ||
Xcode with Clang Project | CMake (64-bit Mac) |
Note
If the Test hardware is the same as production hardware check box is not selected, the Test hardware settings for device vendor and type control the availability of shipped toolchain definitions.
Generate Only Code and CMake Configuration File for Algorithm Export
To export generated code to another development environment, use this workflow:
In the Configuration Parameters dialog box, from the Toolchain drop-down list, select
CMake
. For this option, the code generator:Generates C and C++ source code from the Simulink model but does not build the code.
Creates a CMake configuration (
CMakeLists.txt
) file that does not depend on specific build tools.
Select the Package code and artifacts check box.
Generate code, which produces a ZIP file that contains the source code and CMake configuration file.
Relocate the ZIP file to your development environment.
Unzip the packaged files.
Use the CMake build tool and configuration file to create an executable file.
If the ZIP file contains mlrFiles.zip
, static dependencies from
your matlabroot
folder tree, you must specify the location of the
unzipped files for the CMake build tool. In your development environment, set the
MATLAB_ROOT
CMake cache entry by running this
command:
cmake -S pathToSource -B pathToProposedLocationOfDerivedFiles -DMATLAB_ROOT=pathToUnzippedmlrFiles
For more information, see Deploy Component Algorithm as Component Model Library by Using CMake (Embedded Coder).
See Also
Related Topics
- Create Custom CMake Toolchain Definition
- Deploy Component Algorithm as Component Model Library by Using CMake (Embedded Coder)
- Relocate or Share Generated Code
- Compile Code in Another Development Environment
- SIL and PIL Simulations (Embedded Coder)
- External Mode Simulations for Parameter Tuning, Signal Monitoring, and Code Execution Profiling