forked from Kitware/VTK
/
CMakeLists.txt
226 lines (209 loc) · 7.18 KB
/
CMakeLists.txt
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
if (NOT DEFINED VTK_INSTALL_PYTHON_EXES)
option(VTK_INSTALL_PYTHON_EXES "Install vtkpython and pvtkpython" ON)
mark_as_advanced(VTK_INSTALL_PYTHON_EXES)
endif ()
# Set up rpaths
set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
if (UNIX)
file(RELATIVE_PATH vtkpython_relpath
"/prefix/${CMAKE_INSTALL_BINDIR}"
"/prefix/${CMAKE_INSTALL_LIBDIR}")
if (APPLE)
set(vtkpython_rpath_prefix
"@executable_path")
else ()
set(vtkpython_rpath_prefix
"$ORIGIN")
endif ()
list(APPEND CMAKE_INSTALL_RPATH
"${vtkpython_rpath_prefix}/${vtkpython_relpath}")
endif ()
# The interpreters are not supported in wheel builds, so skip them.
if (NOT VTK_WHEEL_BUILD)
add_executable(vtkpython
vtkpython.rc
vtkPythonAppInit.cxx)
target_link_libraries(vtkpython
PRIVATE
VTK::WrappingPythonCore
VTK::PythonInterpreter
VTK::Python
VTK::vtkpythonmodules
VTK::vtksys)
add_executable(VTK::vtkpython ALIAS vtkpython)
if (VTK_INSTALL_PYTHON_EXES)
install(
TARGETS vtkpython
EXPORT VTKPython
DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif ()
if (TARGET VTK::ParallelMPI)
add_executable(pvtkpython
vtkPythonAppInit.cxx)
target_compile_definitions(pvtkpython
PRIVATE
VTK_COMPILED_USING_MPI)
target_link_libraries(pvtkpython
PRIVATE
VTK::WrappingPythonCore
VTK::PythonInterpreter
VTK::ParallelMPI
VTK::Python
VTK::mpi
VTK::vtkpythonmodules)
add_executable(VTK::pvtkpython ALIAS pvtkpython)
if (VTK_INSTALL_PYTHON_EXES)
install(
TARGETS pvtkpython
EXPORT VTKPython
DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif ()
endif ()
endif ()
# goes in __init__.py for when vtkmodules is BUILD_STATIC
set(_vtkmodules_static_import "_load_vtkmodules_static()")
if (BUILD_SHARED_LIBS)
string(PREPEND _vtkmodules_static_import "#")
endif ()
set(_vtkmodules_all)
set(_vtk_python_imports)
foreach (_vtk_python_module IN LISTS vtk_python_wrapped_modules)
get_property(_vtk_python_library_name
TARGET "${_vtk_python_module}"
PROPERTY "INTERFACE_vtk_module_library_name")
string(APPEND _vtkmodules_all
" \'${_vtk_python_library_name}\',\n")
string(APPEND _vtk_python_imports
"from .${_vtk_python_library_name} import *\n")
endforeach ()
set(_vtk_python_files)
foreach (_vtk_module IN LISTS vtk_modules)
_vtk_module_get_module_property("${_vtk_module}"
PROPERTY "python_modules"
VARIABLE _vtk_module_python_files)
list(APPEND _vtk_python_files
${_vtk_module_python_files})
endforeach()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/vtkmodules/all.py.in"
"${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/vtkmodules/all.py"
@ONLY)
list(APPEND _vtk_python_files
"${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/vtkmodules/all.py")
if (BUILD_SHARED_LIBS)
install(
FILES "${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/vtkmodules/all.py"
DESTINATION "${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/vtkmodules"
COMPONENT "python")
endif ()
set(python_files
vtk.py
vtkmodules/__init__.py.in
vtkmodules/gtk/GtkGLExtVTKRenderWindow.py
vtkmodules/gtk/GtkGLExtVTKRenderWindowInteractor.py
vtkmodules/gtk/GtkVTKRenderWindow.py
vtkmodules/gtk/GtkVTKRenderWindowInteractor.py
vtkmodules/gtk/__init__.py
vtkmodules/numpy_interface/__init__.py
vtkmodules/numpy_interface/algorithms.py
vtkmodules/numpy_interface/dataset_adapter.py
vtkmodules/numpy_interface/internal_algorithms.py
vtkmodules/qt/QVTKRenderWindowInteractor.py
vtkmodules/qt/__init__.py
vtkmodules/test/BlackBox.py
vtkmodules/test/ErrorObserver.py
vtkmodules/test/Testing.py
vtkmodules/test/__init__.py
vtkmodules/tk/__init__.py
vtkmodules/tk/vtkLoadPythonTkWidgets.py
vtkmodules/tk/vtkTkImageViewerWidget.py
vtkmodules/tk/vtkTkPhotoImage.py
vtkmodules/tk/vtkTkRenderWidget.py
vtkmodules/tk/vtkTkRenderWindowInteractor.py
vtkmodules/util/__init__.py
vtkmodules/util/colors.py
vtkmodules/util/keys.py
vtkmodules/util/misc.py
vtkmodules/util/numpy_support.py
vtkmodules/util/vtkAlgorithm.py
vtkmodules/util/vtkConstants.py
vtkmodules/util/vtkImageExportToArray.py
vtkmodules/util/vtkImageImportFromArray.py
vtkmodules/util/vtkMethodParser.py
vtkmodules/util/vtkVariant.py
vtkmodules/wx/__init__.py
vtkmodules/wx/wxVTKRenderWindow.py
vtkmodules/wx/wxVTKRenderWindowInteractor.py)
foreach (python_file IN LISTS python_files)
# add submodules that don't begin with "_" to _vtkmodules_all
if (python_file MATCHES "^vtkmodules\/([A-Za-z][A-Za-z0-9_]*)(\/__init__)?[.]py")
string(APPEND _vtkmodules_all " \'${CMAKE_MATCH_1}\',\n")
endif ()
endforeach ()
set(python_copied_modules)
foreach (python_file IN LISTS python_files)
set(output_python_file
"${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/${python_file}")
if (python_file MATCHES "\\.in$")
string(REPLACE ".in" "" output_python_file "${output_python_file}")
configure_file(
"${python_file}"
"${output_python_file}"
@ONLY)
else ()
add_custom_command(
OUTPUT "${output_python_file}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${python_file}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/${python_file}"
"${output_python_file}"
COMMENT "Copying ${python_file} to the binary directory")
endif ()
if (BUILD_SHARED_LIBS)
get_filename_component(python_file_directory "${python_file}" DIRECTORY)
install(
FILES "${output_python_file}"
DESTINATION "${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/${python_file_directory}"
COMPONENT "python")
endif ()
list(APPEND python_copied_modules
"${output_python_file}")
endforeach ()
set(vtk_build_paths_module
"${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/vtkmodules/_build_paths.py")
if (WIN32 AND VTK_DLL_PATHS)
string(REPLACE ";" "',\n '" vtk_dll_paths_python "${VTK_DLL_PATHS}")
file(WRITE "${vtk_build_paths_module}"
"paths = [\n '${vtk_dll_paths_python}',\n]\n")
# Add the file to the zip only if required in the install tree.
if (NOT VTK_RELOCATABLE_INSTALL AND NOT VTK_UNIFIED_INSTALL_TREE)
list(APPEND _vtk_python_files
"${vtk_build_paths_module}")
endif ()
elseif (EXISTS "${vtk_build_paths_module}")
file(REMOVE "${vtk_build_paths_module}")
endif ()
list(APPEND _vtk_python_files
${python_copied_modules})
set(_vtk_python_zip)
if (NOT BUILD_SHARED_LIBS)
set(_vtk_python_zip "${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/_vtk.zip")
add_custom_command(
OUTPUT "${_vtk_python_zip}"
COMMAND ${CMAKE_COMMAND} -E tar "cfv"
"${_vtk_python_zip}" --format=zip ${_vtk_python_files}
DEPENDS ${_vtk_python_files}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}"
COMMENT "Creating _vtk.zip Python modules archive")
install(
FILES "${_vtk_python_zip}"
DESTINATION "${VTK_PYTHON_SITE_PACKAGES_SUFFIX}/"
COMPONENT "python")
endif ()
add_custom_target(vtk_python_copy ALL
DEPENDS
${python_copied_modules}
${_vtk_python_zip})
if (VTK_BUILD_TESTING)
add_subdirectory(Testing)
endif ()