Documentation/4.0/Developers/Tutorials/ExternalModuleWriting

From Slicer Wiki
Revision as of 15:43, 14 May 2011 by Gregsharp (talk | contribs) (Created page with 'QtSlicer/Tutorials← This tutorial describes how to make a (Slicer4 / QT) loadable module that is compiled outside of the sli…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Documentation < 4.0 < Developers < Tutorials < ExternalModuleWriting

QtSlicer/Tutorials

This tutorial describes how to make a (Slicer4 / QT) loadable module that is compiled outside of the slicer build tree.

  • Create the skeleton code
 $ export SD=$HOME/build/slicer-4/Slicer4
 $ python ${SD}/Scripts/ModuleWizard.py \
      --template ${SD}/QTModules/ModuleTemplate \
      --target MY_MODULE_NAME \
      MY_MODULE_NAME
  • Set up your CMakeLists
    • Get FindSlicer.cmake
    • Detect Slicer and add your module subdirectory
 find_package (Slicer QUIET)
 if (SLICER_FOUND)
   include ("${Slicer_USE_FILE}")
   if (SLICER_IS_SLICER4)
     add_subdirectory (MY_MODULE_NAME)
   endif ()
 endif ()
  • You might need to undo some of Slicer's settings. If you don't think you need this, then you probably don't. It depends how complicated your project is. But if you need it, you can do something like this:
 if (Slicer_USE_FILE)
   get_directory_property (OLD_INCLUDE_DIR INCLUDE_DIRECTORIES)
   set_directory_properties (PROPERTIES INCLUDE_DIRECTORIES "")
   set (OLD_CFLAGS ${CMAKE_C_FLAGS})
   set (OLD_CXXFLAGS ${CMAKE_CXX_FLAGS})

   include ("${Slicer_USE_FILE}")

   get_directory_property (SLICER_INCLUDE_DIRS INCLUDE_DIRECTORIES)
   set_directory_properties (PROPERTIES INCLUDE_DIRECTORIES
     "${OLD_INCLUDE_DIR}")
   set (CMAKE_C_FLAGS "${OLD_CFLAGS}" CACHE STRING "CMake CXX Flags" FORCE)
   set (CMAKE_CXX_FLAGS "${OLD_CXXFLAGS}" CACHE STRING "CMake CXX Flags" FORCE)
 endif ()
  • You might need to copy over TestingMacros.h, it depends how you set up your include directories above.
 $ cp ${SD}/TestingMacros.h MY_MODULE_NAME
  • Compile your module. At this point, it will compile. You may see some warnings from CMake
CMake Warning at /home/gsharp/build/slicer-4/Slicer4/CMake/vtkMacroKitPythonWrap.cmake:86 (ADD_LIBRARY):
 Cannot generate a safe runtime search path for target
 vtkSlicerMY_MODULE_NAMEModuleLogicPython because files in some directories
 may conflict with libraries in implicit directories:

   runtime library [libpython2.6.so.1.0] in /usr/lib may be hidden by files in:
     /home/gsharp/build/slicer-4/Slicer4-Build/python-build/lib

 Some of these libraries may not be found correctly.
Call Stack (most recent call first):
 /home/gsharp/build/slicer-4/Slicer4/CMake/SlicerMacroPythonWrapModuleLibrary.cmake:66 (vtkMacroKitPythonWrap)
 /home/gsharp/build/slicer-4/Slicer4/CMake/SlicerMacroBuildModuleLogic.cmake:76 (SlicerMacroPythonWrapModuleLibrary)
 src/slicer/QTModules/MY_MODULE_NAME/Logic/CMakeLists.txt:28 (SlicerMacroBuildModuleLogic)

These warnings are benign. Anyone know how to turn them off?

  • The above setup will put the shared libraries directly into the slicer build directory. I guess this isn't what you want, but now is a good time to test that everything is working. Make sure the files are there.

On unix:

 $ cd ${SLICER_BUILD}/Slicer-build
 $ find . -name "*MY*" -print
 ./bin/MY_MODULE_NAMECxxTests
 ./bin/libvtkSlicerMY_MODULE_NAMEModuleLogicPythonD.so
 ./bin/vtkSlicerMY_MODULE_NAMEModuleLogicPython.so
 ./bin/Python/slicer/modulelogic/vtkSlicerMY_MODULE_NAMEModuleLogic.py
 ./bin/Python/slicer/modulelogic/vtkSlicerMY_MODULE_NAMEModuleLogic.pyc
 ./lib/Slicer3/QTLoadableModules/libvtkSlicerMY_MODULE_NAMEModuleLogic.so
 ./lib/Slicer3/QTLoadableModules/libqSlicerMY_MODULE_NAMEModule.so