Main Content

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:

  1. Uses the configuration file CMakeLists.txt to generate standard the build files

  2. Runs 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:

  1. 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.

  2. 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 optimizations

      • Debug — Disable optimizations and generate debug symbols

      • RelWithDebInfo — Enable optimizations and generate debug symbols

      • MinSizeRel — Optimize for size and do not generate debug symbols

      • Specify — 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:

  1. If necessary, configure the target hardware by assigning a coder.hardware object to the Hardware property or modifying the HardwareImplementation property by assigning a coder.HardwareImplementation object. This information determines the available toolchain definitions. For more information, see Available CMake Toolchain Definitions.

  2. Specify the build process by assigning the Toolchain and the BuildConfiguration properties. If you set BuildConfiguration to "Specify", use the CustomToolchainOptions property to customize tool settings in the selected toolchain. For more information on the available BuildConfiguration options, see the previous section.

Using the Simulink Configuration Parameters Dialog

In the Configuration Parameters dialog box:

  1. 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.

  2. 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 optimizations

      • Debug — Disable optimizations and generate debug symbols

      • RelWithDebInfo — Enable optimizations and generate debug symbols

      • MinSizeRel — Optimize for size and do not generate debug symbols

      • Specify — 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

PlatformShipped Toolchain Definition
WindowsMicrosoft 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)
LinuxGNU gcc/g++ | CMake/gmake (64-bit Linux)
GNU gcc/g++ | CMake/Ninja (64-bit Linux)

See Also

(Simulink) | | | |

Related Topics

External Websites