Difference between revisions of "Documentation/Nightly/Developers/Build Module"

From Slicer Wiki
Jump to: navigation, search
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<noinclude>{{documentation/versioncheck}}</noinclude>
 
= Build module outside of Slicer source tree =
 
= Build module outside of Slicer source tree =
  
 
The different [[Documentation/{{documentation/version}}/Developers/Modules|type of modules]] supported by Slicer can easily be built outside of the Slicer source tree.
 
The different [[Documentation/{{documentation/version}}/Developers/Modules|type of modules]] supported by Slicer can easily be built outside of the Slicer source tree.
 +
 +
'''Note: to build C++ modules you need to have built Slicer from source on your machine; they cannot be built against a binary download.'''
  
 
The following examples are specific to unix-like platforms and can easily be adapted for Windows.
 
The following examples are specific to unix-like platforms and can easily be adapted for Windows.
Line 19: Line 22:
 
For this to work, in addition to invoke <code>cmake_minimum_required</code> at the top of the top-level <code>CMakeLists.txt</code>, it's important to make sure the following line are added after setting <code>MODULE_NAME</code>:
 
For this to work, in addition to invoke <code>cmake_minimum_required</code> at the top of the top-level <code>CMakeLists.txt</code>, it's important to make sure the following line are added after setting <code>MODULE_NAME</code>:
 
<pre>
 
<pre>
#-----------------------------------------------------------------------------
+
find_package(Slicer REQUIRED)
if(NOT Slicer_SOURCE_DIR)
+
include(${Slicer_USE_FILE})
  find_package(Slicer REQUIRED)
 
  include(${Slicer_USE_FILE})
 
endif()
 
 
</pre>
 
</pre>
  
Line 30: Line 30:
  
 
<pre>
 
<pre>
cmake_minimum_required(VERSION 2.8.8)  <- - - - ADD THIS
+
cmake_minimum_required(VERSION 2.8.9<- - - - ADD THIS
 +
 
 +
find_package(Slicer COMPONENTS ConfigurePrerequisites)  <- - - - ADD THIS
 +
 
 +
project(EmptyExtensionTemplate) <- - - - ADD THIS
  
 
#-----------------------------------------------------------------------------
 
#-----------------------------------------------------------------------------
set(MODULE_NAME MyModule)
+
set(MODULE_NAME ${PROJECT_NAME})
 
set(MODULE_TITLE ${MODULE_NAME})
 
set(MODULE_TITLE ${MODULE_NAME})
  
Line 39: Line 43:
  
 
#-----------------------------------------------------------------------------
 
#-----------------------------------------------------------------------------
if(NOT Slicer_SOURCE_DIR)  <- - - - - - - - - - ADD THIS
+
find_package(Slicer REQUIRED)  <- - - - - - - ADD THIS
  find_package(Slicer REQUIRED)  <- - - - - - - ADD THIS
+
include(${Slicer_USE_FILE})  <- - - - - - - - ADD THIS
  include(${Slicer_USE_FILE})  <- - - - - - - - ADD THIS
 
endif()
 
  
 
#-----------------------------------------------------------------------------
 
#-----------------------------------------------------------------------------
Line 53: Line 55:
 
</pre>
 
</pre>
  
After successfully compiling the Slicer module, the executable will be located in your main Slicer build directory, Slicer-Superbuild/Slicer-build. Refer to http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/DirectoryStructure for the directory structure.  
+
After successfully compiling the Slicer module, the Slicer module executables and libraries are located in your module build directory under lib <code>build_dir/lib/Slicer-X.Y/module_type</code>. Adding this directory to the Additional module paths in the Application Settings GUI within slicer, will allow testing of your module without recompiling the super-build. Refer to [[Documentation/{{documentation/version}}/Developers/DirectoryStructure|Directory Structure]] description for more details.
 
 
  
{{:Documentation/{{documentation/version}}/FAQ/Extensions|Extensions}}
 
  
{{:Documentation/{{documentation/version}}/Developers/FAQ/Extensions|Extensions}}
+
{{:Documentation/{{documentation/version}}/Developers/FAQ/Modules|Modules}}

Latest revision as of 17:17, 24 June 2017

Home < Documentation < Nightly < 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.

Note: to build C++ modules you need to have built Slicer from source on your machine; they cannot be built against a binary download.

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 module build directory under lib build_dir/lib/Slicer-X.Y/module_type. Adding this directory to the Additional module paths in the Application Settings GUI within slicer, will allow testing of your module without recompiling the super-build. Refer to Directory Structure description for more details.



Developer FAQ: Modules

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

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}

How to call a CLI module from a C++ loadable module?

Discussion: http://slicer-devel.65872.n3.nabble.com/Calling-CLI-module-from-a-C-loadable-module-tt4031930.html

Example: vtkSlicerCropVolumeLogic.cxx#L318-351

How to call a CLI module from command-line?

Example:

   Slicer.exe --launch CastScalarVolume input.mha output.mha

Notes for windows:

  • Full name of the Slicer executable is required (Slicer.exe, not just Slicer)
  • To get help on command-line arguments the CLI module supports, run:
   Slicer.exe --launch CastScalarVolume 2>c:\SomeWriteAbleDirectory\usage.txt