Difference between revisions of "AHM2012-Slicer-Extension"
From NAMIC Wiki
(Created page with '== Writing an s4ext file == * Extensions are described using a simple text file. <pre> # # First token of each non-comment line is the keyword and the rest of the line # (includ…') |
|||
| Line 32: | Line 32: | ||
* This file will be automatically generated using information specified within your CMakeLists.txt | * This file will be automatically generated using information specified within your CMakeLists.txt | ||
| + | |||
| + | == Example of CMakeLists.txt == | ||
| + | <pre> | ||
| + | [...] | ||
| + | set(EXTENSION_NAME LoadableExtensionTemplate) | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Prerequisites | ||
| + | #----------------------------------------------------------------------------- | ||
| + | if(NOT Slicer_SOURCE_DIR) | ||
| + | set(EXTENSION_HOMEPAGE "http://www.slicer.org/slicerWiki/index.php/Slicer4:Developers:Projects:QtSlicer/Tutorials/ExtensionWriting") | ||
| + | set(EXTENSION_CATEGORY "Examples") | ||
| + | set(EXTENSION_STATUS "Beta") | ||
| + | set(EXTENSION_DESCRIPTION "This is an example of Qt loadable module built as an extension") | ||
| + | set(EXTENSION_DEPENDS CLIExtensionTemplate) # Specified as a space separated list or 'NA' if any | ||
| + | |||
| + | find_package(Slicer REQUIRED) | ||
| + | |||
| + | # Additional C/CXX flags - Should be defined before including Slicer_USE_FILE | ||
| + | set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional ${EXTENSION_NAME} C Flags") | ||
| + | set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional ${EXTENSION_NAME} CXX Flags") | ||
| + | |||
| + | include(${Slicer_USE_FILE}) | ||
| + | |||
| + | set(EXTENSION_LICENSE_FILE ${Slicer_LICENSE_FILE}) | ||
| + | set(EXTENSION_README_FILE ${Slicer_README_FILE}) | ||
| + | |||
| + | include(SlicerEnableExtensionTesting) | ||
| + | |||
| + | endif() | ||
| + | |||
| + | |||
| + | # Add subdirectories | ||
| + | add_subdirectory(Logic) | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Sources | ||
| + | #----------------------------------------------------------------------------- | ||
| + | set(qt_module_export_directive "Q_SLICER_QTMODULES_LOADABLEEXTENSIONTEMPLATE_EXPORT") | ||
| + | |||
| + | # Additional includes - Current_{source,binary} and Slicer_{Libs,Base} already included | ||
| + | set(qt_module_include_directories | ||
| + | ${CMAKE_CURRENT_SOURCE_DIR}/Logic | ||
| + | ${CMAKE_CURRENT_BINARY_DIR}/Logic | ||
| + | ) | ||
| + | |||
| + | # Source files | ||
| + | set(qt_module_SRCS | ||
| + | qSlicerLoadableExtensionTemplateModule.cxx | ||
| + | qSlicerLoadableExtensionTemplateModule.h | ||
| + | qSlicerLoadableExtensionTemplateModuleWidget.cxx | ||
| + | qSlicerLoadableExtensionTemplateModuleWidget.h | ||
| + | ) | ||
| + | |||
| + | # Headers that should run through moc | ||
| + | set(qt_module_MOC_SRCS | ||
| + | qSlicerLoadableExtensionTemplateModule.h | ||
| + | qSlicerLoadableExtensionTemplateModuleWidget.h | ||
| + | ) | ||
| + | |||
| + | # UI files | ||
| + | set(qt_module_UI_SRCS | ||
| + | Resources/UI/qSlicerLoadableExtensionTemplateModule.ui | ||
| + | ) | ||
| + | |||
| + | # Additional Target libraries | ||
| + | set(qt_module_target_libraries | ||
| + | vtkSlicerLoadableExtensionTemplateModuleLogic | ||
| + | ) | ||
| + | |||
| + | # Resources | ||
| + | set(qt_module_resources | ||
| + | Resources/qSlicerLoadableExtensionTemplateModule.qrc | ||
| + | ) | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Build | ||
| + | #----------------------------------------------------------------------------- | ||
| + | slicerMacroBuildQtModule( | ||
| + | NAME ${EXTENSION_NAME} | ||
| + | EXPORT_DIRECTIVE ${qt_module_export_directive} | ||
| + | INCLUDE_DIRECTORIES ${qt_module_include_directories} | ||
| + | SRCS ${qt_module_SRCS} | ||
| + | MOC_SRCS ${qt_module_MOC_SRCS} | ||
| + | UI_SRCS ${qt_module_UI_SRCS} | ||
| + | TARGET_LIBRARIES ${qt_module_target_libraries} | ||
| + | RESOURCES ${qt_module_resources} | ||
| + | ) | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Testing | ||
| + | #----------------------------------------------------------------------------- | ||
| + | if(BUILD_TESTING) | ||
| + | add_subdirectory(Testing) | ||
| + | endif() | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Generate extension description file '<EXTENSION_NAME>.s4ext' | ||
| + | #----------------------------------------------------------------------------- | ||
| + | if(NOT Slicer_SOURCE_DIR) | ||
| + | include(SlicerFunctionGenerateExtensionDescription) | ||
| + | slicerFunctionGenerateExtensionDescription( | ||
| + | EXTENSION_NAME ${EXTENSION_NAME} | ||
| + | EXTENSION_CATEGORY ${EXTENSION_CATEGORY} | ||
| + | EXTENSION_STATUS ${EXTENSION_STATUS} | ||
| + | EXTENSION_HOMEPAGE ${EXTENSION_HOMEPAGE} | ||
| + | EXTENSION_DESCRIPTION ${EXTENSION_DESCRIPTION} | ||
| + | EXTENSION_DEPENDS ${EXTENSION_DEPENDS} | ||
| + | DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR} | ||
| + | SLICER_WC_REVISION ${Slicer_WC_REVISION} | ||
| + | SLICER_WC_ROOT ${Slicer_WC_ROOT} | ||
| + | ) | ||
| + | endif() | ||
| + | |||
| + | #----------------------------------------------------------------------------- | ||
| + | # Packaging | ||
| + | #----------------------------------------------------------------------------- | ||
| + | if(NOT Slicer_SOURCE_DIR) | ||
| + | include(${Slicer_EXTENSION_CPACK}) | ||
| + | endif() | ||
| + | </pre> | ||
== Testing your extension == | == Testing your extension == | ||
Revision as of 14:53, 10 January 2012
Home < AHM2012-Slicer-ExtensionContents
Writing an s4ext file
- Extensions are described using a simple text file.
# # First token of each non-comment line is the keyword and the rest of the line # (including spaces) is the value. # - the value can be blank # # This is source code manager (i.e. svn) scm local scmurl Testing/LoadableExtensionTemplate # list dependencies # - These should be names of other modules that have .s4ext files # - The dependencies will be built first depends NA # homepage homepage http://www.slicer.org/slicerWiki/index.php/Slicer4:Developers:Projects:QtSlicer/Tutorials/ExtensionWriting # Match category in the xml description of the module (where it shows up in Modules menu) category Examples # Give people an idea what to expect from this code # - Is it just a test or something you stand beind? status Beta # One line stating what the module does description This is an example of Qt loadable module built as an extension
- This file will be automatically generated using information specified within your CMakeLists.txt
Example of CMakeLists.txt
[...]
set(EXTENSION_NAME LoadableExtensionTemplate)
#-----------------------------------------------------------------------------
# Prerequisites
#-----------------------------------------------------------------------------
if(NOT Slicer_SOURCE_DIR)
set(EXTENSION_HOMEPAGE "http://www.slicer.org/slicerWiki/index.php/Slicer4:Developers:Projects:QtSlicer/Tutorials/ExtensionWriting")
set(EXTENSION_CATEGORY "Examples")
set(EXTENSION_STATUS "Beta")
set(EXTENSION_DESCRIPTION "This is an example of Qt loadable module built as an extension")
set(EXTENSION_DEPENDS CLIExtensionTemplate) # Specified as a space separated list or 'NA' if any
find_package(Slicer REQUIRED)
# Additional C/CXX flags - Should be defined before including Slicer_USE_FILE
set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional ${EXTENSION_NAME} C Flags")
set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional ${EXTENSION_NAME} CXX Flags")
include(${Slicer_USE_FILE})
set(EXTENSION_LICENSE_FILE ${Slicer_LICENSE_FILE})
set(EXTENSION_README_FILE ${Slicer_README_FILE})
include(SlicerEnableExtensionTesting)
endif()
# Add subdirectories
add_subdirectory(Logic)
#-----------------------------------------------------------------------------
# Sources
#-----------------------------------------------------------------------------
set(qt_module_export_directive "Q_SLICER_QTMODULES_LOADABLEEXTENSIONTEMPLATE_EXPORT")
# Additional includes - Current_{source,binary} and Slicer_{Libs,Base} already included
set(qt_module_include_directories
${CMAKE_CURRENT_SOURCE_DIR}/Logic
${CMAKE_CURRENT_BINARY_DIR}/Logic
)
# Source files
set(qt_module_SRCS
qSlicerLoadableExtensionTemplateModule.cxx
qSlicerLoadableExtensionTemplateModule.h
qSlicerLoadableExtensionTemplateModuleWidget.cxx
qSlicerLoadableExtensionTemplateModuleWidget.h
)
# Headers that should run through moc
set(qt_module_MOC_SRCS
qSlicerLoadableExtensionTemplateModule.h
qSlicerLoadableExtensionTemplateModuleWidget.h
)
# UI files
set(qt_module_UI_SRCS
Resources/UI/qSlicerLoadableExtensionTemplateModule.ui
)
# Additional Target libraries
set(qt_module_target_libraries
vtkSlicerLoadableExtensionTemplateModuleLogic
)
# Resources
set(qt_module_resources
Resources/qSlicerLoadableExtensionTemplateModule.qrc
)
#-----------------------------------------------------------------------------
# Build
#-----------------------------------------------------------------------------
slicerMacroBuildQtModule(
NAME ${EXTENSION_NAME}
EXPORT_DIRECTIVE ${qt_module_export_directive}
INCLUDE_DIRECTORIES ${qt_module_include_directories}
SRCS ${qt_module_SRCS}
MOC_SRCS ${qt_module_MOC_SRCS}
UI_SRCS ${qt_module_UI_SRCS}
TARGET_LIBRARIES ${qt_module_target_libraries}
RESOURCES ${qt_module_resources}
)
#-----------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()
#-----------------------------------------------------------------------------
# Generate extension description file '<EXTENSION_NAME>.s4ext'
#-----------------------------------------------------------------------------
if(NOT Slicer_SOURCE_DIR)
include(SlicerFunctionGenerateExtensionDescription)
slicerFunctionGenerateExtensionDescription(
EXTENSION_NAME ${EXTENSION_NAME}
EXTENSION_CATEGORY ${EXTENSION_CATEGORY}
EXTENSION_STATUS ${EXTENSION_STATUS}
EXTENSION_HOMEPAGE ${EXTENSION_HOMEPAGE}
EXTENSION_DESCRIPTION ${EXTENSION_DESCRIPTION}
EXTENSION_DEPENDS ${EXTENSION_DEPENDS}
DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}
SLICER_WC_REVISION ${Slicer_WC_REVISION}
SLICER_WC_ROOT ${Slicer_WC_ROOT}
)
endif()
#-----------------------------------------------------------------------------
# Packaging
#-----------------------------------------------------------------------------
if(NOT Slicer_SOURCE_DIR)
include(${Slicer_EXTENSION_CPACK})
endif()
Testing your extension
- Since extension contains one or more modules, writing test shouldn't be different.
How users will access your extension
- Two options:
- Extension manager within Slicer
- Download from http://slicer.kitware.com/midas3/slicerpackages