# Include and compile itk, vtk as an ExternalProject or Submodule

**URL:** <https://discourse.slicer.org/t/include-and-compile-itk-vtk-as-an-externalproject-or-submodule/35337>\
**Category:** Development\
**Tags:** vtk, qt, itk\
**Created:** [April 7, 2024, 7:25pm UTC](https://discourse.slicer.org/t/include-and-compile-itk-vtk-as-an-externalproject-or-submodule/35337 "2024-04-07T19:25:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weidonglian](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/weidonglian/32/69941_2.png) [@weidonglian](https://discourse.slicer.org/u/weidonglian)\
**Post date:** [April 7, 2024, 7:25pm UTC](https://discourse.slicer.org/t/include-and-compile-itk-vtk-as-an-externalproject-or-submodule/35337/1 "2024-04-07T19:25:40Z")

</div>

In my c++ application, I need to use both itk, vtk and qt. In order to make the development reproducible without build itk/vtk as a seperate cmake project which definitely has a lot overhead.  
I have tried so far add itk/vtk as submodule into my third\_party/itk and third\_party/vtk folder. It ended up the following conflict targets (zlib, h5detect, such), as below. I also tried to use the CMake’s new feature FetchContent instead of ExternalProject\_Add, I got the same error as below. I reckon the `FetchContent and FetchContent_MakeAvailable` works the same as my submodule solution.  
Any suggestion to mitigate this limitation? I do not want to hack into vtk and change those target name or CMP0002.  
Thanks in advanced,  
Weidong

```auto
CMake Error at build/_deps/vtk-src/CMake/vtkModule.cmake:3829 (add_library):
  add_library cannot create target "zlib" because another target with the
  same name already exists. The existing target is a static library created
  in source directory
  "/home/weidong/develop/brain-flow-app/build/_deps/itk-src/Modules/ThirdParty/ZLIB/src/itkzlib-ng".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/vtk-src/ThirdParty/zlib/vtkzlib/CMakeLists.txt:118 (vtk_module_add_module)

CMake Warning at build/_deps/vtk-src/Rendering/OpenGL2/CMakeLists.txt:408 (message):
  X11::Xcursor not found; custom cursors will be ignored.

CMake Error at build/_deps/vtk-src/ThirdParty/hdf5/vtkhdf5/src/CMakeLists.txt:1067 (add_executable):
  add_executable cannot create target "H5detect" because another target with
  the same name already exists. The existing target is an executable created
  in source directory
  "/home/weidong/develop/brain-flow-app/build/_deps/itk-src/Modules/ThirdParty/HDF5/src/itkhdf5/src".
  See documentation for policy CMP0002 for more details.

CMake Error at build/_deps/vtk-src/ThirdParty/hdf5/vtkhdf5/src/CMakeLists.txt:1128 (add_executable):
  add_executable cannot create target "H5make_libsettings" because another
  target with the same name already exists. The existing target is an
  executable created in source directory
  "/home/weidong/develop/brain-flow-app/build/_deps/itk-src/Modules/ThirdParty/HDF5/src/itkhdf5/src".
  See documentation for policy CMP0002 for more details.

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 7, 2024, 7:32pm UTC](https://discourse.slicer.org/t/include-and-compile-itk-vtk-as-an-externalproject-or-submodule/35337/2 "2024-04-07T19:32:45Z")

</div>

Youncan set `USE_SYSTEM_...` CMake variable if you want tonuse any externally built libraries. Note that Slicer’s VTK fork contains a number of carefully selected patches that are required for correct functioning of the application, so make sure you include all those in your externally built VTK. The same may apply to ITK, too.

So, it is probably simpler if you use Slicer’s VTK and ITK in your application. I would recommend to use SlicerCAT to build your application and Slicer together.

---

<div class="post-metadata">

**Author:** ![weidonglian](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/weidonglian/32/69941_2.png) [@weidonglian](https://discourse.slicer.org/u/weidonglian)\
**Post date:** [April 7, 2024, 7:47pm UTC](https://discourse.slicer.org/t/include-and-compile-itk-vtk-as-an-externalproject-or-submodule/35337/3 "2024-04-07T19:47:51Z")

</div>

Indeed, your pointed SlicerCAT is really interesting and is exactly what I am looking for. That saves a lot of time to build everything from scrach.  
I will take a look and thanks so much for your help  
BR,  
Weidong
