Commit beae7c64 authored by Dave DeMarle's avatar Dave DeMarle
Browse files

Use cmake install instead of setup.py to install python wrapping.

Distutils path is not well maintained and from what packagers
tell me, largely unused. It is also buggy and hard to use.
Removing it and letting CMake install instead. Doing this will
properly remove rpath and likely fix other bugs.

Change-Id: I60f375449344bcd8b2b2823c248eb69163026a3a
parent 4f84906f
......@@ -78,11 +78,6 @@ function(_vtk_add_python_module name)
if (BUILD_SHARED_LIBS)
add_library(${name} MODULE ${ARGN})
set_property(TARGET ${name} PROPERTY PREFIX "${PYTHON_MODULE_PREFIX}")
if (VTK_INSTALL_PYTHON_USING_CMAKE)
# if setup.py is not being used to install python modules, we need to
# add install rules for them.
vtk_target_install(${name})
endif()
if (WIN32 AND NOT CYGWIN)
# when building shared on Windows, the python module files need to be
# named as *.pyd
......
......@@ -97,12 +97,12 @@ function(VTK_CREATE_SIP_MODULE KIT WRAP_SRCS)
COMMAND ${CMAKE_COMMAND} -E copy "${lib_loc}" "${VTK_BINARY_DIR}/Wrapping/Python/vtk/"
)
IF(VTK_INSTALL_PYTHON_USING_CMAKE AND NOT VTK_INSTALL_NO_LIBRARIES)
IF(NOT VTK_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS vtk${KIT}PythonSIP
EXPORT ${VTK_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${VTK_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${VTK_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${VTK_INSTALL_ARCHIVE_DIR} COMPONENT Development)
ENDIF(VTK_INSTALL_PYTHON_USING_CMAKE AND NOT VTK_INSTALL_NO_LIBRARIES)
ENDIF(NOT VTK_INSTALL_NO_LIBRARIES)
ENDIF(NOT SIP_EXECUTABLE)
endfunction(VTK_CREATE_SIP_MODULE)
......@@ -272,107 +272,36 @@ if(PYTHON_EXECUTABLE)
set(VTK_INSTALL_NO_PYTHON 1)
endif()
# If set (generally by projects that include VTK), we install the
# 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)
# Install python module directory (*.py and *.pyd)
if (NOT VTK_INSTALL_NO_PYTHON)
set(pymodule_instdir
"${VTK_INSTALL_LIBRARY_DIR}/python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}/site-packages")
# Install python modules (.py and *.pyd)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/vtk"
DESTINATION "${VTK_INSTALL_RUNTIME_DIR}/Python" COMPONENT RuntimeLibraries
DESTINATION ${pymodule_instdir} COMPONENT RuntimeLibraries
USE_SOURCE_PERMISSIONS)
endif()
# Add a rule to use python distutils to install the python wrappers.
if(NOT VTK_INSTALL_NO_PYTHON)
set(DOLLAR "$")
# Create default python setup arguments if they are not set.
if(NOT DEFINED VTK_PYTHON_SETUP_ARGS)
set(VTK_PYTHON_SETUP_ARGS "--prefix=\"${DOLLAR}{CMAKE_INSTALL_PREFIX}\""
CACHE STRING "Arguments passed to \"python setup.py install ...\" during installation.")
mark_as_advanced(VTK_PYTHON_SETUP_ARGS)
# Install python extension library behind the modules (.dll,.lib,.so)
if (BUILD_SHARED_LIBS AND NOT VTK_INSTALL_NO_LIBRARIES)
foreach(module ${VTK_PYTHON_MODULES})
install(TARGETS ${module}Python
EXPORT ${VTK_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${VTK_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${pymodule_instdir}/vtk COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${VTK_INSTALL_ARCHIVE_DIR} COMPONENT Development
)
endforeach()
endif()
# Change dollar sign to DOLLARSIGN
string(REGEX REPLACE "\\${DOLLAR}" "DOLLARSIGN"
PYTHON_SETUP_ARGS "${VTK_PYTHON_SETUP_ARGS}")
# Get the install path for python modules
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
"setup_install_paths.py" "purelib" ${PYTHON_SETUP_ARGS}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE PYTHON_MODULE_INSTALL_DIR)
# Get the install path for binary python modules
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
"setup_install_paths.py" "platlib" ${PYTHON_SETUP_ARGS}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE PYTHON_MODULE_PLATFORM_INSTALL_DIR)
# Change DOLLARSIGN to dollar sign
string(REGEX REPLACE "DOLLARSIGN" "${DOLLAR}"
PYTHON_MODULE_INSTALL_DIR "${PYTHON_MODULE_INSTALL_DIR}")
string(REGEX REPLACE "DOLLARSIGN" "${DOLLAR}"
PYTHON_MODULE_PLATFORM_INSTALL_DIR
"${PYTHON_MODULE_PLATFORM_INSTALL_DIR}")
# Replace backslashes with forward slashes
if(WIN32)
string(REGEX REPLACE "\\\\" "/" PYTHON_MODULE_INSTALL_DIR
"${PYTHON_MODULE_INSTALL_DIR}")
string(REGEX REPLACE "\\\\" "/" PYTHON_MODULE_PLATFORM_INSTALL_DIR
"${PYTHON_MODULE_PLATFORM_INSTALL_DIR}")
endif()
set(VTK_PYTHON_MODULE_INSTALL_DIR "${PYTHON_MODULE_INSTALL_DIR}"
CACHE INTERNAL "Install directory for Python .py and .pyc files")
set(VTK_PYTHON_MODULE_PLATFORM_INSTALL_DIR
"${PYTHON_MODULE_PLATFORM_INSTALL_DIR}"
CACHE INTERNAL "Install directory for Python binary modules")
# Install the vtkpython executable
install(TARGETS vtkpython ${VTKPYTHON_EXECUTABLE}
DESTINATION ${VTK_INSTALL_RUNTIME_DIR})
# 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()
set(VTK_PYTHON_SETUP_BUILD_TYPE)
if(PVTKPYTHON_EXECUTABLE)
# Install the mpi enabled vtkpython executable
install(TARGETS pvtkpython ${PVTKPYTHON_EXECUTABLE}
DESTINATION ${VTK_INSTALL_RUNTIME_DIR})
endif()
# Configure the post-install script to run python on setup.py.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PythonInstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/PythonInstall.cmake
@ONLY)
install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/PythonInstall.cmake
COMPONENT RuntimeLibraries)
endif()
endif()
# 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()
set(VTK_PYTHON_BUILD_TYPE "[]")
endif()
else()
# 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()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
${CMAKE_CURRENT_BINARY_DIR}/setup.py @ONLY)
if(NOT VTK_INSTALL_NO_RUNTIME AND NOT VTK_INSTALL_NO_PYTHON)
install(TARGETS vtkpython ${VTKPYTHON_EXECUTABLE}
DESTINATION ${VTK_INSTALL_RUNTIME_DIR})
endif()
\ No newline at end of file
#!/usr/bin/env python
"""
setup.py for installing the VTK-Python bindings using distutils.
Created by Prabhu Ramachandran, June 2002.
Updated for install with configuration types by Brad King, August 2005.
"""
import sys
import string
import os
import os.path
from types import StringType
from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.sysconfig import get_config_var
# Support for Python Eggs:
# http://peak.telecommunity.com/DevCenter/PythonEggs
# http://peak.telecommunity.com/DevCenter/EasyInstall
has_setup_tools = 0
try:
from setuptools import setup
except ImportError:
pass
else:
has_setup_tools = 1
# VTK build configuration settings.
vtk_version = "@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@"
vtk_lib_dir = "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@"
vtk_bin_dir = "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"
vtk_has_configuration_types = @VTK_PYTHON_HAS_CONFIG_TYPES@
vtk_modules = """@VTK_PYTHON_MODULES@""".split(';')
# The build type ('Release', 'Debug' etc.). If vtk_has_configuration_types
# is true this must be set. It may be set on the command line by something
# like 'BUILD_TYPE=Release'. For example::
# python setup.py install --prefix=D:\\Python23 BUILD_TYPE=Release
vtk_build_type = @VTK_PYTHON_BUILD_TYPE@
# Construct the list of executable names to be installed.
vtk_exe_names = ['vtkpython']
def get_libs():
"""Returns a list of libraries to be installed. """
libs = []
# Select platform-specific components of the module file names.
if os.name == 'posix':
dir = vtk_lib_dir
suffix = get_config_var('SO')
else:
dir = vtk_bin_dir.replace('/', '\\')
suffix = '.pyd'
# If this build has configuration types append the selected configuration.
if vtk_has_configuration_types:
dir = os.path.join(dir, vtk_build_type)
# Enumerate the list of module files.
for mod in vtk_modules:
libs.append(os.path.abspath(os.path.join(dir, mod+'Python'+suffix)))
return libs
def get_scripts():
"""Returns the appropriate vtkpython executable and pvtkpython
that is to be installed."""
scripts = []
# Select platform-specific components of the executable file names.
if os.name == 'posix':
dir = vtk_lib_dir
suffix = ''
else:
dir = vtk_bin_dir.replace('/', '\\')
suffix = '.exe'
# If this build has configuration types append the selected configuration.
if vtk_has_configuration_types:
dir = os.path.join(dir, vtk_build_type)
# Enumerate the list of executable files.
for exe in vtk_exe_names:
scripts.append(os.path.abspath(os.path.join(dir, exe+suffix)))
return scripts
class my_install_data (install_data):
def finalize_options (self):
"""Needed to make this thing work properly."""
self.set_undefined_options ('install',
('install_lib', 'install_dir'),
('root', 'root'),
('force', 'force'),
)
if __name__ == '__main__':
# Get the optional build type argument.
for x in sys.argv[:]:
if string.find(x, 'BUILD_TYPE') > -1:
vtk_build_type = string.strip(string.split(x, '=')[1])
sys.argv.remove(x)
break
# Make sure a build type was specified if it is required.
if vtk_has_configuration_types:
if not vtk_build_type:
raise "ERROR: Must specify BUILD_TYPE=<config-name> on command line."
def mk_dict(**kw):
# Unnecessary in recent Pythons but handy for earlier
# versions.
return kw
# The options for setup.
opts = mk_dict(name = "VTK",
version = vtk_version,
description = "The Visualization Toolkit",
maintainer = "VTK Developers",
maintainer_email = "vtk-developers@vtk.org",
license = "BSD",
long_description = "A high level visualization library",
url = "http://www.vtk.org/",
platforms = ['Any'],
cmdclass = {'install_data': my_install_data},
packages = ['vtk', 'vtk.gtk', 'vtk.qt4',
'vtk.tk', 'vtk.util', 'vtk.wx',
'vtk.test'],
#scripts = get_scripts(),
data_files = [('vtk', get_libs())]
)
# If setup_tools is available, then add an extra option to disable
# creation of a ZIP file.
if has_setup_tools:
opts['zip_safe'] = 0
setup(**opts)
#!/bin/env python
"""
This script will return the paths that distutils will use for installing
a package. To use this script, execute it the same way that you would
execute setup.py, but instead of providing 'install' or 'build' as the
command, specify 'purelib' or 'platlib' and the corresponding path
will be printed. The 'purelib' command will print the install location
for .py files, while the 'platlib' command will print the install location
of binary modules (.so or .dll).
Written by David Gobbi, Feb 25, 2006.
"""
import string
import sys
import os
def get_install_path(command, *args):
"""Return the module install path, given the arguments that were
provided to setup.py. The paths that you can request are 'purelib'
for the .py installation directory and 'platlib' for the binary
module installation directory.
"""
# convert setup args into an option dictionary
options = {}
for arg in args:
if arg == '--':
break
if arg[0:2] == "--":
try:
option, value = string.split(arg,"=")
options[option] = value
except ValueError:
options[arg] = 1
# check for the prefix and exec_prefix
try:
prefix = options["--prefix"]
except KeyError:
prefix = None
try:
exec_prefix = options["--exec-prefix"]
except KeyError:
exec_prefix = prefix
# if prefix or exec_prefix aren't set, use default system values
if prefix == None:
prefix = sys.prefix
if exec_prefix == None:
exec_prefix = sys.exec_prefix
# replace backslashes with slashes
if os.name != 'posix':
prefix = string.replace(prefix, os.sep, "/")
exec_prefix = string.replace(exec_prefix, os.sep, "/")
# get rid of trailing separator
if prefix != "" and prefix[-1] == "/":
prefix = prefix[0:-1]
if exec_prefix != "" and exec_prefix[-1] == "/":
exec_prefix = exec_prefix[0:-1]
# check for "home" install scheme
try:
home = options["--home"]
if os.name != 'posix':
home = string.replace(home, os.sep, "/")
if home != "" and home[-1] == "/":
home = home[0:-1]
except KeyError:
home = None
# apply "home" install scheme, but not for Windows with python < 2.4
# (distutils didn't allow home scheme for windows until 2.4)
if home != None and not (os.name != 'posix' and sys.version < '2.4'):
purelib = home+'/lib/python'
platlib = home+'/lib/python'
scripts = home+'/bin'
data = home
elif os.name == 'posix':
ver = sys.version[0:3]
purelib = prefix+'/lib/python'+ver+'/site-packages'
platlib = exec_prefix+'/lib/python'+ver+'/site-packages'
scripts = prefix+'/bin'
data = prefix
elif sys.version < '2.2':
purelib = prefix
platlib = prefix
scripts = prefix+'/Scripts'
data = prefix
else:
purelib = prefix+'/Lib/site-packages'
platlib = prefix+'/Lib/site-packages'
scripts = prefix+'/Scripts'
data = prefix
# allow direct setting of install directories
try:
purelib = options["--install-purelib"]
except KeyError:
pass
try:
platlib = options["--install-platlib"]
except KeyError:
pass
try:
scripts = options["--install-scripts"]
except KeyError:
pass
try:
data = options["--install-data"]
except KeyError:
pass
# return the information that was asked for
if command == 'purelib':
return purelib
elif command == 'platlib':
return platlib
elif command == 'scripts':
return scripts
elif command == 'data':
return data
if __name__ == "__main__":
print apply(get_install_path, sys.argv[1:])
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