cmake_minimum_required(VERSION 3.16)
option(SIMULATION_QEMU "Build for QEMU simulation" OFF)
message(STATUS "ROOT:: SIMULATION_QEMU = ${SIMULATION_QEMU}")
# -------------------------------------------------
# CONFIGURATION AVANT project() : uniquement CMake pur
# -------------------------------------------------



if(SIMULATION_QEMU)
    message(STATUS "SIMULATION_QEMU = ON")
    option(SIMULATION_QEMU "Build for QEMU simulation" ON)
    set(COMPONENTS
        components/meteofrance
        components/domotic_display
        managed_components/lvgl_lvgl
        main
        esp-timer
        $ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs
    )
    
else()
    message(STATUS "SIMULATION_QEMU = OFF")
    option(SIMULATION_QEMU "Build for QEMU simulation" OFF)
#    set(COMPONENTS
#        components/meteofrance
#        components/domotic_display
#        managed_components/lvgl_lvgl
#        main
#        $ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs
#    )
endif()
#list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/esp_timer")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(rgb_lcd)


# -------------------------------------------------
# APRÈS project() : maintenant CONFIG_SIMULATION_QEMU existe
# -------------------------------------------------

if(CONFIG_SIMULATION_QEMU)
    message(STATUS "Compilation IHM (simulation)")
    add_compile_definitions(CONFIG_SIMULATION_QEMU=1)

    #add_custom_target(run_ihm
    #    COMMAND ${CMAKE_COMMAND} -E echo "Building and launching IHM native..."
    #    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_SOURCE_DIR}/components/ihm --target all
    #    COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR}/components/ihm ./ihm_simulator
    #)
else()
    message(STATUS "Compilation standard")
    #add_link_options("-Wl,--disable-non-contiguous-regions")
        add_compile_options(
        -fsanitize=address
        -fno-omit-frame-pointer
        -O0
        -g
    )

    add_link_options(-fsanitize=address)
endif()
