Commit 867d93c2 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Cleanup VTK's Python package.

VTK's wrapped C++-Python module libraries are built under the
`VTK_BUILD_PYTHON_MODULE_DIR`. That way, we don't need to add extra
paths to locate those. Since those are indeed Python module files,
they should indeed be under the VTK_BUILD_PYTHON_MODULE_DIR.

VTK's Python package is built under the path specified by
`VTK_BUILD_PYTHON_MODULE_DIR` and installed to
`VTK_INSTALL_PYTHON_MODULE_DIR`.

Improved defaults for VTK_BUILD_PYTHON_MODULE_DIR and
VTK_INSTALL_PYTHON_MODULE_DIR. The new defaults avoid having to
separately deal with python module paths for build and install
directories.
parent 6dcef46e
......@@ -38,7 +38,17 @@ function (vtk_module_python_package name)
vtk_module_impl()
vtk_module_export("")
vtk_python_package(${name} ${ARGN})
endfunction()
#------------------------------------------------------------------------------
# This is same as vtk_module_python_package except it can be used for a Python
# package that's not a VTK module. This is indeed called by
# `vtk_module_python_package` once the VTK module specific init/export calls are
# invoked.
#------------------------------------------------------------------------------
function(vtk_python_package name)
set(_packages)
set(_no_install)
set(_can_use_system)
......
......@@ -165,6 +165,16 @@ function(_vtk_add_python_module name)
# named as *.pyd
set_target_properties(${name} PROPERTIES SUFFIX ".pyd")
endif()
# build python module libraries under the ${VTK_BUILD_PYTHON_MODULE_DIR} dir.
set_target_properties(${name}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${VTK_BUILD_PYTHON_MODULE_DIR}/vtk)
if (NOT VTK_INSTALL_NO_RUNTIME)
install(TARGETS ${name}
RUNTIME DESTINATION ${VTK_INSTALL_PYTHON_MODULE_DIR}/vtk
LIBRARY DESTINATION ${VTK_INSTALL_PYTHON_MODULE_DIR}/vtk
ARCHIVE DESTINATION ${VTK_INSTALL_ARCHIVE_DIR}
)
endif()
else ()
# when building statically, the module targets need to be exported since
# others can link against them, unlike when building shared, and hence we
......
......@@ -28,17 +28,31 @@ vtk_module_impl()
# Export location of python module dirs in install and build tree for every vtkpython module to use
# As long as those modules depend on vtkpython, they can retrieve and use these
if (NOT VTK_BUILD_PYTHON_MODULE_DIR)
set(VTK_BUILD_PYTHON_MODULE_DIR
"${VTK_BINARY_DIR}/Wrapping/Python"
if(WIN32)
set(VTK_BUILD_PYTHON_MODULE_DIR
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Lib/site-packages"
CACHE
PATH "Directory where python modules will be built" FORCE)
else()
set(VTK_BUILD_PYTHON_MODULE_DIR
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}/site-packages"
CACHE
PATH "Directory where python modules will be built" FORCE)
endif()
endif()
if (NOT VTK_INSTALL_PYTHON_MODULE_DIR)
set(VTK_INSTALL_PYTHON_MODULE_DIR
if(WIN32)
set(VTK_INSTALL_PYTHON_MODULE_DIR
"${VTK_INSTALL_RUNTIME_DIR}/Lib/site-packages"
CACHE
PATH "Directory where python modules will be installed" FORCE)
else()
set(VTK_INSTALL_PYTHON_MODULE_DIR
"${VTK_INSTALL_LIBRARY_DIR}/python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}/site-packages"
CACHE
PATH "Directory where python modules will be installed" FORCE)
endif()
endif()
# Export location of python module dirs in install and build tree for for
......
......@@ -277,173 +277,43 @@ endif()
# *** Step 1 has to be done carefully to avoid missing out files ***
if(PYTHON_EXECUTABLE)
# Make the necessary directories.
file(MAKE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/vtk/gtk
${CMAKE_CURRENT_BINARY_DIR}/vtk/qt4
${CMAKE_CURRENT_BINARY_DIR}/vtk/qt
${CMAKE_CURRENT_BINARY_DIR}/vtk/tk
${CMAKE_CURRENT_BINARY_DIR}/vtk/util
${CMAKE_CURRENT_BINARY_DIR}/vtk/wx
${CMAKE_CURRENT_BINARY_DIR}/vtk/test
${CMAKE_CURRENT_BINARY_DIR}/vtk/numpy_interface)
# Now create a list of Python files.
# Configure files that need to be configured, including generation of the *.py
# files for each of the enabled VTK modules.
# Wrapping/Python/vtk/*.py
unset(VTK_PYTHON_FILES)
unset(VTK_PYTHON_IMPORT_ALL)
foreach(module IN LISTS VTK_PYTHON_MODULES_AND_KITS)
set(VTK_PYTHON_IMPORT_ALL
"${VTK_PYTHON_IMPORT_ALL}from .${module} import *\n")
configure_file(vtk/module.py.in vtk/${module}.py @ONLY)
list(APPEND VTK_PYTHON_FILES
"${CMAKE_CURRENT_BINARY_DIR}/vtk/${module}.py")
configure_file(vtk/module.py.in
"${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/${module}.py" @ONLY)
endforeach()
configure_file(vtk/__init__.py.in vtk/__init__.py @ONLY)
list(APPEND VTK_PYTHON_FILES
"${CMAKE_CURRENT_BINARY_DIR}/vtk/__init__.py")
configure_file(vtk/__init__.py.in
"${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/__init__.py" @ONLY)
# Kit module adapters
foreach(kit IN LISTS vtk_kits)
set(_module_kit ${kit}${VTK_KIT_SUFFIX})
foreach(dep IN LISTS _${kit}_modules)
configure_file(vtk/kit_module__init__.py.in vtk/${dep}.py @ONLY)
list(APPEND VTK_PYTHON_FILES
"${CMAKE_CURRENT_BINARY_DIR}/vtk/${dep}.py")
configure_file(vtk/kit_module__init__.py.in
"${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/${dep}.py" @ONLY)
endforeach()
endforeach()
unset(_module_kit)
# vtk.util package
list(APPEND VTK_PYTHON_FILES
vtk/util/__init__
vtk/util/_argparse
vtk/util/vtkMethodParser
vtk/util/misc
vtk/util/vtkConstants
vtk/util/vtkImageExportToArray
vtk/util/vtkImageImportFromArray
vtk/util/vtkVariant
vtk/util/colors
vtk/util/numpy_support
vtk/util/vtkAlgorithm
vtk/util/keys
)
# vtk.test package
list(APPEND VTK_PYTHON_FILES
vtk/test/BlackBox
vtk/test/Testing
vtk/test/__init__
)
# Tk related files
list(APPEND VTK_PYTHON_FILES
vtk/tk/__init__
vtk/tk/vtkLoadPythonTkWidgets
vtk/tk/vtkTkImageViewerWidget
vtk/tk/vtkTkRenderWidget
vtk/tk/vtkTkRenderWindowInteractor
vtk/tk/vtkTkPhotoImage
)
# PyQt related files
list(APPEND VTK_PYTHON_FILES
vtk/qt/__init__
vtk/qt/QVTKRenderWindowInteractor
vtk/qt4/__init__
vtk/qt4/QVTKRenderWindowInteractor
)
# wxPython related files
list(APPEND VTK_PYTHON_FILES
vtk/wx/__init__
vtk/wx/wxVTKRenderWindow
vtk/wx/wxVTKRenderWindowInteractor
)
# pyGTK related files
list(APPEND VTK_PYTHON_FILES
vtk/gtk/GtkVTKRenderWindow
vtk/gtk/__init__
vtk/gtk/GtkVTKRenderWindowInteractor
vtk/gtk/GtkGLExtVTKRenderWindow
vtk/gtk/GtkGLExtVTKRenderWindowInteractor
)
# vtk.numpy_interface related files
list(APPEND VTK_PYTHON_FILES
vtk/numpy_interface/__init__
vtk/numpy_interface/algorithms
vtk/numpy_interface/dataset_adapter
vtk/numpy_interface/internal_algorithms
)
# Done listing of files.
# Now copy these files if necessary.
unset(VTK_PYTHON_SOURCE_FILES)
unset(VTK_PYTHON_OUTPUT_FILES)
foreach(file ${VTK_PYTHON_FILES})
if (NOT IS_ABSOLUTE "${file}")
set(src "${CMAKE_CURRENT_BINARY_DIR}/${file}.py")
list(APPEND VTK_PYTHON_SOURCE_FILES "${src}")
endif ()
unset(_module_kit)
endforeach()
if(NOT "${VTK_BINARY_DIR}" STREQUAL "${VTK_SOURCE_DIR}")
foreach(file ${VTK_PYTHON_FILES})
if (NOT IS_ABSOLUTE "${file}")
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}.py")
set(tgt "${CMAKE_CURRENT_BINARY_DIR}/${file}.py")
add_custom_command(DEPENDS ${src}
COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
OUTPUT ${tgt}
COMMENT "source copy")
endif ()
endforeach()
endif()
# Build all py files that form the `vtk` package.
vtk_python_package(vtkpython_pyc vtk)
# 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)
add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/compile_all_vtk.py
DEPENDS ${VTK_PYTHON_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/compile_all_vtk.py
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vtk_compile_complete"
)
# 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.
add_custom_target(vtkpython_pyc ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/vtk_compile_complete")
if(TARGET vtkpython)
add_dependencies(vtkpython_pyc
vtkpython
)
add_dependencies(vtkpython vtkpython_pyc)
endif()
if(TARGET pvtkpython)
add_dependencies(pvtkpython vtkpython_pyc)
endif()
# If no runtime is to be installed then do not install python modules.
if(NOT VTK_INSTALL_NO_RUNTIME)
# Install python modules
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/vtk"
DESTINATION ${VTK_INSTALL_PYTHON_MODULE_DIR} COMPONENT RuntimeLibraries
USE_SOURCE_PERMISSIONS)
# Install python extension library that backs the modules
if (BUILD_SHARED_LIBS AND NOT VTK_INSTALL_NO_LIBRARIES)
foreach(module IN LISTS VTK_PYTHON_MODULES_AND_KITS)
install(TARGETS ${module}Python
RUNTIME DESTINATION ${VTK_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${VTK_INSTALL_PYTHON_MODULE_DIR}/vtk COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${VTK_INSTALL_ARCHIVE_DIR} COMPONENT Development
)
endforeach()
endif()
# Install the conveniently configured python interpretters
if(NOT VTK_INSTALL_NO_PYTHON_EXES AND VTK_ENABLE_VTKPYTHON)
# Install the vtkpython executable
......@@ -456,7 +326,5 @@ if(PYTHON_EXECUTABLE)
DESTINATION ${VTK_INSTALL_RUNTIME_DIR})
endif()
endif()
endif()
endif()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment