CMakeLists.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.2)
  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(ENABLE_PCAP_PARSE "Enable PCAP file parse" ON)
  17. option(ENABLE_TRANSFORM "Enable transform functions" OFF)
  18. option(ENABLE_HIGH_PRIORITY_THREAD "Use High priority thread to receive packets" OFF)
  19. option(ENABLE_RECVMMSG "Enable recvmmsg() to receive MSOP message" OFF)
  20. option(ENABLE_PCL_POINTCLOUD "Enable PCL Point Cloud" OFF)
  21. #=============================
  22. # Compile Demos, Tools, Tests
  23. #=============================
  24. option(COMPILE_DEMOS "Build rs_driver demos" OFF)
  25. option(COMPILE_TOOLS "Build point cloud visualization tool" OFF)
  26. option(COMPILE_TESTS "Build rs_driver unit tests" OFF)
  27. #========================
  28. # Platform cross setup
  29. #========================
  30. if(MSVC)
  31. set(COMPILER "MSVC Compiler")
  32. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
  33. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi")
  34. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
  35. set(CompilerFlags
  36. CMAKE_CXX_FLAGS CMAKE_C_FLAGS
  37. CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
  38. CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
  39. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL
  40. CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO)
  41. foreach(CompilerFlag ${CompilerFlags})
  42. string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}")
  43. endforeach()
  44. add_compile_definitions(_DISABLE_EXTENDED_ALIGNED_STORAGE) # to disable a msvc error
  45. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:100000000")
  46. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  47. if(UNIX)
  48. set(COMPILER "UNIX GNU Compiler")
  49. elseif(MINGW)
  50. set(COMPILER "MINGW Compiler")
  51. else()
  52. message(FATAL_ERROR "Unsupported compiler.")
  53. endif()
  54. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14")
  55. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
  56. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
  57. endif()
  58. message(=============================================================)
  59. message("-- CMake run for ${COMPILER}")
  60. message(=============================================================)
  61. #========================
  62. # Path Setup
  63. #========================
  64. set(CMAKE_INSTALL_PREFIX /usr/local)
  65. set(INSTALL_DRIVER_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}/include)
  66. set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake)
  67. set(DRIVER_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/src)
  68. set(DRIVER_CMAKE_ROOT ${CMAKE_CURRENT_LIST_DIR}/cmake)
  69. # fix pthread missing on ubuntu18.04 or ubuntu20.04
  70. if(WIN32)
  71. else()
  72. list(APPEND EXTERNAL_LIBS pthread)
  73. endif(WIN32)
  74. #========================
  75. # Build Features
  76. #========================
  77. if(${ENABLE_HIGH_PRIORITY_THREAD})
  78. message(=============================================================)
  79. message("-- Enable High Priority Thread")
  80. message(=============================================================)
  81. add_definitions("-DENABLE_HIGH_PRIORITY_THREAD")
  82. endif(${ENABLE_HIGH_PRIORITY_THREAD})
  83. if(${ENABLE_PCAP_PARSE})
  84. message(=============================================================)
  85. message("-- Enable PCAP parse")
  86. message(=============================================================)
  87. add_definitions("-DENABLE_PCAP_PARSE")
  88. if(WIN32)
  89. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
  90. find_package(PCAP REQUIRED)
  91. include_directories(${PCAP_INCLUDE_DIR})
  92. list(APPEND EXTERNAL_LIBS ${PCAP_LIBRARY})
  93. else()
  94. list(APPEND EXTERNAL_LIBS pcap)
  95. endif(WIN32)
  96. endif(${ENABLE_PCAP_PARSE})
  97. if(${ENABLE_TRANSFORM})
  98. message(=============================================================)
  99. message("-- Enable Transform Fucntions")
  100. message(=============================================================)
  101. add_definitions("-DENABLE_TRANSFORM")
  102. # Eigen
  103. find_package(Eigen3 REQUIRED)
  104. include_directories(${EIGEN3_INCLUDE_DIR})
  105. endif(${ENABLE_TRANSFORM})
  106. #============================
  107. # Build Demos, Tools, Tests
  108. #============================
  109. if(${ENABLE_RECVMMSG})
  110. add_definitions("-DENABLE_RECVMMSG")
  111. endif(${ENABLE_RECVMMSG})
  112. if(${COMPILE_DEMOS})
  113. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/demo)
  114. endif(${COMPILE_DEMOS})
  115. if(${COMPILE_TOOLS})
  116. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tool)
  117. endif(${COMPILE_TOOLS})
  118. if(${COMPILE_TESTS})
  119. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test)
  120. endif(${COMPILE_TESTS})
  121. #========================
  122. # Cmake
  123. #========================
  124. configure_file(
  125. ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake.in
  126. ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
  127. @ONLY)
  128. configure_file(
  129. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake.in
  130. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
  131. @ONLY)
  132. configure_file (
  133. ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp.in
  134. ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp
  135. @ONLY)
  136. if(NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  137. set(rs_driver_DIR ${DRIVER_CMAKE_ROOT} PARENT_SCOPE)
  138. endif()
  139. #========================
  140. # Install & Uninstall
  141. #========================
  142. if(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  143. install(FILES ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
  144. ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
  145. DESTINATION ${INSTALL_CMAKE_DIR}/${CMAKE_PROJECT_NAME})
  146. install(DIRECTORY src/
  147. DESTINATION ${INSTALL_DRIVER_DIR}
  148. FILES_MATCHING PATTERN "*.h")
  149. install(DIRECTORY src/
  150. DESTINATION ${INSTALL_DRIVER_DIR}
  151. FILES_MATCHING PATTERN "*.hpp")
  152. if(NOT TARGET uninstall)
  153. configure_file(
  154. ${CMAKE_CURRENT_LIST_DIR}/cmake/cmake_uninstall.cmake.in
  155. ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)
  156. add_custom_target(uninstall
  157. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  158. endif(NOT TARGET uninstall)
  159. endif(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})