# Relocatable package that correctly handles the included directories...is it possible?

**URL:** <https://discourse.cmake.org/t/relocatable-package-that-correctly-handles-the-included-directories-is-it-possible/12955>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [November 12, 2024, 2:21pm UTC](https://discourse.cmake.org/t/relocatable-package-that-correctly-handles-the-included-directories-is-it-possible/12955 "2024-11-12T14:21:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JtTest](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/90db22/32.png) [@JtTest](https://discourse.cmake.org/u/JtTest)\
**Post date:** [November 12, 2024, 2:21pm UTC](https://discourse.cmake.org/t/relocatable-package-that-correctly-handles-the-included-directories-is-it-possible/12955/1 "2024-11-12T14:21:39Z")

</div>

Hi there,  
I have realized a Linux library _fooLib_ that provides some functions to be used with [alsa-lib](https://github.com/alsa-project/alsa-lib) data types. I want cmake to configure the compilation of the library and also to create a relocatable package that users of _fooLib_ can import in their CMake project. For that purpose, I have thought to rely upon the FindALSA.cmake that I found in my Ubuntu 22.04 system (actually, I do not know which package installed it).

The key point is that the generated relocatable package should address the correct position of alsa-lib headers in the user machine, but I am failing to achieve this goal.  
This is my simplified CMakeLists.txt file:

```auto
project(foo)

find_package(ALSA REQUIRED) # uses FindALSA.cmake
# For sake of brevity, assume that ALSA is found

add_library(fooLib SHARED foo.c) # my source code

target_include_directories(fooLib PUBLIC 
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # where my foo.h is
     $<INSTALL_INTERFACE:include> # where my foo.h will be
     ${ALSA_INCLUDE_DIRS}) # this path is defined after calling find_package(ALSA)

target_link_libraries(fooLib PUBLIC 
    ALSA::ALSA) # this target is defined after calling find_package(ALSA) 

install(TARGETS fooLib EXPORT fooLibTargets)

install(
  EXPORT fooLibTargets
  NAMESPACE fooLib::
  FILE "fooLibTargets.cmake"
  DESTINATION "lib/cmake/fooLib")

```

The generated fooLibTargets.cmake contains (among others) the following lines:

```auto
# Create imported target fooLib::fooLib
add_library(fooLib::fooLib SHARED IMPORTED)

set_target_properties(fooLib::fooLib PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;/usr/include"
)

```

This file is not relocatable because the alsa-lib headers path are assumed to be in ‘/usr/include’, which is correct for my machine but non necessarily for the users’ one. I need something that is relocatable (similarly to the above “${\_IMPORT\_PREFIX}/include”).

How can I overcome this issue and make CMake to generate a relocatable package that correctly handles the included directories in such situation?

And (possibly), which is the correct approach to generate a relocatable CMake package that does not suffer of this issue? Please note that the official tutorials do not cover this aspect.

Thank you in advance.
