Răsfoiți Sursa

cmake: Add parameter PROTOC_OUT_DIR to protobuf_generate

Christian von Arnim 7 ani în urmă
părinte
comite
b9c0c5f526
1 a modificat fișierele cu 7 adăugiri și 3 ștergeri
  1. 7 3
      cmake/protobuf-config.cmake.in

+ 7 - 3
cmake/protobuf-config.cmake.in

@@ -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)
   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)
 
 
     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 )