CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. set(SON_PROJECT_NAME tof3d)
  2. message("========== Load son project ${SON_PROJECT_NAME} ==========" )
  3. unset(OPTION_ENABLE_TENSORRT_DETECT_CODE CACHE)
  4. option(OPTION_ENABLE_TENSORRT_DETECT_CODE "" OFF)
  5. message("<=${SON_PROJECT_NAME}=> OPTION_ENABLE_TENSORRT_DETECT_CODE: " ${OPTION_ENABLE_TENSORRT_DETECT_CODE})
  6. if (OPTION_ENABLE_TENSORRT_DETECT_CODE)
  7. set(CMAKE_CUDA_ARCHITECTURES 60 61 62 70 72 75 86)
  8. set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
  9. project(${SON_PROJECT_NAME} LANGUAGES CXX CUDA)
  10. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
  11. set(CMAKE_CXX_STANDARD 17)
  12. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
  13. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
  14. option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
  15. # CUDA
  16. find_package(CUDA REQUIRED)
  17. message(STATUS "CUDA Libs: \n${CUDA_LIBRARIES}\n")
  18. get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
  19. message(STATUS "CUDA Headers: \n${CUDA_INCLUDE_DIRS}\n")
  20. # OpenCV
  21. message(STATUS "OpenCV Libs: \n${OpenCV_LIBS}\n")
  22. message(STATUS "OpenCV Libraries: \n${OpenCV_LIBRARIES}\n")
  23. message(STATUS "OpenCV Headers: \n${OpenCV_INCLUDE_DIRS}\n")
  24. if(${OpenCV_VERSION} VERSION_GREATER_EQUAL 4.7.0)
  25. message(STATUS "Build with -DBATCHED_NMS")
  26. add_definitions(-DBATCHED_NMS)
  27. endif()
  28. # TensorRT
  29. set(TensorRT_INCLUDE_DIRS /usr/include/aarch64-linux-gnu)
  30. set(TensorRT_LIBRARIES /usr/lib/aarch64-linux-gnu)
  31. message(STATUS "TensorRT Libs: \n${TensorRT_LIBRARIES}\n")
  32. message(STATUS "TensorRT Headers: \n${TensorRT_INCLUDE_DIRS}\n")
  33. list(APPEND INCLUDE_DIRS
  34. ${CUDA_INCLUDE_DIRS}
  35. ${TensorRT_INCLUDE_DIRS}
  36. )
  37. list(APPEND ALL_LIBS
  38. nvinfer
  39. nvinfer_plugin
  40. ${CUDA_LIBRARIES}
  41. ${CUDA_LIB_DIR}
  42. ${TensorRT_LIBRARIES}
  43. )
  44. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect/tensorrt_detect yolov8_detect)
  45. else ()
  46. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect/onnx_detect yolov8_detect)
  47. endif ()
  48. find_package(gRPC CONFIG REQUIRED)
  49. find_package(Ceres REQUIRED)
  50. option(OPTION_COMMUNICATION_WITH_PLC "plc通信" OFF)
  51. message("<=${SON_PROJECT_NAME}=> OPTION_COMMUNICATION_WITH_PLC: " ${OPTION_COMMUNICATION_WITH_PLC})
  52. # 获取系统架构
  53. message("SYSTEM: ${CMAKE_SYSTEM_PROCESSOR}")
  54. if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  55. set(NebulaSDK_PATH "${CMAKE_CURRENT_LIST_DIR}/vzense/NebulaSDK/AArch64")
  56. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  57. set(NebulaSDK_PATH "${CMAKE_CURRENT_LIST_DIR}/vzense/NebulaSDK/x86_64")
  58. endif()
  59. include_directories(
  60. ${INCLUDE_DIRS}
  61. ${CMAKE_CURRENT_LIST_DIR}
  62. ${PCL_INCLUDE_DIRS}
  63. ${OpenCV_INCLUDE_DIRS}
  64. ${PROTOBUF_INCLUDE_DIR}
  65. ${CERES_INCLUDE_DIR}
  66. ${NebulaSDK_PATH}/include
  67. )
  68. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/proto proto)
  69. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/vzense vzense)
  70. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication communication)
  71. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication/grpc communication_grpc)
  72. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication/mqtt communication_mqtt)
  73. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication/rabbitmq communication_rabbitmq)
  74. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect detect)
  75. aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect/ceres_detect ceres_detect)
  76. set(SON_PROJECT_SOURCE_LIST ${SON_PROJECT_SOURCE_LIST}
  77. ${proto}
  78. ${vzense}
  79. ${communication}
  80. ${communication_grpc}
  81. ${communication_mqtt}
  82. ${communication_rabbitmq}
  83. ${detect}
  84. ${ceres_detect}
  85. ${yolov8_detect}
  86. ${CMAKE_CURRENT_LIST_DIR}/tof3DMain.cpp
  87. )
  88. set(SON_PROJECT_DEPEND_LIST ${SON_PROJECT_DEPEND_LIST}
  89. zxthread
  90. zxrabbitmq
  91. zxpahoc
  92. ${NebulaSDK_PATH}/lib/libNebula_api.so
  93. ${absl_LIBRARIES}
  94. protobuf::libprotobuf
  95. gRPC::grpc++_reflection
  96. ${OpenCV_LIBRARIES}
  97. ${PCL_LIBRARIES}
  98. ${CERES_LIBRARIES}
  99. ${ALL_LIBS}
  100. )
  101. add_executable(${SON_PROJECT_NAME} ${SON_PROJECT_SOURCE_LIST})
  102. target_link_libraries(${SON_PROJECT_NAME} ${SON_PROJECT_DEPEND_LIST})
  103. target_compile_definitions(${SON_PROJECT_NAME} PRIVATE PROJECT_NAME="${SON_PROJECT_NAME}")
  104. if (OPTION_ENABLE_TENSORRT_DETECT_CODE)
  105. target_compile_definitions(${SON_PROJECT_NAME} PRIVATE ENABLE_TENSORRT_DETECT)
  106. endif ()
  107. install(TARGETS ${SON_PROJECT_NAME}
  108. LIBRARY DESTINATION lib # 动态库安装路径
  109. ARCHIVE DESTINATION lib # 静态库安装路径
  110. RUNTIME DESTINATION bin # 可执行文件安装路径
  111. PUBLIC_HEADER DESTINATION include # 头文件安装路径
  112. )