Incremental rebuild of custom (SlicerCAT) application

when I change something in my SlicerCAT based custom application, I would like to make an incremental build, such that only those changed parts are updated/compiled.

However, running make in the $BUILD_DIR/Slicer-build directory starts to re-generate wrappers, re-compile a lot of .cxx files and re-link a lot of shared libs and binaries, e.g.:


Consolidate compiler generated dependencies of target MRMLLogic
[ 32%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLAbstractLogic.cxx.o
[ 32%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLApplicationLogic.cxx.o
[ 32%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLColorLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLDisplayableHierarchyLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLRemoteIOLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLLayoutLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLSliceLayerLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLSliceLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLSliceLinkLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLViewLogic.cxx.o
[ 33%] Building CXX object Libs/MRML/Logic/CMakeFiles/MRMLLogic.dir/vtkMRMLViewLinkLogic.cxx.o
[ 33%] Linking CXX shared library ../../../bin/
[ 33%] Built target MRMLLogic

and then it continues with a lot of other targets:

Consolidate compiler generated dependencies of target MRMLLogicCxxTests
Consolidate compiler generated dependencies of target MRMLDisplayableManager
Consolidate compiler generated dependencies of target MRMLDisplayableManagerPython
Consolidate compiler generated dependencies of target MRMLDisplayableManagerCxxTests

I’m not a CMake expert and the generated Makefiles are far too complex and contain too many targets for my limited make-foo.

Is there a way of rebuilding without this time-consuming compilation step?

Thank you


You find the directories corresponding to each target in the subfolders. For example if you have a Widgets target within your custom app it is here: [SuperBuildPath]\Slicer-build\E[CustomAppName]\Widgets

You can run make from that folder on Linux or build the vcxproj if you’re on Windows.

I had to made a bunch of assumptions so let me know if this helped…

Hi Csaba,
thank you for your help and sorry for the incomplete information: I’m on Ubuntu 22.04 with gcc 11.4.

I do have a directory SuperBuildPath/Slicer-build/E/ (not ECustomAppName) and in that directory, I find the Home module from the source tree Modules/Scripted/ directory plus the modules and extensions which I added in my top-level CMakeLists.txt file.

When I add a new module, I probably have to re-run cmake to generate the Makefile. Will that lead to a recompile of the other (unrelated) parts?



I haven’t found a way to re-run CMake without running the superbuild. However, this does not bother me, because 1) adding new modules is not an everyday task, 2) If you’re in a hurry you can copy the new Python source files (only if the module is a scripted one of course) to [SuperBuildPath]\Slicer-build\lib[CustomAppName]-5.5\qt-scripted-modules and just start your application, which will instantiate the new module because it found the new .py file.

Just in case it helps: usually when I develop in Python I don’t run any build, but run a script that copies the source files to the appropriate directory in the superbuild. Some people change the AdditionalModulePaths in the ini file to point to their source codes, but I found that limiting. Still others make the Python changes directly in the superbuild and then copy those to the working copy of the source code, but I’m too cautious for that (a build would make those changes disappear).

and there are these handy build targets to achieve this copy as well:

cmake --build ~/customapp-superbuild/Slicer-build --target CopySlicerPythonScriptFiles
cmake --build ~/customapp-superbuild/Slicer-build --target CopySlicerPythonResourceFiles

Thank you for your helpful tricks @cpinter and @ebrahim!

1 Like