# 插件子目录 CMakeLists.txt

# 插件源文件列表
set(SOURCES gpu_rocm.c)

# 创建插件库目标
add_library(rocm SHARED ${SOURCES})

set(LIB_AMDSMI_PATH "" CACHE STRING "amdsmi library dir")

if("${LIB_AMDSMI_PATH}" STREQUAL "")
    if(UNIX)
        if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
            set(LIB_AMDSMI_PATH "\"/usr/lib/x86_64-linux-gnu/libamd_smi.so\"")
        elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
            set(LIB_AMDSMI_PATH "\"/usr/lib/aarch64-linux-gnu/libamd_smi.so\"")
        endif()
    elseif(ANDROID)
        set(LIB_AMDSMI_PATH "path/to/android/library")
    endif()
endif()

add_definitions(-DLIB_AMDSMI_PATH=${LIB_AMDSMI_PATH})

message("LIB_AMDSMI_PATH: ${LIB_AMDSMI_PATH}")

set_target_properties(rocm PROPERTIES LIBRARY_OUTPUT_DIRECTORY ..)

target_include_directories(rocm PRIVATE "${SOURCE_TOP_DIR}/include" "${SOURCE_TOP_DIR}/third_party/rocm")

target_compile_options("rocm" PRIVATE -O2)

install(TARGETS rocm 
        LIBRARY DESTINATION lib/kyml/plugins/xpu)
