# How to build module dependencies with CMakeLists.txt?

**URL:** <https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371>\
**Category:** Development\
**Tags:** module, cmake\
**Created:** [October 26, 2021, 8:24pm UTC](https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371 "2021-10-26T20:24:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [October 26, 2021, 8:24pm UTC](https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371/1 "2021-10-26T20:24:39Z")

</div>

Consider an extension with two modules _Wheel_ and _Car_ :

```auto
.
├── CMakeLists.txt
├── Car
│ ├── CMakeLists.txt
│ ├── Widgets
│ │ ├── CMakeLists.txt
│ │ ├── qSlicerCarFooBarWidget.cxx
│ │ └── qSlicerCarFooBarWidget.h
│ ├── qSlicerCarModule.cxx
│ ├── qSlicerCarModule.h
│ ├── qSlicerCarModuleWidget.cxx
│ └── qSlicerCarModuleWidget.h
└── Wheel
    ├── CMakeLists.txt
    ├── Widgets
    │ ├── CMakeLists.txt
    │ ├── qSlicerWheelFooBarWidget.cxx
    │ └── qSlicerWheelFooBarWidget.h
    ├── qSlicerWheelModule.cxx
    ├── qSlicerWheelModule.h
    ├── qSlicerWheelModuleWidget.cxx
    └── qSlicerWheelModuleWidget.h

```

The module _Car_ depends on some of the classes in module _Wheel_ (for example `qSlicerWheelFooBarWidget`). What do I need to put in `./Car/CMakeLists.txt` and `./CMakeLists.txt` in order to successfully build _Car_?

_Extension Wizard_ just creates an extension with two independent module projects; my build fails because project _Car_ can’t find header files located in project _Wheel_.

Should I also manually override the virtual `qSlicerCarModule::dependencies() const` method and add `Wheel`?

---

<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:** [October 26, 2021, 9:08pm UTC](https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371/2 "2021-10-26T21:08:01Z")

</div>

Nothing special is needed, just add the library that you want to use to the list of target libraries and add the directory that contains header files to the include directories. See for example how CropVolume uses the Volumes module.

---

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [October 26, 2021, 10:36pm UTC](https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371/3 "2021-10-26T22:36:28Z")

</div>

Thanks, this did actually work! Funny that I had actually been looking at the `CMakeLists.txt` of _CropVolume_ but couldn’t get it right the first time.

I guess I should add `Wheel` to the implementation of `qSlicerWheelModule::dependencies()` too:

```auto
QStringList qSlicerCarModule::dependencies() const
{
    return Superclass::dependencies() << "Wheel";
}

```

---

<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:** [October 27, 2021, 3:57am UTC](https://discourse.slicer.org/t/how-to-build-module-dependencies-with-cmakelists-txt/20371/4 "2021-10-27T03:57:14Z")

</div>

Yes, you need to add the modules that your modules depends on in `dependencies()` method. It is used for determining startup order of the modules.
