#
# Copyright 2019 Xilinx Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#

# list(APPEND CMAKE_MODULE_PATH "${CMAKE_SYSROOT}/usr/share/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(XilinxCommon)
include(XilinxTest)
include(CheckIncludeFileCXX)
include(CheckIncludeFile)

option(BUILD_DOXYGEN_DOC "enable doxygen or not" OFF)
set(SAMPLE_INATLL_PATH share/${PROJECT_NAME}/samples)
set(DEMO_INATLL_PATH share/${PROJECT_NAME}/apps)

find_path(DRM_PATH drm)
if(NOT ${DRM_PATH} EQUAL "DRM_PATH-NOTFOUND")
  set(CMAKE_REQUIRED_INCLUDES ${DRM_PATH}/drm)
endif()

# 3Dsegmentation
vai_overview_add_test(3Dsegmentation 3Dsegmentation Segmentation3D NO_VIDEO
                      NO_CONFIG)
vai_overview_add_performance(3Dsegmentation 3Dsegmentation Segmentation3D
                             NO_CONFIG)
vai_overview_add_accuracy(3Dsegmentation 3Dsegmentation)
# centerpoint
vai_overview_add_test(
  test_file_centerpoint
  centerpoint
  CenterPoint
  NO_VIDEO
  NO_CONFIG
  NAME
  test_file_centerpoint)
vai_overview_add_performance(centerpoint centerpoint CenterPoint NO_VIDEO
                             NO_CONFIG)
vai_overview_add_accuracy(centerpoint centerpoint)

# bcc
vai_overview_add_test(bcc bcc BCC)
vai_overview_add_performance(bcc bcc BCC)
vai_overview_add_accuracy(bcc bcc)
vai_overview_add_accuracy(bcc_mt bcc)

# bts
if(ENABLE_BTS AND (NOT DISABLE_ALL))
  vai_overview_add_test(bts bts BTS)
  vai_overview_add_performance(bts bts BTS)
  vai_overview_add_accuracy(bts bts)
endif()

# classification
vai_overview_add_test(classification classification Classification)
vai_overview_add_performance(classification classification Classification)
vai_overview_add_accuracy(classification classification)
vai_overview_add_accuracy(classification_mt classification)

vai_overview_add_test(classification_squeezenet classification Classification
                      NO_VIDEO NO_CONFIG)
vai_overview_add_performance(classification_squeezenet classification
                             Classification NO_CONFIG)
vai_overview_add_accuracy(classification_squeezenet classification)

# covid19segmentation
vai_overview_add_test(covid19segmentation covid19segmentation
                      Covid19Segmentation NO_VIDEO NO_CONFIG)
vai_overview_add_performance(covid19segmentation covid19segmentation
                             Covid19Segmentation NO_CONFIG)
vai_overview_add_accuracy(covid19segmentation covid19segmentation)

# facedetect
vai_overview_add_test(facedetect facedetect FaceDetect)
vai_overview_add_performance(facedetect facedetect FaceDetect)
vai_overview_add_accuracy(facedetect facedetect)
vai_overview_add_accuracy(facedetect_mt facedetect)

# facefeature
vai_overview_add_test(facefeature facefeature FaceFeature NO_VIDEO)
vai_overview_add_performance(facefeature facefeature FaceFeature)
vai_overview_add_accuracy(facefeature facefeature)
vai_overview_add_accuracy(facerec_pretrain_res20 facefeature)

# facelandmark
vai_overview_add_test(facelandmark facelandmark FaceLandmark NO_VIDEO)
vai_overview_add_performance(facelandmark facelandmark FaceLandmark)
vai_overview_add_accuracy(facelandmark facelandmark)
vai_overview_add_accuracy(facelandmark_mt facelandmark)

# facequality5pt
vai_overview_add_test(facequality5pt facequality5pt FaceQuality5pt NO_VIDEO)
vai_overview_add_performance(facequality5pt facequality5pt FaceQuality5pt)
vai_overview_add_accuracy(facequality5pt facequality5pt)
vai_overview_add_accuracy(facequality5pt_mt facequality5pt)

# hourglass
vai_overview_add_test(hourglass hourglass Hourglass)
vai_overview_add_performance(hourglass hourglass Hourglass)
vai_overview_add_accuracy(hourglass hourglass REQUIRE
                          ${PROJECT_NAME}::hourglass json-c)

# lanedetect
vai_overview_add_test(lanedetect lanedetect RoadLine)
vai_overview_add_performance(lanedetect lanedetect RoadLine)
vai_overview_add_accuracy(lanedetect lanedetect)

# medicaldetection
vai_overview_add_test(medicaldetection medicaldetection MedicalDetection)
vai_overview_add_performance(medicaldetection medicaldetection MedicalDetection)
vai_overview_add_accuracy(medicaldetection medicaldetection)
vai_overview_add_accuracy(medicaldetection_mt medicaldetection)

# medicalsegcell
vai_overview_add_test(medicalsegcell medicalsegcell MedicalSegcell)
vai_overview_add_performance(medicalsegcell medicalsegcell MedicalSegcell)
vai_overview_add_accuracy(medicalsegcell medicalsegcell)
vai_overview_add_accuracy(medicalsegcell_mt medicalsegcell)

# medicalsegmentation
vai_overview_add_test(medicalsegmentation medicalsegmentation
                      MedicalSegmentation NO_VIDEO)
vai_overview_add_performance(medicalsegmentation medicalsegmentation
                             MedicalSegmentation)
vai_overview_add_accuracy(medicalsegmentation medicalsegmentation)
vai_overview_add_accuracy(medicalsegmentation_mt medicalsegmentation)

# centerpoint


# multitask
vai_overview_add_test(multitask multitask MultiTask8UC3)
vai_overview_add_performance(multitask multitask MultiTask8UC3)
vai_overview_add_accuracy(multitask multitask)
vai_overview_add_accuracy(multitask_mt multitask)

# multitaskv3
vai_overview_add_test(multitaskv3 multitaskv3 MultiTaskv38UC3)
vai_overview_add_performance(multitaskv3 multitaskv3 MultiTaskv38UC1)
vai_overview_add_accuracy(multitaskv3_detection multitaskv3)
vai_overview_add_accuracy(multitaskv3_segmentation multitaskv3)

# openpose
vai_overview_add_test(openpose openpose OpenPose)
vai_overview_add_performance(openpose openpose OpenPose)
vai_overview_add_accuracy(openpose openpose REQUIRE ${PROJECT_NAME}::openpose
                          json-c)
vai_overview_add_accuracy(openpose_mt openpose REQUIRE
                          ${PROJECT_NAME}::openpose json-c)

# platedetect
vai_overview_add_test(platedetect platedetect PlateDetect)
vai_overview_add_performance(platedetect platedetect PlateDetect)
vai_overview_add_accuracy(platedetect platedetect)
vai_overview_add_accuracy(platedetect_mt platedetect)

# platenum
vai_overview_add_test(platenum platenum PlateNum)
vai_overview_add_performance(platenum platenum PlateNum)
vai_overview_add_accuracy(platenum platenum)
vai_overview_add_accuracy(platenum_mt platenum)

# pmg
vai_overview_add_test(pmg pmg PMG)
vai_overview_add_performance(pmg pmg PMG)
vai_overview_add_accuracy(pmg pmg)

# pointpillars
vai_overview_add_test(
  test_bin_pointpillars
  pointpillars
  PointPillars
  NO_VIDEO
  NO_CONFIG
  NAME
  test_bin_pointpillars)
vai_overview_add_performance(pointpillars pointpillars PointPillars NO_CONFIG)
vai_overview_add_accuracy(pointpillars pointpillars)

# pointpillars_nuscenes
vai_overview_add_test(
  test_bin_pointpillars_nuscenes
  pointpillars_nuscenes
  PointPillarsNuscenes
  NO_VIDEO
  NO_CONFIG
  NAME
  test_bin_pointpillars_nuscenes)
vai_overview_add_performance(pointpillars_nuscenes pointpillars_nuscenes
                             PointPillarsNuscenes NO_VIDEO NO_CONFIG)
vai_overview_add_accuracy(pointpillars_nuscenes pointpillars_nuscenes)

# pointpainting
vai_overview_add_test(
  test_bin_pointpainting
  pointpainting
  PointPainting
  NO_VIDEO
  NO_CONFIG
  NAME
  test_bin_pointpainting)
vai_overview_add_performance(pointpainting pointpainting PointPainting NO_VIDEO
                             NO_CONFIG)
vai_overview_add_accuracy(pointpainting_seg pointpainting)
vai_overview_add_accuracy(pointpainting_nuscenes pointpainting)
vai_overview_add_accuracy(pointpainting pointpainting)

# x_autonomous3d
if(ENABLE_X_AUTONOMOUS3D AND (NOT DISABLE_ALL))
  vai_overview_add_test(
    test_bin_x_autonomous3d
    x_autonomous3d
    X_Autonomous3D
    NO_VIDEO
    NO_CONFIG
    NAME
    test_bin_x_autonomous3d)
  vai_overview_add_performance(x_autonomous3d x_autonomous3d X_Autonomous3D
                               NO_VIDEO NO_CONFIG)
  # vai_overview_add_accuracy(x_autonomous3d x_autonomous3d)
endif()

# clocs
vai_overview_add_test(
  test_bin_clocs
  clocs
  Clocs
  NO_VIDEO
  NO_CONFIG
  NAME
  test_bin_clocs)
vai_overview_add_performance(clocs clocs Clocs NO_VIDEO NO_CONFIG)
vai_overview_add_accuracy(clocs clocs)

# posedetect
vai_overview_add_test(posedetect posedetect PoseDetect)
vai_overview_add_performance(posedetect posedetect PoseDetect)
vai_overview_add_accuracy(posedetect posedetect)
vai_overview_add_accuracy(posedetect_mt posedetect)

vai_overview_add_test(
  posedetect_with_ssd
  posedetect
  PoseDetect
  NO_CONFIG
  REQUIRE
  ${PROJECT_NAME}::posedetect
  ${PROJECT_NAME}::ssd)

# refinedet
vai_overview_add_test(refinedet refinedet RefineDet)
vai_overview_add_performance(refinedet refinedet RefineDet)
vai_overview_add_accuracy(refinedet refinedet)
vai_overview_add_accuracy(refinedet_mt refinedet)

vai_overview_add_test(refinedet_tf refinedet RefineDet NO_VIDEO NO_CONFIG)

# reid
vai_overview_add_test(reid reid Reid NO_VIDEO NO_CONFIG)
vai_overview_add_performance(reid reid Reid)
vai_overview_add_accuracy(reid reid)

# rcan
vai_overview_add_test(rcan rcan Rcan)
vai_overview_add_performance(rcan rcan Rcan)
vai_overview_add_accuracy(rcan rcan Rcan)

# solo
vai_overview_add_performance(solo solo Solo)
vai_overview_add_test(solo solo Solo)
# fairmot
vai_overview_add_test(fairmot fairmot FairMot)
vai_overview_add_performance(fairmot fairmot FairMot)
vai_overview_add_accuracy(fairmot fairmot REQUIRE ${PROJECT_NAME}::fairmot
                          ${PROJECT_NAME}::reidtracker)
# vai_overview_add_accuracy(fairmot fairmot REQUIRE ${PROJECT_NAME}::FairMot
# ${PROJECT_NAME}::ReidTracker)

# retinaface
vai_overview_add_test(retinaface retinaface RetinaFace)
vai_overview_add_performance(retinaface retinaface RetinaFace)
vai_overview_add_accuracy(retinaface retinaface)

# segmentation
vai_overview_add_test(segmentation segmentation Segmentation8UC3)
vai_overview_add_performance(segmentation segmentation Segmentation8UC3)
foreach(TMPMODEL segmentation segmentation_mt endov unet)
  vai_overview_add_accuracy(${TMPMODEL} segmentation REQUIRE
                            ${PROJECT_NAME}::segmentation json-c)
endforeach(TMPMODEL)

# RGBDsegmentation
vai_overview_add_test(RGBDsegmentation RGBDsegmentation RGBDsegmentation
                      NO_VIDEO NO_CONFIG)
vai_overview_add_performance(RGBDsegmentation RGBDsegmentation RGBDsegmentation
                             NO_CONFIG)
vai_overview_add_accuracy(RGBDsegmentation RGBDsegmentation)

# C2D2_lite
vai_overview_add_test(c2d2_lite c2d2_lite C2D2_lite NO_VIDEO NO_CONFIG)
vai_overview_add_performance(c2d2_lite c2d2_lite C2D2_lite NO_CONFIG)

# ssd
vai_overview_add_test(ssd ssd SSD)
vai_overview_add_performance(ssd ssd SSD)
foreach(TMPMODEL ssd_mt ssd_pedestrian_pruned_0_97 ssd_traffic_pruned_0_9
                 ssd_adas_pruned_0_95 ssd_mobilenet_v2 mlperf_ssd_resnet34_tf)
  vai_overview_add_accuracy(${TMPMODEL} ssd)
endforeach(TMPMODEL)

# tfssd
vai_overview_add_test(tfssd tfssd TFSSD)
vai_overview_add_performance(tfssd tfssd TFSSD)
vai_overview_add_accuracy(tfssd tfssd REQUIRE ${PROJECT_NAME}::tfssd json-c)
vai_overview_add_accuracy(tfssd_mt tfssd REQUIRE ${PROJECT_NAME}::tfssd json-c)

# yolov2
vai_overview_add_test(yolov2 yolov2 YOLOv2)
vai_overview_add_performance(yolov2 yolov2 YOLOv2)
vai_overview_add_accuracy(yolov2_mt yolov2)

# yolov3
vai_overview_add_test(yolov3 yolov3 YOLOv3)
vai_overview_add_performance(yolov3 yolov3 YOLOv3)
vai_overview_add_accuracy(yolov3_mt yolov3)
foreach(TMPMODEL yolov3_adas_pruned_0_9 yolov3_voc yolov3_voc_tf yolov3_bdd
                 tiny_yolov3_vmss)
  vai_overview_add_accuracy(${TMPMODEL} yolov3)
endforeach(TMPMODEL)

# polypsegmentation
vai_overview_add_test(polypsegmentation polypsegmentation PolypSegmentation)
vai_overview_add_performance(polypsegmentation polypsegmentation
                             PolypSegmentation)
vai_overview_add_accuracy(polypsegmentation_mt polypsegmentation)
vai_overview_add_accuracy(polypsegmentation polypsegmentation)

# yolov5
if(ENABLE_YOLOV5 AND (NOT DISABLE_ALL))
  vai_overview_add_test(yolov5 yolov5 YOLOv5)
  vai_overview_add_performance(yolov5 yolov5 YOLOv5)
  vai_overview_add_accuracy(yolov5_mt yolov5)
endif()

# yolovx
vai_overview_add_test(yolovx yolovx YOLOvX)
vai_overview_add_performance(yolovx yolovx YOLOvX)
vai_overview_add_accuracy(yolovx_mt yolovx)
vai_overview_add_accuracy(yolovx_coco_mt yolovx REQUIRE ${PROJECT_NAME}::yolovx
                          json-c)

# yolov4
vai_overview_add_test(yolov4 yolov4 YOLOv3 NO_CONFIG REQUIRE
                      ${PROJECT_NAME}::yolov3)
vai_overview_add_performance(yolov4 yolov4 YOLOv3 NO_CONFIG REQUIRE
                             ${PROJECT_NAME}::yolov3)
vai_overview_add_accuracy(yolov4_mt yolov4 REQUIRE ${PROJECT_NAME}::yolov3)

# ultrafast
vai_overview_add_test(ultrafast ultrafast UltraFast NO_VIDEO)
vai_overview_add_performance(ultrafast ultrafast UltraFast)
vai_overview_add_accuracy(ultrafast ultrafast)

# ocr vai_overview_add_test( ocr ocr OCR NO_VIDEO) vai_overview_add_performance(
# ocr ocr OCR ) vai_overview_add_accuracy(ocr ocr)

# demos demo_yolov3
vai_overview_add_demo(
  NAME
  yolov3
  SRCS
  samples/dpu_task/yolov3/demo_yolov3.cpp
  REQUIRE
  ${PROJECT_NAME}::dpu_task
  ${PROJECT_NAME}::xnnpp
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FILES
  samples/dpu_task/yolov3/demo_yolov3.cpp
  samples/dpu_task/yolov3/readme
  samples/dpu_task/yolov3/build.sh)

vai_overview_add_dpu_task(
  NAME
  fadnet
  SRCS
  samples/dpu_task/fadnet/fadnet.cpp
  REQUIRE
  ${PROJECT_NAME}::dpu_task
  ${PROJECT_NAME}::xnnpp
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FOLDER
  samples/dpu_task/fadnet)

vai_overview_add_dpu_task(
  NAME
  ssr
  SRCS
  samples/dpu_task/ssr/ssr.cpp
  REQUIRE
  ${PROJECT_NAME}::dpu_task
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FOLDER
  samples/dpu_task/ssr)

if(ENABLE_PSMNET AND (NOT DISABLE_ALL))
vai_overview_add_dpu_task(
  NAME
  psmnet
  SRCS
  samples/dpu_task/psmnet/psmnet.cpp
  samples/dpu_task/psmnet/cpu_op.cpp
  REQUIRE
  ${PROJECT_NAME}::dpu_task
  ${PROJECT_NAME}::math
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FOLDER
  samples/dpu_task/psmnet)
endif()

# apps seg_and_pose_detect
vai_overview_add_app(
  NAME
  seg_and_pose_detect
  SRCS
  apps/seg_and_pose_detect/seg_and_pose_detect.cpp
  REQUIRE
  ${PROJECT_NAME}::multitask
  ${PROJECT_NAME}::posedetect
  ${PROJECT_NAME}::ssd
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FILES
  apps/seg_and_pose_detect/seg_and_pose_detect.cpp
  apps/seg_and_pose_detect/readme
  apps/seg_and_pose_detect/build.sh
  apps/seg_and_pose_detect/builddrm.sh)

vai_overview_add_app(
  NAME
  multitask_v3_quad_windows
  SRCS
  apps/multitask_v3_quad_windows/multitaskv3_quad_windows.cpp
  REQUIRE
  ${PROJECT_NAME}::multitaskv3
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FILES
  apps/multitask_v3_quad_windows/multitaskv3_quad_windows.cpp
  apps/multitask_v3_quad_windows/readme
  apps/multitask_v3_quad_windows/build.sh
  apps/multitask_v3_quad_windows/builddrm.sh)

# segs_and_roadline_detect
vai_overview_add_app(
  NAME
  segs_and_roadline_detect
  SRCS
  apps/segs_and_roadline_detect/segs_and_roadline_detect.cpp
  REQUIRE
  ${PROJECT_NAME}::multitask
  ${PROJECT_NAME}::lanedetect
  ${PROJECT_NAME}::ssd
  ${PROJECT_NAME}::benchmark
  VAI_INSTALL_FILES
  apps/segs_and_roadline_detect/segs_and_roadline_detect.cpp
  apps/segs_and_roadline_detect/readme
  apps/segs_and_roadline_detect/build.sh
  apps/segs_and_roadline_detect/builddrm.sh)
