# ANSOCR — Optical Character Recognition DLL (PaddleOCR, ONNX, TensorRT)
file(GLOB ANSOCR_HEADERS "*.h")
file(GLOB ANSOCR_SOURCES "*.cpp")
# Remove orphan files not in original vcxproj
list(FILTER ANSOCR_SOURCES EXCLUDE REGEX "ANSOdOCR\\.cpp$")
list(FILTER ANSOCR_SOURCES EXCLUDE REGEX "ANSOCR\\.cpp$")
file(GLOB_RECURSE PADDLE_HEADERS "ANSPaddleOCR/*.h")
file(GLOB_RECURSE PADDLE_SOURCES "ANSPaddleOCR/*.cpp")
list(FILTER PADDLE_SOURCES EXCLUDE REGEX "args\\.cpp$")
file(GLOB_RECURSE ONNXOCR_SOURCES "ANSONNXOCR/*.cpp" "ANSONNXOCR/*.h")
file(GLOB_RECURSE RTOCR_SOURCES "ANSRTOCR/*.cpp" "ANSRTOCR/*.h")

add_library(ANSOCR SHARED
    ${ANSOCR_HEADERS}
    ${ANSOCR_SOURCES}
    ${PADDLE_HEADERS}
    ${PADDLE_SOURCES}
    ${ONNXOCR_SOURCES}
    ${RTOCR_SOURCES}
)

target_include_directories(ANSOCR PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
)

target_include_directories(ANSOCR PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/ANSPaddleOCR
    ${CMAKE_CURRENT_SOURCE_DIR}/ANSPaddleOCR/include
    ${CMAKE_CURRENT_SOURCE_DIR}/ANSONNXOCR
    ${CMAKE_CURRENT_SOURCE_DIR}/ANSRTOCR
    ${CMAKE_SOURCE_DIR}/engines/ONNXEngine
    ${CMAKE_SOURCE_DIR}/engines/OpenVINOEngine/include
    ${CMAKE_SOURCE_DIR}/engines/TensorRTAPI/include
    ${CMAKE_SOURCE_DIR}/core/ANSLicensingSystem
    ${ANSLIBS_DIR}/nlohmann
    ${VCPKG_INCLUDE_DIR}
    ${SHARED_INCLUDE_DIR}
)

target_link_libraries(ANSOCR
    PUBLIC  ANSLibsLoader
    PRIVATE ANSODEngine
    PUBLIC  ANSLicensingSystem   # PUBLIC: FileExist/SPDLogger symbols must be re-exported
    PRIVATE labview
    PRIVATE spdlog_dep
    PRIVATE opencv
    PRIVATE onnxruntime
    PRIVATE tensorrt
    PRIVATE openvino
    PRIVATE CUDA::cudart
)

target_compile_definitions(ANSOCR PRIVATE UNICODE _UNICODE
    ANSOCR_EXPORTS
    _USRDLL
    ENABLE_ORT_BACKEND
    ENABLE_OPENVINO_BACKEND
    WITH_GPU
    ENABLE_NVJPEG
    ENABLE_TRT_BACKEND
    ENABLE_VISION
    ENABLE_PADDLE2ONNX
)

target_precompile_headers(ANSOCR PRIVATE pch.h)
