diff --git a/cmake/gz_msgs_generate.cmake b/cmake/gz_msgs_generate.cmake index 366ca11c..679b9cae 100644 --- a/cmake/gz_msgs_generate.cmake +++ b/cmake/gz_msgs_generate.cmake @@ -8,6 +8,7 @@ # FACTORY_GEN_SCRIPT - Location of the factory generator script # PROTO_PATH - Base directory of the proto files # DEPENDENCY_DESCRIPTIONS - .gz_desc files for each dependency +# DLLEXPORT_DECL - Visibilty macro to apply to messages # OUTPUT_DIRECTORY - CMake binary directoy to place generated artifacts # OUTPUT_SOURCES - Variable to contain list of generated source files # OUTPUT_HEADERS - Variable to contain list of generated header files @@ -21,6 +22,7 @@ function(gz_msgs_generate_messages_impl) # Inputs PROTO_PACKAGE MSGS_GEN_SCRIPT GZ_PROTOC_PLUGIN FACTORY_GEN_SCRIPT PROTO_PATH DEPENDENCY_DESCRIPTIONS + DLLEXPORT_DECL OUTPUT_DIRECTORY # Outputs OUTPUT_SOURCES @@ -57,6 +59,8 @@ function(gz_msgs_generate_messages_impl) # Cpp Specific arguments GENERATE_CPP + DLLEXPORT_DECL + ${generate_messages_DLLEXPORT_DECL} OUTPUT_CPP_HH_VAR ${generate_messages_OUTPUT_HEADERS} OUTPUT_DETAIL_CPP_HH_VAR diff --git a/cmake/gz_msgs_protoc.cmake b/cmake/gz_msgs_protoc.cmake index d929cf8b..077e266c 100644 --- a/cmake/gz_msgs_protoc.cmake +++ b/cmake/gz_msgs_protoc.cmake @@ -8,6 +8,7 @@ # 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 +# DLLEXPORT_DECL - DLL visibility macro (eg GZ_MSGS_VISIBLE) # INPUT_PROTO - Path to the input .proto file # OUTPUT_CPP_DIR - Path where C++ files are saved # OUTPUT_PYTON_DIR - Path where Python files are saved @@ -25,6 +26,7 @@ function(gz_msgs_protoc) PROTO_PACKAGE PROTOC_EXEC GZ_PROTOC_PLUGIN + DLLEXPORT_DECL INPUT_PROTO OUTPUT_CPP_DIR OUTPUT_CPP_HH_VAR @@ -96,6 +98,12 @@ function(gz_msgs_protoc) ) endif() + if(gz_msgs_protoc_DLLEXPORT_DECL) + list(APPEND GENERATE_ARGS + --dllexport-decl "${gz_msgs_protoc_DLLEXPORT_DECL}" + ) + endif() + if(${gz_msgs_protoc_GENERATE_CPP}) list(APPEND GENERATE_ARGS --generate-cpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3227d900..2bbe9114 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -35,6 +35,8 @@ gz_msgs_generate_messages_impl( $ INPUT_PROTOS ${proto_files} + DLLEXPORT_DECL + "GZ_MSGS_VISIBLE" PROTO_PACKAGE "gz.msgs" PROTO_PATH diff --git a/tools/gz_msgs_generate.py b/tools/gz_msgs_generate.py index 35f4e590..1805e2f3 100755 --- a/tools/gz_msgs_generate.py +++ b/tools/gz_msgs_generate.py @@ -57,6 +57,9 @@ def main(argv=sys.argv[1:]): '--dependency-proto-descs', nargs='*', help='The location of proto descriptor files these messages depend on') + parser.add_argument( + '--dllexport-decl', + help='The DLL visibility macro to use, if not set, no macro will be used') args = parser.parse_args(argv) # First generate the base cpp files @@ -71,7 +74,11 @@ def main(argv=sys.argv[1:]): if args.generate_cpp: cmd += [f'--plugin=protoc-gen-gzmsgs={args.gz_generator_bin}'] - cmd += [f'--cpp_out=dllexport_decl=GZ_MSGS_VISIBLE:{args.output_cpp_path}'] + if args.dllexport_decl: + cmd += [f'--cpp_out=dllexport_decl={args.dllexport_decl}:{args.output_cpp_path}'] + else: + cmd += [f'--cpp_out={args.output_cpp_path}'] + cmd += [f'--gzmsgs_out={args.output_cpp_path}'] if args.generate_python: cmd += [f'--python_out={args.output_python_path}']