├── .gitignore ├── package.xml ├── unused_parameter_warnings_wire_format.patch ├── README.md ├── CMakeLists.txt ├── unused_parameter_warnings.patch └── cmake └── protobuf-generate-cpp.cmake.in /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | 23 | # Bloom. 24 | debian 25 | obj* 26 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | protobuf_catkin 3 | 3.0.0 4 | protobuf_catkin 5 | Simon Lynen 6 | 7 | See package 8 | 9 | catkin 10 | catkin_simple 11 | 12 | 13 | grpc 14 | 15 | -------------------------------------------------------------------------------- /unused_parameter_warnings_wire_format.patch: -------------------------------------------------------------------------------- 1 | From 9079079ec0dac15700400a8c86b12595e9524901 Mon Sep 17 00:00:00 2001 2 | From: Aurimas Liutikas 3 | Date: Fri, 10 Feb 2017 16:23:49 -0800 4 | Subject: [PATCH] Fix compiler warnings about unused variables in wire_format.h 5 | 6 | --- 7 | src/google/protobuf/wire_format.h | 3 +++ 8 | 1 file changed, 3 insertions(+) 9 | 10 | diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h 11 | index 67afc77..5e9aca5 100644 12 | --- src/google/protobuf/wire_format.h 13 | +++ src/google/protobuf/wire_format.h 14 | @@ -326,5 +326,8 @@ inline void WireFormat::VerifyUTF8StringNamedField( 15 | #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED 16 | WireFormat::VerifyUTF8StringFallback(data, size, op, field_name); 17 | +#else 18 | + // Avoid the compiler warning about unused variables. 19 | + (void)data; (void)size; (void)op; (void)field_name; 20 | #endif 21 | } 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | protobuf_catkin 2 | =============== 3 | 4 | A catkin wrapper for Google protocol buffers 5 | 6 | ## Usage 7 | In your `CMakeLists.txt`, call the protobuf compiler: 8 | 9 | ```cmake 10 | set(PROTO_DEFNS proto/path-to-my-protos/my-proto.proto) 11 | set(BASE_PATH "proto") 12 | PROTOBUF_CATKIN_GENERATE_CPP2(${BASE_PATH} PROTO_SRCS PROTO_HDRS ${PROTO_DEFNS}) 13 | 14 | ... 15 | 16 | cs_add_library(${PROJECT_NAME} src/my-source-files.cc 17 | ${PROTO_SRCS} 18 | ${PROTO_HDRS}) 19 | ``` 20 | where `BASE_PATH` is the base path to the folder containing all protobuf definitions (in this example, the base path is `proto`). 21 | 22 | This will generate C++ codes for the protos given by `PROTO_DEFNS`. 23 | The C++ files will be generated under `catkin_wsbuild/${PROJECT_NAME}/compiled_proto`. 24 | The structure within this folder mirrors the structure of the source definitions (within `BASE_PATH`). 25 | 26 | From the compiled C++ files, the generated headers (`*.pb.h`) are installed into `catkin_ws/devel/include`, again keeping the folder structure from within `BASE_PATH`. 27 | The `*.proto` definition files are installed into `catkin_ws/devel/share/proto` so that they can be used by other packages. 28 | 29 | The example code above would generate the following files: 30 | - `catkin_ws/build/${PROJECT_NAME}/compiled_proto/path-to-my-protos/my-proto.pb.cc` 31 | - `catkin_ws/build/${PROJECT_NAME}/compiled_proto/path-to-my-protos/my-proto.pb.h` 32 | - `catkin_ws/devel/include/path-to-my-protos/my-proto.pb.h` 33 | - `catkin_ws/devel/share/proto/path-to-my-protos/my-proto.pb.h` 34 | 35 | The protobuf definitions can then be used with `#include 3 | Date: Fri, 31 Oct 2014 16:27:55 -0700 4 | Subject: [PATCH 1/2] Fixed Unused Parameter warning in headers. 5 | 6 | --- 7 | src/google/protobuf/descriptor.h | 10 +++++----- 8 | src/google/protobuf/message.h | 12 ++++++------ 9 | src/google/protobuf/repeated_field.h | 3 ++- 10 | 3 files changed, 13 insertions(+), 12 deletions(-) 11 | 12 | diff --git src/google/protobuf/descriptor.h src/google/protobuf/descriptor.h 13 | index 67afc77..68013f8 100644 14 | --- src/google/protobuf/descriptor.h 15 | +++ src/google/protobuf/descriptor.h 16 | @@ -1280,11 +1280,11 @@ class LIBPROTOBUF_EXPORT DescriptorPool { 17 | // Reports a warning in the FileDescriptorProto. Use this function if the 18 | // problem occured should NOT interrupt building the FileDescriptorProto. 19 | virtual void AddWarning( 20 | - const string& filename, // File name in which the error occurred. 21 | - const string& element_name, // Full name of the erroneous element. 22 | - const Message* descriptor, // Descriptor of the erroneous element. 23 | - ErrorLocation location, // One of the location constants, above. 24 | - const string& message // Human-readable error message. 25 | + const string& /*filename*/, // File name in which the error occurred. 26 | + const string& /*element_name*/, // Full name of the erroneous element. 27 | + const Message* /*descriptor*/, // Descriptor of the erroneous element. 28 | + ErrorLocation /*location*/, // One of the location constants, above. 29 | + const string& /*message*/ // Human-readable error message. 30 | ) {} 31 | 32 | private: 33 | diff --git src/google/protobuf/message.h src/google/protobuf/message.h 34 | index 9593560..67d4549 100644 35 | --- src/google/protobuf/message.h 36 | +++ src/google/protobuf/message.h 37 | @@ -389,19 +389,19 @@ class LIBPROTOBUF_EXPORT Reflection { 38 | // is set, false otherwise. 39 | // TODO(jieluo) - make it pure virtual after updating all 40 | // the subclasses. 41 | - virtual bool HasOneof(const Message& message, 42 | - const OneofDescriptor* oneof_descriptor) const { 43 | + virtual bool HasOneof(const Message& /*message*/, 44 | + const OneofDescriptor* /*oneof_descriptor*/) const { 45 | return false; 46 | } 47 | 48 | - virtual void ClearOneof(Message* message, 49 | - const OneofDescriptor* oneof_descriptor) const {} 50 | + virtual void ClearOneof(Message* /*message*/, 51 | + const OneofDescriptor* /*oneof_descriptor*/) const {} 52 | 53 | // Returns the field descriptor if the oneof is set. NULL otherwise. 54 | // TODO(jieluo) - make it pure virtual. 55 | virtual const FieldDescriptor* GetOneofFieldDescriptor( 56 | - const Message& message, 57 | - const OneofDescriptor* oneof_descriptor) const { 58 | + const Message& /*message*/, 59 | + const OneofDescriptor* /*oneof_descriptor*/) const { 60 | return NULL; 61 | } 62 | 63 | diff --git src/google/protobuf/repeated_field.h src/google/protobuf/repeated_field.h 64 | index 5005183..816ea68 100644 65 | --- src/google/protobuf/repeated_field.h 66 | +++ src/google/protobuf/repeated_field.h 67 | @@ -83,7 +83,8 @@ inline int CalculateReserve(Iter begin, Iter end, std::forward_iterator_tag) { 68 | } 69 | 70 | template 71 | -inline int CalculateReserve(Iter begin, Iter end, std::input_iterator_tag) { 72 | +inline int CalculateReserve(Iter /*begin*/, Iter /*end*/, 73 | + std::input_iterator_tag) { 74 | return -1; 75 | } 76 | 77 | 78 | From ec71d5d31946f48c3b7adafa65dadcdbf47702c3 Mon Sep 17 00:00:00 2001 79 | From: Austin Schuh 80 | Date: Fri, 31 Oct 2014 19:15:54 -0700 81 | Subject: [PATCH 2/2] Fixed Unused Parameter warning in compiler headers. 82 | 83 | --- 84 | src/google/protobuf/compiler/cpp/cpp_field.h | 11 ++++++----- 85 | 1 file changed, 6 insertions(+), 5 deletions(-) 86 | 87 | diff --git src/google/protobuf/compiler/cpp/cpp_field.h src/google/protobuf/compiler/cpp/cpp_field.h 88 | index 96c2963..0342c35 100644 89 | --- src/google/protobuf/compiler/cpp/cpp_field.h 90 | +++ src/google/protobuf/compiler/cpp/cpp_field.h 91 | @@ -77,7 +77,7 @@ class FieldGenerator { 92 | // Generate static default variable for this field. These are placed inside 93 | // the message class. Most field types don't need this, so the default 94 | // implementation is empty. 95 | - virtual void GenerateStaticMembers(io::Printer* printer) const {} 96 | + virtual void GenerateStaticMembers(io::Printer* /*printer*/) const {} 97 | 98 | // Generate prototypes for all of the accessor functions related to this 99 | // field. These are placed inside the class definition. 100 | @@ -92,7 +92,7 @@ class FieldGenerator { 101 | // placed somewhere in the .cc file. 102 | // Most field types don't need this, so the default implementation is empty. 103 | virtual void GenerateNonInlineAccessorDefinitions( 104 | - io::Printer* printer) const {} 105 | + io::Printer* /*printer*/) const {} 106 | 107 | // Generate lines of code (statements, not declarations) which clear the 108 | // field. This is used to define the clear_$name$() method as well as 109 | @@ -122,14 +122,15 @@ class FieldGenerator { 110 | // Generate any code that needs to go in the class's SharedDtor() method, 111 | // invoked by the destructor. 112 | // Most field types don't need this, so the default implementation is empty. 113 | - virtual void GenerateDestructorCode(io::Printer* printer) const {} 114 | + virtual void GenerateDestructorCode(io::Printer* /*printer*/) const {} 115 | 116 | // Generate code that allocates the fields's default instance. 117 | - virtual void GenerateDefaultInstanceAllocator(io::Printer* printer) const {} 118 | + virtual void GenerateDefaultInstanceAllocator(io::Printer* /*printer*/) 119 | + const {} 120 | 121 | // Generate code that should be run when ShutdownProtobufLibrary() is called, 122 | // to delete all dynamically-allocated objects. 123 | - virtual void GenerateShutdownCode(io::Printer* printer) const {} 124 | + virtual void GenerateShutdownCode(io::Printer* /*printer*/) const {} 125 | 126 | // Generate lines to decode this field, which will be placed inside the 127 | // message's MergeFromCodedStream() method. 128 | -------------------------------------------------------------------------------- /cmake/protobuf-generate-cpp.cmake.in: -------------------------------------------------------------------------------- 1 | # Adapted by Helen Oleynikova from Simon Lynen's version. 2 | #============================================================================= 3 | # Copyright 2009 Kitware, Inc. 4 | # Copyright 2009-2011 Philip Lowman 5 | # Copyright 2008 Esben Mose Hansen, Ange Optimization ApS 6 | # 7 | # Distributed under the OSI-approved BSD License (the "License"); 8 | # see accompanying file Copyright.txt for details. 9 | # 10 | # This software is distributed WITHOUT ANY WARRANTY; without even the 11 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | # See the License for more information. 13 | #============================================================================= 14 | # (To distribute this file outside of CMake, substitute the full 15 | # License text for the above reference.) 16 | 17 | # Copy the preferred protoc excutable. 18 | set(PREFERRED_PROTOC_EXECUTABLE "@PREFERRED_PROTOC_EXECUTABLE@") 19 | message(STATUS "Preferred Protoc Executable: ${PREFERRED_PROTOC_EXECUTABLE}") 20 | 21 | function(_find_protobuf_compiler) 22 | # get first directory that points into devel space of protobuf catkin workspace 23 | list (GET protobuf_catkin_INCLUDE_DIRS 0 first_protobuf_catkin_include_dir) 24 | 25 | set(PROTOBUF_COMPILER_CANDIDATES 26 | "${PREFERRED_PROTOC_EXECUTABLE}" # Set by preferences and exported. 27 | "${PROTOBUF_PROTOC_EXECUTABLE}" # This will be "/usr/bin/protoc" on Ubuntu if find_package succeeded. 28 | "${CATKIN_DEVEL_PREFIX}/bin/protoc" # only works from same workspace 29 | # (DEVEL_PREFIX evaluates to workspace that is built, 30 | # not workspace where protobuf_catkin is) 31 | "/opt/ros/$ENV{ROS_DISTRO}/bin/protoc" 32 | "${first_protobuf_catkin_include_dir}/../bin/protoc" # if protoc is needed from another merged workspace, 33 | # use path that leads to package workspace 34 | ) 35 | 36 | foreach(candidate ${PROTOBUF_COMPILER_CANDIDATES}) 37 | if(EXISTS ${candidate}) 38 | message(STATUS "Found protobuf compiler: ${candidate}") 39 | set(PROTOBUF_COMPILER ${candidate} PARENT_SCOPE) 40 | return() 41 | endif() 42 | endforeach() 43 | message(FATAL_ERROR "Couldn't find protobuf compiler. Please ensure that protobuf_catkin is properly installed. Checked the following paths: ${PROTOBUF_COMPILER_CANDIDATES}") 44 | endfunction() 45 | 46 | # Legacy function for backwards compatibility. 47 | function(PROTOBUF_CATKIN_GENERATE_CPP SRCS HDRS) 48 | message(WARNING "PROTOBUF_CATKIN_GENERATE_CPP is deprecated. Please use PROTOBUF_CATKIN_GENERATE_CPP2 instead. Check the Readme for details.") 49 | 50 | if(NOT ARGN) 51 | message(SEND_ERROR "Error: PROTOBUF_CATKIN_GENERATE_CPP() called without any proto files") 52 | return() 53 | endif(NOT ARGN) 54 | 55 | if(PROTOBUF_GENERATE_CPP_APPEND_PATH) 56 | # Create an include path for each file specified 57 | foreach(FIL ${ARGN}) 58 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 59 | get_filename_component(ABS_PATH ${ABS_FIL} PATH) 60 | list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) 61 | if(${_contains_already} EQUAL -1) 62 | list(APPEND _protobuf_include_path -I ${ABS_PATH}) 63 | endif() 64 | endforeach() 65 | else() 66 | set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) 67 | endif() 68 | 69 | # Add custom protobuf include directories 70 | if(PROTOBUF_EXPORT_PATH) 71 | foreach(PBEP ${PROTOBUF_EXPORT_PATH}) 72 | list(APPEND _protobuf_include_path -I ${PBEP}) 73 | endforeach() 74 | endif() 75 | 76 | set(${SRCS}) 77 | set(${HDRS}) 78 | _find_protobuf_compiler() 79 | foreach(FIL ${ARGN}) 80 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 81 | get_filename_component(FIL_WE ${FIL} NAME_WE) 82 | 83 | list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") 84 | list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") 85 | 86 | add_custom_command( 87 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" 88 | "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" 89 | COMMAND "${PROTOBUF_COMPILER}" 90 | ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} 91 | DEPENDS ${ABS_FIL} 92 | COMMENT "Running C++ protocol buffer compiler on ${FIL}" 93 | VERBATIM ) 94 | endforeach() 95 | 96 | set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) 97 | set(${SRCS} ${${SRCS}} PARENT_SCOPE) 98 | set(${HDRS} ${${HDRS}} PARENT_SCOPE) 99 | install(FILES ${${HDRS}} 100 | DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}) 101 | endfunction() 102 | 103 | function(PROTOBUF_CATKIN_GENERATE_CPP2 BASE_PATH SRCS HDRS) 104 | if(NOT ARGN) 105 | message(SEND_ERROR "Error: PROTOBUF_CATKIN_GENERATE_CPP2() called without any proto files") 106 | return() 107 | endif(NOT ARGN) 108 | 109 | list(APPEND _protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}/${BASE_PATH}) 110 | 111 | set(${SRCS}) 112 | set(${HDRS}) 113 | 114 | # Folder where the proto sources are generated in. This should resolve to 115 | # "build/project_name/compiled_proto". 116 | set(COMPILED_PROTO_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/compiled_proto") 117 | file(MAKE_DIRECTORY ${COMPILED_PROTO_FOLDER}) 118 | 119 | # Folder where the generated headers are installed to. This should resolve to 120 | # "devel/include". 121 | set(PROTO_GENERATED_HEADERS_INSTALL_DIR 122 | ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}) 123 | file(MAKE_DIRECTORY ${PROTO_GENERATED_HEADERS_INSTALL_DIR}) 124 | 125 | # Folder where the proto files are placed, so that they can be used in other 126 | # proto definitions. This should resolve to "devel/share/proto". 127 | set(PROTO_SHARE_SUB_FOLDER "proto") 128 | set(PROTO_FILE_INSTALL_DIR 129 | ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_SHARE_DESTINATION}/${PROTO_SHARE_SUB_FOLDER}) 130 | file(MAKE_DIRECTORY ${PROTO_FILE_INSTALL_DIR}) 131 | 132 | set(include_candidates 133 | "/usr/include" 134 | "${PROTO_FILE_INSTALL_DIR}" 135 | "${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_SHARE_DESTINATION}/${PROTO_SHARE_SUB_FOLDER}" 136 | "/opt/ros/$ENV{ROS_DISTRO}/${CATKIN_GLOBAL_SHARE_DESTINATION}/${PROTO_SHARE_SUB_FOLDER}" 137 | "/opt/ros/$ENV{ROS_DISTRO}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/grpc/" 138 | ) 139 | foreach(include_candidate ${include_candidates}) 140 | if(EXISTS "${include_candidate}") 141 | list(APPEND _protobuf_include_path "-I" ${include_candidate}) 142 | endif() 143 | endforeach() 144 | 145 | set(PYTHON_PROTOC_ARG_VALUE "") 146 | set(PYTHON_PROTOC_ARG_FLAGS "") 147 | set(PROTOC_PYTHON_COMMENT "") 148 | if(${PROTOBUF_COMPILE_PYTHON}) 149 | # Setting the protoc arguments to include compilation of Python files. 150 | set(PYTHON_PROTOC_ARG_FLAG "--python_out") 151 | set(PYTHON_PROTOC_ARG_VALUE ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION}) 152 | set(PROTOC_PYTHON_COMMENT " and Python") 153 | endif() 154 | set(GRPC_PROTOC_ARG_FLAG "") 155 | set(GRPC_PROTOC_ARG_VALUE "") 156 | set(GRPC_PROTOC_PLUGIN_FLAG "") 157 | set(GRPC_PROTOC_DEP "") 158 | set(GRPC_PROTOC_COMMENT "") 159 | if (${PROTOBUF_COMPILE_GRPC}) 160 | set(GRPC_PROTOC_ARG_FLAG "--grpc_out") 161 | set(GRPC_PROTOC_ARG_VALUE ${COMPILED_PROTO_FOLDER}) 162 | set(GRPC_PROTOC_PLUGIN_FLAG "--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN_GLOBAL}") 163 | set(GRPC_PROTOC_COMMENT " and GRPC") 164 | endif() 165 | 166 | _find_protobuf_compiler() 167 | foreach(FIL ${ARGN}) 168 | get_filename_component(ABS_FIL ${FIL} ABSOLUTE) 169 | get_filename_component(FIL_WE ${FIL} NAME_WE) 170 | get_filename_component(FIL_REL_DIR ${FIL} DIRECTORY) 171 | 172 | # FIL_REL_DIR contains the path to the proto file, starting inside 173 | # BASE_PATH. E.g., for base path "proto" and file 174 | # "proto/project/definitions.proto", FIL_REL_DIR would be "project". 175 | string(REGEX REPLACE "${BASE_PATH}/?" "" FIL_REL_DIR ${FIL_REL_DIR}) 176 | 177 | # Variable for the protobuf share folder (e.g., ../devel/share/proto/project-name) 178 | set(PROTO_SHARE_FOLDER ${PROTO_FILE_INSTALL_DIR}/${FIL_REL_DIR}) 179 | file(MAKE_DIRECTORY ${PROTO_SHARE_FOLDER}) 180 | 181 | # The protoc output folder for C++ .h/.cc files. 182 | set(OUTPUT_FOLDER ${COMPILED_PROTO_FOLDER}/${FIL_REL_DIR}) 183 | set(OUTPUT_FOLDER_BASE ${COMPILED_PROTO_FOLDER}) 184 | file(MAKE_DIRECTORY ${OUTPUT_FOLDER}) 185 | file(MAKE_DIRECTORY "${PROTO_GENERATED_HEADERS_INSTALL_DIR}/${FIL_REL_DIR}") 186 | set(OUTPUT_BASE_FILE_NAME "${OUTPUT_FOLDER}/${FIL_WE}") 187 | 188 | list(APPEND ${SRCS} "${OUTPUT_BASE_FILE_NAME}.pb.cc") 189 | list(APPEND ${HDRS} "${OUTPUT_BASE_FILE_NAME}.pb.h") 190 | 191 | add_custom_command( 192 | OUTPUT "${OUTPUT_BASE_FILE_NAME}.pb.cc" 193 | "${OUTPUT_BASE_FILE_NAME}.pb.h" 194 | "${PROTO_GENERATED_HEADERS_INSTALL_DIR}/${FIL_WE}.pb.h" 195 | "${PROTO_SHARE_FOLDER}/${FIL_WE}.proto" 196 | COMMAND "${PROTOBUF_COMPILER}" 197 | ARGS --cpp_out ${OUTPUT_FOLDER_BASE} ${PYTHON_PROTOC_ARG_FLAG} ${PYTHON_PROTOC_ARG_VALUE} ${GRPC_PROTOC_ARG_FLAG} ${GRPC_PROTOC_ARG_VALUE} ${GRPC_PROTOC_PLUGIN_FLAG} ${_protobuf_include_path} ${ABS_FIL} 198 | COMMAND ${CMAKE_COMMAND} -E copy 199 | "${OUTPUT_BASE_FILE_NAME}.pb.h" 200 | "${PROTO_GENERATED_HEADERS_INSTALL_DIR}/${FIL_REL_DIR}/${FIL_WE}.pb.h" 201 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 202 | ${ABS_FIL} 203 | "${PROTO_SHARE_FOLDER}/${FIL_WE}.proto" 204 | DEPENDS ${ABS_FIL} 205 | COMMENT "Running C++${PYTHON_PROTOC_COMMENT}${GRPC_PROTOC_COMMENT} protocol buffer compiler on ${FIL}." 206 | VERBATIM) 207 | install( 208 | FILES ${ABS_FIL} 209 | DESTINATION ${CATKIN_GLOBAL_SHARE_DESTINATION}/${PROTO_SHARE_SUB_FOLDER}/${FIL_REL_DIR} 210 | ) 211 | 212 | # Copy over the GRPC stuff as well. 213 | if (${PROTOBUF_COMPILE_GRPC}) 214 | add_custom_command( 215 | OUTPUT "${OUTPUT_BASE_FILE_NAME}.grpc.pb.cc" 216 | "${OUTPUT_BASE_FILE_NAME}.grpc.pb.h" 217 | "${PROTO_GENERATED_HEADERS_INSTALL_DIR}/{FIL_REL_DIR}/${FIL_WE}.grpc.pb.h" 218 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 219 | "${OUTPUT_BASE_FILE_NAME}.grpc.pb.h" 220 | "${PROTO_GENERATED_HEADERS_INSTALL_DIR}/${FIL_REL_DIR}/${FIL_WE}.grpc.pb.h" 221 | DEPENDS ${ABS_FIL} "${OUTPUT_BASE_FILE_NAME}.pb.h" 222 | COMMENT "Copying over GRPC artifacts on ${FIL}." 223 | VERBATIM) 224 | list(APPEND ${SRCS} "${OUTPUT_BASE_FILE_NAME}.grpc.pb.cc") 225 | list(APPEND ${HDRS} "${OUTPUT_BASE_FILE_NAME}.grpc.pb.h") 226 | endif() 227 | endforeach() 228 | 229 | set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) 230 | set(${SRCS} ${${SRCS}} PARENT_SCOPE) 231 | set(${HDRS} ${${HDRS}} PARENT_SCOPE) 232 | 233 | include_directories(${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}) 234 | install(FILES ${${HDRS}} 235 | DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${FIL_REL_DIR}) 236 | 237 | if(${PROTOBUF_COMPILE_PYTHON}) 238 | # The path of the Python package under devel/lib/python../dist-packages/{project_name}. 239 | set(PYTHON_PACKAGE_PATH ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}) 240 | file(MAKE_DIRECTORY ${PYTHON_PACKAGE_PATH}) 241 | # The filepath of the Python package init file. 242 | set(PYTHON_INIT_FILEPATH "${PYTHON_PACKAGE_PATH}/__init__.py") 243 | if(NOT EXISTS ${PYTHON_INIT_FILEPATH}) 244 | add_custom_target(create_empty_init ALL 245 | COMMAND ${CMAKE_COMMAND} -E touch ${PYTHON_INIT_FILEPATH} 246 | COMMENT "Created empty __init__.py." 247 | VERBATIM) 248 | endif() 249 | install(DIRECTORY ${PYTHON_PACKAGE_PATH} 250 | DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}) 251 | endif() 252 | 253 | endfunction() 254 | # 255 | # Main. 256 | # 257 | 258 | 259 | # By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc 260 | # for each directory where a proto file is referenced. 261 | if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) 262 | set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) 263 | endif() 264 | 265 | # Ensure that devel/include is part of the include directories. This is 266 | # necessary as otherwise sometimes that folder is not added to the include dirs 267 | # which means that the compiler cannot find the generated proto header from 268 | # other packages. 269 | include_directories(${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}) 270 | --------------------------------------------------------------------------------