CMakeLists.txt 4.8 KB

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