if(NOT UDB_SDIO_P2 IN_LIST COMPONENTS AND
   NOT UDB_SDIO_P9 IN_LIST COMPONENTS AND
   NOT UDB_SDIO_P12 IN_LIST COMPONENTS)
  return()
endif()

psoc6_load_library(
  NAME udb-sdio-whd
  VERSION 1.0.1
)

set(UDB_SDIO_WHD_SOURCES
  ${UDB_SDIO_WHD_DIR}/SDIO_HOST.h
  ${UDB_SDIO_WHD_DIR}/SDIO_HOST.c
)
set(UDB_SDIO_WHD_INCLUDE_DIRS
  ${UDB_SDIO_WHD_DIR}
)
set(UDB_SDIO_WHD_LINK_LIBRARIES
  mtb-pdl-cat1
)

if(UDB_SDIO_P2 IN_LIST COMPONENTS)
  list(APPEND UDB_SDIO_WHD_SOURCES
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P2/SDIO_HOST_cfg.h
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P2/SDIO_HOST_cfg.c
  )
  list(APPEND UDB_SDIO_WHD_INCLUDE_DIRS
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P2
  )
elseif(UDB_SDIO_P9 IN_LIST COMPONENTS)
  list(APPEND UDB_SDIO_WHD_SOURCES
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P9/SDIO_HOST_cfg.h
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P9/SDIO_HOST_cfg.c
  )
  list(APPEND UDB_SDIO_WHD_INCLUDE_DIRS
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P9
  )
elseif(UDB_SDIO_P12 IN_LIST COMPONENTS)
  list(APPEND UDB_SDIO_WHD_SOURCES
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P12/SDIO_HOST_cfg.h
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P12/SDIO_HOST_cfg.c
  )
  list(APPEND UDB_SDIO_WHD_INCLUDE_DIRS
    ${UDB_SDIO_WHD_DIR}/COMPONENT_UDB_SDIO_P12
  )
endif()

add_library(udb-sdio-whd STATIC EXCLUDE_FROM_ALL ${UDB_SDIO_WHD_SOURCES})
target_include_directories(udb-sdio-whd PUBLIC ${UDB_SDIO_WHD_INCLUDE_DIRS})
target_link_libraries(udb-sdio-whd PUBLIC ${UDB_SDIO_WHD_LINK_LIBRARIES})

# HAL library conditionally includes SDIO_HOST.h
target_link_libraries(udb-sdio-whd PRIVATE mtb-hal-cat1)
target_include_directories(mtb-hal-cat1 PUBLIC ${UDB_SDIO_WHD_INCLUDE_DIRS})
target_link_libraries(mtb-hal-cat1 PRIVATE udb-sdio-whd)
