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_compile_definitions 41 "$<TARGET_PROPERTY:${_vtk_client_server_target_name},COMPILE_DEFINITIONS>") 42 set(_vtk_client_server_genex_include_directories 43 "$<TARGET_PROPERTY:${_vtk_client_server_target_name},INCLUDE_DIRECTORIES>") 45 OUTPUT "${_vtk_client_server_args_file}" 46 CONTENT "$<$<BOOL:${_vtk_client_server_genex_compile_definitions}>:\n-D\'$<JOIN:${_vtk_client_server_genex_compile_definitions},\'\n-D\'>\'>\n 47 $<$<BOOL:${_vtk_client_server_genex_include_directories}>:\n-I\'$<JOIN:${_vtk_client_server_genex_include_directories},\'\n-I\'>\'>\n") 49 _vtk_module_get_module_property("${module}" 51 VARIABLE _vtk_client_server_hierarchy_file) 53 get_property(_vtk_client_server_is_imported 54 TARGET "${_vtk_client_server_target_name}" 56 if (_vtk_client_server_is_imported OR CMAKE_GENERATOR MATCHES "Ninja") 57 set(_vtk_client_server_command_depend "${_vtk_client_server_hierarchy_file}") 59 if (TARGET "${_vtk_client_server_library_name}-hierarchy") 60 set(_vtk_client_server_command_depend "${_vtk_client_server_library_name}-hierarchy") 63 "The ${module} hierarchy file is attached to a non-imported target " 64 "and a hierarchy target " 65 "(${_vtk_client_server_library_name}-hierarchy) is missing.") 69 # create directory for wrapped source files 70 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_library_name}CS") 72 set(_vtk_client_server_sources) 74 _vtk_module_get_module_property("${module}" 76 VARIABLE _vtk_client_server_headers) 77 set(_vtk_client_server_classes) 78 foreach (_vtk_client_server_header IN LISTS _vtk_client_server_headers) 79 get_filename_component(_vtk_client_server_basename "${_vtk_client_server_header}" NAME_WE) 80 list(APPEND _vtk_client_server_classes 81 "${_vtk_client_server_basename}") 83 set(_vtk_client_server_source_output 84 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_library_name}CS/${_vtk_client_server_basename}ClientServer.cxx") 85 list(APPEND _vtk_client_server_sources 86 "${_vtk_client_server_source_output}") 89 OUTPUT "${_vtk_client_server_source_output}" 90 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} 91 "$<TARGET_FILE:ParaView::WrapClientServer>" 92 "@${_vtk_client_server_args_file}" 93 -o "${_vtk_client_server_source_output}" 94 "${_vtk_client_server_header}" 95 --types "${_vtk_client_server_hierarchy_file}" 97 CXX "${_vtk_client_server_header}" 98 COMMENT "Generating client_server wrapper sources for ${_vtk_client_server_basename}" 100 "$<TARGET_FILE:ParaView::WrapClientServer>" 101 "${_vtk_client_server_header}" 102 "${_vtk_client_server_args_file}" 103 "${_vtk_client_server_command_depend}") 107 "${_vtk_client_server_sources}" 110 "${_vtk_client_server_classes}" 115 ## Generating a client server library 117 A client server library may consist of the wrappings of multiple VTK modules. 118 This is useful for kit-based builds where the modules part of the same kit 119 belong to the same client server library as well. 122 _vtk_module_wrap_client_server_library(<name> <module>...) 125 The first argument is the name of the client server library. The remaining 126 arguments are VTK modules to include in the library. 128 The remaining information it uses is assumed to be provided by the 129 `vtk_module_wrap_client_server` function. 131 function (_vtk_module_wrap_client_server_library name) 132 set(_vtk_client_server_library_sources) 133 set(_vtk_client_server_library_classes) 134 foreach (_vtk_client_server_module IN LISTS ARGN) 135 _vtk_module_get_module_property("${_vtk_client_server_module}" 136 PROPERTY "exclude_wrap" 137 VARIABLE _vtk_client_server_exclude_wrap) 138 if (_vtk_client_server_exclude_wrap) 141 _vtk_module_get_module_property("${_vtk_client_server_module}" 142 PROPERTY "client_server_exclude" 143 VARIABLE _vtk_client_server_exclude) 144 if (_vtk_client_server_exclude) 148 _vtk_module_wrap_client_server_sources("${_vtk_client_server_module}" _vtk_client_server_sources _vtk_client_server_classes) 149 list(APPEND _vtk_client_server_library_sources 150 ${_vtk_client_server_sources}) 151 list(APPEND _vtk_client_server_library_classes 152 ${_vtk_client_server_classes}) 155 if (NOT _vtk_client_server_library_sources) 159 set(_vtk_client_server_declarations) 160 set(_vtk_client_server_calls) 161 foreach (_vtk_client_server_class IN LISTS _vtk_client_server_library_classes) 162 string(APPEND _vtk_client_server_declarations 163 "extern void ${_vtk_client_server_class}_Init(vtkClientServerInterpreter*);\n") 164 string(APPEND _vtk_client_server_calls 165 " ${_vtk_client_server_class}_Init(csi);\n") 167 set(_vtk_client_server_init_content 168 "#include \"vtkABI.h\" 169 #include \"vtkClientServerInterpreter.h\" 171 ${_vtk_client_server_declarations} 172 extern \"C\" void VTK_ABI_EXPORT ${name}_Initialize(vtkClientServerInterpreter* csi) 175 ${_vtk_client_server_calls}}\n") 177 set(_vtk_client_server_init_file 178 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}Init.cxx") 180 OUTPUT "${_vtk_client_server_init_file}" 181 CONTENT "${_vtk_client_server_init_content}") 182 # XXX(cmake): Why is this necessary? One would expect that `file(GENERATE)` 183 # would do this automatically. 184 set_property(SOURCE "${_vtk_client_server_init_file}" 188 add_library("${name}" STATIC 189 ${_vtk_client_server_library_sources} 190 "${_vtk_client_server_init_file}") 191 if (BUILD_SHARED_LIBS) 192 set_property(TARGET "${name}" 194 POSITION_INDEPENDENT_CODE 1) 196 set(_vtk_build_LIBRARY_NAME_SUFFIX "${_vtk_client_server_LIBRARY_NAME_SUFFIX}") 197 set(_vtk_build_ARCHIVE_DESTINATION "${_vtk_client_server_DESTINATION}") 198 _vtk_module_apply_properties("${name}") 204 target_link_libraries("${name}" 207 ParaView::RemotingClientServerStream 210 set(_vtk_client_server_export) 211 if (_vtk_client_server_INSTALL_EXPORT) 212 list(APPEND _vtk_client_server_export 213 EXPORT "${_vtk_client_server_INSTALL_EXPORT}") 218 ${_vtk_client_server_export} 219 COMPONENT "${_vtk_client_server_COMPONENT}" 220 ARCHIVE DESTINATION "${_vtk_client_server_DESTINATION}") 224 ## Wrapping a set of VTK modules for ClientServer 227 vtk_module_wrap_client_server( 230 [WRAPPED_MODULES <varname>] 232 [FUNCTION_NAME <function>] 233 [DESTINATION <destination>] 235 [INSTALL_EXPORT <export>] 236 [COMPONENT <component>]) 239 * `MODULES`: (Required) The list of modules to wrap. 240 * `TARGET`: (Required) The target to create which represents all wrapped 241 ClientServer modules. This is used to provide the function used to 242 initialize the bindings. 243 * `WRAPPED_MODULES`: (Recommended) Not all modules are wrappable. This 244 variable will be set to contain the list of modules which were wrapped. 245 * `FUNCTION_NAME`: (Recommended) (Defaults to `<TARGET>_initialize`) The 246 function name to generate in order to initialize the client server 247 bindings.A header with the name `<TARGET>.h` should be included in order to 248 access the initialization function. 249 * `DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where to install the 251 * `INSTALL_EXPORT`: If provided, installs will add the installed 252 libraries and generated interface target to the provided export set. 253 * `COMPONENT`: (Defaults to `development`) All install rules created by this 254 function will use this installation component. 256 function (vtk_module_wrap_client_server) 257 cmake_parse_arguments(_vtk_client_server 259 "DESTINATION;INSTALL_EXPORT;TARGET;COMPONENT;FUNCTION_NAME;WRAPPED_MODULES" 263 if (_vtk_client_server_UNPARSED_ARGUMENTS) 265 "Unparsed arguments for vtk_module_wrap_client_server: " 266 "${_vtk_client_server_UNPARSED_ARGUMENTS}") 269 if (NOT _vtk_client_server_MODULES) 271 "No modules were requested for client server wrapping.") 275 if (NOT _vtk_client_server_TARGET) 277 "The `TARGET` argument is required.") 280 if (NOT DEFINED _vtk_client_server_DESTINATION) 281 set(_vtk_client_server_DESTINATION "${CMAKE_INSTALL_LIBDIR}") 284 if (NOT DEFINED _vtk_client_server_COMPONENT) 285 set(_vtk_client_server_COMPONENT "development") 288 if (NOT DEFINED _vtk_client_server_FUNCTION_NAME) 289 set(_vtk_client_server_FUNCTION_NAME "${_vtk_client_server_TARGET}_initialize") 292 # Disable CMake's automoc support
for these targets.
297 # TODO: Install cmake properties?
299 set(_vtk_client_server_all_modules)
300 set(_vtk_client_server_all_wrapped_modules)
301 foreach (_vtk_client_server_module IN LISTS _vtk_client_server_MODULES)
303 PROPERTY
"exclude_wrap" 304 VARIABLE _vtk_client_server_exclude_wrap)
305 if (_vtk_client_server_exclude_wrap)
309 PROPERTY "client_server_exclude
" 310 VARIABLE _vtk_client_server_exclude) 311 if (_vtk_client_server_exclude) 314 _vtk_module_real_target(_vtk_client_server_target_name "${_vtk_client_server_module}
") 315 _vtk_module_get_module_property("${_vtk_client_server_module}
" 316 PROPERTY "library_name
" 317 VARIABLE _vtk_client_server_library_name) 318 _vtk_module_wrap_client_server_library("${_vtk_client_server_library_name}CS
" "${_vtk_client_server_module}
") 320 if (TARGET "${_vtk_client_server_library_name}CS
") 321 list(APPEND _vtk_client_server_all_modules 322 "${_vtk_client_server_library_name}CS
") 323 list(APPEND _vtk_client_server_all_wrapped_modules 324 "${_vtk_client_server_module}
") 328 if (NOT _vtk_client_server_all_modules) 330 "No modules given could be wrapped.
") 333 if (DEFINED _vtk_client_server_WRAPPED_MODULES) 334 set("${_vtk_client_server_WRAPPED_MODULES}
" 335 "${_vtk_client_server_all_wrapped_modules}
" 339 if (_vtk_client_server_TARGET) 340 add_library("${_vtk_client_server_TARGET}
" INTERFACE) 341 target_include_directories("${_vtk_client_server_TARGET}
" 343 "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_TARGET}>
") 345 set(_vtk_client_server_all_modules_include_file 346 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_client_server_TARGET}/${_vtk_client_server_TARGET}.h
") 348 set(_vtk_client_server_declarations) 349 set(_vtk_client_server_calls) 350 foreach (_vtk_client_server_module IN LISTS _vtk_client_server_all_modules) 351 string(APPEND _vtk_client_server_declarations 352 "extern \
"C\" void ${_vtk_client_server_module}_Initialize(vtkClientServerInterpreter*);\n")
353 string(APPEND _vtk_client_server_calls
354 " ${_vtk_client_server_module}_Initialize(csi);\n")
357 set(_vtk_client_server_all_modules_include_content
358 "#ifndef ${_vtk_client_server_TARGET}_h 359 #define ${_vtk_client_server_TARGET}_h 361 #include \"vtkClientServerInterpreter.h\" 363 ${_vtk_client_server_declarations} 364 void ${_vtk_client_server_FUNCTION_NAME}(vtkClientServerInterpreter* csi) 367 ${_vtk_client_server_calls}} 372 OUTPUT
"${_vtk_client_server_all_modules_include_file}" 373 CONTENT
"${_vtk_client_server_all_modules_include_content}")
375 target_link_libraries(
"${_vtk_client_server_TARGET}" 377 ${_vtk_client_server_all_modules})
379 set(_vtk_client_server_export)
380 if (_vtk_client_server_INSTALL_EXPORT)
381 list(APPEND _vtk_client_server_export
382 EXPORT "${_vtk_client_server_INSTALL_EXPORT}")
386 TARGETS
"${_vtk_client_server_TARGET}" 387 ${_vtk_client_server_export}
388 COMPONENT
"${_vtk_client_server_COMPONENT}" 389 ARCHIVE DESTINATION
"${_vtk_client_server_DESTINATION}")
394 ## Excluding a module from wrapping 396 Some modules should not be wrapped
using client server bindings. Since
this is
397 independent of general wrapping facilities, an additional
property is used to
405 The `MODULE` defaults to the module currently being built. If a module is not
406 being built when
this function is called, it must be provided.
409 cmake_parse_arguments(_vtk_client_server_exclude
415 if (_vtk_client_server_exclude_UNPARSED_ARGUMENTS)
417 "Unparsed arguments for vtk_module_wrap_client_server_exclude: " 418 "${_vtk_client_server_exclude_UNPARSED_ARGUMENTS}")
421 if (NOT DEFINED _vtk_client_server_exclude_MODULE)
422 if (NOT DEFINED _vtk_build_module)
424 "The `MODULE` argument must be provided outside of a module build.")
426 set(_vtk_client_server_exclude_MODULE
"${_vtk_build_module}")
430 PROPERTY
"client_server_exclude"
function _vtk_module_get_module_property(module)
Get a module property.
function vtk_module_client_server_exclude()
.md Excluding a module from wrapping
function _vtk_module_set_module_property(module)
Set a module property.