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:
Open a component model that is configured for the AUTOSAR adaptive target
(autosar_adaptive.tlc)
.Open the Configuration Parameters dialog box and select Code Generation. Under Toolchain settings:
Set Toolchain to
AUTOSAR Adaptive | CMake
.Set Build configuration to
Specify
.Set CMake Target Type to
Static
(for a static library) orShared
(for a shared library).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
, wheremodelName
is the name of the adaptive model.Click OK.
Build the model. The build generates C++ code, ARXML files, and a
CMakeLists.txt
file.In the model build folder, open
CMakeLists.txt
and verify that it is configured for static or shared library generation. For example, check that:The
CMakeLists.txt
file containsoradd_library(modelName SHARED...) % for shared library
add_library(modelName STATIC...) % for static library
The specifications for
target_include_directories
,target_link_libraries
, andlink_directories
include the values specified in Toolchain settings.
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:
Use
AUTOSAR Adaptive | CMake
toolchain. Follow the same procedure as for libraries, but set CMake Target Type toExecutable
.To generate a standalone executable, use the
AUTOSAR Adaptive Linux Executable
toolchain. For more information, see Build Out of the Box Linux Executable from AUTOSAR Adaptive Model.