123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- cmake_minimum_required(VERSION 3.5)
- cmake_policy(SET CMP0048 NEW) # CMake 3.6 required
- if(WIN32)
- cmake_policy(SET CMP0074 NEW) # CMake 3.12 required
- endif(WIN32)
- project(rs_driver VERSION 1.5.2)
- #========================
- # Project setup
- #========================
- if (CMAKE_BUILD_TYPE STREQUAL "")
- set(CMAKE_BUILD_TYPE Release)
- endif()
- #=============================
- # Compile Features
- #=============================
- option(ENABLE_PCAP_PARSE "Enable PCAP file parse" ON)
- option(ENABLE_TRANSFORM "Enable transform functions" OFF)
- option(ENABLE_HIGH_PRIORITY_THREAD "Use High priority thread to receive packets" OFF)
- option(ENABLE_RECVMMSG "Enable recvmmsg() to receive MSOP message" OFF)
- option(ENABLE_PCL_POINTCLOUD "Enable PCL Point Cloud" OFF)
- #=============================
- # Compile Demos, Tools, Tests
- #=============================
- option(COMPILE_DEMOS "Build rs_driver demos" OFF)
- option(COMPILE_TOOLS "Build point cloud visualization tool" OFF)
- option(COMPILE_TESTS "Build rs_driver unit tests" OFF)
- #========================
- # Platform cross setup
- #========================
- if(MSVC)
- set(COMPILER "MSVC Compiler")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
- set(CompilerFlags
- CMAKE_CXX_FLAGS CMAKE_C_FLAGS
- CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
- CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
- CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL
- CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO)
- foreach(CompilerFlag ${CompilerFlags})
- string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}")
- endforeach()
- add_compile_definitions(_DISABLE_EXTENDED_ALIGNED_STORAGE) # to disable a msvc error
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:100000000")
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
- if(UNIX)
- set(COMPILER "UNIX GNU Compiler")
- elseif(MINGW)
- set(COMPILER "MINGW Compiler")
- else()
- message(FATAL_ERROR "Unsupported compiler.")
- endif()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
- endif()
- message(=============================================================)
- message("-- CMake run for ${COMPILER}")
- message(=============================================================)
- #========================
- # Path Setup
- #========================
- set(CMAKE_INSTALL_PREFIX /usr/local)
- set(INSTALL_DRIVER_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}/include)
- set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake)
- set(DRIVER_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/src)
- set(DRIVER_CMAKE_ROOT ${CMAKE_CURRENT_LIST_DIR}/cmake)
- # fix pthread missing on ubuntu18.04 or ubuntu20.04
- if(WIN32)
- else()
- list(APPEND EXTERNAL_LIBS pthread)
- endif(WIN32)
- #========================
- # Build Features
- #========================
- if(${ENABLE_HIGH_PRIORITY_THREAD})
- message(=============================================================)
- message("-- Enable High Priority Thread")
- message(=============================================================)
- add_definitions("-DENABLE_HIGH_PRIORITY_THREAD")
- endif(${ENABLE_HIGH_PRIORITY_THREAD})
- if(${ENABLE_PCAP_PARSE})
- message(=============================================================)
- message("-- Enable PCAP parse")
- message(=============================================================)
- add_definitions("-DENABLE_PCAP_PARSE")
- if(WIN32)
- set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
- find_package(PCAP REQUIRED)
- include_directories(${PCAP_INCLUDE_DIR})
- list(APPEND EXTERNAL_LIBS ${PCAP_LIBRARY})
- else()
- list(APPEND EXTERNAL_LIBS pcap)
- endif(WIN32)
- endif(${ENABLE_PCAP_PARSE})
- if(${ENABLE_TRANSFORM})
- message(=============================================================)
- message("-- Enable Transform Fucntions")
- message(=============================================================)
- add_definitions("-DENABLE_TRANSFORM")
- # Eigen
- find_package(Eigen3 REQUIRED)
- include_directories(${EIGEN3_INCLUDE_DIR})
- endif(${ENABLE_TRANSFORM})
- #============================
- # Build Demos, Tools, Tests
- #============================
- if(${ENABLE_RECVMMSG})
- add_definitions("-DENABLE_RECVMMSG")
- endif(${ENABLE_RECVMMSG})
- if(${COMPILE_DEMOS})
- add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/demo)
- endif(${COMPILE_DEMOS})
- if(${COMPILE_TOOLS})
- add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tool)
- endif(${COMPILE_TOOLS})
- if(${COMPILE_TESTS})
- add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test)
- endif(${COMPILE_TESTS})
- #========================
- # Cmake
- #========================
- configure_file(
- ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake.in
- ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
- @ONLY)
- configure_file(
- ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake.in
- ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
- @ONLY)
- configure_file (
- ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp.in
- ${CMAKE_CURRENT_LIST_DIR}/src/rs_driver/macro/version.hpp
- @ONLY)
- if(NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
- set(rs_driver_DIR ${DRIVER_CMAKE_ROOT} PARENT_SCOPE)
- endif()
- #========================
- # Install & Uninstall
- #========================
- if(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
- install(FILES ${DRIVER_CMAKE_ROOT}/rs_driverConfig.cmake
- ${DRIVER_CMAKE_ROOT}/rs_driverConfigVersion.cmake
- DESTINATION ${INSTALL_CMAKE_DIR}/${CMAKE_PROJECT_NAME})
- install(DIRECTORY src/
- DESTINATION ${INSTALL_DRIVER_DIR}
- FILES_MATCHING PATTERN "*.h")
- install(DIRECTORY src/
- DESTINATION ${INSTALL_DRIVER_DIR}
- FILES_MATCHING PATTERN "*.hpp")
- if(NOT TARGET uninstall)
- configure_file(
- ${CMAKE_CURRENT_LIST_DIR}/cmake/cmake_uninstall.cmake.in
- ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)
- add_custom_target(uninstall
- COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
- endif(NOT TARGET uninstall)
- endif(UNIX AND ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|