# Proposition to modify \`slicerMacroBuildAppLibrary\`

**URL:** <https://discourse.slicer.org/t/proposition-to-modify-slicermacrobuildapplibrary/20043>\
**Category:** Development\
**Created:** [October 7, 2021, 12:26am UTC](https://discourse.slicer.org/t/proposition-to-modify-slicermacrobuildapplibrary/20043 "2021-10-07T00:26:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [October 7, 2021, 12:26am UTC](https://discourse.slicer.org/t/proposition-to-modify-slicermacrobuildapplibrary/20043/1 "2021-10-07T00:26:04Z")

</div>

Hi,

I need to link to my SlicerCAT main target `qMyApp` (that is added via `slicerMacroBuildAppLibrary`) from external module.

From that external module I can see that `qMyApp` target is defined (it is exported in `SlicerTargets.cmake`) but it doesn’t have `INCLUDE_DIRECTORIES` property:

```bash
# Snippet of code that is part of an external module CMakeLists after Slicer is found
get_target_property(qMyApp_INCLUDE_DIR qMyApp INCLUDE_DIRECTORIES)
message("qMyApp_INCLUDE_DIR: ${qMyApp_INCLUDE_DIR}")

```

and the message says `qMyApp_INCLUDE_DIR: qMyApp_INCLUDE_DIR-NOTFOUND`.

Thus to link `qMyApp` from external module I need to explicitely link include dirs via `target_include_directories(...)` for example.

That is little bit strange as `slicerMacroBuildAppLibrary` uses `include_directories(${include_dirs})` and `add_library` and cmake documentation says (even target is added from `.cmake` file and dirs included also from there):

> The include directories are added to the [`INCLUDE_DIRECTORIES`](https://cmake.org/cmake/help/latest/prop_dir/INCLUDE_DIRECTORIES.html#prop_dir:INCLUDE_DIRECTORIES) directory property for the current `CMakeLists` file. They are also added to the [`INCLUDE_DIRECTORIES`](https://cmake.org/cmake/help/latest/prop_tgt/INCLUDE_DIRECTORIES.html#prop_tgt:INCLUDE_DIRECTORIES) target property for each target in the current `CMakeLists` file. The target property values are the ones used by the generators.

I think the best solution would be to modify `SlicerMacroBuildApplication.cmake` and use `target_include_directories` instead of `include_directories`. Or to explicitely set property to target within `SlicerMacroBuildApplication.cmake`.

**I also have the related question in order to solve my problem without modifying Slicer’s cmake macro:**

How to export `qMyApp_INCLUDE_DIR` from my SlicerCAT CMakeLists to `SlicerConfig.cmake`?  
For external projects I do that with `mark_as_superbuild(qColadaApp_INCLUDE_DIR)` but this doesn’t seem to work with SlicerCAT project. There is no `qColadaApp_INCLUDE_DIR` var in `SlicerConfig.cmake`

---

<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 7, 2021, 1:15pm UTC](https://discourse.slicer.org/t/proposition-to-modify-slicermacrobuildapplibrary/20043/2 "2021-10-07T13:15:49Z")

</div>

@jcfr what do you think?

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [October 16, 2021, 11:03pm UTC](https://discourse.slicer.org/t/proposition-to-modify-slicermacrobuildapplibrary/20043/3 "2021-10-16T23:03:00Z")

</div>

I was wrong about the idea that include dirs were not exported to `SlicerConfig.cmake` because they were included with `include_directories` instead of `target_include_directories`.

I looked to other cmake macros like `SlicerMacroBuildModule...cmake` and understood how include dirs are exported to `SlicerConfig.cmake`

With that I created a [pull request](https://github.com/Slicer/Slicer/pull/5950) that does export `_INCLUDE_DIRS` of custom library to `SlicerConfig.cmake`.
