2@defgroup module-wrapping-java Module Java CMake APIs
6@file vtkModuleWrapJava.cmake
7@brief APIs
for wrapping modules
for Java
12@brief Generate sources
for using a module
's classes from Java
14This function generates the wrapped sources for a module. It places the list of
15generated source files and Java source files in variables named in the second
16and third arguments, respectively.
19_vtk_module_wrap_java_sources(<module> <sources> <classes>)
24cmake_policy(SET CMP0053 NEW)
26function (_vtk_module_wrap_java_sources module sources java_sources)
27 _vtk_module_get_module_property("${module}"
28 PROPERTY "exclude_wrap"
29 VARIABLE _vtk_java_exclude_wrap)
30 if (_vtk_java_exclude_wrap)
34 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_java_library_name}Java")
36 set(_vtk_java_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_java_library_name}Java/${_vtk_java_library_name}-java.$<CONFIGURATION>.args")
37 set(_vtk_java_init_data_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_java_library_name}Java/${_vtk_java_library_name}-java-init.data")
39 set(_vtk_java_hierarchy_depends "${module}")
40 _vtk_module_get_module_property("${module}"
41 PROPERTY "private_depends"
42 VARIABLE _vtk_java_private_depends)
43 list(APPEND _vtk_java_hierarchy_depends
44 ${_vtk_java_private_depends})
45 _vtk_module_get_module_property("${module}"
46 PROPERTY "optional_depends"
47 VARIABLE _vtk_java_optional_depends)
48 foreach (_vtk_java_optional_depend IN LISTS _vtk_java_optional_depends)
49 if (TARGET "${_vtk_java_optional_depend}")
50 list(APPEND _vtk_java_hierarchy_depends
51 "${_vtk_java_optional_depend}")
55 set(_vtk_java_command_depends)
56 foreach (_vtk_java_hierarchy_depend IN LISTS _vtk_java_hierarchy_depends)
57 _vtk_module_get_module_property("${_vtk_java_hierarchy_depend}"
59 VARIABLE _vtk_java_hierarchy_file)
60 if (_vtk_java_hierarchy_file)
61 list(APPEND _vtk_java_hierarchy_files "${_vtk_java_hierarchy_file}")
62 get_property(_vtk_java_is_imported
63 TARGET "${_vtk_java_hierarchy_depend}"
65 if (_vtk_java_is_imported OR CMAKE_GENERATOR MATCHES "Ninja")
66 list(APPEND _vtk_java_command_depends "${_vtk_java_hierarchy_file}")
68 _vtk_module_get_module_property("${_vtk_java_hierarchy_depend}"
69 PROPERTY "library_name"
70 VARIABLE _vtk_java_hierarchy_library_name)
71 if (TARGET "${_vtk_java_hierarchy_library_name}-hierarchy")
72 list(APPEND _vtk_java_command_depends "${_vtk_java_hierarchy_library_name}-hierarchy")
75 "The ${_vtk_java_hierarchy_depend} hierarchy file is attached to a non-imported target "
76 "and a hierarchy target (${_vtk_java_hierarchy_library_name}-hierarchy) is "
83 set(_vtk_java_genex_compile_definitions
84 "$<TARGET_PROPERTY:${_vtk_java_target_name},COMPILE_DEFINITIONS>")
85 set(_vtk_java_genex_include_directories
86 "$<TARGET_PROPERTY:${_vtk_java_target_name},INCLUDE_DIRECTORIES>")
88 OUTPUT "${_vtk_java_args_file}"
89 CONTENT "$<$<BOOL:${_vtk_java_genex_compile_definitions}>:\n-D\'$<JOIN:${_vtk_java_genex_compile_definitions},\'\n-D\'>\'>\n
90$<$<BOOL:${_vtk_java_genex_include_directories}>:\n-I\'$<JOIN:${_vtk_java_genex_include_directories},\'\n-I\'>\'>\n
91$<$<BOOL:${_vtk_java_hierarchy_files}>:\n--types \'$<JOIN:${_vtk_java_hierarchy_files},\'\n--types \'>\'>\n")
93 set(_vtk_java_sources)
94 set(_vtk_java_java_sources)
96 _vtk_module_get_module_property("${module}"
98 VARIABLE _vtk_java_headers)
99 set(_vtk_java_classes)
100 foreach (_vtk_java_header IN LISTS _vtk_java_headers)
101 get_filename_component(_vtk_java_basename "${_vtk_java_header}" NAME_WE)
102 list(APPEND _vtk_java_classes
103 "${_vtk_java_basename}")
105 # The vtkWrapJava tool has special logic for the `vtkRenderWindow` class.
106 # This extra logic requires its wrappers to be compiled as ObjC++ code
108 set(_vtk_java_ext "cxx")
109 if (APPLE AND _vtk_java_basename STREQUAL "vtkRenderWindow")
110 set(_vtk_java_ext "mm")
113 set(_vtk_java_source_output
114 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_java_library_name}Java/${_vtk_java_basename}Java.${_vtk_java_ext}")
115 list(APPEND _vtk_java_sources
116 "${_vtk_java_source_output}")
118 set(_vtk_java_wrap_target "VTK::WrapJava")
119 set(_vtk_java_macros_args)
120 if (TARGET VTKCompileTools::WrapJava)
121 set(_vtk_java_wrap_target "VTKCompileTools::WrapJava")
122 if (TARGET VTKCompileTools_macros)
123 list(APPEND _vtk_java_command_depends
124 "VTKCompileTools_macros")
125 list(APPEND _vtk_java_macros_args
127 -imacros "${_VTKCompileTools_macros_file}")
131 set(_vtk_java_parse_target "VTK::ParseJava")
132 if (TARGET VTKCompileTools::ParseJava)
133 set(_vtk_java_parse_target "VTKCompileTools::ParseJava")
137 OUTPUT "${_vtk_java_source_output}"
138 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
139 "$<TARGET_FILE:${_vtk_java_wrap_target}>"
140 "@${_vtk_java_args_file}"
141 -o "${_vtk_java_source_output}"
142 "${_vtk_java_header}"
143 ${_vtk_java_macros_args}
145 CXX "${_vtk_java_header}"
146 COMMENT "Generating Java wrapper sources for ${_vtk_java_basename}"
148 "${_vtk_java_header}"
149 "${_vtk_java_args_file}"
150 "$<TARGET_FILE:${_vtk_java_wrap_target}>"
151 ${_vtk_java_command_depends})
153 set(_vtk_java_java_source_output
154 "${_vtk_java_JAVA_OUTPUT}/${_vtk_java_basename}.java")
155 list(APPEND _vtk_java_java_sources
156 "${_vtk_java_java_source_output}")
159 OUTPUT "${_vtk_java_java_source_output}"
160 COMMAND "${_vtk_java_parse_target}"
161 "@${_vtk_java_args_file}"
162 -o "${_vtk_java_java_source_output}"
163 "${_vtk_java_header}"
164 ${_vtk_java_macros_args}
166 CXX "${_vtk_java_header}"
167 COMMENT "Generating Java sources for ${_vtk_java_basename}"
169 "${_vtk_java_header}"
170 "${_vtk_java_args_file}"
171 "$<TARGET_FILE:${_vtk_java_parse_target}>"
172 ${_vtk_java_command_depends})
176 "${_vtk_java_sources}"
179 set("${java_sources}"
180 "${_vtk_java_java_sources}"
186@brief Generate a JNI library for a set of modules
188A single JNI library may consist of the Java wrappings of multiple modules.
189This is useful for kit-based builds where the modules part of the same kit
190belong to the same JNI library as well.
193_vtk_module_wrap_java_library(<name> <module>...)
196The first argument is the name of the JNI library. The remaining arguments are
197modules to include in the JNI library.
199The remaining information it uses is assumed to be provided by the
200@ref vtk_module_wrap_java function.
202function (_vtk_module_wrap_java_library name)
203 set(_vtk_java_library_sources)
204 set(_vtk_java_library_java_sources)
205 set(_vtk_java_library_link_depends)
206 foreach (_vtk_java_module IN LISTS ARGN)
207 _vtk_module_get_module_property("${_vtk_java_module}"
208 PROPERTY "exclude_wrap"
209 VARIABLE _vtk_java_exclude_wrap)
210 if (_vtk_java_exclude_wrap)
213 _vtk_module_real_target(_vtk_java_target_name "${_vtk_java_module}")
214 _vtk_module_get_module_property("${_vtk_java_module}"
215 PROPERTY "library_name"
216 VARIABLE _vtk_java_library_name)
217 _vtk_module_wrap_java_sources("${_vtk_java_module}" _vtk_java_sources _vtk_java_java_sources)
218 list(APPEND _vtk_java_library_sources
219 ${_vtk_java_sources})
220 list(APPEND _vtk_java_library_java_sources
221 ${_vtk_java_java_sources})
223 _vtk_module_get_module_property("${_vtk_java_module}"
225 VARIABLE _vtk_java_module_depends)
226 foreach (_vtk_java_module_depend IN LISTS _vtk_java_module_depends)
227 _vtk_module_get_module_property("${_vtk_java_module_depend}"
228 PROPERTY "exclude_wrap"
229 VARIABLE _vtk_java_module_depend_exclude_wrap)
230 if (_vtk_java_module_depend_exclude_wrap)
234 _vtk_module_get_module_property("${_vtk_java_module_depend}"
235 PROPERTY "library_name"
236 VARIABLE _vtk_java_depend_library_name)
238 # XXX(kits): This doesn't work
for kits.
239 list(APPEND _vtk_java_library_link_depends
240 "${_vtk_java_depend_library_name}Java")
244 if (NOT _vtk_java_library_sources)
248 if (_vtk_java_library_link_depends)
249 list(REMOVE_DUPLICATES _vtk_java_library_link_depends)
252 set(_vtk_java_target "${name}Java
")
254 # XXX(java): Should this be a `MODULE`? If not, we should probably export
255 # these targets, but then we'll need logic akin to the `vtkModuleWrapPython`
256 # logic for loading wrapped modules from other packages.
257 add_library("${_vtk_java_target}
" SHARED
258 ${_vtk_java_library_sources})
260 if (_vtk_java_UTILITY_TARGET)
261 target_link_libraries("${_vtk_java_target}
"
263 "${_vtk_java_UTILITY_TARGET}
")
266 add_custom_target("${_vtk_java_target}-java-sources
"
268 ${_vtk_java_library_java_sources})
269 add_dependencies("${_vtk_java_target}
"
270 "${_vtk_java_target}-java-sources
")
272 set_property(TARGET "${_vtk_java_target}
"
277 set_property(TARGET "${_vtk_java_target}
"
281 set_property(TARGET "${_vtk_java_target}
"
283 "_vtk_module_java_files
" "${_vtk_java_library_java_sources}
")
285 if (_vtk_java_JNILIB_DESTINATION)
287 TARGETS "${_vtk_java_target}
"
290 DESTINATION "${_vtk_java_JNILIB_DESTINATION}
"
291 COMPONENT "${_vtk_java_JNILIB_COMPONENT}
"
294 DESTINATION "${_vtk_java_JNILIB_DESTINATION}
"
295 COMPONENT "${_vtk_java_JNILIB_COMPONENT}
")
300 TARGETS "${_vtk_java_target}
")
302 target_link_libraries("${_vtk_java_target}
"
305 # XXX(java): If we use modules, remove this.
306 ${_vtk_java_library_link_depends}
311@ingroup module-wrapping-java
312@brief Wrap a set of modules for use in Java
317 [WRAPPED_MODULES <varname>]
319 [UTILITY_TARGET <target>]
321 [JAVA_OUTPUT <destination>]
323 [LIBRARY_DESTINATION <destination>]
324 [JNILIB_DESTINATION <destination>]
325 [JNILIB_COMPONENT <component>])
328 * `MODULES`: (Required) The list of modules to wrap.
329 * `WRAPPED_MODULES`: (Recommended) Not all modules are wrappable. This
330 variable will be set to contain the list of modules which were wrapped.
331 * `UTILITY_TARGET`: If specified, all libraries made by the Java wrapping
332 will link privately to this target. This may be used to add compile flags
333 to the Java libraries.
334 * `JAVA_OUTPUT`: Defaults to
335 `${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/vtkJava`. Java source files are
336 written to this directory. After generation, the files may be compiled as
338 * `LIBRARY_DESTINATION` (Recommended): If provided, dynamic loader
339 information will be added to modules for loading dependent libraries.
340 * `JNILIB_DESTINATION`: Where to install JNI libraries.
341 * `JNILIB_COMPONENT`: Defaults to `jni`. The install component to use for JNI
344For each wrapped module, a `<module>Java` target will be created. These targets
345will have a `_vtk_module_java_files` property which is the list of generated
346Java source files for that target.
348For dependency purposes, the `<module>Java-java-sources` target may also be
351function (vtk_module_wrap_java)
352 cmake_parse_arguments(PARSE_ARGV 0 _vtk_java
354 "JAVA_OUTPUT;WRAPPED_MODULES;LIBRARY_DESTINATION;JNILIB_DESTINATION;JNILIB_COMPONENT;UTILITY_TARGET
"
357 if (_vtk_java_UNPARSED_ARGUMENTS)
360 "${_vtk_java_UNPARSED_ARGUMENTS}
")
363 if (NOT _vtk_java_JAVA_OUTPUT)
364 set(_vtk_java_JAVA_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/vtkJava
")
367 if (NOT _vtk_java_JNILIB_COMPONENT)
368 set(_vtk_java_JNILIB_COMPONENT "jni
")
372 set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
375 set(_vtk_java_origin_rpath_prefix
378 set(_vtk_java_origin_rpath_prefix
382 list(APPEND CMAKE_INSTALL_RPATH
383 # For sibling wrapped modules.
384 "${_vtk_java_origin_rpath_prefix}
")
386 if (DEFINED _vtk_java_LIBRARY_DESTINATION AND DEFINED _vtk_java_JNILIB_DESTINATION)
387 file(RELATIVE_PATH _vtk_java_relpath
388 "/prefix/${_vtk_java_JNILIB_DESTINATION}
"
389 "/prefix/${_vtk_java_LIBRARY_DESTINATION}
")
391 list(APPEND CMAKE_INSTALL_RPATH
393 "${_vtk_java_origin_rpath_prefix}/${_vtk_java_relpath}
")
397 if (DEFINED _vtk_java_JNILIB_DESTINATION)
398 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_java_JNILIB_DESTINATION}
")
399 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_java_JNILIB_DESTINATION}
")
402 if (NOT _vtk_java_MODULES)
404 "No modules were requested
for java wrapping.
")
408 # Disable CMake's automoc support for these targets.
413 set(_vtk_java_all_wrapped_modules)
414 foreach (_vtk_java_module IN LISTS _vtk_java_MODULES)
415 _vtk_module_get_module_property("${_vtk_java_module}
"
416 PROPERTY "library_name
"
417 VARIABLE _vtk_java_exclude_wrap)
418 _vtk_module_get_module_property("${_vtk_java_module}
"
419 PROPERTY "library_name
"
420 VARIABLE _vtk_java_library_name)
421 _vtk_module_wrap_java_library("${_vtk_java_library_name}
" "${_vtk_java_module}
")
423 if (TARGET "${_vtk_java_library_name}Java
")
424 list(APPEND _vtk_java_all_wrapped_modules
425 "${_vtk_java_module}
")
429 if (NOT _vtk_java_all_wrapped_modules)
431 "No modules given could be wrapped.
")
434 if (DEFINED _vtk_java_WRAPPED_MODULES)
435 set("${_vtk_java_WRAPPED_MODULES}
"
436 "${_vtk_java_all_wrapped_modules}
"
function vtk_module_wrap_java()
Wrap a set of modules for use in Java.