diff --git a/CMakeLists.txt b/CMakeLists.txt index 898c6ffbd..6f4bdb946 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() # 指定struct_pb库目录 set(struct_pb_plugin_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/protoc-plugin) # struct_pb_plugin_DIRS 将指定 proto_to_struct.proto,struct_pb.cmake等目录 -set(Protobuf_IMPORT_DIRS ${struct_pb_plugin_DIRS} ) # 设置protoc --proto_path参数 +set(Protobuf_IMPORT_DIRS ${CMAKE_SOURCE_DIR}) # 设置protoc --proto_path参数 # add_subdirectory(src/protoc-plugin) diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index d65735057..5752859a8 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -10,16 +10,29 @@ include(${struct_pb_plugin_DIRS}/cmake/struct_pb.cmake) find_package(PCL REQUIRED COMPONENTS common io) find_package(OpenCV REQUIRED COMPONENTS core) -file(GLOB PROTO_FILES "*.proto") +# file(GLOB PROTO_FILES "*.proto") + +# set(PROTO_FILES "base.proto" "zframe.proto" "imu.proto") +set(PROTO_FILES "/home/gsk/pro/yalantinglibs/src/example/base.proto" "/home/gsk/pro/yalantinglibs/src/example/zframe.proto") + + +# 输出到指定目录 +message(!!!!!!"${CMAKE_BINARY_DIR}"!!!!!!!) +protobuf_generate_cpp(COMMON_PROTO_SRCS COMMON_PROTO_HDRS + ${struct_pb_plugin_DIRS}/proto_to_struct.proto + PROTOC_OUT_DIR ${CMAKE_BINARY_DIR}/src/protoc-plugin +) +protobuf_generate_python(COMMON_PROTO_PYTHON_SRCS + ${struct_pb_plugin_DIRS}/proto_to_struct.proto + PROTOC_OUT_DIR ${CMAKE_BINARY_DIR}/src/protoc-plugin +) # generate .pb.cc .pb.h protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS - ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} ) protobuf_generate_python(PROTO_PYTHON_SRCS - ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} ) @@ -30,15 +43,19 @@ list(FILTER PROTO_FILES EXCLUDE REGEX "pointcloud\\.proto$|image\\.proto$") protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS ${PROTO_FILES} -OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter") +OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter" +# PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} +) add_executable(struct_pb_tutorial tutorial.cpp - zpointcloud.cpp zimage.cpp + # + ${COMMON_PROTO_SRCS} ${COMMON_PROTO_HDRS} ${COMMON_PROTO_PYTHON_SRCS} + # zpointcloud.cpp zimage.cpp ${PROTO_SRCS} ${PROTO_HDRS} ${PROTO_STRUCT_SRCS} ${PROTO_STRUCT_HDRS} - ${PROTO_PYTHON_SRCS} + # ${PROTO_PYTHON_SRCS} ) target_link_libraries(struct_pb_tutorial protobuf::libprotobuf @@ -52,6 +69,7 @@ target_include_directories(struct_pb_tutorial PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${PCL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR}/src/protoc-plugin ) diff --git a/src/example/base.proto b/src/example/base.proto index 9cb70824b..8c202be7f 100644 --- a/src/example/base.proto +++ b/src/example/base.proto @@ -1,8 +1,7 @@ syntax = "proto3"; package zhito.inner_class; -import "proto_to_struct.proto"; - +import "src/protoc-plugin/proto_to_struct.proto"; option(write_eigen_helper) = true; message Vector4f diff --git a/src/example/chasis.proto b/src/example/chasis.proto index b6e43ffa7..fb8e2d954 100644 --- a/src/example/chasis.proto +++ b/src/example/chasis.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZChassis { ZFrame header = 1 [(inherits_from) = true]; diff --git a/src/example/gnss.proto b/src/example/gnss.proto index b8af39d83..0479ccb3f 100644 --- a/src/example/gnss.proto +++ b/src/example/gnss.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZGnss { ZFrame header = 1 [(inherits_from) = true];; diff --git a/src/example/image.proto b/src/example/image.proto index adead8242..f7a1d3d04 100644 --- a/src/example/image.proto +++ b/src/example/image.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; +import "src/example/zframe.proto"; message ZImage { diff --git a/src/example/imu.proto b/src/example/imu.proto index 0c7f9d64b..d81dea670 100644 --- a/src/example/imu.proto +++ b/src/example/imu.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZImu { ZFrame header = 1 [(inherits_from) = true]; diff --git a/src/example/perception.proto b/src/example/perception.proto index 8301c1fce..09ef8170d 100644 --- a/src/example/perception.proto +++ b/src/example/perception.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZPercBase { int32 track_id = 1; diff --git a/src/example/pointcloud.proto b/src/example/pointcloud.proto index 8f310f39e..68f03c673 100644 --- a/src/example/pointcloud.proto +++ b/src/example/pointcloud.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZPointCloudXYZIT { ZFrame header = 1 ; diff --git a/src/example/state.proto b/src/example/state.proto index f874f7b73..454da1a15 100644 --- a/src/example/state.proto +++ b/src/example/state.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package zhito.inner_class; -import "zframe.proto"; -import "base.proto"; +import "src/example/zframe.proto"; +import "src/example/base.proto"; import "proto_to_struct.proto"; - message ZState{ ZFrame header = 1 [(inherits_from) = true]; Vector3d pos = 2;//位置: X Y Z diff --git a/src/example/tutorial.cpp b/src/example/tutorial.cpp index 1e58c9e24..7dd7ed58d 100644 --- a/src/example/tutorial.cpp +++ b/src/example/tutorial.cpp @@ -4,60 +4,60 @@ #include // #include "addressbook.struct_pb.h" -#include "imu.struct_pb.h" -#include "zimage.hpp" -#include "zpointcloud.hpp" +// #include "imu.struct_pb.h" +// #include "zimage.hpp" +// #include "zpointcloud.hpp" -void PointcloudDemo() { - using namespace zhito; - pcl::PointXYZIT p2{1, 2}; +// void PointcloudDemo() { +// using namespace zhito; +// pcl::PointXYZIT p2{1, 2}; - inner_struct::spZPointCloudXYZIT pc = std::make_shared(); - *(std::shared_ptr)pc = - inner_struct::ZFrame{1, 2, 3, inner_struct::ZFrameType::PointCloud, "/zhito/pointcloud"}; - for (int i = 0; i < 1e5; ++i) { - p2.x += (rand() % 10000 * 0.0001); - pc->push_back(p2); - } +// inner_struct::spZPointCloudXYZIT pc = std::make_shared(); +// *(std::shared_ptr)pc = +// inner_struct::ZFrame{1, 2, 3, inner_struct::ZFrameType::PointCloud, "/zhito/pointcloud"}; +// for (int i = 0; i < 1e5; ++i) { +// p2.x += (rand() % 10000 * 0.0001); +// pc->push_back(p2); +// } - inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc); - inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2); +// inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc); +// inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2); - // pcl::io::savePCDFileBinaryCompressed("1.pcd", *pc3); +// // pcl::io::savePCDFileBinaryCompressed("1.pcd", *pc3); - std::cout << *pc3 << std::endl; -} +// std::cout << *pc3 << std::endl; +// } -void ImuDemo() { - using namespace zhito; +// void ImuDemo() { +// using namespace zhito; - inner_struct::ZImu imu1{1, 2, 3, inner_struct::ZFrameType::IMU, "channel_name", {4, 5, 6}, {7, 8, 9}, 10}; - inner_class::ZImu imu2 = converter::StructToClass(imu1); - inner_struct::ZImu imu3 = converter::ClassToStruct(imu2); +// inner_struct::ZImu imu1{1, 2, 3, inner_struct::ZFrameType::IMU, "channel_name", {4, 5, 6}, {7, 8, 9}, 10}; +// inner_class::ZImu imu2 = converter::StructToClass(imu1); +// inner_struct::ZImu imu3 = converter::ClassToStruct(imu2); - std::cout << imu1 << std::endl; - std::cout << imu2.ShortDebugString() << std::endl; - std::cout << imu3 << std::endl; -} +// std::cout << imu1 << std::endl; +// std::cout << imu2.ShortDebugString() << std::endl; +// std::cout << imu3 << std::endl; +// } -void ImageDemo() { - using namespace zhito; +// void ImageDemo() { +// using namespace zhito; - inner_struct::ZImage image1{1, 2, 3, inner_struct::ZFrameType::CvImage, "/zhito/image"}; - (cv::Mat&)image1 = cv::Mat::eye(4, 4, CV_64F); +// inner_struct::ZImage image1{1, 2, 3, inner_struct::ZFrameType::CvImage, "/zhito/image"}; +// (cv::Mat&)image1 = cv::Mat::eye(4, 4, CV_64F); - inner_class::ZImage image2 = converter::StructToClass(image1); - inner_struct::ZImage image3 = converter::ClassToStruct(image2); +// inner_class::ZImage image2 = converter::StructToClass(image1); +// inner_struct::ZImage image3 = converter::ClassToStruct(image2); - std::cout << image1 << std::endl; - std::cout << image2.ShortDebugString() << std::endl; - std::cout << image3 << std::endl; -} +// std::cout << image1 << std::endl; +// std::cout << image2.ShortDebugString() << std::endl; +// std::cout << image3 << std::endl; +// } int main() { // ImuDemo(); // PointcloudDemo(); - ImageDemo(); + // ImageDemo(); std::cout << "Done!!!" << std::endl; diff --git a/src/example/zframe.proto b/src/example/zframe.proto index 830b8a254..c63692340 100644 --- a/src/example/zframe.proto +++ b/src/example/zframe.proto @@ -1,9 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "base.proto"; -import "proto_to_struct.proto"; - +import "src/example/base.proto"; +import "src/protoc-plugin/proto_to_struct.proto"; enum ZFrameType{ None = 0; VEHICLE_MODEL = 1; // 车辆运动约束虚拟帧 diff --git a/src/protoc-plugin/cmake/struct_pb.cmake b/src/protoc-plugin/cmake/struct_pb.cmake index 3c24182ef..52c7c14be 100644 --- a/src/protoc-plugin/cmake/struct_pb.cmake +++ b/src/protoc-plugin/cmake/struct_pb.cmake @@ -119,7 +119,7 @@ function(protobuf_generate_modified) # message(status _out!!!!!!!!${protobuf_generate_LANGUAGE}_out}) - # message(status _opt!!!!!!!!${_opt}${protobuf_generate_PROTOC_OUT_DIR}) + message(status _opt!!!!!!!!${_opt}${protobuf_generate_PROTOC_OUT_DIR}) add_custom_command( diff --git a/src/struct_pb/examples/addressbook.proto b/src/struct_pb/examples/addressbook.proto index fc658387e..87ae727e0 100644 --- a/src/struct_pb/examples/addressbook.proto +++ b/src/struct_pb/examples/addressbook.proto @@ -2,7 +2,6 @@ syntax = "proto3"; import "proto_to_struct.proto"; - package tutorial; enum MyType {