Including header files (in an extension build)

Hi All,

I have an extension which contains two modules. One of these modules has a folder “ITKFilters” which contains .h and .hxx files. These don’t get built, but need to be linked. We used to recompile ITK with the filter inside, but we want to make the module/extension standalone - so you don’t need a modified version of ITK/Slicer. I can compile it by having the MODULE_INCLUDE_DIRECTORIES include the source folder (${CMAKE_CURRENT_SOURCE_DIR}/ITKFilters) when the extension is compiled outside Slicer. However, when I try to build the extension during the Slicer compilation (using Slicer_Remote_Add) the folder does not appear to be linked (I get an error about missing a .h file).

Slicer_Remote_Add(NorMIT-Plan
GIT_REPOSITORY "${git_protocol}://github.com/TheInterventionCentre/NorMIT-Plan"
GIT_TAG "90e7c84571f19bf7db65b5eb17e0c465278737f0"
OPTION_NAME Slicer_BUILD_NorMIT-Plan
LABELS REMOTE_MODULE
)
list_conditional_append(Slicer_BUILD_NorMIT-Plan Slicer_REMOTE_DEPENDENCIES NorMIT-Plan)

Is there something I am not understanding about how Slicer_Remote_Add works? Is there a way to get cmake to copy the folder over to the build, so I can link it from there?

Thanks for your help,

Louise

Operating system: OSX 10.10.5
Slicer version: 4.6.0 - master

To add more extensions to your Slicer build you just have to add paths of your extensions to the Slicer_EXTENSION_SOURCE_DIRS variable when you configure Slicer build. See detailed description of all Slicer build customization options (custom application name, startup message, included/excluded modules, etc.) here: https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions#CONFIGURE_and_generate_Slicer_solution_files.

I think maybe I was a bit misleading with the question. I had no problem using Slicer_Remote_Add when I only had folders in my module that contained cmake files (what was in the folders was compiled) but it no longer works once my module contains a folder with only .h/.hxx files, as something is different about how the cmake works when it is made / compiled inside Slicer vs made / compiled separately (linked to a Slicer build).

Andras - are you saying it will compile the way I expect it to if I use the extension_source_dirs instead of slicer_remote_add?

Thanks again,

Louise

If you have a custom ITK filter, you could make it is a proper “ITK remote module”. It will then be possible to compile it as an ITK module against an ITK build tree (that could be the one from Slicer or your own ITK build tree).

Here is an example of remote module: GitHub - InsightSoftwareConsortium/ITKModuleTemplate: A template to start an ITK Module

The function Slicer_Add_Remove ultimately end up passing the extension source directory to Slicer as Slicer_EXTENSION_SOURCE_DIRS.

Reading the following comment may be helpful:

Everything should work well if you specify additional extensions through Slicer_EXTENSION_SOURCE_DIRS.

Can you share the source code? In GitHub - TheInterventionCentre/NorMIT-Plan I did not see any ITKFilters directory. Normally you put these files in the Logic directory. If you add them in subdirectories then make sure to add the directory to the list of include directories defined for that target.

Hi Andras and JC,

We were compiling the ITK filter as a remote filter (so it follows that convention), but we would like to create an extension that can be used with “vanilla” Slicer and not just with one where the ITK has been recompiled with the extra filter. I believe the most transparent way to do this for now is to package the filter along with the module. Or is there a different way of doing things?
(Another way I had tried was to use ExternalProject_Add to get and insert the filter into ITK and then recompile ITK with the filter on)

The code is in Github, just on a branch called “vessel_segmentation_integration”, for the folder containing the filters check inside the VesselSegmentation folder:
https://github.com/TheInterventionCentre/NorMIT-Plan/tree/feature/vessel_segmentation_integration

From what JC posted it looks like if I add the label remote_extension inside the slicer_remote_add, then it will add the extension source directories.
LABELS REMOTE_EXTENSION

Thanks for your help as always,
Louise

If you want to make your ITK filters available for non-Slicer users then it is a good idea to distribute them as remote ITK modules (as far as I know, your extension can load additional remote ITK modules; you don’t need to change anything in the Slicer core build).

If you only plan to use those ITK filters in Slicer modules then put those files in the module Logic directory. Don’t create a new directory, as all algorithms are expected to be in the module Logic classes.

For your modules you must not use slicer_remote_add macro, as it would require changing Slicer source code. Instead, with specifying your custom extensions using cmake -DSlicer_EXTENSION_SOURCE_DIRS you can incorporate extensions into a custom Slicer build without making any modification in the Slicer source code.

Note that custom Slicer builds may not be compatible with Slicer extensions in the Extension manager (and depending on what Slicer version you build it from, extensions may not even show up in the Extension manager), so these custom builds are only useful for heavily customized, stripped-down versions of Slicer. If you create such custom build, it is strongly recommended to change the application name and other settings to distinguish it from regular Slicer builds.