if(NOT ${CORE} STREQUAL CM4F)
  return()
endif()

psoc6_load_library(
  NAME ml-inference
  VERSION 1.1.0
)

set(ML_INFERENCE_SOURCES
  ${ML_INFERENCE_DIR}/include/cy_ml_inference.h
)
set(ML_INFERENCE_INCLUDE_DIRS
  ${ML_INFERENCE_DIR}/include
)
set(ML_INFERENCE_INT8x8_DEFINES
  COMPONENT_ML_INT8x8
  CY_ML_FIXED_POINT_8_IN=1
  CY_ML_FIXED_POINT_8_NN=1
)
set(ML_INFERENCE_INT8x8_LINK_LIBRARIES
  ml-inference
)
set(ML_INFERENCE_INT8x16_DEFINES
  COMPONENT_ML_INT8x16
  CY_ML_FIXED_POINT_8_IN=1
  CY_ML_FIXED_POINT_16_NN=1
)
set(ML_INFERENCE_INT8x16_LINK_LIBRARIES
  ml-inference
)
set(ML_INFERENCE_INT16x8_DEFINES
  COMPONENT_ML_INT16x8
  CY_ML_FIXED_POINT_16_IN=1
  CY_ML_FIXED_POINT_8_NN=1
)
set(ML_INFERENCE_INT16x8_LINK_LIBRARIES
  ml-inference
)
set(ML_INFERENCE_INT16x16_DEFINES
  COMPONENT_ML_INT16x16
  CY_ML_FIXED_POINT_16_IN=1
  CY_ML_FIXED_POINT_16_NN=1
)
set(ML_INFERENCE_INT16x16_LINK_LIBRARIES
  ml-inference
)
set(ML_INFERENCE_FLOAT32_DEFINES
  COMPONENT_ML_FLOAT32
  CY_ML_FLOATING_POINT_fltxflt_NN=1
)
set(ML_INFERENCE_FLOAT32_LINK_LIBRARIES
  ml-inference
)

if(${TOOLCHAIN} STREQUAL GCC OR ${TOOLCHAIN} STREQUAL LLVM)
  list(APPEND ML_INFERENCE_INT8x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x8/TOOLCHAIN_GCC_ARM/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT8x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x16/TOOLCHAIN_GCC_ARM/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT16x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x8/TOOLCHAIN_GCC_ARM/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT16x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x16/TOOLCHAIN_GCC_ARM/libml-inference.a
  )
  list(APPEND ML_INFERENCE_FLOAT32_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_FLOAT32/COMPONENT_HARDFP/TOOLCHAIN_GCC_ARM/libml-inference.a
  )
elseif(${TOOLCHAIN} STREQUAL ARM)
  list(APPEND ML_INFERENCE_INT8x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x8/TOOLCHAIN_ARM/libml-inference.ar
  )
  list(APPEND ML_INFERENCE_INT8x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x16/TOOLCHAIN_ARM/libml-inference.ar
  )
  list(APPEND ML_INFERENCE_INT16x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x8/TOOLCHAIN_ARM/libml-inference.ar
  )
  list(APPEND ML_INFERENCE_INT16x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x16/TOOLCHAIN_ARM/libml-inference.ar
  )
  list(APPEND ML_INFERENCE_FLOAT32_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_FLOAT32/COMPONENT_HARDFP/TOOLCHAIN_ARM/libml-inference.ar
  )
elseif(${TOOLCHAIN} STREQUAL IAR)
  list(APPEND ML_INFERENCE_INT8x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x8/TOOLCHAIN_IAR/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT8x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT8x16/TOOLCHAIN_IAR/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT16x8_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x8/TOOLCHAIN_IAR/libml-inference.a
  )
  list(APPEND ML_INFERENCE_INT16x16_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_INT16x16/TOOLCHAIN_IAR/libml-inference.a
  )
  list(APPEND ML_INFERENCE_FLOAT32_LINK_LIBRARIES
    ${ML_INFERENCE_DIR}/COMPONENT_ML_FLOAT32/COMPONENT_HARDFP/TOOLCHAIN_IAR/libml-inference.a
  )
else()
  message(FATAL_ERROR "ml-inference: TOOLCHAIN ${TOOLCHAIN} is not supported.")
endif()

add_library(ml-inference INTERFACE EXCLUDE_FROM_ALL)
target_sources(ml-inference INTERFACE ${ML_INFERENCE_SOURCES})
target_include_directories(ml-inference INTERFACE ${ML_INFERENCE_INCLUDE_DIRS})

add_library(ml-inference-int8x8 INTERFACE EXCLUDE_FROM_ALL)
target_compile_definitions(ml-inference-int8x8 INTERFACE ${ML_INFERENCE_INT8x8_DEFINES})
target_link_libraries(ml-inference-int8x8 INTERFACE ${ML_INFERENCE_INT8x8_LINK_LIBRARIES})

add_library(ml-inference-int8x16 INTERFACE EXCLUDE_FROM_ALL)
target_compile_definitions(ml-inference-int8x16 INTERFACE ${ML_INFERENCE_INT8x16_DEFINES})
target_link_libraries(ml-inference-int8x16 INTERFACE ${ML_INFERENCE_INT8x16_LINK_LIBRARIES})

add_library(ml-inference-int16x8 INTERFACE EXCLUDE_FROM_ALL)
target_compile_definitions(ml-inference-int16x8 INTERFACE ${ML_INFERENCE_INT16x8_DEFINES})
target_link_libraries(ml-inference-int16x8 INTERFACE ${ML_INFERENCE_INT16x8_LINK_LIBRARIES})

add_library(ml-inference-int16x16 INTERFACE EXCLUDE_FROM_ALL)
target_compile_definitions(ml-inference-int16x16 INTERFACE ${ML_INFERENCE_INT16x16_DEFINES})
target_link_libraries(ml-inference-int16x16 INTERFACE ${ML_INFERENCE_INT16x16_LINK_LIBRARIES})

add_library(ml-inference-float32 INTERFACE EXCLUDE_FROM_ALL)
target_compile_definitions(ml-inference-float32 INTERFACE ${ML_INFERENCE_FLOAT32_DEFINES})
target_link_libraries(ml-inference-float32 INTERFACE ${ML_INFERENCE_FLOAT32_LINK_LIBRARIES})
