Configure CMake Build Process
CMake is a third-party, open-source tool for build process management. To build code generated from MATLAB® code, 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 during code generation. When you generate code, 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:
Specify CMake Toolchain Definition
Using MATLAB Coder App
In the Generate Code, step, on the More Settings > Hardware tab:
Specify your hardware board and, optionally, hardware implementation parameters. This information determines the selection of toolchain definitions that is available. The default value,
MATLAB Host Computer, is applicable for deploying 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— 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.
At Command Line
If necessary, configure the target hardware by assigning a
coder.hardwareobject to the
Hardwareproperty or modifying the
HardwareImplementationproperty by assigning a
coder.HardwareImplementationobject. This information determines the selection of toolchain definitions that is available. For more information, see Available CMake Toolchain Definitions.
Specify the build process by assigning the
BuildConfigurationproperties. If you set
'Specify', use the
CustomToolchainOptionsproperty for customization of settings for tools in the selected toolchain. For more information on the available
BuildConfigurationoptions, see the previous section.
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|
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
When you generate only the C/C++ source code for your MATLAB code, you can instruct the code generator to also produce a
CMakeLists.txt file that does not depend on specific build tools.
Do one of the following:
To export generated code to another development environment, use this workflow:
Package the generated code to produce a ZIP file that contains the source code and CMake configuration file. Use the hierarchical packaging type. See
packNGoand Package Code for Other Development Environments.
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
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
cmake -S pathToSource -B pathToProposedLocationOfDerivedFiles -DMATLAB_ROOT=pathToUnzippedmlrFiles