Skip to content

Commit

Permalink
feat: move proto compile part to aruku interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
marfanr committed Nov 6, 2023
1 parent 56bfc40 commit 534f0c2
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)

find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

set(_GRPC_GRPCPP gRPC::grpc++)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)

# Proto file
get_filename_component(aruku_proto "./proto/aruku.proto" ABSOLUTE)
get_filename_component(aruku_proto_path "${aruku_proto}" PATH)

# Generated sources
add_custom_command(
OUTPUT "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.cc}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.grpc.pb.h}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${aruku_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${aruku_proto}"
DEPENDS "${aruku_proto}")

add_library(aruku_proto
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.cc}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.grpc.pb.h})

target_link_libraries(aruku_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Point2.msg"
"msg/SetConfig.msg"
Expand All @@ -25,4 +66,20 @@ rosidl_generate_interfaces(${PROJECT_NAME}
"srv/SaveConfig.srv")

ament_export_dependencies(rosidl_default_runtime)
ament_export_targets(aruku_proto HAS_LIBRARY_TARGET)

install (
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DESTINATION include
)

install (
TARGETS aruku_proto
EXPORT aruku_proto
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_package()

0 comments on commit 534f0c2

Please sign in to comment.