CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. cmake_minimum_required(VERSION 3.5)
  2. project(rslidar_sdk)
  3. #=======================================
  4. # Compile setup (ORIGINAL,CATKIN,COLCON)
  5. #=======================================
  6. #set(COMPILE_METHOD ORIGINAL)
  7. set(COMPILE_METHOD CATKIN)
  8. #========================
  9. # Project Version
  10. #========================
  11. set (PROJECT_VERSION_MAJOR 1)
  12. set (PROJECT_VERSION_MINOR 2)
  13. set (PROJECT_VERSION_PATCH 1)
  14. #========================
  15. # Project details / setup
  16. #========================
  17. set(PROJECT_NAME rslidar_sdk)
  18. add_definitions(-DPROJECT_PATH="${PROJECT_SOURCE_DIR}")
  19. cmake_policy(SET CMP0048 NEW)
  20. set(CMAKE_BUILD_TYPE RELEASE)
  21. add_definitions(-O3)
  22. add_definitions(-std=c++14)
  23. add_compile_options(-Wall)
  24. #========================
  25. # Version
  26. #========================
  27. configure_file (
  28. "${PROJECT_SOURCE_DIR}/src/rs_driver/src/rs_driver/macro/version.h.in"
  29. "${PROJECT_SOURCE_DIR}/src/rs_driver/src/rs_driver/macro/version.h"
  30. )
  31. #========================
  32. # Dependencies Setup
  33. #========================
  34. #ROS#
  35. find_package(roscpp 1.12 QUIET)
  36. if(roscpp_FOUND)
  37. message(=============================================================)
  38. message("-- ROS Found, Ros Support is turned On!")
  39. message(=============================================================)
  40. add_definitions(-DROS_FOUND)
  41. include_directories(${roscpp_INCLUDE_DIRS})
  42. else(roscpp_FOUND)
  43. message(=============================================================)
  44. message("-- ROS Not Found, Ros Support is turned Off!")
  45. message(=============================================================)
  46. endif(roscpp_FOUND)
  47. #ROS2#
  48. find_package(rclcpp QUIET)
  49. if(rclcpp_FOUND)
  50. find_package(ament_cmake REQUIRED)
  51. find_package(sensor_msgs REQUIRED)
  52. find_package(rslidar_msg REQUIRED)
  53. find_package(std_msgs REQUIRED)
  54. set(CMAKE_CXX_STANDARD 14)
  55. message(=============================================================)
  56. message("-- ROS2 Found, Ros2 Support is turned On!")
  57. message(=============================================================)
  58. add_definitions(-DROS2_FOUND)
  59. include_directories(${rclcpp_INCLUDE_DIRS})
  60. else(rclcpp_FOUND)
  61. message(=============================================================)
  62. message("-- ROS2 Not Found, Ros2 Support is turned Off!")
  63. message(=============================================================)
  64. endif(rclcpp_FOUND)
  65. #Protobuf#
  66. find_package(Protobuf QUIET)
  67. find_program(PROTOC protoc)
  68. if(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  69. message(=============================================================)
  70. message("-- Protobuf Found, Protobuf Support is turned On!")
  71. message(=============================================================)
  72. add_definitions(-DPROTO_FOUND)
  73. include_directories(${PROTOBUF_INCLUDE_DIRS})
  74. SET(PROTO_FILE_PATH ${PROJECT_SOURCE_DIR}/src/msg/proto_msg)
  75. file(GLOB PROTOBUF_FILELIST ${PROTO_FILE_PATH}/*.proto)
  76. foreach(proto_file ${PROTOBUF_FILELIST})
  77. message(STATUS "COMPILING ${proto_file} USING ${PROTOBUF_PROTOC_EXECUTABLE}")
  78. execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
  79. --proto_path=${PROTO_FILE_PATH}
  80. --cpp_out=${PROTO_FILE_PATH}
  81. ${proto_file})
  82. endforeach()
  83. else(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  84. message(=============================================================)
  85. message("-- Protobuf Not Found, Protobuf Support is turned Off!")
  86. message(=============================================================)
  87. endif(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  88. #OMP#
  89. find_package( OpenMP QUIET)
  90. if(OPENMP_FOUND)
  91. message(=============================================================)
  92. message("-- OpenMP Found, OpenMP support is turned On!")
  93. message(=============================================================)
  94. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  95. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  96. set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS}${OpenMP_EXE_LINKER_FLAGS}")
  97. endif()
  98. #Others#
  99. find_package(yaml-cpp REQUIRED)
  100. find_package(PCL REQUIRED)
  101. include_directories(${PCL_INCLUDE_DIRS})
  102. link_directories(${PCL_LIBRARY_DIRS})
  103. add_definitions(${PCL_DEFINITIONS})
  104. #Catkin#
  105. if(${COMPILE_METHOD} MATCHES "CATKIN")
  106. find_package(catkin REQUIRED COMPONENTS
  107. roscpp
  108. sensor_msgs
  109. )
  110. catkin_package(
  111. CATKIN_DEPENDS sensor_msgs
  112. )
  113. endif(${COMPILE_METHOD} MATCHES "CATKIN")
  114. #Include directory#
  115. include_directories(${PROJECT_SOURCE_DIR}/src)
  116. #Driver core#
  117. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/src/rs_driver/cmake)
  118. include(rs_driver)
  119. include_directories(${rs_driver_INCLUDE_DIRS})
  120. #========================
  121. # Build Setup
  122. #========================
  123. #Protobuf#
  124. if(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  125. add_executable(rslidar_sdk_node
  126. node/rslidar_sdk_node.cpp
  127. ${PROTO_FILE_PATH}/packet.pb.cc
  128. ${PROTO_FILE_PATH}/scan.pb.cc
  129. ${PROTO_FILE_PATH}/point_cloud.pb.cc
  130. )
  131. target_link_libraries(rslidar_sdk_node
  132. ${PCL_LIBRARIES}
  133. ${YAML_CPP_LIBRARIES}
  134. ${PROTOBUF_LIBRARY}
  135. ${rs_driver_LIBRARIES}
  136. )
  137. else(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  138. add_executable(rslidar_sdk_node
  139. node/rslidar_sdk_node.cpp
  140. )
  141. target_link_libraries(rslidar_sdk_node
  142. ${PCL_LIBRARIES}
  143. ${YAML_CPP_LIBRARIES}
  144. ${rs_driver_LIBRARIES}
  145. )
  146. endif(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
  147. #Ros#
  148. if(roscpp_FOUND)
  149. target_link_libraries(rslidar_sdk_node ${roscpp_LIBRARIES})
  150. endif(roscpp_FOUND)
  151. #Ros2#
  152. if(rclcpp_FOUND)
  153. ament_target_dependencies(rslidar_sdk_node rclcpp sensor_msgs std_msgs rslidar_msg)
  154. install(TARGETS
  155. rslidar_sdk_node
  156. DESTINATION lib/${PROJECT_NAME}
  157. )
  158. install(DIRECTORY
  159. launch
  160. rviz
  161. DESTINATION share/${PROJECT_NAME}
  162. )
  163. ament_package()
  164. endif(rclcpp_FOUND)