mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-12 09:08:58 -05:00
FindProtobuf: add optional export declaration macro to generated cpp files
This commit is contained in:
committed by
Brad King
parent
56f87f179a
commit
1ee2019239
@@ -0,0 +1,6 @@
|
|||||||
|
FindProtobuf-export-macro
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
* The :module:`FindProtobuf` module :command:`protobuf_generate_cpp`
|
||||||
|
command gained an ``EXPORT_MACRO`` option to specify the name of
|
||||||
|
a DLL export markup macro.
|
||||||
@@ -76,6 +76,7 @@
|
|||||||
# include_directories(${Protobuf_INCLUDE_DIRS})
|
# include_directories(${Protobuf_INCLUDE_DIRS})
|
||||||
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
|
# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
|
||||||
|
# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto)
|
||||||
# protobuf_generate_python(PROTO_PY foo.proto)
|
# protobuf_generate_python(PROTO_PY foo.proto)
|
||||||
# add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
|
# add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
|
||||||
# target_link_libraries(bar ${Protobuf_LIBRARIES})
|
# target_link_libraries(bar ${Protobuf_LIBRARIES})
|
||||||
@@ -89,12 +90,15 @@
|
|||||||
#
|
#
|
||||||
# Add custom commands to process ``.proto`` files to C++::
|
# Add custom commands to process ``.proto`` files to C++::
|
||||||
#
|
#
|
||||||
# protobuf_generate_cpp (<SRCS> <HDRS> [<ARGN>...])
|
# protobuf_generate_cpp (<SRCS> <HDRS> [EXPORT_MACRO <MACRO>] [<ARGN>...])
|
||||||
#
|
#
|
||||||
# ``SRCS``
|
# ``SRCS``
|
||||||
# Variable to define with autogenerated source files
|
# Variable to define with autogenerated source files
|
||||||
# ``HDRS``
|
# ``HDRS``
|
||||||
# Variable to define with autogenerated header files
|
# Variable to define with autogenerated header files
|
||||||
|
# ``EXPORT_MACRO``
|
||||||
|
# is a macro which should expand to ``__declspec(dllexport)`` or
|
||||||
|
# ``__declspec(dllimport)`` depending on what is being compiled.
|
||||||
# ``ARGN``
|
# ``ARGN``
|
||||||
# ``.proto`` files
|
# ``.proto`` files
|
||||||
#
|
#
|
||||||
@@ -110,14 +114,21 @@
|
|||||||
# ``.proto`` filess
|
# ``.proto`` filess
|
||||||
|
|
||||||
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
||||||
if(NOT ARGN)
|
cmake_parse_arguments(protobuf "" "EXPORT_MACRO" "" ${ARGN})
|
||||||
|
|
||||||
|
set(PROTO_FILES "${protobuf_UNPARSED_ARGUMENTS}")
|
||||||
|
if(NOT PROTO_FILES)
|
||||||
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
|
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(protobuf_EXPORT_MACRO)
|
||||||
|
set(DLL_EXPORT_DECL "dllexport_decl=${protobuf_EXPORT_MACRO}:")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
||||||
# Create an include path for each file specified
|
# Create an include path for each file specified
|
||||||
foreach(FIL ${ARGN})
|
foreach(FIL ${PROTO_FILES})
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
|
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
|
||||||
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
|
||||||
@@ -145,7 +156,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
|||||||
|
|
||||||
set(${SRCS})
|
set(${SRCS})
|
||||||
set(${HDRS})
|
set(${HDRS})
|
||||||
foreach(FIL ${ARGN})
|
foreach(FIL ${PROTO_FILES})
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||||
if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
||||||
@@ -162,7 +173,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
|||||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||||
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
|
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
|
||||||
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
|
ARGS "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" ${_protobuf_include_path} ${ABS_FIL}
|
||||||
DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
|
DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
|
||||||
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
||||||
VERBATIM )
|
VERBATIM )
|
||||||
|
|||||||
Reference in New Issue
Block a user