# Generated ONCE by PAIO (Code Generation > PRTE) for the ECU 'ECU' — developer-owned
# from here on: edit freely, PAIO never overwrites it. The shape is the PRTE SDK project
# template (`prte new`); `prte build` configures it with -DPRTE_SDK_ROOT=<SDK root>.
cmake_minimum_required(VERSION 3.28)
project(ECU C)
if(NOT DEFINED PRTE_SDK_ROOT)
  set(PRTE_SDK_ROOT "/opt/prte" CACHE PATH "PRTE SDK root (prte build passes it)")
endif()
include(${PRTE_SDK_ROOT}/cmake/PrteEcuProject.cmake)

# gen/ is produced from arxml/ by the SDK generator before compilation.
prte_ecu_project_codegen(ECU)
prte_bsw_instantiate(ECU ${CMAKE_CURRENT_SOURCE_DIR}/gen/include)

file(GLOB _gen_sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen/src/*.c)
file(GLOB _app_sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
add_executable(ECU ${_gen_sources} ${_app_sources})
target_include_directories(ECU PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/gen/include
  ${CMAKE_CURRENT_SOURCE_DIR}/include)

# The module libraries this ECU deploys (its ECUC module configurations at generation time);
# a configured module without an SDK library is skipped by the TARGET guard.
set(_modules "")
foreach(_m IN ITEMS bswm can canif cannm cansm com comm det ecuc ecum lsdur mcu nm os pdur)
  if(TARGET ECU_${_m})
    list(APPEND _modules ECU_${_m})
  endif()
endforeach()
target_link_libraries(ECU PRIVATE ${_modules} ECU_rte prte_build_flags)
add_dependencies(ECU ECU_generate)
