cmake_minimum_required(VERSION 3.10)

get_filename_component(app_name ${CMAKE_CURRENT_SOURCE_DIR} NAME)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libtorch-cxx11-abi-shared-with-deps-2.3.0+cpu/libtorch)
    message(WARNING "Skipping MultiModel application: libtorch is not found. Please ensure the required file is available. Refer to the README for more details.")
endif()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libtorch-cxx11-abi-shared-with-deps-2.3.0+cpu/libtorch")

find_package(OpenCV REQUIRED)
find_package(Torch REQUIRED)

include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${TORCH_INCLUDE_DIRECTORIES}
    ${MX_API_DIR}/include 
)

# Find all source files
file(GLOB local_src
    "*.c"
    "*.cpp"
    "*.h"
)

# Add executable
add_executable(${app_name} ${local_src})

# Link libraries
target_link_libraries(${app_name}
    mx_accl
    ${OpenCV_LIBS}
    ${TORCH_LIBRARIES}
)

# Set additional C++ flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

# Copy models directory to the binary directory
file(COPY "../models/multimodel/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
