cmake_minimum_required(VERSION 3.13)

#
# Create Library and add Curent Library to project library list
#

# Create Library
cp_internal_library_register(chip_drv #module name
                             0 # close source or not
                             )

#
#############################################################
#   Create static Library and add source code
# Create Library and add Curent Library to project library list
#############################################################
#

set(SRCS
    "chip_module/init/dummy.c")

list(APPEND SRCS
  "chip_module/chip/v0/chip_phy_v0.c"
  "chip_module/init/chip_drv_init.c"
  "chip_module/spinlock/v0/spinlock_phy_v0.c"
)

#
# I2C/I3C
#
#if(NOT CONFIG_CHIP_VER STREQUAL ROC1)
  if(CONFIG_MOCONF_CHIP_DRV_I2C)
    list(APPEND SRCS
      "chip_module/i2c/i2c_hal_v2.c"
      "chip_module/i2c/r8p0/sprd_i2c.c"
    )
  endif()
#endif()

if(CONFIG_MOCONF_CHIP_DRV_I3C_TO_I2C)
  list(APPEND SRCS
    "chip_module/i2c/i2c_hal_v2.c"
    "chip_module/i2c/i3c/sprd_i3c.c"
  )
endif() #CONFIG_MOCONF_CHIP_DRV_I3C_TO_I2C

#
# GPIO
#
if(CONFIG_SPRD_GPIO_PLUS_SUPPORT)
  list(APPEND SRCS
    "chip_plf/${CONFIG_SOC_ID}/gpio_cfg.c"
    "chip_module/gpio/plus/gpio_phy.c"
    "chip_module/gpio/gpio_hal.c"
  )
else()
  list(APPEND SRCS
    "chip_plf/${CONFIG_SOC_ID}/gpio_cfg.c"
    "chip_module/gpio/v5/gpio_phy_v5.c"
    "chip_module/gpio/gpio_hal.c"
  )
endif()

#
# SDI
#
if(1)
  list(APPEND SRCS
    "chip_module/adi/r4p0/adi_phy.c"
  )
endif()

#
# sprd_boot_monitor
#
if(1)
    list(APPEND SRCS
        "chip_module/sprd_boot_monitor/sprd_boot_monitor_phy.c"
    )
endif()

#
# regulator
#
if((CONFIG_CHIP_VER_SHARKL5PRO) OR (CONFIG_CHIP_VER_SHARKL5) OR (CONFIG_CHIP_VER_QogirL6))
  list(APPEND SRCS
    "chip_module/regulator/sc27xx_regulator.c"
  )
endif()

#
# DMA
#
list(APPEND SRCS
  "chip_plf/${CONFIG_SOC_ID}/dma_cfg.c"
)

#
# Timer
#
list(APPEND SRCS
  "chip_plf/${CONFIG_SOC_ID}/timer_cfg.c"
  "chip_plf/${CONFIG_SOC_ID}/int_cfg.c"
)

#
# Sleep Reference
#
if(NOT (CONFIG_PM_SLEEP_REMOVE))
  list(APPEND SRCS
    "chip_plf/${CONFIG_SOC_ID}/sleep_cfg.c"
  )
endif()

#
# EIC
#
if(1)
  list(APPEND SRCS
    "chip_module/eic/eic_hal.c"
    "chip_module/eic/v5/eic_phy_v5.c"
    "chip_plf/${CONFIG_SOC_ID}/eic_cfg.c"
  )
endif()

#
# mailbox
#
if(CONFIG_MAILBOX_SUPPORT)
  list(APPEND SRCS
    "chip_module/mailbox/mbox_hal.c"
  )
  if(CONFIG_MAILBOX_VERSION_V0)
    list(APPEND SRCS
      "chip_module/mailbox/mbox_phy_sp_v0.c"
    )
  endif()
  if(CONFIG_MAILBOX_VERSION_V1)
    list(APPEND SRCS
      "chip_module/mailbox/mbox_phy_sp_v1.c"
    )
  endif()
  if(CONFIG_MAILBOX_VERSION_V2)
    list(APPEND SRCS
      "chip_module/mailbox/mbox_phy_sp_v2.c"
    )
  endif()
  if(CONFIG_MAILBOX_VERSION_V3)
    list(APPEND SRCS
      "chip_module/mailbox/mbox_phy_sp_v3.c"
    )
  endif()
endif()

#
# UART
#
if(CONFIG_PM_SPRD_UART)
  list(APPEND SRCS
    "chip_module/uart/uart_sprd.c"
  )
endif()
if(CONFIG_SIO_ZERO_COPY)
  if(CONFIG_MOCONF_LOG_USE)
    list(APPEND SRCS
      "chip_module/uart/uart_sprd_hal.c"
    )
  endif()
endif()

#
# CONFIG_FIREWALL_SUPPORT
#
if(CONFIG_FIREWALL_SUPPORT)
  list(APPEND SRCS
    "chip_module/firewall/${CONFIG_SOC_ID}/firewall.c"
  )
endif()

#
# SPI
#
if(CONFIG_SPRD_SPI_SUPPORT)
  list(APPEND SRCS
    "chip_module/spi/spi_hal.c"
    "chip_module/spi/r8p0/sprd_spi.c"
  )
endif()

#cp_library_link_libraries(main)

#
#############################################################
# Add Internel depend header file
#############################################################
#
if(0)
cp_library_include_directories(
  ${PROJECT_SOURCE_ROOT}/Include
)
endif()

#
#############################################################
# Public curent header file to total project
# Add the directory to INTERFACE LIBRARY
#############################################################
#
cp_library_include_directories(
    ./export/inc/outdated
    ./export/inc
    ./chip_plf/export/inc
    ./chip_plf
    ./chip_module/mmu
    ./chip_module/i2c
    ./common/export/inc_pm
    ./chip_module/mpu
)

cp_library_include_directories(
  ./chip_plf/${CONFIG_SOC_ID}
)

if((CONFIG_CHIP_VER_SHARKL5PRO) OR (CONFIG_CHIP_VER_QogirL6))
  if(CONFIG_CM4_GNSS_CACHE_R3P0_RECFG_ENABLE)
    cp_library_include_directories(
      ./chip_module/cache_sprd
    )
  endif()

  if(CONFIG_SP_GNSS_ENABLE)
    cp_library_include_directories(
      ${PROJECT_SOURCE_ROOT}/fusion_location
    )
  endif()
endif()


#
#############################################################
# Extenel Libriry that need to link
#
#############################################################
#
#cp_library_link_libraries()


#
#############################################################
# The defined flags that compile need use
#############################################################
#
if(0)
cp_library_compile_definitions(SOC_SHARKL5PRO)
endif()



#
#############################################################
# The compile option flags that need use
#############################################################
#
#cp_library_cc_option()

#
# Add source code to library
#
#cp_library_sources_ifdef(CONFIG_APP main.c)
cp_library_sources(${SRCS})
