cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0074 NEW)

message("NVIDIA NX PLATFORM")
set(PROJECT_NAME train)
project(${PROJECT_NAME} VERSION 1.0)


add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)

set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)
#add_definitions("-Wall -g")


#opencv
find_package(OpenCV REQUIRED)
# message(STATUS "${OpenCV_LIBS}")
# message(STATUS "${OpenCV_INCLUDE_DIRS}")

find_package(CUDA REQUIRED)

# 设置编译工具
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")


# 设置项目生成目录
set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_CURRENT_LIST_DIR}/app)

# 设置调用库文件的位置
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "./lib")

set(SYS_USR_INCLUDE_DIR "/usr/include")
set(SYS_USR_LIB_DIR "/usr/lib")
set(SYS_USR_LOCAL_INCLUDE_DIR "/usr/local/include")
set(SYS_USR_LOCAL_LIB_DIR "/usr/local/lib")
set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/x86_64-linux-gnu")
set(AARCH64_LINUX_LIB_DIR "/usr/lib/x86_64-linux-gnu")
#set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/aarch64-linux-gnu")
#set(AARCH64_LINUX_LIB_DIR "/usr/lib/aarch64-linux-gnu")


#opencv3.2.0的库文件在/usr/lib/aarch64-linux-gnu下 头文件路径在/usr/include/opencv2
#opencv4.5.5的库文件在/usr/local/lib下 头文件路径在/usr/local/include/opencv4
#目前使用最新版opencv4.5.5
set(OPENCV_INCLUDE_DIR  ${SYS_USR_LOCAL_INCLUDE_DIR}/opencv4)
set(OPENCV_LIB_DIR  ${SYS_USR_LOCAL_LIB_DIR})

set(CUDA_DIR  "/usr/local/cuda-11.7")
set(CUDA_INCLUDE_DIR  ${CUDA_DIR}/include)
set(CUDA_LIB_DIR  ${CUDA_DIR}/lib64)

set(TENSORRT_INCLUDE_DIR  ${AARCH64_LINUX_INCLUDE_DIR})  #tensorrt的头文件在/usr/include/aarch64-linux-gnu下
set(TENSORRT_LIB_DIR  ${AARCH64_LINUX_LIB_DIR})   #tensorrt的库文件在/usr/lib/aarch64-linux-gnu下

set(DRM_INCLUDE_DIR ${SYS_USR_INCLUDE_DIR}/libdrm)  #DRM的头文件在/usr/include/libdrm下

set(TEGRA_LIB_DIR ${AARCH64_LINUX_LIB_DIR}/tegra)   #tegra库文件路径/usr/lib/aarch64-linux-gnu/tegra

#set(PCL_INCLUDE ${SYS_USR_LOCAL_INCLUDE_DIR}/pcl-1.7) #pcl头文件路径


# nvidia ascend common include
include_directories(
        #ai_matrix include
        ${PROJECT_SOURCE_DIR}/ai_matrix
        ${PROJECT_SOURCE_DIR}/ai_matrix/framework
        ${PROJECT_SOURCE_DIR}/ai_matrix/myftp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myhttp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myJson
        ${PROJECT_SOURCE_DIR}/ai_matrix/myJson/json
        ${PROJECT_SOURCE_DIR}/ai_matrix/mylog
        ${PROJECT_SOURCE_DIR}/ai_matrix/pcl
        ${PROJECT_SOURCE_DIR}/ai_matrix/myqueue
        ${PROJECT_SOURCE_DIR}/ai_matrix/myshell
        ${PROJECT_SOURCE_DIR}/ai_matrix/myutils

        #nvidia ascend common cann include
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/BlockingQueue
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/CBase64
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/CommandParser
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/CommonDataType
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/ConfigParser
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/ErrorCode
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/FileManager
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/Log
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/

        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common
        #common engine include
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine

        #common tools rtsp_server include
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/3rdpart/md5
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/xop/
)


include_directories(
        #nvidia engine include

        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ContainerEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/DecodeEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MoveEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MyYaml
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/TrainStepOneEngine
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine

        #nvidia_tools yolov5 include
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/include

        #third party include
        ${CUDA_INCLUDE_DIR}
        ${TENSORRT_INCLUDE_DIR}
        ${DRM_INCLUDE_DIR}
        ${OpenCV_DIR}
        ${AARCH64_LINUX_INCLUDE_DIR}
        ${SYS_USR_LOCAL_INCLUDE_DIR}
#        ${PCL_INCLUDE}
)



link_directories(${SYS_USR_LOCAL_LIB_DIR}
        ${AARCH64_LINUX_LIB_DIR}
        ${OPENCV_LIB_DIR}
        ${CUDA_LIB_DIR}
        ${TENSORRT_LIB_DIR}
        ${TEGRA_LIB_DIR}
)

#源文件
#公共源文件
file(GLOB_RECURSE COMMON_SRCS_LISTS
        main.cpp
        #ai_matrix src
        ${PROJECT_SOURCE_DIR}/ai_matrix/framework/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myftp/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myhttp/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myJson/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/mylog/*.cpp
        #${PROJECT_SOURCE_DIR}/ai_matrix/mypcl/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myqueue/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myshell/*.cpp
        ${PROJECT_SOURCE_DIR}/ai_matrix/myutils/*.cpp

        #common cann src
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/CommandParser/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/ConfigParser/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/ErrorCode/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/FileManager/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/Log/*.cpp

        #common engine src
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp

        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/*.cpp

        #common tools rtsp_server src
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/xop/*.cpp
)

file(GLOB_RECURSE SRCS_LISTS
        #nvidia engine src
        #nvidia engine include

        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MyYaml/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/TrainStepOneEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ContainerEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/DecodeEngine/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MoveEngine/*.cpp

        ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/*.cpp

        #nvidia tools yolov5 src
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cpp
        ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/nvidia_tools/yolov5/src/*.cu
)

cuda_add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})

target_link_libraries(${PROJECT_NAME} pthread)       #other
target_link_libraries(${PROJECT_NAME} nvinfer nvonnxparser nvcaffe_parser nvinfer_plugin)   #TensorRT
target_link_libraries(${PROJECT_NAME} cudart cuda)   #CUDA

target_link_libraries(${PROJECT_NAME}
        ${OpenCV_LIBS}  #third party librarys
#        ${PCL_LIBRARY_DIRS}
#        pcl_common pcl_io_ply pcl_keypoints pcl_registration pcl_segmentation pcl_features pcl_io pcl_octree #pcl
#        pcl_sample_consensus  pcl_surface pcl_filters pcl_kdtree pcl_recognition pcl_search pcl_tracking
        avformat avcodec avutil avfilter swresample swscale postproc #VideoCodecV2
        yaml-cpp https_sn
        jsoncpp curl boost_system boost_filesystem ssh2
        -Wl,-z,relro,-z,now,-z,noexecstack -pie -s
)
