CMakeLists.txt 20.7 KB
Newer Older
Alexander Neundorf's avatar
   
Alexander Neundorf committed
1
# this file is used directly from VTK/CMakeLists.txt, not from VTK/Wrapping/CMakeLists.txt
2

3
4
5
#-----------------------
# for libvtkPythonCore.so, the core classes and utilities for VTK-Python
SET(VTK_PYTHON_CORE_SRCS
6
  vtkPythonArgs.cxx
7
  vtkPythonOverload.cxx
8
9
  vtkPythonUtil.cxx
  PyVTKClass.cxx
10
  PyVTKMutableObject.cxx
11
12
13
14
  PyVTKObject.cxx
  PyVTKSpecialObject.cxx
)

15
# SIP directory will be searched before other python dirs
16
17
18
19
IF(VTK_WRAP_PYTHON_SIP)
  INCLUDE_DIRECTORIES(${SIP_INCLUDE_DIR})
ENDIF(VTK_WRAP_PYTHON_SIP)

20
21
INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_PATH}")

David Partyka's avatar
David Partyka committed
22
VTK_ADD_LIBRARY(vtkPythonCore ${VTK_PYTHON_CORE_SRCS})
23
24
25
TARGET_LINK_LIBRARIES(vtkPythonCore vtkCommon)
IF(NOT VTK_INSTALL_NO_LIBRARIES)
  INSTALL(TARGETS vtkPythonCore
David Partyka's avatar
David Partyka committed
26
    EXPORT ${VTK_INSTALL_EXPORT_NAME}
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
    RUNTIME DESTINATION ${VTK_INSTALL_BIN_DIR_CM24} COMPONENT RuntimeLibraries
    LIBRARY DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT RuntimeLibraries
    ARCHIVE DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT Development)
ENDIF(NOT VTK_INSTALL_NO_LIBRARIES)

IF(NOT VTK_INSTALL_NO_DEVELOPMENT)
  SET(__inst_files
    vtkPython.h
    vtkPythonUtil.h
    PyVTKClass.h
    PyVTKObject.h
    PyVTKSpecialObject.h
  )
  INSTALL(FILES ${__inst_files}
    DESTINATION ${VTK_INSTALL_INCLUDE_DIR_CM24}
    COMPONENT Development)
ENDIF(NOT VTK_INSTALL_NO_DEVELOPMENT)

# Underlinking on purpose. The following library will not compile
# with LDFLAGS=-Wl,--no-undefined by design:
# On some UNIX platforms the python library is static and therefore
# should not be linked into the shared library.  Instead the symbols
# are exported from the python executable so that they can be used by
# shared libraries that are linked or loaded.  On Windows and OSX we
# want to link to the python libray to resolve its symbols
# immediately.
IF(WIN32 OR APPLE)
  TARGET_LINK_LIBRARIES (vtkPythonCore ${VTK_PYTHON_LIBRARIES})
55
  TARGET_LINK_LIBRARIES (vtkPythonCore LINK_INTERFACE_LIBRARIES ${VTK_PYTHON_LIBRARIES})
56
57
58
59
60
61
62
63
64
65
66
ENDIF(WIN32 OR APPLE)

# Apply user-defined properties to the library targets.
IF(VTK_LIBRARY_PROPERTIES)
  SET_TARGET_PROPERTIES(vtkPythonCore PROPERTIES
    ${VTK_LIBRARY_PROPERTIES}
    )
ENDIF(VTK_LIBRARY_PROPERTIES)

#-----------------------
# for the vtkpython executable
67
68
69
IF(VTK_USE_CARBON)
  FIND_PROGRAM(VTK_APPLE_RESOURCE Rez /Developer/Tools)
ENDIF(VTK_USE_CARBON)
70

71
72
73
74
75
76
77
IF(UNIX)
  FIND_LIBRARY(PYTHON_UTIL_LIBRARY
    NAMES util
    DOC "Utility library needed for vtkpython"
    )
  MARK_AS_ADVANCED(PYTHON_UTIL_LIBRARY)
ENDIF(UNIX)
Andy Cedilnik's avatar
Andy Cedilnik committed
78

Alexander Neundorf's avatar
   
Alexander Neundorf committed
79
80
81
82
83
84
85
PYTHON_WRITE_MODULES_HEADER("${CMAKE_CURRENT_BINARY_DIR}/vtkpythonmodules.h")
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")

# create the VTK/Python  executable
CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/vtkPythonAppInitConfigure.h.in
               ${VTK_BINARY_DIR}/Wrapping/Python/vtkPythonAppInitConfigure.h)

David Partyka's avatar
David Partyka committed
86
VTK_ADD_EXECUTABLE(vtkpython vtkPythonAppInit.cxx)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
87
88
89
90
91
92
93
94
95
96
97
98

SET(VTKPYTHON_LINK_FLAGS)
SET(VTKPYTHON_LINK_LIBS)

IF(CMAKE_SYSTEM_NAME MATCHES "AIX")
  GET_FILENAME_COMPONENT(CMAKE_PYTHON_LIB_PREFIX "${PYTHON_LIBRARY}" PATH)
  FIND_FILE(CMAKE_PYTHON_LIBRARY_EXPORT python.exp "${CMAKE_PYTHON_LIB_PREFIX}")
  IF(CMAKE_PYTHON_LIBRARY_EXPORT)
    SET(VTKPYTHON_LINK_FLAGS "-Wl,-bE:${CMAKE_PYTHON_LIBRARY_EXPORT}")
  ENDIF(CMAKE_PYTHON_LIBRARY_EXPORT)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "AIX")

99
IF (APPLE)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
100
101
102
103
104
105
106
  IF(VTK_USE_CARBON AND VTK_APPLE_RESOURCE)
    ADD_CUSTOM_COMMAND(
      TARGET vtkpython POST_BUILD
      COMMAND ${VTK_APPLE_RESOURCE} Carbon.r -o ${VTK_EXECUTABLE_DIR}/vtkpython
      )
  ENDIF(VTK_USE_CARBON AND VTK_APPLE_RESOURCE)

Thomas Otahal's avatar
   
Thomas Otahal committed
107
108
109
110
111
  IF(VTK_USE_MATLAB_MEX)
   SET(VTKPYTHON_LINK_FLAGS "-u _PyMac_Error")
  ELSE(VTK_USE_MATLAB_MEX)
   SET(VTKPYTHON_LINK_FLAGS "-flat_namespace -undefined suppress -u _PyMac_Error")
  ENDIF(VTK_USE_MATLAB_MEX)
Andy Cedilnik's avatar
Andy Cedilnik committed
112
ENDIF (APPLE)
113

114
# Link against all the kit wrappers.
115
116
SET(VTKPYTHON_LINK_LIBS
  ${VTK_PYTHON_LIBRARIES}
117
  vtksys
118
  vtkCommon
Andy Cedilnik's avatar
Andy Cedilnik committed
119
120
121
  vtkFiltering
  vtkIO
  vtkGraphics
Alexander Neundorf's avatar
   
Alexander Neundorf committed
122
123
  vtkImaging )

124
125
126
127
128
129
130
131
SET (vtkpython_pyc_depends
    vtkCommonPython
    vtkFilteringPython
    vtkIOPython
    vtkGraphicsPython
    vtkImagingPython
    )

132
IF(BORLAND)
133
  SET(KITS Common Filtering Graphics IO Imaging)
134
135
136
  IF (VTK_USE_PARALLEL)
    SET(KITS ${KITS} Parallel)
  ENDIF(VTK_USE_PARALLEL)
137
138
139
  IF(VTK_USE_CHARTS)
    SET(KITS ${KITS} Charts)
  ENDIF(VTK_USE_CHARTS)
Ken Martin's avatar
Ken Martin committed
140
141
142
  IF (VTK_USE_GEOVIS)
    SET(KITS ${KITS} Geovis)
  ENDIF(VTK_USE_GEOVIS)
143
144
145
  IF (VTK_USE_INFOVIS)
    SET(KITS ${KITS} Infovis)
  ENDIF(VTK_USE_INFOVIS)
146
147
148
  IF (VTK_USE_TEXTAN_ALYSIS)
    SET(KITS ${KITS} TextAnalysis)
  ENDIF(VTK_USE_TEXT_ANALYIS)
149
150
151
  IF (VTK_USE_VIEWS)
    SET(KITS ${KITS} Views)
  ENDIF(VTK_USE_VIEWS)
152
  IF (VTK_USE_RENDERING)
153
154
155
    SET(KITS ${KITS} Widgets)
    SET(KITS ${KITS} Hybrid)
    SET(KITS ${KITS} VolumeRendering)
156
157
158
159
160
161
162
163
    SET(KITS ${KITS} Rendering)
  ENDIF(VTK_USE_RENDERING)
  FOREACH(KIT ${KITS})
    WRITE_FILE(${LIBRARY_OUTPUT_PATH}/vtk${KIT}Python.def
               "EXPORTS\ninitvtk${KIT}Python=_initvtk${KIT}Python\n")
  ENDFOREACH(KIT)
ENDIF(BORLAND)

Alexander Neundorf's avatar
   
Alexander Neundorf committed
164
165
166
IF(PYTHON_UTIL_LIBRARY)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS}  ${PYTHON_UTIL_LIBRARY})
ENDIF(PYTHON_UTIL_LIBRARY)
167

Andy Cedilnik's avatar
Andy Cedilnik committed
168
IF (VTK_USE_RENDERING)
169
170
171
172
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS}
                          vtkRendering
                          vtkVolumeRendering
                          vtkHybrid
Alexander Neundorf's avatar
   
Alexander Neundorf committed
173
                          vtkWidgets )
174
175
176
177
178
179
180
  SET (vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkRenderingPython
      vtkVolumeRenderingPython
      vtkHybridPython
      vtkWidgetsPython
      )
181
ENDIF (VTK_USE_RENDERING)
182

Andy Cedilnik's avatar
Andy Cedilnik committed
183
IF (VTK_USE_PARALLEL)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
184
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkParallel)
185
186
187
188
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkParallelPython
      )
Andy Cedilnik's avatar
Andy Cedilnik committed
189
ENDIF (VTK_USE_PARALLEL)
Brad King's avatar
Brad King committed
190

191
192
193
194
195
196
197
198
IF(VTK_USE_CHARTS)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkCharts)
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkChartsPython
      )
ENDIF(VTK_USE_CHARTS)

Ken Martin's avatar
Ken Martin committed
199
200
201
202
203
204
205
206
IF (VTK_USE_GEOVIS)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkGeovis)
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkGeovisPython
      )
ENDIF (VTK_USE_GEOVIS)

207
IF (VTK_USE_INFOVIS)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
208
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkInfovis)
209
210
211
212
213
214
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkInfovisPython
      )
ENDIF (VTK_USE_INFOVIS)

215
216
217
218
219
220
221
222
IF (VTK_USE_TEXT_ANALYSIS)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkTextAnalysis)
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkTextAnalysisPython
      )
ENDIF (VTK_USE_TEXT_ANALYSIS)

223
224
225
226
227
228
229
230
IF (VTK_USE_VIEWS)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} vtkViews)
  SET(vtkpython_pyc_depends
      ${vtkpython_pyc_depends}
      vtkViewsPython
      )
ENDIF (VTK_USE_VIEWS)

231
232
# The PYTHON_ADD_MODULE macro stores the list of static modules in a global property
GET_PROPERTY(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
233
234
235
236
IF(PY_STATIC_MODULES_LIST)
  SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} ${PY_STATIC_MODULES_LIST})
ENDIF(PY_STATIC_MODULES_LIST)

237
# Link to rt to prevent undefined symbol 'fdatasync'
Alexander Neundorf's avatar
   
Alexander Neundorf committed
238
239
240
241
242
243
IF(CMAKE_SYSTEM MATCHES "SunOS.*" AND NOT CMAKE_COMPILER_IS_GNUCXX)
  FIND_LIBRARY(VTK_SUNCC_RT_LIBRARY rt)
  IF(VTK_SUNCC_RT_LIBRARY)
    SET(VTKPYTHON_LINK_LIBS ${VTKPYTHON_LINK_LIBS} ${VTK_SUNCC_RT_LIBRARY})
  ENDIF(VTK_SUNCC_RT_LIBRARY)
ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*" AND NOT CMAKE_COMPILER_IS_GNUCXX)
244

Alexander Neundorf's avatar
   
Alexander Neundorf committed
245
246
247
IF(VTK_WRAP_TCL)
  TARGET_LINK_LIBRARIES(vtkpython ${VTK_TK_LIBRARIES})
ENDIF(VTK_WRAP_TCL)
248

249
IF(HAVE_PTHREAD_H AND CMAKE_USE_PTHREADS)
250
251
252
  TARGET_LINK_LIBRARIES(vtkpython ${CMAKE_THREAD_LIBS_INIT})
ENDIF()

253
IF(VTK_USE_FFMPEG_ENCODER)
254
  LIST(APPEND VTKPYTHON_LINK_LIBS ${FFMPEG_BASIC_LIBRARIES})
255
ENDIF(VTK_USE_FFMPEG_ENCODER)
256

Alexander Neundorf's avatar
   
Alexander Neundorf committed
257
TARGET_LINK_LIBRARIES(vtkpython ${VTKPYTHON_LINK_LIBS})
258
TARGET_LINK_LIBRARIES(vtkpython LINK_INTERFACE_LIBRARIES ${VTK_PYTHON_LIBRARIES})
Alexander Neundorf's avatar
   
Alexander Neundorf committed
259

260
261
262
263
264
265
266
267
IF(VTK_USE_MATLAB_MEX)
  INCLUDE(${MATLAB_MEX_USE_FILE})
  SET_TARGET_PROPERTIES(vtkpython PROPERTIES
                        LINK_FLAGS "${MEX_RPATH} ${VTKPYTHON_LINK_FLAGS}")
ELSE(VTK_USE_MATLAB_MEX)
  SET_TARGET_PROPERTIES(vtkpython PROPERTIES LINK_FLAGS "${VTKPYTHON_LINK_FLAGS}")
ENDIF(VTK_USE_MATLAB_MEX)

Alexander Neundorf's avatar
   
Alexander Neundorf committed
268
269

SET(PVTKPYTHON_EXECUTABLE)
270
# Create the pvtkpython Python wrapper executable with MPI support.
Alexander Neundorf's avatar
   
Alexander Neundorf committed
271
IF (VTK_USE_PARALLEL AND VTK_USE_MPI)
272
  INCLUDE_DIRECTORIES("${MPI_INCLUDE_PATH}")
273
274
275
276
277
278
  IF (MPI_LIBRARY)
    SET(MPI_LIBRARIES ${MPI_LIBRARY})
  ENDIF (MPI_LIBRARY)
  IF (MPI_EXTRA_LIBRARY)
    SET(MPI_LIBRARIES ${MPI_LIBRARIES} "${MPI_EXTRA_LIBRARY}")
  ENDIF (MPI_EXTRA_LIBRARY)
279
  IF (VTK_USE_PARALLEL_BGL)
280
    SET(MPI_LIBRARIES ${MPI_LIBRARIES} "${Boost_LIBRARIES}")
281
282
  ENDIF (VTK_USE_PARALLEL_BGL)

283

Alexander Neundorf's avatar
   
Alexander Neundorf committed
284
285
286
287
  # Needed for mpich 2
  ADD_DEFINITIONS("-DMPICH_IGNORE_CXX_SEEK")

  SET(PVTKPYTHON_EXECUTABLE pvtkpython)
David Partyka's avatar
David Partyka committed
288
  VTK_ADD_EXECUTABLE(pvtkpython vtkParaPythonAppInit.cxx)
289
  TARGET_LINK_LIBRARIES(pvtkpython ${VTKPYTHON_LINK_LIBS} ${MPI_LIBRARIES})
290
  TARGET_LINK_LIBRARIES(vtkpython LINK_INTERFACE_LIBRARIES ${VTK_PYTHON_LIBRARIES})
291
292
293
294
295
296
297
  IF(VTK_USE_MATLAB_MEX)
    INCLUDE(${MATLAB_MEX_USE_FILE})
    SET_TARGET_PROPERTIES(pvtkpython PROPERTIES
                         LINK_FLAGS "${MEX_RPATH} ${VTKPYTHON_LINK_FLAGS}")
  ELSE(VTK_USE_MATLAB_MEX)
    SET_TARGET_PROPERTIES(pvtkpython PROPERTIES LINK_FLAGS "${VTKPYTHON_LINK_FLAGS}")
  ENDIF(VTK_USE_MATLAB_MEX)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
298
299
300
301
302
303

  IF(VTK_USE_CARBON AND VTK_APPLE_RESOURCE)
      ADD_CUSTOM_COMMAND( TARGET pvtkpython POST_BUILD
                          COMMAND ${VTK_APPLE_RESOURCE} Carbon.r -o ${VTK_EXECUTABLE_DIR}/pvtkpython )
  ENDIF(VTK_USE_CARBON AND VTK_APPLE_RESOURCE)
ENDIF (VTK_USE_PARALLEL AND VTK_USE_MPI)
304

305
IF(NOT VTK_INSTALL_NO_RUNTIME AND NOT VTK_INSTALL_NO_VTKPYTHON)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
306
  INSTALL(TARGETS vtkpython ${PVTKPYTHON_EXECUTABLE}
David Partyka's avatar
David Partyka committed
307
    EXPORT ${VTK_INSTALL_EXPORT_NAME}
308
309
310
311
    RUNTIME DESTINATION ${VTK_INSTALL_BIN_DIR_CM24} COMPONENT RuntimeExecutables # .exe, .dll
    LIBRARY DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT RuntimeLibraries # .so, mod.dll
    ARCHIVE DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT Development      # .a, .lib
    )
312
ENDIF(NOT VTK_INSTALL_NO_RUNTIME AND NOT VTK_INSTALL_NO_VTKPYTHON)
Andy Cedilnik's avatar
Andy Cedilnik committed
313

314
315
316
317
318
319
320
321
# 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 ***

322
IF(PYTHON_EXECUTABLE)
323
# Make the necessary directories.
Alexander Neundorf's avatar
   
Alexander Neundorf committed
324
325
326
327
328
329
330
    FILE(MAKE_DIRECTORY  ${VTK_BINARY_DIR}/Wrapping/Python/vtk/gtk
                         ${VTK_BINARY_DIR}/Wrapping/Python/vtk/qt
                         ${VTK_BINARY_DIR}/Wrapping/Python/vtk/qt4
                         ${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 )
331

332
333
334
# Now create a list of Python files.

# Wrapping/Python/vtk/*.py
335
  SET(VTK_PYTHON_FILES
336
337
338
    vtk/__helper
    vtk/__init__
    vtk/common
339
    vtk/charts
340
    vtk/filtering
341
    vtk/genericfiltering
Ken Martin's avatar
Ken Martin committed
342
    vtk/geovis
343
344
345
346
    vtk/graphics
    vtk/hybrid
    vtk/imaging
    vtk/io
Berk Geveci's avatar
Berk Geveci committed
347
    vtk/infovis
348
    vtk/textanalysis
349
350
351
    vtk/parallel
    vtk/rendering
    vtk/required
352
    vtk/views
353
    vtk/volumerendering
354
    vtk/widgets
355
    vtk/qvtk
356
357
358
    )

# vtk.util package
359
  SET(VTK_PYTHON_FILES
360
    ${VTK_PYTHON_FILES}
361
362
363
364
365
366
    vtk/util/__init__
    vtk/util/vtkMethodParser
    vtk/util/misc
    vtk/util/vtkConstants
    vtk/util/vtkImageExportToArray
    vtk/util/vtkImageImportFromArray
367
    vtk/util/vtkVariant
368
    vtk/util/colors
369
    vtk/util/numpy_support
370
371
372
    )

# vtk.test package
373
  SET(VTK_PYTHON_FILES
374
    ${VTK_PYTHON_FILES}
375
376
377
    vtk/test/BlackBox
    vtk/test/Testing
    vtk/test/__init__
378
379
    )

380
# Tk related files
381
  SET(VTK_PYTHON_FILES
382
383
384
385
386
387
388
389
390
    ${VTK_PYTHON_FILES}
    vtk/tk/__init__
    vtk/tk/vtkLoadPythonTkWidgets
    vtk/tk/vtkTkImageViewerWidget
    vtk/tk/vtkTkRenderWidget
    vtk/tk/vtkTkRenderWindowInteractor
    vtk/tk/vtkTkPhotoImage
    )

391
# PyQt v3 related files
392
  SET(VTK_PYTHON_FILES
393
    ${VTK_PYTHON_FILES}
394
395
396
    vtk/qt/QVTKRenderWidget
    vtk/qt/__init__
    vtk/qt/QVTKRenderWindowInteractor
397
    )
398

399
# PyQt v4 related files
400
  SET(VTK_PYTHON_FILES
401
402
403
404
405
    ${VTK_PYTHON_FILES}
    vtk/qt4/__init__
    vtk/qt4/QVTKRenderWindowInteractor
    )

406
# wxPython related files
407
  SET(VTK_PYTHON_FILES
408
409
410
411
412
413
414
    ${VTK_PYTHON_FILES}
    vtk/wx/__init__
    vtk/wx/wxVTKRenderWindow
    vtk/wx/wxVTKRenderWindowInteractor
    )

# pyGTK related files
415
  SET(VTK_PYTHON_FILES
416
417
418
419
420
421
422
423
424
    ${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
425
426
427
428
429
430
431
  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)

Alexander Neundorf's avatar
   
Alexander Neundorf committed
432
  IF (NOT "${VTK_BINARY_DIR}" MATCHES "^${VTK_SOURCE_DIR}$")
433
434
435
    FOREACH(file ${VTK_PYTHON_FILES})
      SET(src "${VTK_SOURCE_DIR}/Wrapping/Python/${file}.py")
      SET(tgt "${VTK_BINARY_DIR}/Wrapping/Python/${file}.py")
436
      ADD_CUSTOM_COMMAND(DEPENDS ${src}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
437
                         COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
438
                         OUTPUT ${tgt}
439
                         COMMENT "source copy")
440
    ENDFOREACH(file)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
441
  ENDIF (NOT "${VTK_BINARY_DIR}" MATCHES "^${VTK_SOURCE_DIR}$")
442

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  # handle the different configuration types (each will have identical files)
  SET(VTK_PYTHON_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES})
  IF(VTK_PYTHON_CONFIGURATION_TYPES)
    FOREACH(config ${VTK_PYTHON_CONFIGURATION_TYPES})
      FOREACH(file ${VTK_PYTHON_FILES})
        SET(src "${VTK_SOURCE_DIR}/Wrapping/Python/${file}.py")
        SET(tgt "${VTK_BINARY_DIR}/Wrapping/Python/${config}/${file}.py")
        ADD_CUSTOM_COMMAND(DEPENDS ${src}
                           COMMAND ${CMAKE_COMMAND}
                           ARGS -E copy ${src} ${tgt}
                           OUTPUT ${tgt}
                           COMMENT "source copy")
      ENDFOREACH(file)
    ENDFOREACH(config)
  ENDIF(VTK_PYTHON_CONFIGURATION_TYPES)

459
460
461
462
  # Byte compile the Python files.
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compile_all_vtk.py.in
                 ${CMAKE_CURRENT_BINARY_DIR}/compile_all_vtk.py
                 @ONLY IMMEDIATE)
463
  ADD_CUSTOM_COMMAND(
Alexander Neundorf's avatar
   
Alexander Neundorf committed
464
    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/compile_all_vtk.py
465
    DEPENDS ${VTK_PYTHON_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/compile_all_vtk.py
466
    OUTPUT "${VTK_BINARY_DIR}/Wrapping/Python/vtk_compile_complete"
467
    )
468

469
470
471
  # Create a target on which custom commands can depend.  When this
  # is up-to-date, it is safe to run VTK python code.  Therefore
  # this should also depend on the vtkpython executable.
472
473
  ADD_CUSTOM_TARGET(vtkpython_pyc ALL echo "..."
    DEPENDS "${VTK_BINARY_DIR}/Wrapping/Python/vtk_compile_complete")
474
  ADD_DEPENDENCIES(vtkpython_pyc
475
476
      vtkpython
      ${vtkpython_pyc_depends})
477

478
479
480
481
482
  # If no runtime is to be installed then do not install python modules.
  IF(VTK_INSTALL_NO_RUNTIME)
    SET(VTK_INSTALL_NO_PYTHON 1)
  ENDIF(VTK_INSTALL_NO_RUNTIME)

483
  # If set (generally by projects that include VTK), we install the
484
485
486
487
488
489
490
  # vtk{*}Python libraries using CMake rather than setup.py. Which implies that
  # they will be put will all other libraries. This is done in
  # KitCommonPythonWrapBlock.cmake
  IF (VTK_INSTALL_PYTHON_USING_CMAKE)
    SET(VTK_INSTALL_NO_PYTHON 1)
  ENDIF (VTK_INSTALL_PYTHON_USING_CMAKE)

491
492
493
  IF(VTK_INSTALL_PYTHON_USING_CMAKE)
    # Install python module directory (*.py and *.pyd)
    INSTALL(DIRECTORY "${VTK_BINARY_DIR}/Wrapping/Python/vtk"
494
      DESTINATION "${VTK_INSTALL_BIN_DIR_CM24}/Python" COMPONENT RuntimeLibraries
495
496
497
      USE_SOURCE_PERMISSIONS)
  ENDIF(VTK_INSTALL_PYTHON_USING_CMAKE)

498
499
500
  # Add a rule to use python distutils to install the python wrappers.
  IF(NOT VTK_INSTALL_NO_PYTHON)
    SET(DOLLAR "$")
501

502
    # Create default python setup arguments if they are not set.
Alexander Neundorf's avatar
   
Alexander Neundorf committed
503
    IF(NOT DEFINED VTK_PYTHON_SETUP_ARGS)
504
505
      SET(VTK_PYTHON_SETUP_ARGS "--prefix=\"${DOLLAR}{CMAKE_INSTALL_PREFIX}\""
        CACHE STRING "Arguments passed to \"python setup.py install ...\" during installation.")
506
      MARK_AS_ADVANCED(VTK_PYTHON_SETUP_ARGS)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
507
    ENDIF(NOT DEFINED VTK_PYTHON_SETUP_ARGS)
508

509
510
    # Change dollar sign to DOLLARSIGN
    STRING(REGEX REPLACE "\\${DOLLAR}" "DOLLARSIGN"
511
      PYTHON_SETUP_ARGS "${VTK_PYTHON_SETUP_ARGS}")
512
513
514
515
516
517
518
519
520
521
522
523
524

    # Get the install path for python modules
    EXEC_PROGRAM("${PYTHON_EXECUTABLE}" "${VTK_SOURCE_DIR}/Wrapping/Python"
      ARGS "setup_install_paths.py" "purelib" ${PYTHON_SETUP_ARGS}
      OUTPUT_VARIABLE PYTHON_MODULE_INSTALL_DIR)

    # Get the install path for binary python modules
    EXEC_PROGRAM("${PYTHON_EXECUTABLE}" "${VTK_SOURCE_DIR}/Wrapping/Python"
      ARGS "setup_install_paths.py" "platlib" ${PYTHON_SETUP_ARGS}
      OUTPUT_VARIABLE PYTHON_MODULE_PLATFORM_INSTALL_DIR)

    # Change DOLLARSIGN to dollar sign
    STRING(REGEX REPLACE "DOLLARSIGN" "${DOLLAR}"
525
      PYTHON_MODULE_INSTALL_DIR "${PYTHON_MODULE_INSTALL_DIR}")
526
    STRING(REGEX REPLACE "DOLLARSIGN" "${DOLLAR}"
527
528
      PYTHON_MODULE_PLATFORM_INSTALL_DIR
      "${PYTHON_MODULE_PLATFORM_INSTALL_DIR}")
529

530
531
532
    # Replace backslashes with forward slashes
    IF (WIN32)
      STRING(REGEX REPLACE "\\\\" "/" PYTHON_MODULE_INSTALL_DIR
533
        "${PYTHON_MODULE_INSTALL_DIR}")
534
      STRING(REGEX REPLACE "\\\\" "/" PYTHON_MODULE_PLATFORM_INSTALL_DIR
535
        "${PYTHON_MODULE_PLATFORM_INSTALL_DIR}")
536
537
    ENDIF (WIN32)

538
    SET(VTK_PYTHON_MODULE_INSTALL_DIR "${PYTHON_MODULE_INSTALL_DIR}"
539
540
541
      CACHE INTERNAL "Install directory for Python .py and .pyc files")

    SET(VTK_PYTHON_MODULE_PLATFORM_INSTALL_DIR
542
      "${PYTHON_MODULE_PLATFORM_INSTALL_DIR}"
543
544
      CACHE INTERNAL "Install directory for Python binary modules")

545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
    # If there are multiple configurations then add a BUILD_TYPE=...
    # argument to the python setup.py call.  The build type to use is set
    # in the CMake variable BUILD_TYPE while running the install script.
    IF(CMAKE_CONFIGURATION_TYPES)
      SET(VTK_PYTHON_SETUP_BUILD_TYPE "BUILD_TYPE=${DOLLAR}{BUILD_TYPE}")
    ELSE(CMAKE_CONFIGURATION_TYPES)
      SET(VTK_PYTHON_SETUP_BUILD_TYPE)
    ENDIF(CMAKE_CONFIGURATION_TYPES)

    # Configure the post-install script to run python on setup.py.
    CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/PythonInstall.cmake.in
                   ${VTK_BINARY_DIR}/Wrapping/Python/PythonInstall.cmake
                   @ONLY IMMEDIATE)
    SET_TARGET_PROPERTIES(vtkpython_pyc PROPERTIES POST_INSTALL_SCRIPT
      ${VTK_BINARY_DIR}/Wrapping/Python/PythonInstall.cmake
      )
  ENDIF(NOT VTK_INSTALL_NO_PYTHON)
562
ENDIF(PYTHON_EXECUTABLE)
563

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# Create the setup.py file.
IF(CMAKE_CONFIGURATION_TYPES)
  # The build has multiple configuration types.  If CMAKE_BUILD_TYPE
  # is set use it as the default BUILD_TYPE for setup.py to install.
  SET(VTK_PYTHON_HAS_CONFIG_TYPES 1)
  IF(CMAKE_BUILD_TYPE)
    SET(VTK_PYTHON_BUILD_TYPE "\"${CMAKE_BUILD_TYPE}\"")
  ELSE(CMAKE_BUILD_TYPE)
    SET(VTK_PYTHON_BUILD_TYPE "[]")
  ENDIF(CMAKE_BUILD_TYPE)
ELSE(CMAKE_CONFIGURATION_TYPES)
  # The build has one configuration type.  The build type does not
  # affect installation.
  SET(VTK_PYTHON_HAS_CONFIG_TYPES 0)
  SET(VTK_PYTHON_BUILD_TYPE "[]")
ENDIF(CMAKE_CONFIGURATION_TYPES)
IF(VTK_USE_RENDERING)
  SET(VTK_PYTHON_USE_RENDERING 1)
ELSE(VTK_USE_RENDERING)
  SET(VTK_PYTHON_USE_RENDERING 0)
ENDIF(VTK_USE_RENDERING)
IF(VTK_USE_PARALLEL)
  SET(VTK_PYTHON_USE_PARALLEL 1)
ELSE(VTK_USE_PARALLEL)
  SET(VTK_PYTHON_USE_PARALLEL 0)
ENDIF(VTK_USE_PARALLEL)
590
591
592
593
594
IF(VTK_USE_CHARTS)
  SET(VTK_PYTHON_USE_CHARTS 1)
ELSE(VTK_USE_CHARTS)
  SET(VTK_PYTHON_USE_CHARTS 0)
ENDIF(VTK_USE_CHARTS)
Ken Martin's avatar
Ken Martin committed
595
596
597
598
599
IF(VTK_USE_GEOVIS)
  SET(VTK_PYTHON_USE_GEOVIS 1)
ELSE(VTK_USE_GEOVIS)
  SET(VTK_PYTHON_USE_GEOVIS 0)
ENDIF(VTK_USE_GEOVIS)
600
601
602
603
604
IF(VTK_USE_INFOVIS)
  SET(VTK_PYTHON_USE_INFOVIS 1)
ELSE(VTK_USE_INFOVIS)
  SET(VTK_PYTHON_USE_INFOVIS 0)
ENDIF(VTK_USE_INFOVIS)
605
606
607
608
609
IF(VTK_USE_TEXT_ANALYSIS)
  SET(VTK_PYTHON_USE_TEXT_ANALYSIS 1)
ELSE(VTK_USE_TEXT_ANALYSIS)
  SET(VTK_PYTHON_USE_TEXT_ANALYSIS 0)
ENDIF(VTK_USE_TEXT_ANALYSIS)
610
611
612
613
614
IF(VTK_USE_VIEWS)
  SET(VTK_PYTHON_USE_VIEWS 1)
ELSE(VTK_USE_VIEWS)
  SET(VTK_PYTHON_USE_VIEWS 0)
ENDIF(VTK_USE_VIEWS)
615
616
617
618
619
IF(VTK_USE_MPI)
  SET(VTK_PYTHON_USE_MPI 1)
ELSE(VTK_USE_MPI)
  SET(VTK_PYTHON_USE_MPI 0)
ENDIF(VTK_USE_MPI)
620
621
622
623
624
625
626
627
628
629
630
IF(VTK_USE_QT AND VTK_WRAP_PYTHON_SIP)
  SET(VTK_PYTHON_USE_QT 1)
ELSE(VTK_USE_QT AND VTK_WRAP_PYTHON_SIP)
  SET(VTK_PYTHON_USE_QT 0)
ENDIF(VTK_USE_QT AND VTK_WRAP_PYTHON_SIP)
IF(VTK_WRAP_PYTHON_SIP)
  SET(VTK_PYTHON_USE_SIP 1)
ELSE(VTK_WRAP_PYTHON_SIP)
  SET(VTK_PYTHON_USE_SIP 0)
ENDIF(VTK_WRAP_PYTHON_SIP)

631
632
633
CONFIGURE_FILE(${VTK_SOURCE_DIR}/Wrapping/Python/setup.py.in
               ${VTK_BINARY_DIR}/Wrapping/Python/setup.py @ONLY IMMEDIATE)

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