Issue with Including Scripted Module in Custom Slicer-Based Application

Hi all,

I’ve developed a custom Slicer-based application and included a custom scripted module called HemisphereVolumeCalculator
In my top-level CMakeLists.txt, I’ve added it using:

set(Slicer_EXTENSION_SOURCE_DIRS
  ${Safe_SOURCE_DIR}/Modules/Scripted/HemisphereVolumeCalculator
)

The module runs fine when I add its path through the application settings → Additional Module Paths. However, after building my application from the generated Safe.sln (on Windows), the module does not appear in the application interface by default.

:red_question_mark: Questions:

  1. Is there anything else I need to do beyond setting Slicer_EXTENSION_SOURCE_DIRS to ensure the module gets built and bundled?
  2. How can I confirm whether the module was recognized or included during the build?
  3. Are there any additional flags (e.g., Slicer_QTSCRIPTEDMODULES_ENABLED) that I need to set manually?

Does the folder Modules/Scripted/HemisphereVolumeCalculator contains a CMakeLists similar to this one ?

  1. How can I confirm whether the module was recognized or included during the build?

You should see the following output when the inner build is configured:

[...]
-- --------------------------------------------------
-- Configuring Safe application: SafeApp
-- --------------------------------------------------
...
-- --------------------------------------------------
-- Configuring extension directory: Home
-- Configuring Scripted module: Home
-- --------------------------------------------------
-- Configuring extension directory: HemisphereVolumeCalculator
-- Configuring Scripted module: HemisphereVolumeCalculator
[...]
  1. Are there any additional flags (e.g., Slicer_QTSCRIPTEDMODULES_ENABLED) that I need to set manually?

Those are related to the Slicer built-in scripted modules and not the one you are explicitly developing as part of the custom app.

Thanks for the reply! Here’s how things are currently set up in my custom Slicer app.

This is the relevant part from the top-level CMakeLists.txt of my custom application (Safe):

# Enable Slicer built-in modules
set(Slicer_CLIMODULES_ENABLED
  ResampleDTIVolume             # Needed by ResampleScalarVectorDWIVolume
  ResampleScalarVectorDWIVolume # Depends on DiffusionApplications, needed by CropVolume
)

set(Slicer_QTLOADABLEMODULES_ENABLED
)

set(Slicer_QTSCRIPTEDMODULES_ENABLED
)

# Disable Slicer built-in modules
set(Slicer_CLIMODULES_DISABLED
)

set(Slicer_QTLOADABLEMODULES_DISABLED
  SceneViews
  SlicerWelcome
  ViewControllers
)

set(Slicer_QTSCRIPTEDMODULES_DISABLED
  DataProbe
  DMRIInstall
  Endoscopy
  LabelStatistics
  PerformanceTests
  SampleData
  SurfaceToolbox
  VectorToScalarVolume
)

# Enable/Disable Slicer custom modules: To create a new module, use the SlicerExtensionWizard.
set(Slicer_EXTENSION_SOURCE_DIRS
  #${Safe_SOURCE_DIR}/Modules/CLI/MyCLIModule
  #${Safe_SOURCE_DIR}/Modules/Loadable/MyLoadableModule
  ${Safe_SOURCE_DIR}/Modules/Scripted/Home
  ${Safe_SOURCE_DIR}/Modules/Scripted/HemisphereVolumeCalculator
)

And this is the CMakeLists.txt inside the HemisphereVolumeCalculator module directory:

#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_NAME}.py
  RESOURCES_DIR Resources/Icons
  WITH_GENERIC_TESTS
)

The module is placed correctly under the Scripted folder, and I’ve confirmed the paths are valid. But it’s still not showing up in the UI after building the application. Let me know if you see anything I’m missing!

After re-configuring & building the project from the top-level, the CMake cache variable Slicer_EXTENSION_SOURCE_DIRS set in the inner-build CMakeCache.txt (see <top-level>/Slicer-build/CMakeCache.txt) should include the path /path/to/Modules/Scripted/HemisphereVolumeCalculator.

Could you check this is the case ?

Next, can you check that:

  • The text Configuring Scripted module: HemisphereVolumeCalculator is displayed when configuring the inner project
  • The relevant module files are copied when you force rebuild only the target CopySlicerPythonScriptFiles after opening the solution file found in the inner build directory
1 Like

@jcfr
Thanks! I just updated the module’s CMakeLists.txt according to the one you shared, and after rebuilding, the module now appears in the application
Before Update:

#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_NAME}.py
  RESOURCES_DIR Resources/Icons
  WITH_GENERIC_TESTS
)

:white_check_mark: After Update:

#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
set(MODULE_PYTHON_SCRIPTS
  ${MODULE_NAME}.py
)

#-----------------------------------------------------------------------------
set(MODULE_PYTHON_RESOURCES
  Resources/Icons/${MODULE_NAME}.png
)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_PYTHON_SCRIPTS}
  RESOURCES ${MODULE_PYTHON_RESOURCES}
)

(post deleted by author)

For future reference, note that the RESOURCES_DIR is not a valid argument for the slicerMacroBuildScriptedModule CMake macro.