CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. cmake_minimum_required(VERSION 3.5)
  2. cmake_policy(SET CMP0048 NEW) # CMake 3.6 required
  3. if(WIN32)
  4. cmake_policy(SET CMP0074 NEW) # CMake 3.12 required
  5. endif(WIN32)
  6. project(rs_driver VERSION 1.5.8)
  7. #========================
  8. # Project setup
  9. #========================
  10. if (CMAKE_BUILD_TYPE STREQUAL "")
  11. set(CMAKE_BUILD_TYPE Release)
  12. endif()
  13. #=============================
  14. # Compile Features
  15. #=============================
  16. option(DISABLE_PCAP_PARSE "Disable PCAP file parse" OFF)
  17. option(ENABLE_TRANSFORM "Enable transform functions" OFF)
  18. option(ENABLE_DOUBLE_RCVBUF "Enable double size of RCVBUF" OFF)
  19. option(ENABLE_WAIT_IF_QUEUE_EMPTY "Enable waiting for a while in handle thread if the queue is empty" OFF)
  20. option(ENABLE_EPOLL_RECEIVE "Receive packets with epoll() instead of select()" OFF)
  21. option(ENABLE_STAMP_WITH_LOCAL "Enable stamp point cloud with local time" OFF)
  22. option(ENABLE_PCL_POINTCLOUD "Enable PCL Point Cloud" OFF)
  23. #=============================
  24. # Compile Demos, Tools, Tests
  25. #=============================
  26. option(COMPILE_DEMOS "Build rs_driver demos" ON)
  27. option(COMPILE_TOOLS "Build rs_driver tools" OFF)
  28. option(COMPILE_TOOL_VIEWER "Build point cloud visualization tool" OFF)
  29. option(COMPILE_TOOL_PCDSAVER "Build point cloud pcd saver tool" OFF)
  30. option(COMPILE_TESTS "Build rs_driver unit tests" OFF)
  31. #========================
  32. # Platform cross setup
  33. #========================
  34. if(MSVC)
  35. set(COMPILER "MSVC Compiler")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
  37. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi")
  38. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
  39. set(CompilerFlags
  40. CMAKE_CXX_FLAGS CMAKE_C_FLAGS
  41. CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
  42. CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
  43. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL
  44. CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO)
  45. foreach(CompilerFlag ${CompilerFlags})
  46. string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}")
  47. endforeach()
  48. add_compile_definitions(_DISABLE_EXTENDED_ALIGNED_STORAGE) # to disable a msvc error
  49. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:100000000")
  50. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  51. if(UNIX)
  52. set(COMPILER "UNIX GNU Compiler")
  53. elseif(MINGW)
  54. set(COMPILER "MINGW Compiler")
  55. else()
  56. message(FATAL_ERROR "Unsupported compiler.")
  57. endif()
  58. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-unused-parameter")
  59. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
  60. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
  61. endif()
  62. message(=============================================================)
  63. message("-- CMake run for ${COMPILER}")
  64. message(=============================================================)
  65. #========================
  66. # Path Setup
  67. #========================
  68. set(CMAKE_INSTALL_PREFIX /usr/local)
  69. set(INSTALL_DRIVER_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}/include)
  70. set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake)
  71. set(DRIVER_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/src)
  72. set(DRIVER_CMAKE_ROOT ${CMAKE_CURRENT_LIST_DIR}/cmake)
  73. if(WIN32)
  74. else()
  75. if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
  76. list(APPEND EXTERNAL_LIBS socket)
  77. else()
  78. list(APPEND EXTERNAL_LIBS pthread)
  79. endif()
  80. endif(WIN32)
  81. #========================
  82. # Build Features
  83. #========================
  84. if(${ENABLE_EPOLL_RECEIVE})
  85. message(=============================================================)
  86. message("-- Enable Epoll Receive")
  87. message(=============================================================)
  88. add_definitions("-DENABLE_EPOLL_RECEIVE")
  89. endif(${ENABLE_EPOLL_RECEIVE})
  90. if(${DISABLE_PCAP_PARSE})
  91. message(=============================================================)
  92. message("-- Disable PCAP parse")
  93. message(=============================================================)
  94. add_definitions("-DDISABLE_PCAP_PARSE")
  95. else()
  96. if(WIN32)
  97. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
  98. find_package(PCAP REQUIRED)
  99. include_directories(${PCAP_INCLUDE_DIR})
  100. list(APPEND EXTERNAL_LIBS ${PCAP_LIBRARY})
  101. else()
  102. list(APPEND EXTERNAL_LIBS pcap)
  103. endif(WIN32)
  104. endif(${DISABLE_PCAP_PARSE})
  105. if(${ENABLE_TRANSFORM})
  106. message(=============================================================)
  107. message("-- Enable Transform Fucntions")
  108. message(=============================================================)
  109. add_definitions("-DENABLE_TRANSFORM")
  110. # Eigen
  111. find_package(Eigen3 REQUIRED)
  112. include_directories(${EIGEN3_INCLUDE_DIR})
  113. endif(${ENABLE_TRANSFORM})
  114. #============================
  115. # Build Demos, Tools, Tests
  116. #============================
  117. if(${ENABLE_DOUBLE_RCVBUF})
  118. add_definitions("-DENABLE_DOUBLE_RCVBUF")
  119. endif(${ENABLE_DOUBLE_RCVBUF})
  120. if(${ENABLE_WAIT_IF_QUEUE_EMPTY})
  121. add_definitions("-DENABLE_WAIT_IF_QUEUE_EMPTY")
  122. endif(${ENABLE_WAIT_IF_QUEUE_EMPTY})
  123. if(${ENABLE_STAMP_WITH_LOCAL})
  124. add_definitions("-DENABLE_STAMP_WITH_LOCAL")
  125. endif(${ENABLE_STAMP_WITH_LOCAL})
  126. if(${ENABLE_PCL_POINTCLOUD})
  127. add_definitions("-DENABLE_PCL_POINTCLOUD")
  128. endif(${ENABLE_PCL_POINTCLOUD})
  129. if(${COMPILE_DEMOS})
  130. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/demo)
  131. endif(${COMPILE_DEMOS})
  132. if (${COMPILE_TOOLS})
  133. set(COMPILE_TOOL_VIEWER ON)
  134. set(COMPILE_TOOL_PCDSAVER ON)
  135. endif (${COMPILE_TOOLS})
  136. if(${COMPILE_TOOL_VIEWER} OR ${COMPILE_TOOL_PCDSAVER})
  137. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tool)
  138. endif(${COMPILE_TOOL_VIEWER} OR ${COMPILE_TOOL_PCDSAVER})
  139. if(${COMPILE_TESTS})
  140. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test)
  141. endif(${COMPILE_TESTS})
  142. #========================
  143. # Cmake
  144. #========================
  145. configure_file(
  146. ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake.in
  147. ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
  148. @ONLY)
  149. configure_file(
  150. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake.in
  151. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
  152. @ONLY)
  153. configure_file (
  154. ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp.in
  155. ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp
  156. @ONLY)
  157. if(NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  158. set(rs_driver_DIR ${DRIVER_CMAKE_ROOT} PARENT_SCOPE)
  159. endif()
  160. #========================
  161. # Install & Uninstall
  162. #========================
  163. if(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  164. install(FILES ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
  165. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
  166. DESTINATION ${INSTALL_CMAKE_DIR}/${CMAKE_PROJECT_NAME})
  167. install(DIRECTORY src/
  168. DESTINATION ${INSTALL_DRIVER_DIR}
  169. FILES_MATCHING PATTERN "*.h")
  170. install(DIRECTORY src/
  171. DESTINATION ${INSTALL_DRIVER_DIR}
  172. FILES_MATCHING PATTERN "*.hpp")
  173. if(NOT TARGET uninstall)
  174. configure_file(
  175. ${CMAKE_CURRENT_LIST_DIR}/cmake/cmake_uninstall.cmake.in
  176. ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)
  177. add_custom_target(uninstall
  178. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  179. endif(NOT TARGET uninstall)
  180. endif(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})