# ANSODEngine — Object Detection Engine DLL (CUDA + ONNX + TensorRT + OpenVINO)
# Source list matches original ANSODEngine.vcxproj exactly

set(ANSOD_SOURCES
    ANSODEngine.cpp
    ANSODHUB.cpp
    ANSEngineCommon.cpp
    ANSMotionDetector.cpp
    ANSANOMALIB.cpp
    ANSCLIPTokenizer.cpp
    ANSCUSTOMDetector.cpp
    ANSCUSTOMPY.cpp
    ANSFD.cpp
    ANSFaceDetectorEngine.cpp
    ANSFaceRecognizerEngine.cpp
    ANSGpuFrameRegistry.cpp
    GpuNV12SlotPool.cpp
    ANSONNXCL.cpp
    ANSONNXOBB.cpp
    ANSONNXPOSE.cpp
    ANSONNXSAM3.cpp
    ANSONNXSEG.cpp
    ANSONNXYOLO.cpp
    ANSOPENVINOCL.cpp
    ANSOPENVINOOD.cpp
    ANSOVFaceDetector.cpp
    ANSOVSEG.cpp
    ANSPOSE.cpp
    ANSRTYOLO.cpp
    ANSSAM.cpp
    ANSSAM3.cpp
    ANSTENSORRTCL.cpp
    ANSTENSORRTPOSE.cpp
    ANSTENSORRTSEG.cpp
    ANSTENSORTRTOD.cpp
    ANSYOLO12OD.cpp
    ANSYOLOOD.cpp
    ANSYOLOV10OVOD.cpp
    ANSYOLOV10RTOD.cpp
    ANSYOLOV12RTOD.cpp
    Movienet.cpp
    NV12PreprocessHelper.cpp
    SCRFDFaceDetector.cpp
    engine.cpp
    dllmain.cpp
    pch.cpp
)

file(GLOB ANSOD_HEADERS "*.h")
file(GLOB ANSOD_CUDA_HEADERS "CUDA/*.h" "CUDA/*.cuh")
file(GLOB ANSOD_CUDA_SOURCES "CUDA/*.cu" "*.cu")

# Engine wrapper sources from original vcxproj
set(ENGINE_SOURCES
    ${CMAKE_SOURCE_DIR}/engines/ONNXEngine/ONNXEngine.cpp
    ${CMAKE_SOURCE_DIR}/engines/ONNXEngine/ONNXSAM3.cpp
)

# OpenVINO engine sources from original vcxproj
set(OPENVINO_ENGINE_SOURCES
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/faceapp/cnn.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/detection_model.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/detection_model_faceboxes.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/detection_model_ssd.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/hpe_model_openpose.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/image_model.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/jpeg_restoration_model.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/model_base.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/openpose_decoder.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/models/super_resolution_model.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/pipelines/async_pipeline.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/pipelines/requests_pool.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/args_helper.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/common.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/config_factory.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/image_utils.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/performance_metrics.cpp
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/src/utils/visualizer.cpp
)

add_library(ANSODEngine SHARED
    ${ANSOD_SOURCES}
    ${ANSOD_HEADERS}
    ${ANSOD_CUDA_HEADERS}
    ${ANSOD_CUDA_SOURCES}
    ${ENGINE_SOURCES}
    ${OPENVINO_ENGINE_SOURCES}
)

target_include_directories(ANSODEngine PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/CUDA
)

target_include_directories(ANSODEngine PRIVATE
    ${CMAKE_SOURCE_DIR}/engines/ONNXEngine
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/include
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/include/faceapp
    ${CMAKE_SOURCE_DIR}/engines/TensorRTAPI/include
    ${CMAKE_SOURCE_DIR}/engines/TensorRTEngine
    ${CMAKE_SOURCE_DIR}/core/ANSLicensingSystem
    ${ANSLIBS_DIR}/nlohmann
    ${ANSLIBS_DIR}/spdlog/include
    ${ANSLIBS_DIR}
    ${ANSLIBS_DIR}/ANS-HWiNFO/include
    ${ANSLIBS_DIR}/ODHUBYOLODarknet/include
    ${ANSLIBS_DIR}/TurboJpeg
    ${ANSLIBS_DIR}/fastdeploy_gpu/include
    ${SHARED_INCLUDE_DIR}
)

target_link_libraries(ANSODEngine
    PUBLIC  ANSLibsLoader
    PUBLIC  ANSLicensingSystem   # PUBLIC: FileExist/SPDLogger symbols must be re-exported
    PUBLIC  opencv
    PRIVATE ANSMOT
    PRIVATE onnxruntime
    PRIVATE tensorrt
    PRIVATE openvino
    PRIVATE python311
    PRIVATE turbojpeg
    PRIVATE boost
    PRIVATE CUDA::cudart_static
    PRIVATE CUDA::cublas
    PRIVATE CUDA::cublasLt
)

# Additional link dependencies from original vcxproj
target_link_directories(ANSODEngine PRIVATE
    ${ANSLIBS_DIR}/ODHUBYOLODarknet/lib
)
target_link_libraries(ANSODEngine PRIVATE
    odhublib.lib odhublib_cpu.lib
    nvinfer_10.lib nvonnxparser_10.lib
    labview
    spdlog_dep
)
# Note: ANSLicensingSystem already linked as PUBLIC above — no need to repeat

target_compile_definitions(ANSODEngine PRIVATE UNICODE _UNICODE NOMINMAX
    ANSODENGINE_EXPORTS
    ENGINE_EXPORTS
    ORT_API_MANUAL_INIT
    _USRDLL
)

if(WIN32)
    target_link_libraries(ANSODEngine PRIVATE ${WIN_COMMON_LIBS})
else()
    target_link_libraries(ANSODEngine PRIVATE ${UNIX_COMMON_LIBS})
endif()

target_precompile_headers(ANSODEngine PRIVATE pch.h)
