C

Qt Quick Ultralite static_library Example

cmake_minimum_required (VERSION 3.17.3)

project(static_library_example VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::QuickUltralite)
    find_package(Qul)
endif()

if(OS STREQUAL "FreeRTOS")
    message(STATUS "Static library example is disabled for FreeRTOS based platforms")
    return()
endif()

string(TOLOWER ${QUL_PLATFORM} QUL_PLATFORM_LOWER)

set(EXAMPLE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Add configuration of Qt4MCU_GUI target for prebuild step
add_subdirectory(lib/Qt_for_MCU)

_add_executable(static_library_example
        src/main.cpp
)

# If QUL GUI library has IPO enabled then we need also enable it for our target
get_target_property(QUL_LIB_IPO_CONFIG Qt4MCU_GUI INTERPROCEDURAL_OPTIMIZATION)
set_target_properties(static_library_example PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${QUL_LIB_IPO_CONFIG})

target_include_directories(static_library_example
    PRIVATE
        # Add include folder from QtForMCU installation folder
        ${Qul_DIR}/include
        # Add folder containing qul_run.h header file
        ${CMAKE_CURRENT_BINARY_DIR}/lib/Qt_for_MCU
        # Add folder containing sensorAPI.h header file
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(static_library_example
    PRIVATE
        # Static library containing UI and interfaces
        Qt4MCU_GUI
        # Static library with Qt QuickUltralite Core
        Qul::QuickUltralite
        # Static library with Qt QuickUltralite Platform abstraction.
        # Should be replaced by custom implementation adapted to target board
        Qul::QuickUltralitePlatform
        # All additional Qul libraries used by QtForMCU GUI needs to be also
        # linked with application
        Qul::QuickUltraliteControlsStyleDefault
        # Satisfy cyclic dependency between Qt4MCU_GUI and Qul::QuickUltralite
        # libraries (Qul::QuickUltralite depends on symbols autogenerated
        # in Qt4MCU_GUI build process)
        Qul::QuickUltralite
        Qt4MCU_GUI
)

# In CMake all linker options are derived from included libraries PUBLIC
# options.
target_link_options(static_library_example
    PRIVATE
        # Adding option with path to linker script
        ${LINKER_SCRIPT_OPTION} ${LINKER_SCRIPT}
)

if(CMAKE_CROSSCOMPILING)
    set(CMAKE_EXECUTABLE_SUFFIX ".elf")
endif()