Rebuilding custom loadable extension that is part of SlicerCAT

Hi,

I’m working on loadable extension and I after successively built SlicerCAT I want to edit my extension source code and rebuild it.

The extension is added to the SlicerCAT via FetchContent_Populate.
Then I can see that in build dir there is my extension source code and extension is build in Slicer-build/E/MyExtension.

Then I do something like:

cd ~/SlicerCAT/d/Slicer-build/E/MyExtension
cmake ../../../MyExtension -DSlicer_DIR=../..

but I get error when configuring:

CMake Error at ~/Documents/Colada/d/slicersources-src/CMake/SlicerMacroBuildModuleVTKLibrary.cmake:120 (add_library):
  add_library cannot create target "vtkSlicerStackLoadModuleLogic" because an
  imported target with the same name already exists.
Call Stack (most recent call first):
  ~/Documents/Colada/d/slicersources-src/CMake/SlicerMacroBuildModuleLogic.cmake:98 (SlicerMacroBuildModuleVTKLibrary)
  StackLoad/Logic/CMakeLists.txt:20 (SlicerMacroBuildModuleLogic)

Thus I can’t rebuilt extension to the dir where SlicerCAT expects loadable modules to be built.
It is highly likely that I can build my extension to different folder then set Slicer to import modules from that folder and delete previous (default) build files but that would be pretty awkward…

By the way I understand that these targets are defined in SlicerTargets.cmake and they should be loaded (all together with SlicerConfig.cmake) when find(Slicer REQUIRED) is processed but I can’t understand how to avoid the error.

For now I work on Ubuntu 20.04 with GCC 9.3
My custom app GitHub - tierra-colada/Colada: Geophysical software (in progress)
The extension GitHub - tierra-colada/Seismic: Slicer 3D extension for seismic modules

If Slicer already builds your custom modules then you must not build your modules as an extension, because it would want to add the same targets that you already have in your Slicer build. Just run make in the appropriate folder to build Slicer, including your modules.

1 Like