summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-03 12:14:22 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-10-03 12:14:34 (GMT)
commit046625d26f8715bd8dc9ddd609a0d8436b810558 (patch)
tree99457aeec90ef45a8638f83b2b4748d2231c6270 /Modules
parent6b2aad04e84dabf59b534be4a9e6b88674492852 (diff)
parent1299f4cc5ee5a996b051f7767049e239092a65a0 (diff)
downloadCMake-046625d26f8715bd8dc9ddd609a0d8436b810558.zip
CMake-046625d26f8715bd8dc9ddd609a0d8436b810558.tar.gz
CMake-046625d26f8715bd8dc9ddd609a0d8436b810558.tar.bz2
Merge topic 'FindProtobuf-gen-desc'
1299f4cc FindProtobuf: add flag to allow descriptor files to be generated 4e91be95 FindProtobuf: Refactor custom command output listing Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1301
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindProtobuf.cmake44
1 files changed, 34 insertions, 10 deletions
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 90f7a2e..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)
@@ -168,22 +176,38 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
endif()
endif()
- list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
- list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
+ set(_protobuf_protoc_src "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
+ set(_protobuf_protoc_hdr "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
+ 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 "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
- "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
+ 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 )
endforeach()
- set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
- set(${SRCS} ${${SRCS}} PARENT_SCOPE)
- set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+ 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)