CMakeLists.txt 7.07 KB
Newer Older
1
# Create a setup.py file.
Brad King's avatar
Brad King committed
2
3
CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/setup.py.in 
               ${VTK_BINARY_DIR}/Wrapping/Python/setup.py)
4

Andy Cedilnik's avatar
Andy Cedilnik committed
5
# create the VTK/Python  executable
6
7
8
CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/vtkPythonAppInitConfigure.h.in
               ${VTK_BINARY_DIR}/Wrapping/Python/vtkPythonAppInitConfigure.h)
ADD_EXECUTABLE(vtkpython vtkPythonAppInit.cxx)
9
10
11
12
13
14
IF(VTK_USE_CARBON)
  FIND_PROGRAM(VTK_APPLE_RESOURCE Rez /Developer/Tools)
  IF(VTK_APPLE_RESOURCE)
    ADD_CUSTOM_COMMAND(
      SOURCE vtkpython
      COMMAND ${VTK_APPLE_RESOURCE}
15
      ARGS Carbon.r -o ${VTK_EXECUTABLE_DIR}/vtkpython
16
17
18
19
      TARGET vtkpython
      )
  ENDIF(VTK_APPLE_RESOURCE)
ENDIF(VTK_USE_CARBON)
20

21

Andy Cedilnik's avatar
Andy Cedilnik committed
22
23
24
FIND_LIBRARY(UTIL_LIBRARY
  NAMES util
  PATHS /usr/lib
25
  DOC "Utility library needed for vtkpython"
Andy Cedilnik's avatar
Andy Cedilnik committed
26
)
Andy Cedilnik's avatar
Andy Cedilnik committed
27
28
29
30
IF(UTIL_LIBRARY)
  SET(UTIL_LIBRARY_LIB ${UTIL_LIBRARY})
ENDIF(UTIL_LIBRARY)

Andy Cedilnik's avatar
Andy Cedilnik committed
31

Brad King's avatar
Brad King committed
32
# Link against all the kit wrappers.
33
34
35
36
IF (APPLE)
  SET_TARGET_PROPERTIES(vtkpython PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
  OPTION(VTK_HAVE_FRAMEWORK_PYTHON "The system has Python installed by default (Mac OSX 10.2)" OFF)
  IF (VTK_HAVE_FRAMEWORK_PYTHON)
Andy Cedilnik's avatar
Andy Cedilnik committed
37
    SET(PYTHON_LIBRARY "-framework Python")
38
  ENDIF (VTK_HAVE_FRAMEWORK_PYTHON)
Andy Cedilnik's avatar
Andy Cedilnik committed
39
ENDIF (APPLE)
40

Andy Cedilnik's avatar
Andy Cedilnik committed
41
42
43
44
45
46
47
TARGET_LINK_LIBRARIES(vtkpython 
  ${PYTHON_LIBRARY} 
  vtkCommon 
  vtkFiltering
  vtkIO
  vtkGraphics
  vtkImaging
Andy Cedilnik's avatar
Andy Cedilnik committed
48
  ${UTIL_LIBRARY_LIB})
Andy Cedilnik's avatar
Andy Cedilnik committed
49
50
51
52

IF (VTK_USE_RENDERING)
  TARGET_LINK_LIBRARIES(vtkpython vtkRendering)
ENDIF (VTK_USE_RENDERING)
53

Andy Cedilnik's avatar
Andy Cedilnik committed
54
55
56
IF (VTK_USE_PATENTED)
  TARGET_LINK_LIBRARIES(vtkpython vtkPatented)
ENDIF (VTK_USE_PATENTED)
57

Andy Cedilnik's avatar
Andy Cedilnik committed
58
59
60
IF (VTK_USE_HYBRID)
  TARGET_LINK_LIBRARIES(vtkpython vtkHybrid)
ENDIF (VTK_USE_HYBRID)
61

Andy Cedilnik's avatar
Andy Cedilnik committed
62
63
64
IF (VTK_USE_PARALLEL)
  TARGET_LINK_LIBRARIES(vtkpython vtkParallel)
ENDIF (VTK_USE_PARALLEL)
Brad King's avatar
Brad King committed
65

66
67
68
69
# Create the pvtkpython Python wrapper executable with MPI support.
IF (VTK_USE_PARALLEL)
  IF (VTK_USE_MPI)
    ADD_EXECUTABLE(pvtkpython vtkParaPythonAppInit.cxx)
70
71
72
73
74
75
    IF(VTK_USE_CARBON)
      FIND_PROGRAM(VTK_APPLE_RESOURCE Rez /Developer/Tools)
      IF(VTK_APPLE_RESOURCE)
        ADD_CUSTOM_COMMAND(
          SOURCE pvtkpython
          COMMAND ${VTK_APPLE_RESOURCE}
76
          ARGS Carbon.r -o ${VTK_EXECUTABLE_DIR}/pvtkpython
77
78
79
80
          TARGET pvtkpython
          )
      ENDIF(VTK_APPLE_RESOURCE)
    ENDIF(VTK_USE_CARBON)
81
82

    TARGET_LINK_LIBRARIES (pvtkpython
Andy Cedilnik's avatar
Andy Cedilnik committed
83
      ${PYTHON_LIBRARY}
84
85
86
87
88
89
      vtkCommon
      vtkFiltering
      vtkIO
      vtkGraphics
      vtkImaging
      vtkParallel
Andy Cedilnik's avatar
Andy Cedilnik committed
90
      ${UTIL_LIBRARY_LIB}
91
92
    )
    IF (VTK_USE_PATENTED)
93
      TARGET_LINK_LIBRARIES(pvtkpython vtkPatented)
94
95
    ENDIF (VTK_USE_PATENTED)
    IF (VTK_USE_HYBRID)
96
      TARGET_LINK_LIBRARIES(pvtkpython vtkHybrid)
97
98
99
100
101
    ENDIF (VTK_USE_HYBRID)
    INSTALL_TARGETS(/bin pvtkpython)
  ENDIF (VTK_USE_MPI)
ENDIF (VTK_USE_PARALLEL)

Brad King's avatar
Brad King committed
102
INSTALL_TARGETS(/bin vtkpython)    
Andy Cedilnik's avatar
Andy Cedilnik committed
103

104
105
106
107
108
109
110
111
# Handle out-of-source builds correctly.
#
#  1. Create a list of Python files to be installed/copied.
#  2. Copy them to VTK_BINARY_DIR if it is different from VTK_SOURCE_DIR.
#  3. Use Python's compileall to compile the copied files.
#
# *** Step 1 has to be done carefully to avoid missing out files ***

112
IF(PYTHON_EXECUTABLE)
113
  ADD_CUSTOM_TARGET(vtkpython_pyc ALL echo "...")
114
115

# Make the necessary directories.
116
117
118
119
120
121
122
123
124
125
  FOREACH(dir
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/gtk
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/qt
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/tk
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/util
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/wx
    ${VTK_BINARY_DIR}/Wrapping/Python/vtk/test
    )
    MAKE_DIRECTORY(${dir})
  ENDFOREACH(dir)
126

127
128
129
# Now create a list of Python files.

# Files in Wrapping/Python (these are actually for backwards compatibility)
130
  SET(VTK_PYTHON_FILES
131
132
133
134
135
136
137
138
139
140
141
142
    QVTKRenderWidget
    vtkRenderWidget
    vtkTkImageViewerWidget
    vtkTkRenderWidget
    vtkpython
    vtkpythontk
    wxVTKRenderWindow
    )

# Wrapping/Python/vtk/*.py
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
143
144
145
146
147
148
149
150
151
152
153
154
    vtk/__helper
    vtk/__init__
    vtk/common
    vtk/filtering
    vtk/graphics
    vtk/hybrid
    vtk/imaging
    vtk/io
    vtk/parallel
    vtk/patented
    vtk/rendering
    vtk/required
155
156
157
158
159
    )

# vtk.util package
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
160
161
162
163
164
165
166
    vtk/util/__init__
    vtk/util/vtkMethodParser
    vtk/util/misc
    vtk/util/vtkConstants
    vtk/util/vtkImageExportToArray
    vtk/util/vtkImageImportFromArray
    vtk/util/colors
167
168
169
170
171
    )

# vtk.test package
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
172
173
174
    vtk/test/BlackBox
    vtk/test/Testing
    vtk/test/__init__
175
176
    )

177
178
179
180
181
182
183
184
185
186
187
188
189
# Tk related files
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
    vtk/tk/__init__
    vtk/tk/vtkLoadPythonTkWidgets
    vtk/tk/vtkTkImageViewerWidget
    vtk/tk/vtkTkRenderWidget
    vtk/tk/vtkTkRenderWindowInteractor
    vtk/tk/vtkTkPhotoImage
    )

# QT related files
  SET(VTK_PYTHON_FILES 
190
    ${VTK_PYTHON_FILES}
191
192
193
    vtk/qt/QVTKRenderWidget
    vtk/qt/__init__
    vtk/qt/QVTKRenderWindowInteractor
194
    )
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

# wxPython related files
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
    vtk/wx/__init__
    vtk/wx/wxVTKRenderWindow
    vtk/wx/wxVTKRenderWindowInteractor
    )

# pyGTK related files
  SET(VTK_PYTHON_FILES 
    ${VTK_PYTHON_FILES}
    vtk/gtk/GtkVTKRenderWindow
    vtk/gtk/__init__
    vtk/gtk/GtkVTKRenderWindowInteractor
    )

# Done listing of files.

# Now copy these files if necessary.
Andy Cedilnik's avatar
Andy Cedilnik committed
215
216
217
218
219
220
221
  SET(VTK_PYTHON_SOURCE_FILES)
  SET(VTK_PYTHON_OUTPUT_FILES)
  FOREACH(file ${VTK_PYTHON_FILES})
    SET(src "${VTK_BINARY_DIR}/Wrapping/Python/${file}.py")
    SET(VTK_PYTHON_SOURCE_FILES ${VTK_PYTHON_SOURCE_FILES} ${src})
  ENDFOREACH(file)

222
  IF ("${VTK_BINARY_DIR}" MATCHES "^${VTK_SOURCE_DIR}$")
223
    #MESSAGE("In source build -- no need to copy Python files.")
224
  ELSE ("${VTK_BINARY_DIR}" MATCHES "^${VTK_SOURCE_DIR}$")
225
226
227
228
229
230
231
    FOREACH(file ${VTK_PYTHON_FILES})
      SET(src "${VTK_SOURCE_DIR}/Wrapping/Python/${file}.py")
      SET(tgt "${VTK_BINARY_DIR}/Wrapping/Python/${file}.py")
      CONFIGURE_FILE(${src} ${tgt} COPYONLY)
    ENDFOREACH(file)
    CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/vtk.pth
                   ${VTK_BINARY_DIR}/Wrapping/Python/vtk.pth COPYONLY)
232
  ENDIF ("${VTK_BINARY_DIR}" MATCHES "^${VTK_SOURCE_DIR}$")
233
234

# Byte compile the Python files.
Andy Cedilnik's avatar
Andy Cedilnik committed
235
236
237
238
239
  WRITE_FILE(${VTK_BINARY_DIR}/Wrapping/Python/compile_all_vtk.py
        "import compileall\n"
        "compileall.compile_dir('${VTK_BINARY_DIR}/Wrapping/Python')\n"
	"file = open('${VTK_BINARY_DIR}/Wrapping/Python/vtk_compile_complete', 'w')\n"
	"file.write('Done')\n")
240
241

  ADD_CUSTOM_COMMAND(
Andy Cedilnik's avatar
Andy Cedilnik committed
242
    SOURCE ${VTK_BINARY_DIR}/Wrapping/Python/compile_all_vtk.py
243
    COMMAND ${PYTHON_EXECUTABLE}
Andy Cedilnik's avatar
Andy Cedilnik committed
244
245
246
247
248
249
250
251
252
    ARGS ${VTK_BINARY_DIR}/Wrapping/Python/compile_all_vtk.py
    DEPENDS ${VTK_PYTHON_SOURCE_FILES}
    OUTPUTS "${VTK_BINARY_DIR}/Wrapping/Python/vtk_compile_complete"
    TARGET vtkpython_pyc
    )

  ADD_CUSTOM_COMMAND(
    SOURCE vtkpython_pyc
    DEPENDS "${VTK_BINARY_DIR}/Wrapping/Python/vtk_compile_complete"
253
254
    TARGET vtkpython_pyc
    )
255

256
ENDIF(PYTHON_EXECUTABLE)
257

Andy Cedilnik's avatar
Andy Cedilnik committed
258
259
# Allow the user to customize their build with some local options
#
Brad King's avatar
Brad King committed
260
261
INCLUDE (${VTK_BINARY_DIR}/Wrapping/Tcl/LocalUserOptions.cmake OPTIONAL)
INCLUDE (${VTK_SOURCE_DIR}/Wrapping/Tcl/LocalUserOptions.cmake OPTIONAL)