protobuf-function.cmake
Go to the documentation of this file.
2  include(CMakeParseArguments)
3 
4  set(_options APPEND_PATH)
5  set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO)
6  if(COMMAND target_sources)
7  list(APPEND _singleargs TARGET)
8  endif()
9  set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS)
10 
11  cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}")
12 
13  if(NOT protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET)
14  message(SEND_ERROR "Error: protobuf_generate called without any targets or source files")
15  return()
16  endif()
17 
18  if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET)
19  message(SEND_ERROR "Error: protobuf_generate called without a target or output variable")
20  return()
21  endif()
22 
23  if(NOT protobuf_generate_LANGUAGE)
24  set(protobuf_generate_LANGUAGE cpp)
25  endif()
26  string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE)
27 
28  if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp)
29  set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:")
30  endif()
31 
32  if(NOT protobuf_GENERATE_EXTENSIONS)
33  if(protobuf_generate_LANGUAGE STREQUAL cpp)
34  set(protobuf_GENERATE_EXTENSIONS .pb.h .pb.cc)
35  elseif(protobuf_generate_LANGUAGE STREQUAL python)
36  set(protobuf_GENERATE_EXTENSIONS _pb2.py)
37  else()
38  message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS")
39  return()
40  endif()
41  endif()
42 
43  if(protobuf_generate_TARGET)
44  get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES)
45  foreach(_file ${_source_list})
46  if(_file MATCHES "proto$")
47  list(APPEND protobuf_generate_PROTOS ${_file})
48  endif()
49  endforeach()
50  endif()
51 
52  if(NOT protobuf_generate_PROTOS)
53  message(SEND_ERROR "Error: protobuf_generate could not find any .proto files")
54  return()
55  endif()
56 
57  if(protobuf_generate_APPEND_PATH)
58  # Create an include path for each file specified
59  foreach(_file ${protobuf_generate_PROTOS})
60  get_filename_component(_abs_file ${_file} ABSOLUTE)
61  get_filename_component(_abs_path ${_abs_file} PATH)
62  list(FIND _protobuf_include_path ${_abs_path} _contains_already)
63  if(${_contains_already} EQUAL -1)
64  list(APPEND _protobuf_include_path -I ${_abs_path})
65  endif()
66  endforeach()
67  else()
68  set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
69  endif()
70 
71  foreach(DIR ${protobuf_generate_IMPORT_DIRS})
72  get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
73  list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
74  if(${_contains_already} EQUAL -1)
75  list(APPEND _protobuf_include_path -I ${ABS_PATH})
76  endif()
77  endforeach()
78 
79  set(_generated_srcs_all)
80  foreach(_proto ${protobuf_generate_PROTOS})
81  get_filename_component(_abs_file ${_proto} ABSOLUTE)
82  get_filename_component(_basename ${_proto} NAME_WE)
83 
84  set(_generated_srcs)
85  foreach(_ext ${protobuf_GENERATE_EXTENSIONS})
86  list(APPEND _generated_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_ext}")
87  endforeach()
88  list(APPEND _generated_srcs_all ${_generated_srcs})
89 
90  add_custom_command(
91  OUTPUT ${_generated_srcs}
92  COMMAND $<TARGET_FILE:ParaView::protoc>
93  ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${_abs_file}
94  DEPENDS ${_abs_file} ParaView::protoc
95  COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
96  VERBATIM )
97  endforeach()
98 
99  set_source_files_properties(${_generated_srcs_all} PROPERTIES GENERATED TRUE)
100  if(protobuf_generate_OUT_VAR)
101  set(${protobuf_generate_OUT_VAR} ${_generated_srcs_all} PARENT_SCOPE)
102  endif()
103  if(protobuf_generate_TARGET)
104  target_sources(${protobuf_generate_TARGET} PRIVATE ${_generated_srcs_all})
105  endif()
106 
107 endfunction()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
on
function paraview_protobuf_generate()
source
value