Commit 34903fe1 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

Move the Python wrapping to the end

This moves the Python wrapping to the end of the build process, using
the information exported by the module files.

Change-Id: I711382f79fc1fdb15cd80c87f55dd2f97a2c5cd8
parent b2b77f1d
......@@ -201,6 +201,7 @@ function(vtk_module_export sources)
get_source_file_property(_wrap_exclude ${src} WRAP_EXCLUDE)
get_source_file_property(_abstract ${src} ABSTRACT)
get_source_file_property(_wrap_special ${src} WRAP_SPECIAL)
get_source_file_property(_wrap_header ${src} WRAP_HEADER)
if(_wrap_special OR NOT _wrap_exclude)
list(APPEND vtk-module-CLASSES ${_cls})
......@@ -219,6 +220,10 @@ function(vtk_module_export sources)
set(vtk-module-WRAP_SPECIAL
"${vtk-module-WRAP_SPECIAL}set(${vtk-module}_CLASS_${_cls}_WRAP_SPECIAL 1)\n")
endif()
if(_wrap_header)
set(vtk-module-WRAP_SPECIAL
"${vtk-module-WRAP_SPECIAL}set(${vtk-module}_CLASS_${_cls}_WRAP_HEADER 1)\n")
endif()
endif()
endif()
endif()
......
find_package(PythonLibs REQUIRED)
include(vtkWrapPython)
function(vtk_add_python_wrapping module_name module_srcs module_hdrs)
function(vtk_add_python_wrapping module_name)
if(NOT VTK_WRAP_PYTHON_INIT_EXE)
if (TARGET vtkWrapPythonInit)
if(TARGET vtkWrapPythonInit)
set (VTK_WRAP_PYTHON_INIT_EXE vtkWrapPythonInit)
else()
message(FATAL_ERROR "VTK must be built with Python wrapping turned on.")
......@@ -30,21 +30,13 @@ function(vtk_add_python_wrapping module_name module_srcs module_hdrs)
set(XY ${PYTHON_MAJOR_VERSION}${PYTHON_MINOR_VERSION})
# Figure out the dependent PythonXYD libraries for the module
foreach(dep ${${vtk-module}_LINK_DEPENDS})
if(NOT "${vtk-module}" STREQUAL "${dep}" AND TARGET ${dep}PythonD)
foreach(dep ${${module_name}_DEPENDS})
if(NOT "${module_name}" STREQUAL "${dep}" AND TARGET ${dep}PythonD)
list(APPEND extra_links ${dep}PythonD)
endif()
endforeach()
set(_wrap_files ${module_srcs})
foreach(hdr ${module_hdrs})
get_source_file_property(_wrap_header "${hdr}" WRAP_HEADER)
if(_wrap_header)
list(APPEND _wrap_files "${hdr}")
endif()
endforeach()
vtk_wrap_python3(${module_name}Python Python_SRCS "${_wrap_files}")
vtk_wrap_python(${module_name}Python Python_SRCS ${module_name})
vtk_add_library(${module_name}PythonD ${Python_SRCS} ${extra_srcs})
get_property(output_name TARGET ${module_name}PythonD PROPERTY OUTPUT_NAME)
string(REPLACE "PythonD" "Python${XY}D" output_name "${output_name}")
......
#
# a cmake implementation of the Wrap Python command
# CMake implementation of the Wrap Python command.
#
macro(VTK_WRAP_PYTHON2 TARGET SOURCE_LIST_NAME)
# convert to the WRAP3 signature
......@@ -198,3 +198,161 @@ if(VTK_WRAP_PYTHON_FIND_LIBS)
# Include any extra libraries for python.
set(VTK_PYTHON_LIBRARIES ${VTK_PYTHON_LIBRARIES} ${PYTHON_EXTRA_LIBS})
endif()
# Determine the location of the supplied header in the include_dirs supplied.
macro(vtk_find_header header include_dirs full_path)
unset(${full_path})
foreach(_dir ${include_dirs})
if(EXISTS "${_dir}/${header}")
set(${full_path} "${_dir}/${header}")
break()
endif()
endforeach()
endmacro()
# Macro that just takes the name of the module, figure the rest out from there.
macro(vtk_wrap_python TARGET SRC_LIST_NAME module)
if(NOT VTK_WRAP_PYTHON_INIT_EXE)
if(TARGET vtkWrapPythonInit)
set(VTK_WRAP_PYTHON_INIT_EXE vtkWrapPythonInit)
else()
message(SEND_ERROR
"VTK_WRAP_PYTHON_INIT_EXE not specified when calling VTK_WRAP_PYTHON3")
endif()
endif()
if(NOT VTK_WRAP_PYTHON_EXE)
if(TARGET vtkWrapPython)
set(VTK_WRAP_PYTHON_EXE vtkWrapPython)
else()
message(SEND_ERROR
"VTK_WRAP_PYTHON_EXE not specified when calling vtk_wrap_python")
endif()
endif()
# The shell into which nmake.exe executes the custom command has some issues
# with mixing quoted and unquoted arguments :( Let's help.
if(CMAKE_GENERATOR MATCHES "NMake Makefiles")
set(verbatim "")
set(quote "\"")
else()
set(verbatim "VERBATIM")
set(quote "")
endif()
# Initialize the custom target counter.
if(VTK_WRAP_PYTHON_NEED_CUSTOM_TARGETS)
set(VTK_WRAP_PYTHON_CUSTOM_COUNT "")
set(VTK_WRAP_PYTHON_CUSTOM_NAME ${TARGET})
set(VTK_WRAP_PYTHON_CUSTOM_LIST)
endif()
# start writing the input file for the init file
set(VTK_WRAPPER_INIT_DATA "${TARGET}")
# all the include directories
if(${module}_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${${module}_INCLUDE_DIRS})
elseif(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
endif()
# collect the common wrapper-tool arguments
set(_common_args)
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
if(VTK_WRAP_HINTS)
set(_common_args "${_common_args}--hints \"${VTK_WRAP_HINTS}\"\n")
endif()
if(KIT_HIERARCHY_FILE)
set(_common_args "${_common_args}--types \"${KIT_HIERARCHY_FILE}\"\n")
endif()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
# Decide what to do for each class.
foreach(class ${${module}_CLASSES})
# Everything in this block is for classes that will be wrapped.
if(${module}_CLASSES_${class}_WRAP_SPECIAL OR
NOT ${module}_CLASSES_${class}_WRAP_EXCLUDE)
# Find the full path to the header file to be wrapped.
vtk_find_header(${class}.h "${${module}_INCLUDE_DIRS}" class_header_path)
if(NOT class_header_path)
message(FATAL_ERROR "Could not find header for ${class}.")
endif()
# add the info to the init file
set(VTK_WRAPPER_INIT_DATA
"${VTK_WRAPPER_INIT_DATA}\n${class}")
# new source file is namePython.cxx, add to resulting list
set(${SRC_LIST_NAME} ${${SRC_LIST_NAME}} ${class}Python.cxx)
# add custom command to output
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${class}Python.cxx
DEPENDS ${VTK_WRAP_PYTHON_EXE} ${VTK_WRAP_HINTS} ${class_header_path}
${_args_file} ${KIT_HIERARCHY_FILE}
COMMAND ${VTK_WRAP_PYTHON_EXE}
ARGS
"${quote}@${_args_file}${quote}"
"-o" "${quote}${CMAKE_CURRENT_BINARY_DIR}/${class}Python.cxx${quote}"
"${quote}${class_header_path}${quote}"
COMMENT "Python Wrapping - generating ${class}Python.cxx"
${verbatim}
)
# Add this output to a custom target if needed.
if(VTK_WRAP_PYTHON_NEED_CUSTOM_TARGETS)
set(VTK_WRAP_PYTHON_CUSTOM_LIST ${VTK_WRAP_PYTHON_CUSTOM_LIST}
${CMAKE_CURRENT_BINARY_DIR}/${class}Python.cxx)
set(VTK_WRAP_PYTHON_CUSTOM_COUNT ${VTK_WRAP_PYTHON_CUSTOM_COUNT}x)
if(VTK_WRAP_PYTHON_CUSTOM_COUNT MATCHES "^${VTK_WRAP_PYTHON_CUSTOM_LIMIT}$")
set(VTK_WRAP_PYTHON_CUSTOM_NAME ${VTK_WRAP_PYTHON_CUSTOM_NAME}Hack)
add_custom_target(${VTK_WRAP_PYTHON_CUSTOM_NAME}
DEPENDS ${VTK_WRAP_PYTHON_CUSTOM_LIST})
set(KIT_PYTHON_DEPS ${VTK_WRAP_PYTHON_CUSTOM_NAME})
set(VTK_WRAP_PYTHON_CUSTOM_LIST)
set(VTK_WRAP_PYTHON_CUSTOM_COUNT)
endif()
endif()
else()
message("${class} will not be wrapped.")
endif()
endforeach()
# finish the data file for the init file
configure_file(
${VTK_CMAKE_DIR}/vtkWrapperInit.data.in
${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data
COPY_ONLY
IMMEDIATE
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.cxx
DEPENDS ${VTK_WRAP_PYTHON_INIT_EXE}
${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data
COMMAND ${VTK_WRAP_PYTHON_INIT_EXE}
ARGS
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data${quote}"
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.cxx${quote}"
COMMENT "Python Wrapping - generating ${TARGET}Init.cxx"
${verbatim}
)
# Create the Init File
set(${SRC_LIST_NAME} ${${SRC_LIST_NAME}} ${TARGET}Init.cxx)
endmacro()
......@@ -4,7 +4,7 @@
# First, ensure we include the correct CMake code so that we can wrap.
if(VTK_WRAP_PYTHON)
include(vtkPythonWrapping)
# include(vtkPythonWrapping)
endif()
if(VTK_WRAP_TCL)
include(vtkTclWrapping)
......@@ -54,11 +54,9 @@ function(vtk_add_wrapping module_name module_srcs module_hdrs)
endif()
# Now to wrap the languages that are on.
if(VTK_WRAP_PYTHON)
if (${module_name}_WRAP_PYTHON)
set_property(GLOBAL APPEND PROPERTY VTK_PYTHON_WRAPPED ${module_name})
vtk_add_python_wrapping(${module_name} "${module_srcs}" "${module_hdrs}")
endif()
if(VTK_WRAP_PYTHON AND ${module_name}_WRAP_PYTHON)
# Note that the module should be Python wrapped.
set_property(GLOBAL APPEND PROPERTY VTK_PYTHON_WRAPPED ${module_name})
endif()
if(VTK_WRAP_TCL)
set_property(GLOBAL APPEND PROPERTY VTK_TCL_WRAPPED ${module_name})
......
......@@ -354,9 +354,14 @@ find_program(VTK_GHOSTSCRIPT_EXECUTABLE gs gswin32c gsos2)
mark_as_advanced(VTK_GHOSTSCRIPT_EXECUTABLE)
#----------------------------------------------------------------------
# Load the module DAG.
# Load the module DAG, assess all modules etc.
include(vtkModuleTop)
# Now build the Python wrapping if necessary.
if(VTK_WRAP_PYTHON)
add_subdirectory(Wrapping/Python)
endif()
if(BUILD_TESTING)
add_subdirectory(Testing/Install)
endif()
......
......@@ -444,6 +444,46 @@ set_source_files_properties(
vtkSparseArray.h
vtkTypedArray.h
vtkTypeTemplate.h
vtkABI.h
vtkArrayInterpolate.h
vtkArrayInterpolate.txx
vtkArrayIteratorIncludes.h
vtkArrayIteratorTemplate.h
vtkArrayIteratorTemplate.txx
vtkArrayIteratorTemplateImplicit.txx
vtkArrayPrint.h
vtkArrayPrint.txx
vtkAutoInit.h
vtkDataArrayTemplate.txx
vtkDataArrayTemplateImplicit.txx
vtkDenseArray.txx
vtkIOStreamFwd.h
vtkInformationInternals.h
vtkMathUtilities.h
vtkNew.h
vtkSetGet.h
vtkSmartPointer.h
vtkSparseArray.txx
vtkTemplateAliasMacro.h
vtkTypeTraits.h
vtkTypedArray.txx
vtkVariantCast.h
vtkVariantCreate.h
vtkVariantExtract.h
vtkVariantInlineOperators.h
vtkWeakPointer.h
vtkWin32Header.h
vtkWindows.h
vtkToolkits.h
# We need to get these wrapped, WRAP_SPECIAL? WRAP_HEADER does not seem to be used.
#vtkSystemIncludes.h
#vtkType.h
#vtkConfigure.h
#vtkMathConfigure.h
#vtkVersionMacros.h
WRAP_EXCLUDE
)
......@@ -482,7 +522,7 @@ if(CMAKE_SYSTEM MATCHES "SunOS.*")
set(KIT_LIBS ${KIT_LIBS} socket nsl)
endif()
vtk_module_library(vtkCommonCore ${Module_SRCS})
vtk_module_library(vtkCommonCore ${Module_SRCS} ${${vtk-module}_HDRS})
target_link_libraries(vtkCommonCore ${CMAKE_THREAD_LIBS_INIT})
set_target_properties(vtkCommonCore PROPERTIES LINK_INTERFACE_LIBRARIES "")
......@@ -177,6 +177,7 @@ set(Module_SRCS
vtkBond.cxx
vtkMolecule.cxx
vtkAbstractElectronicData.cxx
vtkCellType.h
# Header only classes
vtkDataArrayDispatcher.h
......@@ -244,6 +245,7 @@ set_source_files_properties(
vtkAtom
vtkBond
vtkBoundingBox
vtkCellType
vtkDataArrayDispatcher
vtkDispatcher_Private
vtkDispatcher
......
This diff is collapsed.
#! /bin/env python
#!/bin/env python
"""
This script will return the paths that distutils will use for installing
......
/* This file has been replaced by vtkPythonAppInit and vtkParaPythonAppInit. */
include(GenerateExportHeader)
include(vtkPythonWrapping)
set(Module_SRCS
vtkPythonArgs.cxx
vtkPythonCommand.cxx
vtkPythonOverload.cxx
vtkPythonUtil.cxx
PyVTKClass.cxx
PyVTKMutableObject.cxx
PyVTKObject.cxx
PyVTKSpecialObject.cxx
PyVTKTemplate.cxx
)
set(Module_HDRS
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}Module.h
)
list(APPEND Module_SRCS ${Module_HDRS})
set_source_files_properties(
${Module_HDRS}
HEADER_FILE_ONLY
)
include_directories(
${VTK_SOURCE_DIR}/Utilities
)
# SIP directory will be searched before other python dirs
set(PYTHON_WRAPPING_INCLUDE_DIRS)
if(VTK_WRAP_PYTHON_SIP)
list(APPEND PYTHON_WRAPPING_INCLUDE_DIRS "${SIP_INCLUDE_DIR}")
endif()
set(${vtk-module}_SYSTEM_INCLUDE_DIRS ${PYTHON_WRAPPING_INCLUDE_DIRS})
set(${vtk-module}_NO_HeaderTest 1)
set(${vtk-module}_INCLUDE_DIRS)
set(XY ${PYTHON_MAJOR_VERSION}${PYTHON_MINOR_VERSION})
vtk_module_library(${vtk-module} ${Module_SRCS})
get_property(output_name TARGET ${vtk-module} PROPERTY OUTPUT_NAME)
string(REPLACE "Python" "Python${XY}" output_name "${output_name}")
set_property(TARGET ${vtk-module} PROPERTY OUTPUT_NAME ${output_name})
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