diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f4bdb946..bc49e21c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,8 +43,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 ${CMAKE_SOURCE_DIR}) # 设置protoc --proto_path参数 + # add_subdirectory(src/protoc-plugin) diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 5752859a8..dd04f98c4 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -1,46 +1,35 @@ - # 设置编译器选项 +set(ENV{proto_message} "proto_message") + +# 设置编译器选项 add_compile_options(-Wno-attributes) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/examples) # protobuf_generate_struct_pb 函数 +set(struct_pb_plugin_DIRS ${CMAKE_SOURCE_DIR}/src/protoc-plugin) # struct_pb_plugin_DIRS 将指定 proto_to_struct.proto,struct_pb.cmake等目录 +set(Protobuf_IMPORT_DIRS ${CMAKE_SOURCE_DIR} ${struct_pb_plugin_DIRS} ${CMAKE_CURRENT_LIST_DIR}) # 设置protoc --proto_path参数 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") - -# 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 -) +file(GLOB PROTO_FILES "*.proto") # generate .pb.cc .pb.h protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS + ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} + # IMPORT_DIRS ${CMAKE_SOURCE_DIR} ) protobuf_generate_python(PROTO_PYTHON_SRCS + ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} + # IMPORT_DIRS ${CMAKE_SOURCE_DIR} ) -# 删除点云,图片proto记录文件 -list(FILTER PROTO_FILES EXCLUDE REGEX "pointcloud\\.proto$|image\\.proto$") -# message(status "-------${PROTO_FILES}-------") - - protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS ${PROTO_FILES} OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter" @@ -48,19 +37,17 @@ OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter" ) add_executable(struct_pb_tutorial tutorial.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 pcl_common pcl_io # pcl opencv_imgcodecs opencv_core # opencv + $ENV{proto_message} ) target_include_directories(struct_pb_tutorial PUBLIC @@ -72,4 +59,4 @@ target_include_directories(struct_pb_tutorial PUBLIC ${CMAKE_BINARY_DIR}/src/protoc-plugin ) - +add_subdirectory(message) diff --git a/src/example/base.proto b/src/example/base.proto index 8c202be7f..e654c9c8d 100644 --- a/src/example/base.proto +++ b/src/example/base.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package zhito.inner_class; -import "src/protoc-plugin/proto_to_struct.proto"; +import "proto_to_struct.proto"; option(write_eigen_helper) = true; message Vector4f diff --git a/src/example/message/CMakeLists.txt b/src/example/message/CMakeLists.txt new file mode 100644 index 000000000..e6fe8d014 --- /dev/null +++ b/src/example/message/CMakeLists.txt @@ -0,0 +1,52 @@ +file(GLOB PROTO_FILES "*.proto") + + +# generate .pb.cc .pb.h +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS + ${PROTO_FILES} + # IMPORT_DIRS ${CMAKE_SOURCE_DIR} +) + +protobuf_generate_python(PROTO_PYTHON_SRCS + ${PROTO_FILES} + # IMPORT_DIRS ${CMAKE_SOURCE_DIR} +) + +# 删除点云,图片proto记录文件 +list(FILTER PROTO_FILES EXCLUDE REGEX "pointcloud\\.proto$|image\\.proto$") +# message(status "-------${PROTO_FILES}-------") + + +protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS + ${PROTO_FILES} +OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter" +# PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} +) + +add_library($ENV{proto_message} OBJECT + # + zpointcloud.cpp zimage.cpp + ${PROTO_SRCS} + ${PROTO_HDRS} + ${PROTO_STRUCT_SRCS} + ${PROTO_STRUCT_HDRS} + # ${PROTO_PYTHON_SRCS} +) + +target_link_libraries($ENV{proto_message} protobuf::libprotobuf + pcl_common pcl_io # pcl + opencv_imgcodecs opencv_core # opencv +) + +target_include_directories($ENV{proto_message} PUBLIC + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/.. # 找到common + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/.. # 找到iguana + ${PCL_INCLUDE_DIRS} + ${OpenCV_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR}/src/protoc-plugin +) + + diff --git a/src/example/chasis.proto b/src/example/message/chasis.proto similarity index 82% rename from src/example/chasis.proto rename to src/example/message/chasis.proto index fb8e2d954..4d679d373 100644 --- a/src/example/chasis.proto +++ b/src/example/message/chasis.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZChassis { diff --git a/src/example/gnss.proto b/src/example/message/gnss.proto similarity index 88% rename from src/example/gnss.proto rename to src/example/message/gnss.proto index 0479ccb3f..cd17cd0af 100644 --- a/src/example/gnss.proto +++ b/src/example/message/gnss.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZGnss { diff --git a/src/example/image.proto b/src/example/message/image.proto similarity index 81% rename from src/example/image.proto rename to src/example/message/image.proto index f7a1d3d04..adead8242 100644 --- a/src/example/image.proto +++ b/src/example/message/image.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; +import "zframe.proto"; message ZImage { diff --git a/src/example/imu.proto b/src/example/message/imu.proto similarity index 82% rename from src/example/imu.proto rename to src/example/message/imu.proto index d81dea670..0f230aef1 100644 --- a/src/example/imu.proto +++ b/src/example/message/imu.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZImu { diff --git a/src/example/perception.proto b/src/example/message/perception.proto similarity index 93% rename from src/example/perception.proto rename to src/example/message/perception.proto index 09ef8170d..a0bc382de 100644 --- a/src/example/perception.proto +++ b/src/example/message/perception.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZPercBase { diff --git a/src/example/pointcloud.proto b/src/example/message/pointcloud.proto similarity index 73% rename from src/example/pointcloud.proto rename to src/example/message/pointcloud.proto index 68f03c673..1273596e6 100644 --- a/src/example/pointcloud.proto +++ b/src/example/message/pointcloud.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZPointCloudXYZIT { diff --git a/src/example/state.proto b/src/example/message/state.proto similarity index 93% rename from src/example/state.proto rename to src/example/message/state.proto index 454da1a15..308d1916f 100644 --- a/src/example/state.proto +++ b/src/example/message/state.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/zframe.proto"; -import "src/example/base.proto"; +import "zframe.proto"; +import "base.proto"; import "proto_to_struct.proto"; message ZState{ ZFrame header = 1 [(inherits_from) = true]; diff --git a/src/example/xyzit_points.hpp b/src/example/message/xyzit_points.hpp similarity index 100% rename from src/example/xyzit_points.hpp rename to src/example/message/xyzit_points.hpp diff --git a/src/example/zframe.proto b/src/example/message/zframe.proto similarity index 96% rename from src/example/zframe.proto rename to src/example/message/zframe.proto index c63692340..1bee861d9 100644 --- a/src/example/zframe.proto +++ b/src/example/message/zframe.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package zhito.inner_class; -import "src/example/base.proto"; -import "src/protoc-plugin/proto_to_struct.proto"; +import "base.proto"; +import "proto_to_struct.proto"; enum ZFrameType{ None = 0; VEHICLE_MODEL = 1; // 车辆运动约束虚拟帧 diff --git a/src/example/zimage.cpp b/src/example/message/zimage.cpp similarity index 100% rename from src/example/zimage.cpp rename to src/example/message/zimage.cpp diff --git a/src/example/zimage.hpp b/src/example/message/zimage.hpp similarity index 100% rename from src/example/zimage.hpp rename to src/example/message/zimage.hpp diff --git a/src/example/zpointcloud.cpp b/src/example/message/zpointcloud.cpp similarity index 100% rename from src/example/zpointcloud.cpp rename to src/example/message/zpointcloud.cpp diff --git a/src/example/zpointcloud.hpp b/src/example/message/zpointcloud.hpp similarity index 100% rename from src/example/zpointcloud.hpp rename to src/example/message/zpointcloud.hpp diff --git a/src/example/tutorial.cpp b/src/example/tutorial.cpp index 7dd7ed58d..c79cad233 100644 --- a/src/example/tutorial.cpp +++ b/src/example/tutorial.cpp @@ -4,9 +4,9 @@ #include // #include "addressbook.struct_pb.h" -// #include "imu.struct_pb.h" -// #include "zimage.hpp" -// #include "zpointcloud.hpp" +#include "src/example/message/imu.struct_pb.h" +// #include "src/message/zimage.hpp" +// #include "src/message/zpointcloud.hpp" // void PointcloudDemo() { // using namespace zhito; @@ -28,17 +28,17 @@ // 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; @@ -55,7 +55,7 @@ // } int main() { - // ImuDemo(); + ImuDemo(); // PointcloudDemo(); // ImageDemo();