123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- # 定义cmake的最低版本
- cmake_minimum_required(VERSION 3.19)
- # 检查vcpkg文件夹是否存在
- if(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg")
- message("Find directory: " "${CMAKE_SOURCE_DIR}/vcpkg")
- else()
- message("Can't find directory: " "${CMAKE_SOURCE_DIR}/vcpkg")
- execute_process(
- COMMAND git clone https://github.com/microsoft/vcpkg.git
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
- RESULT_VARIABLE vcpkg_ret
- )
- if (vcpkg_ret EQUAL 0)
- message("clone vcpkg success... ")
- else ()
- message("clone vcpkg failed... ")
- return()
- endif ()
- endif()
- # 查看vcpkg版本
- execute_process(
- COMMAND "${CMAKE_SOURCE_DIR}/vcpkg/vcpkg.exe" --version
- RESULT_VARIABLE result
- OUTPUT_VARIABLE output
- )
- # cmake 无法在执行project之前获取系统类型,所以只能通过一个个安装尝试
- if(NOT result EQUAL 0)
- message("Can't get vcpkg version, run vcpkg install script file.")
- if (EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.sh")
- message("Find script ${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.sh, try to install...")
- execute_process(
- COMMAND "${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.sh"
- RESULT_VARIABLE install_result
- OUTPUT_VARIABLE install_output
- )
- endif ()
- message("vcpkg sh script install result: ${install_result}")
- if (NOT install_result EQUAL 0 AND EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.bat")
- message("${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.sh can't install vcpkg, try to use bat script...")
- message("Find script ${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.bat, try to install...")
- execute_process(
- COMMAND "${CMAKE_SOURCE_DIR}/vcpkg/bootstrap-vcpkg.bat"
- RESULT_VARIABLE install_result
- OUTPUT_VARIABLE install_output
- )
- message(${install_result})
- endif ()
- endif()
- # vcpkg 环境变量定义,必须在project之前定义
- set(VCPKG_ROOT "${CMAKE_SOURCE_DIR}/vcpkg")
- set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
- # 定义工程名称
- project(Project)
- set(CMAKE_CXX_STANDARD 17)
- option(MeasureTest "Enable test" OFF)
- option(GFLAGS "Enable Google Flags." ON)
- option(DataToCloud "Enable collect data to mqtt server." ON)
- option(AlgAddTest "Enable test alg module." OFF)
- option(ClampSafety "Enable clamp safety." OFF)
- option(WatchDog "Enable watch dog." ON)
- option(MeasureNode "Enable Measure node." ON)
- option(LidarICP "Enable LidarICP" OFF)
- option(ExecutorTest "Enable ExecutorTest" OFF)
- option(Cloud2Mat "Enable ExecutorTest" OFF)
- # 指定安装目录
- if (MeasureTest)
- set(CMAKE_INSTALL_PREFIX
- ${PROJECT_SOURCE_DIR}/build/out
- )
- message("ON test, set install path to ${PROJECT_SOURCE_DIR}/build/out")
- else ()
- set(CMAKE_INSTALL_PREFIX
- # /out
- ${PROJECT_SOURCE_DIR}/build/out
- )
- message("OFF test, set install path to ${PROJECT_SOURCE_DIR}/build/out")
- add_definitions(-DETC_PATH="${CMAKE_INSTALL_PREFIX}")
- endif ()
- SET (CMAKE_EXPORT_COMPILE_COMMANDS ON)
- set (CMAKE_BUILD_TYPE "RELEASE")
- # 打印工程定级目录(非必要)
- message("project path: " ${PROJECT_SOURCE_DIR})
- #execute_process(COMMAND bash ${PROJECT_SOURCE_DIR}/proto.sh ${PROJECT_SOURCE_DIR})
- execute_process(COMMAND ${PROJECT_SOURCE_DIR}/proto.bat ${PROJECT_SOURCE_DIR})
- # 第三方库
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(nanomsg REQUIRED nanomsg)
- pkg_check_modules(YAML_CPP REQUIRED yaml-cpp)
- find_path(YAML_CPP_INCLUDE_DIR
- NAMES yaml_cpp.h
- PATHS ${YAML_CPP_INCLUDE_DIRS})
- find_library(YAML_CPP_LIBRARY
- NAMES YAML_CPP
- PATHS ${YAML_CPP_LIBRARY_DIRS})
- if (NOT ${YAML_CPP_VERSION} VERSION_LESS "0.5")
- add_definitions(-DHAVE_NEW_YAMLCPP)
- endif (NOT ${YAML_CPP_VERSION} VERSION_LESS "0.5")
- add_subdirectory(thirdpart/rs_driver)
- # Don't search with REQUIRED as we can continue without gflags.
- find_package(gflags 2.2.0)
- if (gflags_FOUND)
- if (TARGET gflags)
- message("-- Found Google Flags (gflags) version ${gflags_VERSION}: ${gflags_DIR}")
- message("-- Found Google Flags (gflags) version ${gflags_VERSION}: ${GFLAGS_LIBRARIES}")
- else()
- message("-- Detected version of gflags: ${gflags_VERSION} does not define "
- "expected gflags CMake target which should be exported by gflags 2.2+. "
- "Building without gflags.")
- update_cache_variable(GFLAGS OFF)
- endif()
- else (gflags_FOUND)
- message("-- Did not find Google Flags (gflags), Building without gflags.")
- update_cache_variable(GFLAGS OFF)
- endif (gflags_FOUND)
- find_package(PCL REQUIRED)
- find_package(Eigen3 REQUIRED)
- find_package(Ceres REQUIRED)
- find_package(OpenCV REQUIRED)
- find_package(rs_driver REQUIRED)
- find_package(Protobuf REQUIRED)
- find_package(rabbitmq-c CONFIG REQUIRED)
- include_directories(
- ${rs_driver_INCLUDE_DIRS}
- ${OpenCV_INCLUDE_DIRS}
- ${EIGEN3_INCLUDE_DIRS}
- ${CERES_INCLUDE_DIR}
- ${PCL_INCLUDE_DIRS}
- ${PROJECT_SOURCE_DIR}/include
- ${PROJECT_SOURCE_DIR}/Modules
- )
- # 添加子目录CMAKE
- add_subdirectory(include)
- if(DataToCloud)
- add_subdirectory(Modules/DataToCloud)
- endif ()
- if(AlgAddTest)
- add_subdirectory(Modules/AlgAddTest)
- endif ()
- if(ClampSafety)
- add_subdirectory(Modules/ClampSafety)
- endif ()
- if(WatchDog)
- add_subdirectory(Modules/WatchDog)
- endif ()
- if(MeasureNode)
- include_directories(${PROJECT_SOURCE_DIR}/Modules/MeasureNode)
- add_subdirectory(Modules/MeasureNode)
- endif ()
- if(LidarICP)
- include_directories(${PROJECT_SOURCE_DIR}/Modules/LidarICP)
- add_subdirectory(Modules/LidarICP)
- endif ()
- if(ExecutorTest)
- include_directories(${PROJECT_SOURCE_DIR}/Modules/ExecutorTest)
- add_subdirectory(Modules/ExecutorTest)
- endif ()
- if(Cloud2Mat)
- add_subdirectory(Modules/Cloud2Mat)
- endif ()
- # install(DIRECTORY ${PROJECT_SOURCE_DIR}/etc
- # DESTINATION ${CMAKE_INSTALL_PREFIX}
- # )
|