Building custom app with SegmentRegistration extension

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).

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

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

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:

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:

find_package(SlicerProstate REQUIRED)
find_package(SlicerRT REQUIRED)

to this:

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?

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:

Thank you for your help!