C

Qt Quick Ultralite static_library Example

cmake_minimum_required (VERSION 3.21.1)

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

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

set(EXAMPLE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

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

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

add_executable(static_library_example
        src/main.cpp
)

qul_generate_flash_target(static_library_example)

# 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

        # Depending on which features the Qt4MCU_GUI static library is using,
        # you need to link the proper static library to the executable.
        # In this example list of the libraries which are changing depending on
        # CMake variables configuration are described. Just uncomment those which
        # apply to your setup. Config which applies to this example is uncommented.

        #
        # Font engines:
        #   - If QUL_FONT_ENGINE == Spark
        #       If QUL_PLATFORM_REQUIRED_IMAGE_ALIGNMENT not set or 0 or 1
        #           Qul::MonotypeFontEngine
        #       else
        #           Qul::MonotypeFontEngineAligned
        #
        #       If QUL_COMPLEX_TEXT_RENDERING == ON
        #           Qul::MonotypeShaperEngine
        #           Qul::MonotypeUnicodeEngine
        #       else
        #           Qul::MonotypeUnicodeEngineShaperDisabled
        #
        #   - If QUL_FONT_ENGINE == Static
        #           Qul::MonotypeUnicodeEngineShaperDisabled
        #
        Qul::MonotypeUnicodeEngineShaperDisabled

        # PNG decoder (add when project uses PNG images):
        #   - QUL_RESOURCE_COMPRESSION == ON
        # Qul::PNGDecoderLodePNG
        #   - QUL_RESOURCE_COMPRESSION not set or OFF
        # Qul::PNGDecoderNull

        # Additional lib which needs to be linked along to Qt QuickUltralite Core
        $<$<BOOL:${CMAKE_CROSSCOMPILING}>:Qul::DeviceLink>

        # Static library with Qt QuickUltralite Core
        Qul::Core
        # Static library with Qt QuickUltralite Platform abstraction.
        # Should be replaced by custom implementation adapted to target board
        Qul::Platform
        # All additional Qul libraries used by QtForMCU GUI needs to be also
        # linked with application
        Qul::Controls
        # Satisfy cyclic dependency between Qt4MCU_GUI and Qul::Core
        # libraries (Qul::Core depends on symbols autogenerated
        # in Qt4MCU_GUI build process)
        # Same sets of libraries chosen above need to match those below.
        # For example if above we choose Qul::MonotypeUnicodeEngineShaperDisabled
        # then here below we add the same library as cyclic dependency to Qul::Core.
        Qul::Core
        $<$<BOOL:${CMAKE_CROSSCOMPILING}>:Qul::DeviceLink>
        Qul::MonotypeUnicodeEngineShaperDisabled
        Qt4MCU_GUI
)

target_link_libraries(static_library_example PRIVATE Qul::PlatformDefaultLinkerScript)