Documentation/4.3/Developers/Build Module

From Slicer Wiki
Jump to: navigation, search
Home < Documentation < 4.3 < Developers < Build Module


For the latest Slicer documentation, visit the read-the-docs.


Build module outside of Slicer source tree

The different type of modules supported by Slicer can easily be built outside of the Slicer source tree.

The following examples are specific to unix-like platforms and can easily be adapted for Windows.


Assuming the source code of your module is located in folder MyModule, externally building modules could be achieved doing:

$ mkdir MyModule-build
$ cd MyModule-build
$ cmake -DSlicer_DIR:PATH=/path/to/Slicer-Superbuild/Slicer-build ../MyModule
$ make


For this to work, in addition to invoke cmake_minimum_required at the top of the top-level CMakeLists.txt, it's important to make sure the following line are added after setting MODULE_NAME:

find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})


For example:

cmake_minimum_required(VERSION 2.8.9)  <- - - - ADD THIS

find_package(Slicer COMPONENTS ConfigurePrerequisites)  <- - - - ADD THIS

project(EmptyExtensionTemplate) <- - - - ADD THIS

#-----------------------------------------------------------------------------
set(MODULE_NAME ${PROJECT_NAME})
set(MODULE_TITLE ${MODULE_NAME})

string(TOUPPER ${MODULE_NAME} MODULE_NAME_UPPER)

#-----------------------------------------------------------------------------
find_package(Slicer REQUIRED)  <- - - - - - - ADD THIS
include(${Slicer_USE_FILE})  <- - - - - - - - ADD THIS

#-----------------------------------------------------------------------------
add_subdirectory(Logic)

#-----------------------------------------------------------------------------
set(MODULE_EXPORT_DIRECTIVE "Q_SLICER_QTMODULES_${MODULE_NAME_UPPER}_EXPORT")

[...]

After successfully compiling the Slicer module, the Slicer module executables and libraries are located in your main Slicer build directory Slicer-Superbuild/Slicer-build. Refer to Directory Structure description for more details.



Developer FAQ: Modules

Within a Slicer build-tree, where are located Slicer modules ?

Slicer module executables and libraries are located in your main Slicer build directory Slicer-Superbuild/Slicer-build. Refer to Directory Structure description for more details.

How to build module outside of Slicer source tree

Follow developers guide for building modules

How to modify local version of External module

Some Slicer modules (such as OpenIGTLink and OpenIGTLinkIF) are built as External git projects by CMake scripts in the Slicer/SuperBuild directory. The SuperBuild process may refresh from the repository unexpectedly, overwriting any local changes. To avoid this, comment out the git settings in the appropriate external build file while making local edits. For example, in SuperBuild/External_OpenIGTLinkIF.cmake:

     GIT_REPOSITORY "${git_protocol}://github.com/openigtlink/OpenIGTLinkIF.git"
     GIT_TAG "f9b65b1ffd2992862025f3c6ec5fe30e6f5dd395"
     SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
     # GIT_REPOSITORY "${git_protocol}://github.com/openigtlink/OpenIGTLinkIF.git"
     # GIT_TAG "f9b65b1ffd2992862025f3c6ec5fe30e6f5dd395"
     SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}