C

Indicators: Creating Safety-Critical UI

cmake_minimum_required(VERSION 3.16)
project(indicators LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

# Define the condition for HOST_BUILD
set(HOST_BUILD OFF)  # Default to OFF

if (NOT CMAKE_CROSSCOMPILING AND (NOT UNIX OR NOT (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm|aarch64") OR APPLE))
    set(HOST_BUILD ON)
endif()

if(NOT DEFINED INSTALL_EXAMPLESDIR)
  set(INSTALL_EXAMPLESDIR "examples")
endif()

set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}")

find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick SafeRenderer SafeRendererTools SafePlatformAdaptation)

set(sources main.cpp
)

set (safeqmls
"MainForm.ui.qml"
)

# Resource files are passed to qtsafelayouttool
set(resource_files
    "iso-icons.qrc"
    "qml.qrc"
)

#resource.bin is loaded by qtsafelayouttool to find the resource data asset.
qt6_add_binary_resources(resources_indicators ${resource_files} DESTINATION resource.bin)
qsr_add_safelayout(generatelayout_indicators SAFE_QMLS ${safeqmls}
                                  OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/layoutData
                                  SAFE_LAYOUT_FONTS "${CMAKE_CURRENT_LIST_DIR}/../qtcluster/fonts"
                                  SAFE_RESOURCE "${CMAKE_CURRENT_LIST_DIR}/safeasset.qrc"
                                  INPUT_RESOURCES resource.bin)
qsr_add_resource(buildresource_indicators sources "${CMAKE_CURRENT_LIST_DIR}/safeasset.qrc")

if (HOST_BUILD)
#The resources are linked with the binary in host to open the ControlUI.qml
qt6_add_resources(sources ${resource_files})
endif()

add_executable(indicators WIN32 MACOSX_BUNDLE
    ${sources}
)

#Enable when using monitor feature:
#target_compile_definitions(indicators PRIVATE USE_OUTPUTVERIFIER)

add_dependencies(indicators generatelayout_indicators)

if (HOST_BUILD)
    target_compile_definitions(indicators PUBLIC
        HOST_BUILD
    )

    target_link_libraries(indicators PUBLIC
        Qt::Quick
        Qt::Widgets
        Qt::Qml
    )
else()
    message(STATUS "Indicators is not linked with Qt when building for embedded systems.")
endif()

target_link_libraries(indicators PUBLIC
    Qt::SafeRenderer
    Qt::SafePlatformAdaptation
)

install(TARGETS indicators
    RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
    BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
    LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)