Proposition to modify `slicerMacroBuildAppLibrary`

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:

# 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 directory property for the current CMakeLists file. They are also added to the 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

@jcfr what do you think?

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 that does export _INCLUDE_DIRS of custom library to SlicerConfig.cmake.