diff options
author | Peter Mitrano <mitranopeter@gmail.com> | 2017-09-21 13:23:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-10-02 12:08:24 (GMT) |
commit | 1299f4cc5ee5a996b051f7767049e239092a65a0 (patch) | |
tree | d3c873f8ec327bc1d094c668a8debb555712ba8f /Modules/FindProtobuf.cmake | |
parent | 4e91be95323fa869a82ea59e733a706a5fd3867b (diff) | |
download | CMake-1299f4cc5ee5a996b051f7767049e239092a65a0.zip CMake-1299f4cc5ee5a996b051f7767049e239092a65a0.tar.gz CMake-1299f4cc5ee5a996b051f7767049e239092a65a0.tar.bz2 |
FindProtobuf: add flag to allow descriptor files to be generated
- The .desc files will be in the same folder as the generated .cc and .h files.
- Paths to generate .desc files are stored in a variable passed in
- This is only implemented for C++
- Remove legacy ARGS
- Add test that generates and uses C++ protobuf message
- Add test that checks that the generated .desc file can be instantiated
with DynamicMessageFactory
- Add Help rst for new feature
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) |