-
Notifications
You must be signed in to change notification settings - Fork 57
Generate messages in downstream builds #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
1c2b31a
Create "core" directory
887d1e9
Remove "filesystem"
12ceb1e
Split message factory into static and non-static parts
bf8ce61
Add cmake functions
14eb585
Move everything that depends on message definitions to "compiled"
1b10efa
Exercise the compiled pipeline
922ef93
Generate messages in "compiled" package
c98833f
Implement header-only conversion functions
03bf781
Fix tool installation
6b90cfd
Fix CMake
71de7f2
Lint
945285b
Address reviewer feedback
4b066b9
Fix typos
558eaf1
Add examples
078e8ed
Add READMEs for the examples
2d8ab98
Fix tests
08eddae
Update copyright year
d215951
Update usage
6d3c94e
Add explicit message generation dependencies
51b6b49
Update migration guide
e4de3b6
Fix factory test
ee7eb4f
Add functional header
4453cf4
Grammar
e35843c
Update examples/generating_custom_msgs/main.cc
e5df01b
Windows compat
edb9d05
Fix Windows visibility
2ff4edf
Also link messages to test
0428d8d
Fix compiler warnings
6e9c02f
Fix Windows build
ee80d3c
Fix path separator on Windows
c7f393a
Add migration note about ruby
3ccce92
Update CMake documentation
7cf741a
Refactor common string operations into functions
263bf11
Style nit
9dfab82
Document target_link_messages
1684866
Lint
85c8ea6
Restore const char* setter
60200f3
Change to array rather than map
48810d9
Windows typo
9e4ea2a
Fix visibility logic
6c55def
Remove conflicting visibility
82331b3
Completely remove visibility from target_link_messages
f0fda37
Drop template from conversions
a3e0182
Address reviewer feedback
52f7e12
Change to implptr
a775cb5
Update core/generator/Generator.cc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| ################################################## | ||
| # A function that generates factory methods for generated gz-msgs | ||
| # The output of this is are a header and source file that can be used as part of your library | ||
| # for the gz::msgs::Factory | ||
| # Options: | ||
| # One value arguments: | ||
| # FACTORY_GEN_SCRIPT - Location of the factory generator script | ||
| # PROTO_PACKAGE - Protobuf package the file belongs to (e.g. "gz.msgs") | ||
| # PROTOC_EXEC - Path to protoc | ||
| # OUTPUT_CPP_DIR - Path where C++ files are saved | ||
| # OUTPUT_CPP_HH_VAR - A CMake variable name containing a list that the C++ headers should be appended to | ||
| # OUTPUT_CPP_CC_VAR - A Cmake variable name containing a list that the C++ sources should be appended to | ||
| # Multi value arguments | ||
| # INPUT_PROTOS - List of input proto files | ||
| # PROTO_PATH - Base directory of the proto files | ||
| function(gz_msgs_factory) | ||
| set(options "") | ||
| set(oneValueArgs | ||
| FACTORY_GEN_SCRIPT | ||
| PROTO_PACKAGE | ||
| OUTPUT_CPP_DIR | ||
| OUTPUT_CPP_HH_VAR | ||
| OUTPUT_CPP_CC_VAR) | ||
| set(multiValueArgs INPUT_PROTOS PROTO_PATH) | ||
|
|
||
| cmake_parse_arguments(gz_msgs_factory "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
|
||
| _gz_msgs_proto_pkg_to_path(${gz_msgs_factory_PROTO_PACKAGE} proto_package_dir) | ||
|
|
||
| set(output_header "${gz_msgs_factory_OUTPUT_CPP_DIR}/${proto_package_dir}/MessageTypes.hh") | ||
| set(output_source "${gz_msgs_factory_OUTPUT_CPP_DIR}/${proto_package_dir}/register.cc") | ||
|
|
||
| list(APPEND ${gz_msgs_factory_OUTPUT_CPP_HH_VAR} ${output_header}) | ||
| list(APPEND ${gz_msgs_factory_OUTPUT_CPP_CC_VAR} ${output_source}) | ||
|
|
||
| list(APPEND output_files ${output_header}) | ||
| list(APPEND output_files ${output_source}) | ||
|
|
||
| set(${gz_msgs_factory_OUTPUT_CPP_HH_VAR} ${${gz_msgs_factory_OUTPUT_CPP_HH_VAR}} PARENT_SCOPE) | ||
| set(${gz_msgs_factory_OUTPUT_CPP_CC_VAR} ${${gz_msgs_factory_OUTPUT_CPP_CC_VAR}} PARENT_SCOPE) | ||
|
|
||
| set(depends_index) | ||
| # Full path to an index file, which contains all defined message types for that proto file | ||
| foreach(proto_file ${gz_msgs_factory_INPUT_PROTOS}) | ||
| # Get a unique path (gz.msgs.foo -> gz_msgs_foo) for naming the index | ||
| _gz_msgs_proto_to_unique(${proto_file} ${gz_msgs_factory_PROTO_PACKAGE} UNIQUE_NAME) | ||
| set(input_index "${gz_msgs_factory_OUTPUT_CPP_DIR}/${UNIQUE_NAME}.pb_index") | ||
| list(APPEND depends_index ${input_index}) | ||
| endforeach() | ||
|
|
||
| set(GENERATE_ARGS | ||
| --output-cpp-path "${gz_msgs_factory_OUTPUT_CPP_DIR}" | ||
| --proto-package "${gz_msgs_factory_PROTO_PACKAGE}" | ||
| --proto-path "${gz_msgs_factory_PROTO_PATH}" | ||
| --protos "${gz_msgs_factory_INPUT_PROTOS}" | ||
| ) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${output_files} | ||
| COMMAND Python3::Interpreter | ||
| ARGS ${gz_msgs_factory_FACTORY_GEN_SCRIPT} ${GENERATE_ARGS} | ||
| DEPENDS | ||
| ${depends_index} | ||
| # While the script is executed in the source directory, it does not write | ||
| # to the source tree. All outputs are stored in the build directory. | ||
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
| COMMENT "Running factory generator" | ||
| VERBATIM | ||
| ) | ||
|
|
||
| endfunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| ################################################## | ||
| # The implementation of gz_msgs_generate_messages | ||
| # Options: | ||
| # One value arguments: | ||
| # MSGS_GEN_SCRIPT - Location of the messge generator script | ||
| # FACTORY_GEN_SCRIPT - Location of the factory generator script | ||
| # GZ_PROTOC_PLUGIN - Location of the gazebo generator plugin | ||
| # PROTO_PATH - Base directory of the proto files | ||
| # PROTO_PACKAGE - Protobuf package the file belongs to (e.g. "gz.msgs") | ||
| # MSGS_LIB - gz-msgs library to link to | ||
| # TARGET - Target (static library) to create | ||
| # Multi value arguments | ||
| # INPUT_PROTOS - List of input proto files | ||
mjcarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # DEPENDENCIES - List of generated messages targets that these messages depend on | ||
| # Primarily used when generating new custom messages downstream | ||
| # that depend on gz-msgs | ||
| function(gz_msgs_generate_messages_impl) | ||
| set(options "") | ||
| set(oneValueArgs TARGET PROTO_PACKAGE MSGS_GEN_SCRIPT GZ_PROTOC_PLUGIN FACTORY_GEN_SCRIPT MSGS_LIB PROTO_PATH) | ||
| set(multiValueArgs INPUT_PROTOS DEPENDENCIES) | ||
|
|
||
| cmake_parse_arguments(generate_messages "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
| _gz_msgs_proto_pkg_to_string(${generate_messages_PROTO_PACKAGE} gen_dir) | ||
|
|
||
| # Extract dependency information from targets | ||
| set(depends_proto_paths) | ||
| set(depends_includes) | ||
|
|
||
| foreach(dep ${generate_messages_DEPENDENCIES}) | ||
| get_target_property(dep_proto_path ${dep} PROTO_DIR) | ||
| get_target_property(dep_proto_include_path ${dep} PROTO_INCLUDE_DIR) | ||
|
|
||
| list(APPEND depends_proto_paths ${dep_proto_path}) | ||
| list(APPEND depends_includes ${dep_proto_include_path}) | ||
| endforeach() | ||
|
|
||
| foreach(proto_file ${generate_messages_INPUT_PROTOS}) | ||
| gz_msgs_protoc( | ||
| MSGS_GEN_SCRIPT | ||
| ${generate_messages_MSGS_GEN_SCRIPT} | ||
| PROTO_PACKAGE | ||
| ${generate_messages_PROTO_PACKAGE} | ||
| GENERATE_CPP | ||
| INPUT_PROTO | ||
| ${proto_file} | ||
| PROTOC_EXEC | ||
| protobuf::protoc | ||
| GZ_PROTOC_PLUGIN | ||
| ${generate_messages_GZ_PROTOC_PLUGIN} | ||
| OUTPUT_CPP_DIR | ||
| "${PROJECT_BINARY_DIR}/${gen_dir}_gen" | ||
| OUTPUT_INCLUDES | ||
| gen_includes | ||
| OUTPUT_CPP_HH_VAR | ||
| gen_headers | ||
| OUTPUT_DETAIL_CPP_HH_VAR | ||
| gen_detail_headers | ||
| OUTPUT_CPP_CC_VAR | ||
| gen_sources | ||
| PROTO_PATH | ||
| ${generate_messages_PROTO_PATH} | ||
| DEPENDENCY_PROTO_PATHS | ||
| ${depends_proto_paths} | ||
| ) | ||
| endforeach() | ||
|
|
||
| gz_msgs_factory( | ||
| FACTORY_GEN_SCRIPT | ||
| ${generate_messages_FACTORY_GEN_SCRIPT} | ||
| PROTO_PACKAGE | ||
| ${generate_messages_PROTO_PACKAGE} | ||
| INPUT_PROTOS | ||
| ${generate_messages_INPUT_PROTOS} | ||
| OUTPUT_CPP_DIR | ||
| "${PROJECT_BINARY_DIR}/${gen_dir}_gen" | ||
| OUTPUT_CPP_HH_VAR | ||
| gen_factory_headers | ||
| OUTPUT_CPP_CC_VAR | ||
| gen_factory_sources | ||
| PROTO_PATH | ||
| ${generate_messages_PROTO_PATH} | ||
| ) | ||
|
|
||
| set_source_files_properties( | ||
| ${gen_headers} | ||
| ${gen_detail_headers} | ||
| ${gen_sources} | ||
| ${gen_factory_headers} | ||
| ${gen_factory_sources} | ||
| PROPERTIES GENERATED TRUE) | ||
|
|
||
| if(WIN32) | ||
| set_source_files_properties(${gen_sources} | ||
| COMPILE_FLAGS "/wd4100 /wd4512 /wd4127 /wd4068 /wd4244 /wd4267 /wd4251 /wd4146") | ||
| endif() | ||
|
|
||
| if(NOT MSVC) | ||
| # -Wno-switch-default flags is required for suppressing a warning in some of | ||
| # the generated protobuf files. | ||
| set_source_files_properties(${gen_sources} COMPILE_FLAGS "-Wno-switch-default -Wno-float-equal") | ||
| endif() | ||
|
|
||
| add_library(${generate_messages_TARGET} STATIC ${gen_sources} ${gen_factory_sources}) | ||
|
|
||
| # Use position indepedent code (-fPIC), because this library may be linked | ||
| # into a shared library by the consumer | ||
| set_property(TARGET ${generate_messages_TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
mjcarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Export the messages path and dependency messages paths for potential dependent message libs | ||
| set(PROTO_DIR) | ||
| list(APPEND PROTO_DIR ${generate_messages_PROTO_PATH}) | ||
| list(APPEND PROTO_DIR ${depends_proto_paths}) | ||
|
|
||
| set(PROTO_INCLUDE_DIR) | ||
| list(APPEND PROTO_INCLUDE_DIR ${PROJECT_BINARY_DIR}/${gen_dir}_gen) | ||
| list(APPEND PROTO_INCLUDE_DIR ${depends_includes}) | ||
|
|
||
| set_target_properties(${generate_messages_TARGET} PROPERTIES PROTO_DIR "${PROTO_DIR}") | ||
| set_target_properties(${generate_messages_TARGET} PROPERTIES PROTO_INCLUDE_DIR "${PROTO_INCLUDE_DIR}") | ||
|
|
||
| foreach(dep ${generate_messages_DEPENDENCIES}) | ||
| add_dependencies(${generate_messages_TARGET} ${dep}) | ||
| endforeach() | ||
|
|
||
| target_link_libraries(${generate_messages_TARGET} PUBLIC protobuf::libprotobuf ${generate_messages_MSGS_LIB}) | ||
| target_include_directories(${generate_messages_TARGET} PUBLIC ${PROJECT_BINARY_DIR}/${gen_dir}_gen ${depends_includes}) | ||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| ################################################## | ||
| # A function that calls protoc on a protobuf file | ||
| # Options: | ||
| # GENERATE_CPP - generates c++ code for the message if specified | ||
| # One value arguments: | ||
| # MSGS_GEN_SCRIPT - Path to the message generation python script | ||
| # PROTO_PACKAGE - Protobuf package the file belongs to (e.g. "gz.msgs") | ||
| # PROTOC_EXEC - Path to protoc | ||
| # GZ_PROTOC_PLUGIN - Path to the gazebo-specific protobuf compiler executable | ||
| # INPUT_PROTO - Path to the input .proto file | ||
| # OUTPUT_CPP_DIR - Path where C++ files are saved | ||
| # OUTPUT_INCLUDES - A CMake variable name containing a list that the C++ header path should be appended to | ||
| # OUTPUT_CPP_HH_VAR - A CMake variable name containing a list generated headers should be appended to | ||
| # OUTPUT_DETAIL_CPP_HH_VAR - A CMake variable name containing a list that the C++ detail headers should be appended to | ||
| # OUTPUT_CPP_CC_VAR - A Cmake variable name containing a list that the C++ source files should be appended to | ||
| # Multi value arguments | ||
| # PROTO_PATH - Passed to protoc --proto_path | ||
| # DEPENDENCY_PROTO_PATHS - Passed to protoc --proto_path | ||
| function(gz_msgs_protoc) | ||
| set(options GENERATE_CPP) | ||
| set(oneValueArgs | ||
| MSGS_GEN_SCRIPT | ||
| PROTO_PACKAGE | ||
| PROTOC_EXEC | ||
| GZ_PROTOC_PLUGIN | ||
| INPUT_PROTO | ||
| OUTPUT_CPP_DIR | ||
| OUTPUT_INCLUDES | ||
| OUTPUT_CPP_HH_VAR | ||
| OUTPUT_DETAIL_CPP_HH_VAR | ||
| OUTPUT_CPP_CC_VAR) | ||
| set(multiValueArgs PROTO_PATH DEPENDENCY_PROTO_PATHS) | ||
|
|
||
| cmake_parse_arguments(gz_msgs_protoc "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
|
||
| get_filename_component(ABS_FIL ${gz_msgs_protoc_INPUT_PROTO} ABSOLUTE) | ||
| get_filename_component(FIL_WE ${gz_msgs_protoc_INPUT_PROTO} NAME_WE) | ||
|
|
||
| set(protoc_args) | ||
| set(output_files) | ||
|
|
||
| _gz_msgs_proto_pkg_to_path(${gz_msgs_protoc_PROTO_PACKAGE} proto_package_dir) | ||
|
|
||
| if(gz_msgs_protoc_GENERATE_CPP) | ||
| # Full path to gazeob-specific header (${PROJECT_BINARY_DIR}/include/gz/msgs/foo.pb.h) | ||
| set(output_header "${gz_msgs_protoc_OUTPUT_CPP_DIR}/${proto_package_dir}/${FIL_WE}.pb.h") | ||
| # Full path to generated protobuf header (${PROJECT_BINARY_DIR}/include/gz/msgs/details/foo.pb.h) | ||
| set(output_detail_header "${gz_msgs_protoc_OUTPUT_CPP_DIR}/${proto_package_dir}/details/${FIL_WE}.pb.h") | ||
| # Full path to generated protobuf source (${PROJECT_BINARY_DIR}/include/foo.pb.cc) | ||
| set(output_source "${gz_msgs_protoc_OUTPUT_CPP_DIR}/${proto_package_dir}/${FIL_WE}.pb.cc") | ||
|
|
||
| _gz_msgs_proto_to_unique(${gz_msgs_protoc_INPUT_PROTO} ${gz_msgs_protoc_PROTO_PACKAGE} UNIQUE_NAME) | ||
|
|
||
| # Full path to an index file, which contains all defined message types for that proto file | ||
| set(output_index "${gz_msgs_protoc_OUTPUT_CPP_DIR}/${UNIQUE_NAME}.pb_index") | ||
|
|
||
| # Generate a clean relative path (gz/msgs/foo.pb.h) | ||
| string(REPLACE "${PROJECT_BINARY_DIR}/include/" "" output_include ${output_header}) | ||
| list(APPEND ${gz_msgs_protoc_OUTPUT_INCLUDES} "${output_include}") | ||
|
|
||
| list(APPEND ${gz_msgs_protoc_OUTPUT_CPP_HH_VAR} ${output_header}) | ||
| list(APPEND ${gz_msgs_protoc_OUTPUT_CPP_CC_VAR} ${output_source}) | ||
| list(APPEND ${gz_msgs_protoc_OUTPUT_DETAIL_CPP_HH_VAR} ${output_detail_header}) | ||
|
|
||
| list(APPEND output_files ${output_header}) | ||
| list(APPEND output_files ${output_detail_header}) | ||
| list(APPEND output_files ${output_source}) | ||
| list(APPEND output_files ${output_index}) | ||
|
|
||
| set(${gz_msgs_protoc_OUTPUT_INCLUDES} ${${gz_msgs_protoc_OUTPUT_INCLUDES}} PARENT_SCOPE) | ||
| set(${gz_msgs_protoc_OUTPUT_DETAIL_CPP_HH_VAR} ${${gz_msgs_protoc_OUTPUT_DETAIL_CPP_HH_VAR}} PARENT_SCOPE) | ||
| set(${gz_msgs_protoc_OUTPUT_CPP_HH_VAR} ${${gz_msgs_protoc_OUTPUT_CPP_HH_VAR}} PARENT_SCOPE) | ||
| set(${gz_msgs_protoc_OUTPUT_CPP_CC_VAR} ${${gz_msgs_protoc_OUTPUT_CPP_CC_VAR}} PARENT_SCOPE) | ||
| endif() | ||
|
|
||
| set(GENERATE_ARGS | ||
| --protoc-exec "$<TARGET_FILE:${gz_msgs_protoc_PROTOC_EXEC}>" | ||
| --gz-generator-bin "${gz_msgs_protoc_GZ_PROTOC_PLUGIN}" | ||
| --proto-path "${gz_msgs_protoc_PROTO_PATH}" | ||
| --input-path "${ABS_FIL}" | ||
| ) | ||
|
|
||
| if(gz_msgs_protoc_DEPENDENCY_PROTO_PATHS) | ||
| list(APPEND GENERATE_ARGS | ||
| --dependency-proto-paths "${gz_msgs_protoc_DEPENDENCY_PROTO_PATHS}" | ||
| ) | ||
| endif() | ||
|
|
||
| if(${gz_msgs_protoc_GENERATE_CPP}) | ||
| list(APPEND GENERATE_ARGS | ||
| --generate-cpp | ||
| --output-cpp-path "${gz_msgs_protoc_OUTPUT_CPP_DIR}") | ||
| endif() | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${output_files} | ||
| COMMAND Python3::Interpreter | ||
| ARGS ${gz_msgs_protoc_MSGS_GEN_SCRIPT} ${GENERATE_ARGS} | ||
| DEPENDS | ||
| ${ABS_FIL} | ||
| # While the script is executed in the source directory, it does not write | ||
| # to the source tree. All outputs are stored in the build directory. | ||
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
| COMMENT "Running protoc on ${gz_msgs_protoc_INPUT_PROTO}" | ||
| VERBATIM | ||
| ) | ||
|
|
||
| endfunction() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.