aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/protobuf.cmake
blob: 155caa144384b3be211850fc72165f7201aad0e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function(target_proto_plugin Tgt Name PluginTarget)
  set_property(TARGET ${Tgt} APPEND PROPERTY
    PROTOC_OPTS --${Name}_out=${CMAKE_BINARY_DIR} --plugin=protoc-gen-${Name}=$<TARGET_FILE:${PluginTarget}>
  )
  set_property(TARGET ${Tgt} APPEND PROPERTY
    PROTOC_DEPS ${PluginTarget}
  )
endfunction()

function(target_proto_messages Tgt Scope)
  get_property(ProtocExtraOutsSuf TARGET ${Tgt} PROPERTY PROTOC_EXTRA_OUTS)
  foreach(proto ${ARGN})
    file(RELATIVE_PATH protoRel ${CMAKE_SOURCE_DIR} ${proto})
    get_filename_component(OutputBase ${protoRel} NAME_WLE)
    get_filename_component(OutputDir ${CMAKE_BINARY_DIR}/${protoRel} DIRECTORY)
    list(TRANSFORM ProtocExtraOutsSuf PREPEND ${OutputDir}/${OutputBase} OUTPUT_VARIABLE ProtocExtraOuts)
    add_custom_command(
        OUTPUT
          ${OutputDir}/${OutputBase}.pb.cc
          ${OutputDir}/${OutputBase}.pb.h
          ${ProtocExtraOuts}
        COMMAND protoc
          ${COMMON_PROTOC_FLAGS}
          -I=${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
          --cpp_out=${CMAKE_BINARY_DIR}
          "$<JOIN:$<TARGET_GENEX_EVAL:${Tgt},$<TARGET_PROPERTY:${Tgt},PROTOC_OPTS>>,;>"
          ${protoRel}
        DEPENDS ${proto} $<TARGET_PROPERTY:${Tgt},PROTOC_DEPS>
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMAND_EXPAND_LISTS
    )
    target_sources(${Tgt} ${Scope}
      ${OutputDir}/${OutputBase}.pb.cc ${OutputDir}/${OutputBase}.pb.h
      ${ProtocExtraOuts}
    )
  endforeach()
endfunction()