Skip to content

Commit

Permalink
cmake 编译完成
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 12, 2024
1 parent 7e15a7a commit a503513
Show file tree
Hide file tree
Showing 37 changed files with 63 additions and 24,999 deletions.
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_C_COMPILER gcc-9)
set(CMAKE_CXX_COMPILER g++-9)
# set(CMAKE_C_COMPILER gcc-9)
# set(CMAKE_CXX_COMPILER g++-9)
set(CMAKE_CXX_STANDARD 17)

project(yaLanTingLibs
Expand All @@ -11,12 +11,11 @@ project(yaLanTingLibs
LANGUAGES CXX
)

find_package(Protobuf REQUIRED)

# 将插件目录添加到环境变量
execute_process(COMMAND export PATH=$PATH:${CMAKE_BINARY_DIR}/output/bin/)

# set(SYSROOT_DIR /opt/zhito/sysroot)
set(CMAKE_PREFIX_PATH /home/gsk/pro/CyberRT/install/)

find_package(Protobuf REQUIRED)

# load pack finder
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Find/)
Expand All @@ -43,5 +42,5 @@ if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs") # if ylt is top-level project
endif()


# add_subdirectory(src/struct_pb/protoc-plugin)
# add_subdirectory(src/protoc-plugin)
add_subdirectory(src/example)
104 changes: 55 additions & 49 deletions src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,65 @@ add_compile_options(-Wno-attributes)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/examples)


set(protobuf_generate_PLUGIN "protoc-gen-struct_pb")
include(cmake/struct_pb.cmake)

cmake_policy(SET CMP0075 NEW)
find_package(PCL REQUIRED COMPONENTS common io)
find_package(OpenCV REQUIRED COMPONENTS core)

# generate .pb.cc .pb.h
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
proto_to_struct.proto
base.proto
imu.proto
gnss.proto
state.proto
chasis.proto
perception.proto
pointcloud.proto
image.proto
)


protobuf_generate_python(PROTO_PYTHON_SRCS
proto_to_struct.proto
base.proto
imu.proto
gnss.proto
state.proto
chasis.proto
perception.proto
pointcloud.proto
image.proto
)

protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS
base.proto
imu.proto
gnss.proto
state.proto
chasis.proto
perception.proto
OPTION "namespace=inner_struct,converter_namespace=converter")

add_executable(struct_pb_tutorial tutorial.cpp zpointcloud.cpp zimage.cpp
${PROTO_SRCS}
${PROTO_HDRS}
${PROTO_STRUCT_SRCS}
${PROTO_STRUCT_HDRS}
${PROTO_PYTHON_SRCS}
)

target_link_libraries(struct_pb_tutorial protobuf::libprotobuf
pcl_common pcl_io # pcl
opencv_imgcodecs opencv_core # opencv
)

target_include_directories(struct_pb_tutorial PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}
${PCL_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)


if (Protobuf_FOUND)

# generate .pb.cc .pb.h
protobuf_generate_cpp(PROTO_SRCS
PROTO_HDRS
# addressbook.proto
proto_to_struct.proto
base.proto
imu.proto
gnss.proto
state.proto
chasis.proto
perception.proto
pointcloud.proto
image.proto
)

protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS
# addressbook.proto
base.proto
imu.proto
gnss.proto
state.proto
chasis.proto
perception.proto
# pointcloud.proto
OPTION "namespace=inner_struct,converter_namespace=converter")


add_executable(struct_pb_tutorial tutorial.cpp
${PROTO_SRCS}
${PROTO_HDRS}
${PROTO_STRUCT_SRCS}
${PROTO_STRUCT_HDRS}
)

target_link_libraries(struct_pb_tutorial protobuf::libprotobuf pcl_common)

target_include_directories(struct_pb_tutorial PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}
${PCL_INCLUDE_DIRS}
)



endif()
3 changes: 2 additions & 1 deletion src/example/cmake/struct_pb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function(protobuf_generate_modified)

add_custom_command(
OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc
#!!!!!!!!!!!!!!!!!!!! 设置环境变量并执行
COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}:${CMAKE_BINARY_DIR}/output/bin/" protoc
ARGS --${protobuf_generate_LANGUAGE}_out ${_opt}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
Expand Down
Loading

0 comments on commit a503513

Please sign in to comment.