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:
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.
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:
if (NOT DEFINED Slicer_EXTENSION_SOURCE_DIRS)
# Allow usage if dependent extension is bundled
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?