Commit b94049f6 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Clean Python related CMake variables.

This change removes `VTK_INSTALL_PYTHON_MODULE_DIR` and
`VTK_BUILD_PYTHON_MODULE_DIR` cmake variables. These were cache
variabels and they were force set using Python version number the first
time CMake was run. This has the issue of leaving an obsolete value if
Python version was changed in CMake config after the first cmake pass.

Secondly, the two variables complicated module path setup logic since
build and install directory structure for Python modules could
potentially be different.

Simplified this as follows:

`VTK_PYTHON_SITE_PACKAGES_SUFFIX` is a new CMake variable available
for users to set to the "site-packges" suffix to use for build and
install trees. This is non-cache variable and hence we we update it
when Python version is changed in subsequent cmake configurations
without issues (unless explicitly overridden).

The build and install directories for Python modules are set as
`${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}`,
`${VTK_INSTALL_LIBRARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}`
respectively. Thus, we are assured that build and install tree
structures won't differ. `VTK_BUILD_PYTHON_MODULES_DIR` and
`VTK_INSTALL_PYTHON_MODULES_DIR` internal cache variable are available
as shortcuts for these two paths, but we may purge them in future.
parent 867d93c2
......@@ -22,11 +22,11 @@ include(vtkPythonPackages)
# VTK/Web/Python/CMakeLists.txt for usage).
# )
# Uses following global variables:
# VTK_BUILD_PYTHON_MODULE_DIR :- location where the entire package will be
# VTK_BUILD_PYTHON_MODULES_DIR :- location where the entire package will be
# copied and built. Thus, for the above example we'd get a
# ${VTK_BUILD_PYTHON_MODULE_DIR}/autobahn package.
# ${VTK_BUILD_PYTHON_MODULES_DIR}/autobahn package.
#
# VTK_INSTALL_PYTHON_MODULE_DIR :- location where the entire package will be
# VTK_INSTALL_PYTHON_MODULES_DIR :- location where the entire package will be
# installed if NO_INSTALL is not provided.
#
# VTK_INSTALL_NO_RUNTIME :- install rules are skipped if set.
......@@ -92,15 +92,15 @@ function(vtk_python_package name)
if (NOT _use_system)
# copy the sources *.py files to build directory.
copy_files_recursive("${_dir}"
DESTINATION "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_target}"
DESTINATION "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_target}"
LABEL "Copying files for Python package '${_name}'"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name}.copy-complete"
REGEX "^(.*\\.py)$"
)
add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} -m compileall "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_target}"
COMMAND ${PYTHON_EXECUTABLE} -O -m compileall "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_target}"
COMMAND ${PYTHON_EXECUTABLE} -m compileall "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_target}"
COMMAND ${PYTHON_EXECUTABLE} -O -m compileall "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_target}"
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${_name}.build-complete"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_name}.copy-complete"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name}.build-complete"
......@@ -112,8 +112,8 @@ function(vtk_python_package name)
# add install rules.
if (NOT _no_install AND NOT VTK_INSTALL_NO_RUNTIME)
install(DIRECTORY "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_target}/"
DESTINATION "${VTK_INSTALL_PYTHON_MODULE_DIR}/${_name_target}"
install(DIRECTORY "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_target}/"
DESTINATION "${VTK_INSTALL_PYTHON_MODULES_DIR}/${_name_target}"
COMPONENT "Runtime")
endif()
endif() # NOT _use_system
......@@ -138,11 +138,11 @@ endfunction()
# # system module.
#
# Uses following global variables:
# VTK_BUILD_PYTHON_MODULE_DIR :- location where the entire package will be
# VTK_BUILD_PYTHON_MODULES_DIR :- location where the entire package will be
# copied and built. Thus, for the above example we'd get a
# ${VTK_BUILD_PYTHON_MODULE_DIR}/autobahn package.
# ${VTK_BUILD_PYTHON_MODULES_DIR}/autobahn package.
#
# VTK_INSTALL_PYTHON_MODULE_DIR :- location where the entire package will be
# VTK_INSTALL_PYTHON_MODULES_DIR :- location where the entire package will be
# installed if NO_INSTALL is not provided.
#
# VTK_INSTALL_NO_RUNTIME :- install rules are skipped if set.
......@@ -187,9 +187,9 @@ function (vtk_module_python_module name)
if (NOT _use_system)
# copy the *.py file to the build directory and compile it.
add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy ${_module} ${VTK_BUILD_PYTHON_MODULE_DIR}/${_name}
COMMAND ${PYTHON_EXECUTABLE} -m py_compile ${VTK_BUILD_PYTHON_MODULE_DIR}/${_name}
COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile ${VTK_BUILD_PYTHON_MODULE_DIR}/${_name}
COMMAND ${CMAKE_COMMAND} -E copy ${_module} ${VTK_BUILD_PYTHON_MODULES_DIR}/${_name}
COMMAND ${PYTHON_EXECUTABLE} -m py_compile ${VTK_BUILD_PYTHON_MODULES_DIR}/${_name}
COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile ${VTK_BUILD_PYTHON_MODULES_DIR}/${_name}
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${_name_we}.build-complete"
DEPENDS ${_module}
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name_we}.build-complete"
......@@ -202,19 +202,19 @@ function (vtk_module_python_module name)
# add install rules.
if (NOT _no_install AND NOT VTK_INSTALL_NO_RUNTIME)
if(VTK_PYTHON_VERSION VERSION_LESS 3)
install(FILES "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name}"
"${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_we}.pyc"
"${VTK_BUILD_PYTHON_MODULE_DIR}/${_name_we}.pyo"
DESTINATION "${VTK_INSTALL_PYTHON_MODULE_DIR}"
install(FILES "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name}"
"${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_we}.pyc"
"${VTK_BUILD_PYTHON_MODULES_DIR}/${_name_we}.pyo"
DESTINATION "${VTK_INSTALL_PYTHON_MODULES_DIR}"
COMPONENT "Runtime")
else()
# python 3 uses a different directory for .pyc files, and .pyo files are gone.
install(FILES "${VTK_BUILD_PYTHON_MODULE_DIR}/${_name}"
DESTINATION "${VTK_INSTALL_PYTHON_MODULE_DIR}"
install(FILES "${VTK_BUILD_PYTHON_MODULES_DIR}/${_name}"
DESTINATION "${VTK_INSTALL_PYTHON_MODULES_DIR}"
COMPONENT "Runtime")
file(GLOB file_matches "${VTK_BUILD_PYTHON_MODULE_DIR}/__pycache__/${_name_we}.*.pyc")
file(GLOB file_matches "${VTK_BUILD_PYTHON_MODULES_DIR}/__pycache__/${_name_we}.*.pyc")
install(FILES ${file_matches}
DESTINATION "${VTK_INSTALL_PYTHON_MODULE_DIR}/__pycache__"
DESTINATION "${VTK_INSTALL_PYTHON_MODULES_DIR}/__pycache__"
COMPONENT "Runtime")
endif()
endif()
......
......@@ -165,13 +165,13 @@ 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.
# build python module libraries under the ${VTK_BUILD_PYTHON_MODULES_DIR} dir.
set_target_properties(${name}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${VTK_BUILD_PYTHON_MODULE_DIR}/vtk)
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${VTK_BUILD_PYTHON_MODULES_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
RUNTIME DESTINATION ${VTK_INSTALL_PYTHON_MODULES_DIR}/vtk
LIBRARY DESTINATION ${VTK_INSTALL_PYTHON_MODULES_DIR}/vtk
ARCHIVE DESTINATION ${VTK_INSTALL_ARCHIVE_DIR}
)
endif()
......
......@@ -93,7 +93,7 @@ function(VTK_CREATE_SIP_MODULE KIT WRAP_SRCS)
TARGET_LINK_LIBRARIES(vtk${KIT}PythonSIP vtk${KIT}PythonD)
get_target_property(lib_loc vtk${KIT}PythonSIP LOCATION)
ADD_CUSTOM_COMMAND(TARGET vtk${KIT}PythonSIP POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${lib_loc}" "${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/"
COMMAND ${CMAKE_COMMAND} -E copy "${lib_loc}" "${VTK_BUILD_PYTHON_MODULES_DIR}/vtk/"
)
IF(NOT VTK_INSTALL_NO_LIBRARIES)
......
......@@ -231,16 +231,18 @@ endif()
if(NOT VTK_WWW_DIR)
set(VTK_WWW_DIR "${VTK_BINARY_DIR}/www")
endif()
if(NOT VTK_INSTALL_PYTHON_MODULE_DIR)
set (VTK_INSTALL_PYTHON_MODULE_DIR "-NOTFOUND" CACHE
PATH "Directory where python modules will be installed")
mark_as_advanced(VTK_INSTALL_PYTHON_MODULE_DIR)
if(DEFINED VTK_INSTALL_PYTHON_MODULE_DIR)
message(WARNING
"VTK_INSTALL_PYTHON_MODULE_DIR is no longer supported. "
"Set `VTK_PYTHON_SITE_PACKAGES_SUFFIX` instead, although not needed in most cases.")
endif()
if(NOT VTK_BUILD_PYTHON_MODULE_DIR)
set (VTK_BUILD_PYTHON_MODULE_DIR "-NOTFOUND" CACHE
PATH "Directory where python modules will be put inside the build tree")
mark_as_advanced(VTK_BUILD_PYTHON_MODULE_DIR)
if(DEFINED VTK_BUILD_PYTHON_MODULE_DIR)
message(WARNING
"VTK_BUILD_PYTHON_MODULE_DIR is no longer supported. "
"Set `VTK_PYTHON_SITE_PACKAGES_SUFFIX` instead, although not needed in most cases.")
endif()
# Full functional CMAKE_CROSSCOMPILING_EMULATOR support for custom_command and
# custom_target is available in CMake 3.8.0
# It was first added in CMake 3.6.0 and later fixed in CMake 3.8.0 (commit e7480d67, CMake issue #16288)
......
......@@ -36,8 +36,8 @@ mark_as_advanced(VTK_USE_SYSTEM_MPI4PY)
if (NOT VTK_USE_SYSTEM_MPI4PY)
# Configure mpi4py.
set (MPI4PY_INSTALL_PACKAGE_DIR "${VTK_INSTALL_PYTHON_MODULE_DIR}")
set (MPI4PY_PACKAGE_BINARY_DIR "${VTK_BUILD_PYTHON_MODULE_DIR}")
set (MPI4PY_INSTALL_PACKAGE_DIR "${VTK_INSTALL_PYTHON_MODULES_DIR}")
set (MPI4PY_PACKAGE_BINARY_DIR "${VTK_BUILD_PYTHON_MODULES_DIR}")
# Block warnings unless we are instructed to allow them.
# SET(VTKMPI4PY_WARNINGS_ALLOW 1)
......
......@@ -27,41 +27,36 @@ 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)
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)
if(NOT VTK_PYTHON_SITE_PACKAGES_SUFFIX)
if(WIN32 AND NOT CYGWIN)
set(VTK_PYTHON_SITE_PACKAGES_SUFFIX "Lib/site-packages")
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)
set(VTK_PYTHON_SITE_PACKAGES_SUFFIX
"python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}/site-packages")
endif()
endif()
if (NOT 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()
set(VTK_BUILD_PYTHON_MODULES_DIR
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}"
CACHE INTERNAL "Directory where python modules will be built")
if(WIN32 AND NOT CYGWIN)
set(VTK_INSTALL_PYTHON_MODULES_DIR
"${VTK_INSTALL_LIBRARY_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}"
CACHE INTERNAL "Directory where python modules will be installed")
else()
set(VTK_INSTALL_PYTHON_MODULES_DIR
"${VTK_INSTALL_RUNTIME_DIR}/${VTK_PYTHON_SITE_PACKAGES_SUFFIX}"
CACHE INTERNAL "Directory where python modules will be installed")
endif()
# Export location of python module dirs in install and build tree for for
# projects that link against VTK
set(${vtk-module}_EXPORT_CODE_BUILD "set(VTK_PYTHONPATH \"${VTK_BUILD_PYTHON_MODULE_DIR}\")")
if(IS_ABSOLUTE ${VTK_INSTALL_PYTHON_MODULE_DIR})
set(${vtk-module}_EXPORT_CODE_INSTALL "set(VTK_PYTHONPATH \"${VTK_INSTALL_PYTHON_MODULE_DIR}\")")
set(${vtk-module}_EXPORT_CODE_BUILD "set(VTK_PYTHONPATH \"${VTK_BUILD_PYTHON_MODULES_DIR}\")")
if(IS_ABSOLUTE ${VTK_INSTALL_PYTHON_MODULES_DIR})
set(${vtk-module}_EXPORT_CODE_INSTALL "set(VTK_PYTHONPATH \"${VTK_INSTALL_PYTHON_MODULES_DIR}\")")
else()
set(${vtk-module}_EXPORT_CODE_INSTALL "set(VTK_PYTHONPATH \"${CMAKE_INSTALL_PREFIX}/${VTK_INSTALL_PYTHON_MODULE_DIR}\")")
set(${vtk-module}_EXPORT_CODE_INSTALL "set(VTK_PYTHONPATH \"${CMAKE_INSTALL_PREFIX}/${VTK_INSTALL_PYTHON_MODULES_DIR}\")")
endif()
vtk_module_export_info()
......
......@@ -287,17 +287,17 @@ if(PYTHON_EXECUTABLE)
set(VTK_PYTHON_IMPORT_ALL
"${VTK_PYTHON_IMPORT_ALL}from .${module} import *\n")
configure_file(vtk/module.py.in
"${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/${module}.py" @ONLY)
"${VTK_BUILD_PYTHON_MODULES_DIR}/vtk/${module}.py" @ONLY)
endforeach()
configure_file(vtk/__init__.py.in
"${VTK_BUILD_PYTHON_MODULE_DIR}/vtk/__init__.py" @ONLY)
"${VTK_BUILD_PYTHON_MODULES_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_BUILD_PYTHON_MODULE_DIR}/vtk/${dep}.py" @ONLY)
"${VTK_BUILD_PYTHON_MODULES_DIR}/vtk/${dep}.py" @ONLY)
endforeach()
unset(_module_kit)
endforeach()
......
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