# Including header files (in an extension build)

**URL:** <https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492>\
**Category:** Development\
**Tags:** extensions-manager\
**Created:** [June 13, 2017, 3:03pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492 "2017-06-13T15:03:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lcoram](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@lcoram](https://discourse.slicer.org/u/lcoram)\
**Post date:** [June 13, 2017, 3:03pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/1 "2017-06-13T15:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 13, 2017, 3:13pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/2 "2017-06-13T15:13:28Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions#CONFIGURE_and_generate_Slicer_solution_files).

---

<div class="post-metadata">

**Author:** ![lcoram](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@lcoram](https://discourse.slicer.org/u/lcoram)\
**Post date:** [June 13, 2017, 3:35pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/3 "2017-06-13T15:35:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 13, 2017, 3:35pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/4 "2017-06-13T15:35:23Z")

</div>

> [@lcoram](#):
>
> 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.

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](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate)

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 13, 2017, 3:38pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/5 "2017-06-13T15:38:44Z")

</div>

> [@lcoram](#):
>
> 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?

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:

> <https://github.com/Slicer/Slicer/blob/main/CMakeLists.txt#L1012-L1038>

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 13, 2017, 3:40pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/6 "2017-06-13T15:40:00Z")

</div>

> [@lcoram](#):
>
> [GitHub - TheInterventionCentre/NorMIT-Plan](http://github.com/TheInterventionCentre/NorMIT-Plan)

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](http://github.com/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.

---

<div class="post-metadata">

**Author:** ![lcoram](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@lcoram](https://discourse.slicer.org/u/lcoram)\
**Post date:** [June 13, 2017, 8:37pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/7 "2017-06-13T20:37:35Z")

</div>

> [@lassoan](#):
>
> [github.com/TheInterventionCentre/NorMIT-Pla](http://github.com/TheInterventionCentre/NorMIT-Pla)

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](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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 13, 2017, 10:31pm UTC](https://discourse.slicer.org/t/including-header-files-in-an-extension-build/492/8 "2017-06-13T22:31:08Z")

</div>

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.
