cmake: Add parameter PROTOC_OUT_DIR to protobuf_generate

parent e8ae76fb
...@@ -11,7 +11,7 @@ function(protobuf_generate) ...@@ -11,7 +11,7 @@ function(protobuf_generate)
include(CMakeParseArguments) include(CMakeParseArguments)
set(_options APPEND_PATH) set(_options APPEND_PATH)
set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO) set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR)
if(COMMAND target_sources) if(COMMAND target_sources)
list(APPEND _singleargs TARGET) list(APPEND _singleargs TARGET)
endif() endif()
...@@ -34,6 +34,10 @@ function(protobuf_generate) ...@@ -34,6 +34,10 @@ function(protobuf_generate)
endif() endif()
string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE) string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE)
if(NOT protobuf_generate_PROTOC_OUT_DIR)
set(protobuf_generate_PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp)
set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:") set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:")
endif() endif()
...@@ -92,14 +96,14 @@ function(protobuf_generate) ...@@ -92,14 +96,14 @@ function(protobuf_generate)
set(_generated_srcs) set(_generated_srcs)
foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS}) foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS})
list(APPEND _generated_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_ext}") list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_basename}${_ext}")
endforeach() endforeach()
list(APPEND _generated_srcs_all ${_generated_srcs}) list(APPEND _generated_srcs_all ${_generated_srcs})
add_custom_command( add_custom_command(
OUTPUT ${_generated_srcs} OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc COMMAND protobuf::protoc
ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${_abs_file} ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${ABS_FIL} protobuf::protoc DEPENDS ${ABS_FIL} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}" COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
VERBATIM ) VERBATIM )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment