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

[CMake] Allow custom plugin options e.g. to generate mocks #9105

Merged
merged 6 commits into from Feb 9, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions cmake/protobuf-config.cmake.in
Expand Up @@ -11,7 +11,7 @@ function(protobuf_generate)
include(CMakeParseArguments)

set(_options APPEND_PATH)
set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN)
set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS)
if(COMMAND target_sources)
list(APPEND _singleargs TARGET)
endif()
Expand Down Expand Up @@ -40,6 +40,8 @@ function(protobuf_generate)

if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp)
tiolan marked this conversation as resolved.
Show resolved Hide resolved
set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:")
else()
set(_plugin_options "${protobuf_generate_PLUGIN_OPTIONS}:")
endif()

if(protobuf_generate_PLUGIN)
Expand Down Expand Up @@ -127,12 +129,20 @@ function(protobuf_generate)
endforeach()
list(APPEND _generated_srcs_all ${_generated_srcs})

set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}")
if(protobuf_generate_PROTOC_OPTIONS)
set(_comment "${_comment}, Custom protoc options: ${protobuf_generate_PROTOC_OPTIONS}")
endif()
if(protobuf_generate_PLUGIN_OPTIONS)
set(_comment "${_comment}, Custom plugin options: ${protobuf_generate_PLUGIN_OPTIONS}")
endif()

add_custom_command(
OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}. Custom options: ${protobuf_generate_PROTOC_OPTIONS}"
COMMENT ${_comment}
VERBATIM )
endforeach()

Expand Down