cmvr-es/CMakeLists.txt
2025-12-15 17:01:32 +08:00

125 lines
4.1 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

cmake_minimum_required(VERSION 3.22.0)
project(cmvr_es)
# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS -pthread)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# 查找依赖
list(APPEND CMAKE_PREFIX_PATH "$ENV{HOME}./local")
###########################################################
## DEPENDENCIES
#############################################################
find_package(jsoncpp REQUIRED)
find_package(protobuf REQUIRED)
find_package(gRPC REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLOG REQUIRED libglog)
include_directories(
${CMAKE_SOURCE_DIR}/third_party/pinocchio/3.8.0/include
${CMAKE_SOURCE_DIR}/third_party/coal/3.0.2/include
${CMAKE_SOURCE_DIR}/third_party/urdfdom/5.0.3/include
${CMAKE_SOURCE_DIR}/third_party/urdfdom_headers/2.0.1/include
${CMAKE_SOURCE_DIR}/third_party/mujoco/3.3.7/include
)
link_directories(
${CMAKE_SOURCE_DIR}/third_party/pinocchio/3.8.0/lib
${CMAKE_SOURCE_DIR}/third_party/coal/3.0.2/lib
${CMAKE_SOURCE_DIR}/third_party/urdfdom/5.0.3/lib
${CMAKE_SOURCE_DIR}/third_party/mujoco/3.3.7/lib
)
############################################################
# PROTO
############################################################
set(PROTO_IMPORT_DIR ${PROJECT_SOURCE_DIR}/protos)
set(PROTO_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/_protobuf)
file(MAKE_DIRECTORY ${PROTO_BINARY_DIR})
file(GLOB_RECURSE PROTO_FILES ${PROTO_IMPORT_DIR}/*.proto)
# 1) 先做 OBJECT只负责生成/编译 pb.cc
add_library(proto-objects OBJECT)
target_sources(proto-objects PRIVATE ${PROTO_FILES})
set_target_properties(proto-objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
protobuf_generate(
TARGET proto-objects
IMPORT_DIRS ${PROTO_IMPORT_DIR}
PROTOC_OUT_DIR ${PROTO_BINARY_DIR}
USAGE_REQUIREMENT PRIVATE
)
protobuf_generate(
TARGET proto-objects
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=$ENV{HOME}/.local/bin/grpc_cpp_plugin"
IMPORT_DIRS ${PROTO_IMPORT_DIR}
PROTOC_OUT_DIR ${PROTO_BINARY_DIR}
USAGE_REQUIREMENT PRIVATE
)
# 2) 把 OBJECT 打包成一个“唯一的”共享库(关键)
add_library(proto SHARED $<TARGET_OBJECTS:proto-objects>)
target_include_directories(proto PUBLIC ${PROTO_BINARY_DIR} ${PROTO_IMPORT_DIR})
target_link_libraries(proto PUBLIC protobuf::libprotobuf gRPC::grpc++ gRPC::grpc++_reflection)
add_library(cmvr_es::proto ALIAS proto)
############################################################
# include
############################################################
include_directories(
/usr/include/opencv4
/usr/include/eigen3
/usr/local/include/osqp
/usr/local/share/osqp/codegen_files/inc/prate/
$ENV{HOME}/.local/include
/usr/local/include/
${PROTO_BINARY_DIR}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src/devices
${PROJECT_SOURCE_DIR}/src/utils
${PROJECT_SOURCE_DIR}/third_party
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/third_party/toppra/0.6.2/include
)
############################################################
# subdirectory
############################################################
add_subdirectory(src)
add_subdirectory(example)
#add_subdirectory(test)
############################################################
# executables
############################################################
add_executable(cmvr_es src/main.cpp)
target_include_directories(cmvr_es PRIVATE ${GLOG_INCLUDE_DIRS})
target_link_libraries(cmvr_es PRIVATE
cmvr_es::proto
service
${GLOG_LIBRARIES}
gflags
jsoncpp_lib
cmvr_es::utils
cmvr_es::service
cmvr_es::monitor_manager
cmvr_es::hardware
cmvr_es::device::canbus
cmvr_es::device::ti5motor
cmvr_es::controller
cmvr_es::data_center
cmvr_es::ik_solver
cmvr_es::planner
cmvr_es::device::humanoid_robot
)