2 # `vtkModuleWrapClientServer`
4 This module includes logic necessary in
order to wrap VTK modules
using
5 ParaView
's ClientServer "language". This allows for classes in the module to be
6 used as proxies between ParaView client and server programs.
10 ## Wrapping a single module
12 This function generates the wrapped sources for a module. It places the list of
13 generated source files and classes in variables named in the second and third
14 arguments, respectively.
17 _vtk_module_wrap_client_server_sources(<module> <sources> <classes>)
22 cmake_policy(SET CMP0053 NEW)
24 function (_vtk_module_wrap_client_server_sources module sources classes)
25 _vtk_module_get_module_property("${module}"
26 PROPERTY "exclude_wrap"
27 VARIABLE _vtk_client_server_exclude_wrap)
28 if (_vtk_client_server_exclude_wrap)
31 _vtk_module_get_module_property("${module}"
32 PROPERTY "client_server_exclude"
33 VARIABLE _vtk_client_server_exclude)
34 if (_vtk_client_server_exclude)
38 set(_vtk_client_server_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_library_name}-client-server.$<CONFIGURATION>.args")
40 set(_vtk_client_server_genex_allowed 1)
41 if (CMAKE_VERSION VERSION_LESS "3.19")
42 get_property(_vtk_client_server_target_type
43 TARGET "${_vtk_client_server_target_name}"
45 if (_vtk_client_server_target_type STREQUAL "INTERFACE_LIBRARY")
46 set(_vtk_client_server_genex_allowed 0)
50 set(_vtk_client_server_genex_compile_definitions "")
51 set(_vtk_client_server_genex_include_directories "")
52 if (_vtk_client_server_genex_allowed)
53 set(_vtk_client_server_genex_compile_definitions
54 "$<TARGET_PROPERTY:${_vtk_client_server_target_name},COMPILE_DEFINITIONS>")
55 set(_vtk_client_server_genex_include_directories
56 "$<TARGET_PROPERTY:${_vtk_client_server_target_name},INCLUDE_DIRECTORIES>")
58 if (NOT DEFINED ENV{CI})
59 message(AUTHOR_WARNING
60 "ClientServer wrapping is not using target-local compile definitions "
61 "or include directories. This may affect generation of the Client "
62 "Server wrapper sources for the ${module} module. Use CMake 3.19+ to "
63 "guarantee intended behavior.")
67 OUTPUT "${_vtk_client_server_args_file}"
68 CONTENT "$<$<BOOL:${_vtk_client_server_genex_compile_definitions}>:\n-D\'$<JOIN:${_vtk_client_server_genex_compile_definitions},\'\n-D\'>\'>\n
69 $<$<BOOL:${_vtk_client_server_genex_include_directories}>:\n-I\'$<JOIN:${_vtk_client_server_genex_include_directories},\'\n-I\'>\'>\n")
71 _vtk_module_get_module_property("${module}"
73 VARIABLE _vtk_client_server_hierarchy_file)
75 get_property(_vtk_client_server_is_imported
76 TARGET "${_vtk_client_server_target_name}"
78 if (_vtk_client_server_is_imported OR CMAKE_GENERATOR MATCHES "Ninja")
79 set(_vtk_client_server_command_depend "${_vtk_client_server_hierarchy_file}")
81 if (TARGET "${_vtk_client_server_library_name}-hierarchy")
82 set(_vtk_client_server_command_depend "${_vtk_client_server_library_name}-hierarchy")
85 "The ${module} hierarchy file is attached to a non-imported target "
86 "and a hierarchy target "
87 "(${_vtk_client_server_library_name}-hierarchy) is missing.")
91 # create directory for wrapped source files
92 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_library_name}CS")
94 set(_vtk_client_server_sources)
96 _vtk_module_get_module_property("${module}"
98 VARIABLE _vtk_client_server_headers)
99 set(_vtk_client_server_classes)
100 foreach (_vtk_client_server_header IN LISTS _vtk_client_server_headers)
101 get_filename_component(_vtk_client_server_basename "${_vtk_client_server_header}" NAME_WE)
102 list(APPEND _vtk_client_server_classes
103 "${_vtk_client_server_basename}")
105 set(_vtk_client_server_source_output
106 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_library_name}CS/${_vtk_client_server_basename}ClientServer.cxx")
107 list(APPEND _vtk_client_server_sources
108 "${_vtk_client_server_source_output}")
111 OUTPUT "${_vtk_client_server_source_output}"
112 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
113 "$<TARGET_FILE:ParaView::WrapClientServer>"
114 "@${_vtk_client_server_args_file}"
115 -o "${_vtk_client_server_source_output}"
116 "${_vtk_client_server_header}"
117 --types "${_vtk_client_server_hierarchy_file}"
119 CXX "${_vtk_client_server_header}"
120 COMMENT "Generating client_server wrapper sources for ${_vtk_client_server_basename}"
122 "$<TARGET_FILE:ParaView::WrapClientServer>"
123 "${_vtk_client_server_header}"
124 "${_vtk_client_server_args_file}"
125 "${_vtk_client_server_command_depend}")
129 "${_vtk_client_server_sources}"
132 "${_vtk_client_server_classes}"
137 ## Generating a client server library
139 A client server library may consist of the wrappings of multiple VTK modules.
140 This is useful for kit-based builds where the modules part of the same kit
141 belong to the same client server library as well.
144 _vtk_module_wrap_client_server_library(<name> <module>...)
147 The first argument is the name of the client server library. The remaining
148 arguments are VTK modules to include in the library.
150 The remaining information it uses is assumed to be provided by the
151 `vtk_module_wrap_client_server` function.
153 function (_vtk_module_wrap_client_server_library name)
154 set(_vtk_client_server_library_sources)
155 set(_vtk_client_server_library_classes)
156 foreach (_vtk_client_server_module IN LISTS ARGN)
157 _vtk_module_get_module_property("${_vtk_client_server_module}"
158 PROPERTY "exclude_wrap"
159 VARIABLE _vtk_client_server_exclude_wrap)
160 if (_vtk_client_server_exclude_wrap)
163 _vtk_module_get_module_property("${_vtk_client_server_module}"
164 PROPERTY "client_server_exclude"
165 VARIABLE _vtk_client_server_exclude)
166 if (_vtk_client_server_exclude)
170 _vtk_module_wrap_client_server_sources("${_vtk_client_server_module}" _vtk_client_server_sources _vtk_client_server_classes)
171 list(APPEND _vtk_client_server_library_sources
172 ${_vtk_client_server_sources})
173 list(APPEND _vtk_client_server_library_classes
174 ${_vtk_client_server_classes})
177 if (NOT _vtk_client_server_library_sources)
181 set(_vtk_client_server_declarations)
182 set(_vtk_client_server_calls)
183 foreach (_vtk_client_server_class IN LISTS _vtk_client_server_library_classes)
184 string(APPEND _vtk_client_server_declarations
185 "extern void ${_vtk_client_server_class}_Init(vtkClientServerInterpreter*);\n")
186 string(APPEND _vtk_client_server_calls
187 " ${_vtk_client_server_class}_Init(csi);\n")
189 set(_vtk_client_server_init_content
190 "#include \"vtkABI.h\"
191 #include \"vtkClientServerInterpreter.h\"
193 ${_vtk_client_server_declarations}
194 extern \"C\" void VTK_ABI_EXPORT ${name}_Initialize(vtkClientServerInterpreter* csi)
197 ${_vtk_client_server_calls}}\n")
199 set(_vtk_client_server_init_file
200 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}Init.cxx")
202 OUTPUT "${_vtk_client_server_init_file}"
203 CONTENT "${_vtk_client_server_init_content}")
204 # XXX(cmake): Why is this necessary? One would expect that `file(GENERATE)`
205 # would do this automatically.
206 set_property(SOURCE "${_vtk_client_server_init_file}"
210 add_library("${name}" STATIC
211 ${_vtk_client_server_library_sources}
212 "${_vtk_client_server_init_file}")
213 if (BUILD_SHARED_LIBS)
214 set_property(TARGET "${name}"
216 POSITION_INDEPENDENT_CODE 1)
218 set(_vtk_build_LIBRARY_NAME_SUFFIX "${_vtk_client_server_LIBRARY_NAME_SUFFIX}")
219 set(_vtk_build_ARCHIVE_DESTINATION "${_vtk_client_server_DESTINATION}")
220 _vtk_module_apply_properties("${name}")
226 target_link_libraries("${name}"
229 ParaView::RemotingClientServerStream
232 set(_vtk_client_server_export)
233 if (_vtk_client_server_INSTALL_EXPORT)
234 list(APPEND _vtk_client_server_export
235 EXPORT "${_vtk_client_server_INSTALL_EXPORT}")
240 ${_vtk_client_server_export}
241 COMPONENT "${_vtk_client_server_COMPONENT}"
242 ARCHIVE DESTINATION "${_vtk_client_server_DESTINATION}")
246 ## Wrapping a set of VTK modules for ClientServer
249 vtk_module_wrap_client_server(
252 [WRAPPED_MODULES <varname>]
254 [FUNCTION_NAME <function>]
255 [DESTINATION <destination>]
257 [INSTALL_EXPORT <export>]
258 [COMPONENT <component>])
261 * `MODULES`: (Required) The list of modules to wrap.
262 * `TARGET`: (Required) The target to create which represents all wrapped
263 ClientServer modules. This is used to provide the function used to
264 initialize the bindings.
265 * `WRAPPED_MODULES`: (Recommended) Not all modules are wrappable. This
266 variable will be set to contain the list of modules which were wrapped.
267 * `FUNCTION_NAME`: (Recommended) (Defaults to `<TARGET>_initialize`) The
268 function name to generate in order to initialize the client server
269 bindings.A header with the name `<TARGET>.h` should be included in order to
270 access the initialization function.
271 * `DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where to install the
273 * `INSTALL_EXPORT`: If provided, installs will add the installed
274 libraries and generated interface target to the provided export set.
275 * `COMPONENT`: (Defaults to `development`) All install rules created by this
276 function will use this installation component.
278 function (vtk_module_wrap_client_server)
279 cmake_parse_arguments(_vtk_client_server
281 "DESTINATION;INSTALL_EXPORT;TARGET;COMPONENT;FUNCTION_NAME;WRAPPED_MODULES"
285 if (_vtk_client_server_UNPARSED_ARGUMENTS)
287 "Unparsed arguments for vtk_module_wrap_client_server: "
288 "${_vtk_client_server_UNPARSED_ARGUMENTS}")
291 if (NOT _vtk_client_server_MODULES)
293 "No modules were requested for client server wrapping.")
297 if (NOT _vtk_client_server_TARGET)
299 "The `TARGET` argument is required.")
302 if (NOT DEFINED _vtk_client_server_DESTINATION)
303 set(_vtk_client_server_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
306 if (NOT DEFINED _vtk_client_server_COMPONENT)
307 set(_vtk_client_server_COMPONENT "development")
310 if (NOT DEFINED _vtk_client_server_FUNCTION_NAME)
311 set(_vtk_client_server_FUNCTION_NAME "${_vtk_client_server_TARGET}_initialize")
314 # Disable CMake's automoc support
for these targets.
319 # TODO: Install cmake properties?
321 set(_vtk_client_server_all_modules)
322 set(_vtk_client_server_all_wrapped_modules)
323 foreach (_vtk_client_server_module IN LISTS _vtk_client_server_MODULES)
324 _vtk_module_get_module_property(
"${_vtk_client_server_module}"
325 PROPERTY
"exclude_wrap"
326 VARIABLE _vtk_client_server_exclude_wrap)
327 if (_vtk_client_server_exclude_wrap)
330 _vtk_module_get_module_property("${_vtk_client_server_module}
"
331 PROPERTY "client_server_exclude
"
332 VARIABLE _vtk_client_server_exclude)
333 if (_vtk_client_server_exclude)
336 _vtk_module_real_target(_vtk_client_server_target_name "${_vtk_client_server_module}
")
337 _vtk_module_get_module_property("${_vtk_client_server_module}
"
338 PROPERTY "library_name
"
339 VARIABLE _vtk_client_server_library_name)
340 _vtk_module_wrap_client_server_library("${_vtk_client_server_library_name}CS
" "${_vtk_client_server_module}
")
342 if (TARGET "${_vtk_client_server_library_name}CS
")
343 list(APPEND _vtk_client_server_all_modules
344 "${_vtk_client_server_library_name}CS
")
345 list(APPEND _vtk_client_server_all_wrapped_modules
346 "${_vtk_client_server_module}
")
350 if (NOT _vtk_client_server_all_modules)
352 "No modules given could be wrapped.
")
355 if (DEFINED _vtk_client_server_WRAPPED_MODULES)
356 set("${_vtk_client_server_WRAPPED_MODULES}
"
357 "${_vtk_client_server_all_wrapped_modules}
"
361 if (_vtk_client_server_TARGET)
362 add_library("${_vtk_client_server_TARGET}
" INTERFACE)
363 target_include_directories("${_vtk_client_server_TARGET}
"
365 "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_TARGET}>
")
367 set(_vtk_client_server_all_modules_include_file
368 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_TARGET}/${_vtk_client_server_TARGET}.h
")
370 set(_vtk_client_server_declarations)
371 set(_vtk_client_server_calls)
372 foreach (_vtk_client_server_module IN LISTS _vtk_client_server_all_modules)
373 string(APPEND _vtk_client_server_declarations
374 "extern \
"C\" void ${_vtk_client_server_module}_Initialize(vtkClientServerInterpreter*);\n")
375 string(APPEND _vtk_client_server_calls
376 " ${_vtk_client_server_module}_Initialize(csi);\n")
379 set(_vtk_client_server_all_modules_include_content
380 "
#ifndef ${_vtk_client_server_TARGET}_h
381 #define ${_vtk_client_server_TARGET}_h
383 #include \"vtkClientServerInterpreter.h\"
385 ${_vtk_client_server_declarations}
389 ${_vtk_client_server_calls}}
394 OUTPUT
"${_vtk_client_server_all_modules_include_file}"
395 CONTENT
"${_vtk_client_server_all_modules_include_content}")
397 target_link_libraries(
"${_vtk_client_server_TARGET}"
399 ${_vtk_client_server_all_modules})
401 set(_vtk_client_server_export)
402 if (_vtk_client_server_INSTALL_EXPORT)
403 list(APPEND _vtk_client_server_export
404 EXPORT
"${_vtk_client_server_INSTALL_EXPORT}")
408 TARGETS "${_vtk_client_server_TARGET}
"
409 ${_vtk_client_server_export}
410 COMPONENT "${_vtk_client_server_COMPONENT}
"
411 ARCHIVE DESTINATION "${_vtk_client_server_DESTINATION}
")
416 ## Excluding a module from wrapping
418 Some modules should not be wrapped using client server bindings. Since this is
419 independent of general wrapping facilities, an additional property is used to
420 check. This may be set using the `vtk_module_client_server_exclude` function.
423 vtk_module_client_server_exclude(
427 The `MODULE` defaults to the module currently being built. If a module is not
428 being built when this function is called, it must be provided.
430 function (vtk_module_client_server_exclude)
431 cmake_parse_arguments(_vtk_client_server_exclude
437 if (_vtk_client_server_exclude_UNPARSED_ARGUMENTS)
439 "Unparsed arguments
for vtk_module_wrap_client_server_exclude:
"
440 "${_vtk_client_server_exclude_UNPARSED_ARGUMENTS}
")
443 if (NOT DEFINED _vtk_client_server_exclude_MODULE)
444 if (NOT DEFINED _vtk_build_module)
446 "The `MODULE` argument must be provided outside of a module build.
")
448 set(_vtk_client_server_exclude_MODULE "${_vtk_build_module}
")
451 _vtk_module_set_module_property("${_vtk_client_server_exclude_MODULE}
"
452 PROPERTY "client_server_exclude
"