diff options
Diffstat (limited to 'Modules/FindProtobuf.cmake')
-rw-r--r-- | Modules/FindProtobuf.cmake | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index c1444a1..7292aec 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -79,6 +79,7 @@ # include_directories(${CMAKE_CURRENT_BINARY_DIR}) # protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto) # protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto) +# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS DESCRIPTORS PROTO_DESCS foo.proto) # protobuf_generate_python(PROTO_PY foo.proto) # add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS}) # target_link_libraries(bar ${Protobuf_LIBRARIES}) @@ -92,12 +93,15 @@ # # Add custom commands to process ``.proto`` files to C++:: # -# protobuf_generate_cpp (<SRCS> <HDRS> [EXPORT_MACRO <MACRO>] [<ARGN>...]) +# protobuf_generate_cpp (<SRCS> <HDRS> +# [DESCRIPTORS <DESC>] [EXPORT_MACRO <MACRO>] [<ARGN>...]) # # ``SRCS`` # Variable to define with autogenerated source files # ``HDRS`` # Variable to define with autogenerated header files +# ``DESCRIPTORS`` +# Variable to define with auotgenerated descriptor files, if requested. # ``EXPORT_MACRO`` # is a macro which should expand to ``__declspec(dllexport)`` or # ``__declspec(dllimport)`` depending on what is being compiled. @@ -116,7 +120,7 @@ # ``.proto`` filess function(PROTOBUF_GENERATE_CPP SRCS HDRS) - cmake_parse_arguments(protobuf "" "EXPORT_MACRO" "" ${ARGN}) + cmake_parse_arguments(protobuf "" "EXPORT_MACRO;DESCRIPTORS" "" ${ARGN}) set(PROTO_FILES "${protobuf_UNPARSED_ARGUMENTS}") if(NOT PROTO_FILES) @@ -158,6 +162,10 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) set(${SRCS}) set(${HDRS}) + if (protobuf_DESCRIPTORS) + set(${protobuf_DESCRIPTORS}) + endif() + foreach(FIL ${PROTO_FILES}) get_filename_component(ABS_FIL ${FIL} ABSOLUTE) get_filename_component(FIL_WE ${FIL} NAME_WE) @@ -173,11 +181,23 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) list(APPEND ${SRCS} "${_protobuf_protoc_src}") list(APPEND ${HDRS} "${_protobuf_protoc_hdr}") + if(protobuf_DESCRIPTORS) + set(_protobuf_protoc_desc "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.desc") + set(_protobuf_protoc_flags "--descriptor_set_out=${_protobuf_protoc_desc}") + list(APPEND ${protobuf_DESCRIPTORS} "${_protobuf_protoc_desc}") + else() + set(_protobuf_protoc_desc "") + set(_protobuf_protoc_flags "") + endif() + add_custom_command( OUTPUT "${_protobuf_protoc_src}" "${_protobuf_protoc_hdr}" + ${_protobuf_protoc_desc} COMMAND protobuf::protoc - ARGS "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" ${_protobuf_include_path} ${ABS_FIL} + "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" + ${_protobuf_protoc_flags} + ${_protobuf_include_path} ${ABS_FIL} DEPENDS ${ABS_FIL} protobuf::protoc COMMENT "Running C++ protocol buffer compiler on ${FIL}" VERBATIM ) @@ -185,6 +205,9 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) set(${SRCS} "${${SRCS}}" PARENT_SCOPE) set(${HDRS} "${${HDRS}}" PARENT_SCOPE) + if(protobuf_DESCRIPTORS) + set(${protobuf_DESCRIPTORS} "${${protobuf_DESCRIPTORS}}" PARENT_SCOPE) + endif() endfunction() function(PROTOBUF_GENERATE_PYTHON SRCS) |