# Building custom app with SegmentRegistration extension

**URL:** <https://discourse.slicer.org/t/building-custom-app-with-segmentregistration-extension/30698>\
**Category:** Development\
**Created:** [July 20, 2023, 7:56am UTC](https://discourse.slicer.org/t/building-custom-app-with-segmentregistration-extension/30698 "2023-07-20T07:56:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darabi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/darabi/32/66736_2.png) [@darabi](https://discourse.slicer.org/u/darabi)\
**Post date:** [July 20, 2023, 7:56am UTC](https://discourse.slicer.org/t/building-custom-app-with-segmentregistration-extension/30698/1 "2023-07-20T07:56:14Z")

</div>

Hello,  
I have successfully created and built a skeleton custom app and would now like to add the extensions which I need for the application. For this, I have added the necessary `FetchContent_Populate` sections to `CMakeLists.txt` (cf. [Extension configuration - Pastebin.com](https://pastebin.com/70yFsart)).

SegmentRegistration has a dependency on SlicerProstate, which contains the DistanceMapBasedRegistration module, but SlicerProstate is not found by cmake:

```auto
-- Checking EXTENSION_NAME variable
-- Checking EXTENSION_NAME variable - SegmentRegistration
CMake Error at .../build/SegmentRegistration/CMakeLists.txt:27 (find_package):
  By not providing "FindSlicerProstate.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "SlicerProstate", but CMake did not find one.

  Could not find a package configuration file provided by "SlicerProstate"
  with any of the following names:

    SlicerProstateConfig.cmake
    slicerprostate-config.cmake

  Add the installation prefix of "SlicerProstate" to CMAKE_PREFIX_PATH or set
  "SlicerProstate_DIR" to a directory containing one of the above files. If
  "SlicerProstate" provides a separate development package or SDK, be sure it
  has been installed.

-- Configuring incomplete, errors occurred!

```

Any hint on what I should change is highly appreciated.

Thank you

Kambiz

---

<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:** [July 22, 2023, 2:17am UTC](https://discourse.slicer.org/t/building-custom-app-with-segmentregistration-extension/30698/2 "2023-07-22T02:17:01Z")

</div>

When an extension depends on extension then usually the one with dependencies calls `find_package(...)` for each dependent extensions. However, when extensions are bundled then they are incorporated directly into the Slicer project and don’t appear as separate projects, therefore `find_package(...)` would fail.

The solution is to only use `find_package(...)` for the extension name if the extension is not bundled. This can be determined by checking if `Slicer_EXTENSION_SOURCE_DIRS` is empty. See for example how it is done in SlicerIGT extension:

> <https://github.com/SlicerIGT/SlicerIGT/blob/245fa92ec7e4533253d1f25f076f9d9026b8692a/CMakeLists.txt#L24-L29>

Note that a different `find_package(...)` may be needed if the dependent extension is a suprerbuild-type extension that includes some additional libraries (SlicerIGSIO extension is a superbuild-type extension that included the `IGSIO` library).

In your case the fix is probably to change the top-level CMakeLists.txt file in SegmentRegistration extension from this:

```auto
find_package(SlicerProstate REQUIRED)
find_package(SlicerRT REQUIRED)

```

to this:

```auto
if (NOT DEFINED Slicer_EXTENSION_SOURCE_DIRS)
  find_package(SlicerProstate REQUIRED)
  find_package(SlicerRT REQUIRED)
else()
  # Allow usage if dependent extension is bundled
  #find_package(IGSIO REQUIRED) 
endif()

```

You may also need to do it for SlicerRT or other extensions that are bundled. If you confirmed that the changes fix the bundling issue on your computer then you can submit pull requests to the repositories.

@jcfr Do you have any comments? Do you find the recommended changes to be a good solution?

---

<div class="post-metadata">

**Author:** ![darabi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/darabi/32/66736_2.png) [@darabi](https://discourse.slicer.org/u/darabi)\
**Post date:** [July 28, 2023, 7:24am UTC](https://discourse.slicer.org/t/building-custom-app-with-segmentregistration-extension/30698/3 "2023-07-28T07:24:48Z")

</div>

I can confirm that the proposed change fixes my issue. I haven’t attempted a Slicer full build with this change.

The pull request is here:

> <https://github.com/SlicerRt/SegmentRegistration/pull/8>
>
> The unconditional use of find\_package leads to an error during the build process… of dependent extensions. See
> 
> https://discourse.slicer.org/t/30698

Thank you for your help!
