[vtkusers] CMake custom class python wrapping doesn't work

Jean-Christophe Fillion-Robin jcfr at kitware.com
Mon Oct 15 01:11:06 EDT 2018


Hi Evgeniya,

Based on my understanding, wrapping of custom classes without (1) creating
an external VTK module or (2) using the VTK build system (like Paraview
does) is not supported.

If possible, I suggest you re-organize your code to create a VTK external
module. That you will be able to use the VTK CMake API by including the
vtkExternalmoduleMacros.
For example, see
https://github.com/Kitware/VTK/blob/master/Rendering/OpenVR/CMakeLists.txt
(while this module can be built both as a built-in module and an external
module, it illustrates the idea)



If not possible, you need to make sure the python hierarchy files are
generated.
Here is a module we maintain in Slicer that enable this. It provides a
macro named "vtkMacroKitPythonWrap"
See
https://github.com/Slicer/Slicer/blob/master/CMake/vtkMacroKitPythonWrap.cmake

Here is an example of usage:

 include(vtkMacroKitPythonWrap)

  vtkMacroKitPythonWrap(
    KIT_NAME vtkFoo
    KIT_SRCS ${vtkFoo_SRCS}
  )


Hth
Jc

On Mon, Oct 15, 2018 at 12:48 AM Evgeniya Malikova <evgenimalikova at gmail.com>
wrote:

> Hello.
> I have a common wrapping that previously worked on windows 8.1 with
> VTK 8.1.1.  As I had problems to compile vtk8 on Mac (don't remember
> all details of that) I switched to
> https://gitlab.kitware.com/vtk/vtk.git.
>
> With following settings compilation on Mac of custom class gives a
> strange error, referencing some hierarchy file:
>
> [ 85%] Built target vtkHF
>
> make[5]: *** No rule to make target
> `../../hf/pythonClasses/vtkHFHierarchy', needed by
> `hf/pythonClasses/vtkHFFunctionPython.cxx'.  Stop.
>
> make[4]: *** [hf/pythonClasses/CMakeFiles/vtkHFPythonD.dir/all] Error 2
>
> make[3]: *** [all] Error 2
>
> make[2]: *** [hfvisual-prefix/src/hfvisual-stamp/hfvisual-build] Error 2
>
> make[1]: *** [CMakeFiles/hfvisual.dir/all] Error 2
>
> make: *** [all] Error 2
>
> //-------------
>
> My CMakeLists:
>
>
> find_package(VTK REQUIRED
>                  vtkCommonCore
>                  vtkCommonDataModel
>                  vtkCommonExecutionModel
>                  vtkImagingHybrid
>                  vtkImagingCore
>                  vtkImagingStencil
>                  vtkImagingGeneral
>                  vtkFiltersCore
>                  vtkRenderingCore
>                  vtkWrappingPythonCore
>
>              )
>  include(${VTK_USE_FILE})
>
>  # Python and vtk wrapping
>   find_package(PythonInterp REQUIRED)
>   find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
>   set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
>  include(vtkWrapPython)
>  include_directories("${PYTHON_INCLUDE_PATH}")
>
>
>   set (OPENAL_INCLUDE_DIR ${INSTALL_DEPENDENCIES_DIR}/include/AL)
>
>   LINK_DIRECTORIES(${INSTALL_DEPENDENCIES_DIR}/lib/)
> set(CMAKE_MACOSX_RPATH 1)
>
> set (openAL OpenAL32)
>  if( APPLE )
>   set (openAL OpenAL)
> endif()
>
>   set (OPENAL_LIBRARY} ${INSTALL_DEPENDENCIES_DIR}/lib/${openAL})
>    set (ALUT_LIBRARY} ${INSTALL_DEPENDENCIES_DIR}/lib/alut)
>   include_directories(${OPENAL_INCLUDE_DIR})
>   include_directories(${INSTALL_DEPENDENCIES_DIR}/include)
>
>
>  #######################################
>  # Building vtkHFFunction
> list(APPEND libraries_list  cppinterpreter)
> ....
>
>  add_library(vtkHF SHARED ${WRAP_LIST})
>
>  # Build main library
>  TARGET_LINK_LIBRARIES(vtkHF ${VTK_LIBRARIES} alut ${openAL}
> ${libraries_list})
> if(APPLE)
>   set_target_properties(vtkHF PROPERTIES SUFFIX ".so")
> endif()
>
> set(vtkHFPython_EXCLUDE_FROM_WRAP_HIERARCHY 1)
> # Python wrapping
>
> include_directories("${PYTHON_INCLUDE_PATH}")
>
>
>  #include_directories(${PythonVTKLibs_SOURCE_DIR})
>  #######################################
>  # Wrapping
>
>  vtk_wrap_python3(vtkHFPython KitPython_SRCS "${WRAP_LIST}")
>  add_library(vtkHFPythonD ${KitPython_SRCS} ${WRAP_LIST} )
>
>
>  IF(KIT_PYTHON_DEPS)
>   ADD_DEPENDENCIES(vtkHFPythonD ${KIT_PYTHON_DEPS} ${VTK_PYTHON_LIBRARIES})
> ENDIF(KIT_PYTHON_DEPS)
>
> #Here happens error
>  python_add_module(vtkHFPython vtkHFPythonInit.cxx)
>
>
> What I do wrong?
> Thank you in advance,
> Best regards, Evgeniya
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181015/914b95c5/attachment.html>


More information about the vtkusers mailing list