Skip to content
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

Support setting (or unsetting) dllexport macros #379

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/gz_msgs_generate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cmake/gz_msgs_protoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ gz_msgs_generate_messages_impl(
$<TARGET_FILE:${PROJECT_NAME}_protoc_plugin>
INPUT_PROTOS
${proto_files}
DLLEXPORT_DECL
"GZ_MSGS_VISIBLE"
PROTO_PACKAGE
"gz.msgs"
PROTO_PATH
Expand Down
9 changes: 8 additions & 1 deletion tools/gz_msgs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}']
Expand Down