Main Content

Build Library or Executable from AUTOSAR Adaptive Model

As part of generating code for an AUTOSAR adaptive model, you can generate a CMakeLists.txt file for building a static or shared library or an executable. The AUTOSAR Adaptive | CMake toolchain generates the CMakeLists.txt file following modular CMake patterns. You can link the resulting library against a main.cpp file or combine it with other model files in an integration environment.

Building the library file from CMakeLists.txt requires running CMake software.

To build a static or shared library:

  1. Open a component model that is configured for the AUTOSAR adaptive target (autosar_adaptive.tlc).

  2. Open the Configuration Parameters dialog box and select Code Generation. Under Toolchain settings:

    1. Set Toolchain to AUTOSAR Adaptive | CMake.

    2. Set Build configuration to Specify.

    3. Set CMake Target Type to Static (for a static library) or Shared (for a shared library).

    4. In the Include Directories, Link Libraries, and Library Paths fields, specify libraries and header files that must be generated in CMakeLists.txt to support compilation. For example, set Include Directories to the string ${START_DIR}/modelName_autosar_adaptive/stub/aragen, where modelName is the name of the adaptive model.

    5. Click OK.

  3. Build the model. The build generates C++ code, ARXML files, and a CMakeLists.txt file.

  4. In the model build folder, open CMakeLists.txt and verify that it is configured for static or shared library generation. For example, check that:

    1. The CMakeLists.txt file contains

      add_library(modelName SHARED...) % for shared library
      
      or
      add_library(modelName STATIC...) % for static library

    2. The specifications for target_include_directories, target_link_libraries, and link_directories include the values specified in Toolchain settings.

  5. Go to the model build folder outside MATLAB. To build the static or shared library file, enter these commands:

    cmake CMakeLists.txt;
    make all;

The make generates a library file for the adaptive model (for example, modelName.a or modelName.so) in the model build folder. You can link the library against a main.cpp file or combine it with other model files in an integration environment.

To build an executable, do one of the following:

Related Topics