Difference between revisions of "Documentation/4.0/Developers/Tutorials/ExternalModuleWriting"
From Slicer Wiki
m |
(Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887) |
||
Line 1: | Line 1: | ||
+ | <noinclude>{{documentation/versioncheck}}</noinclude> | ||
Back to [[Documentation/{{documentation/version}}/Developers|Developers Information]]← | Back to [[Documentation/{{documentation/version}}/Developers|Developers Information]]← | ||
Latest revision as of 07:29, 14 June 2013
Home < Documentation < 4.0 < Developers < Tutorials < ExternalModuleWriting
For the latest Slicer documentation, visit the read-the-docs. |
Back to Developers Information←
This tutorial describes how to make a (Slicer4 / QT) loadable module that is compiled outside of the slicer build tree.
Consider also reading:
- Create the skeleton code using the module wizard
$ export SD=$HOME/build/slicer-4/Slicer4 $ python ${SD}/Scripts/ModuleWizard.py \ --template ${SD}/QTModules/ModuleTemplate \ --target MY_MODULE_NAME \ MY_MODULE_NAME
- Setting up your CMakeLists.txt
- Download FindSlicer.cmake
- Edit CMakeLists.txt, and make it (1) detect Slicer, (2) load the Slicer "Use file", and (3) 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. 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
When you fire up slicer, you should see the module. For me, it looks like this:
- It is possible (with some work), to tell your program to build the module in your own directory instead of Slicer's. However, there is not yet any way to tell slicer to look in your own directory. So we leave the tutorial and await further developments.