C
Monitor Integration to Qt Ultralite with AUTOSAR
cmake_minimum_required(VERSION 3.10)
project(QSRMonitor C CXX)
# Check for required QSR source directory
if(NOT DEFINED QSR_SOURCE_DIR)
message(FATAL_ERROR "QSR_SOURCE_DIR must be defined. Please provide it with -DQSR_SOURCE_DIR=<path>")
endif()
if(NOT IS_DIRECTORY "${QSR_SOURCE_DIR}")
message(FATAL_ERROR "QSR_SOURCE_DIR (${QSR_SOURCE_DIR}) is not a directory.")
endif()
# Define build options
option(BUILD_FOR_MCU "Build for MCU target" ON)
option(BUILD_LIBRARIES_ONLY "Build only libraries without executable" OFF)
# Include QSR tools macros and header export
include(${QSR_SOURCE_DIR}/cmake/qsr_tools_custom_macros.cmake)
include(${QSR_SOURCE_DIR}/cmake/export_qsr_headers.cmake)
# Set the QML file for monitor data generation
set(QSR_INPUT_QML "${CMAKE_CURRENT_SOURCE_DIR}/qml/SafeUI.qml" CACHE STRING "The QML file for the monitor data generation")
if(NOT EXISTS "${QSR_INPUT_QML}")
message(FATAL_ERROR "QSR_INPUT_QML (${QSR_INPUT_QML}) does not exist.")
endif()
# Set variables needed by QSR subdirectories
set(QSR_SOURCE_DIR "${QSR_SOURCE_DIR}" CACHE PATH "QSR source directory" FORCE)
# Add QSR subdirectories with binary directories
add_subdirectory(${QSR_SOURCE_DIR}/src/saferenderer ${CMAKE_BINARY_DIR}/qsr/saferenderer)
add_subdirectory(${QSR_SOURCE_DIR}/src/adaptation/outputverifier ${CMAKE_BINARY_DIR}/qsr/outputverifier)
add_subdirectory(${QSR_SOURCE_DIR}/src/monitor ${CMAKE_BINARY_DIR}/qsr/monitor)
# Generate monitorconfig data from QML to a library
add_subdirectory(libmonitordata)
# Include export QSR headers
include_directories(
.
${CMAKE_BINARY_DIR}/include
${CMAKE_BINARY_DIR}/include/QtSafeMonitor
${CMAKE_BINARY_DIR}/include/QtSafeOutputVerifierAdaptation
${CMAKE_BINARY_DIR}/include/QtSafeRenderer
)
# Create a custom target for all libraries
add_custom_target(qsr_libraries
DEPENDS
SafeRenderer
OutputVerifier
SafeMonitor
qsrmonitordata
COMMENT "Building QSR libraries"
)
# In case you want to build the example test executable
if(NOT BUILD_LIBRARIES_ONLY)
# The example test executable
set(TEST_SRCS
cdd_qsr_stub.c
main.c
)
# Create the test executable
add_executable(test_exe ${TEST_SRCS})
# Link the test executable with the libraries
target_link_libraries(test_exe
OutputVerifier
SafeMonitor
qsrmonitordata
SafeRenderer
)
# Set the output directory for the test executable
set_target_properties(test_exe PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
endif()
# Set default target based on BUILD_LIBRARIES_ONLY
if(BUILD_LIBRARIES_ONLY)
set(CMAKE_DEFAULT_TARGET qsr_libraries)
endif()