# Problematic absolute paths in cmake file created by INSTALL(EXPORT)

**URL:** https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246
**Category:** Usage
**Created:** [November 26, 2020, 3:28pm UTC](https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246 "2020-11-26T15:28:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Holger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@Holger](https://discourse.cmake.org/u/Holger)
#### Post date: [November 26, 2020, 3:28pm UTC](https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246/1 "2020-11-26T15:28:27Z")

</div>

Hi,

I am building the NetworkManagerQt package inside a Yocto project.

NetworkMangagerQt creates a file called `KF5NetworkManagerQtTargets.cmake` using  
the following command inside a `CMakeLists.txt` file:

```auto
install(EXPORT KF5NetworkManagerQtTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5NetworkManagerQtTargets.cmake NAMESPACE KF5:: )

```

This exported cmake-file contains absolute paths:

```auto
...
set_target_properties(KF5::NetworkManagerQt PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/KF5/NetworkManagerQt;
  /home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/usr/include/libnm;
  /home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/usr/include/libmount;
  /home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/usr/include/blkid;
  /home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/usr/include/glib-2.0;
  /home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/usr/lib/glib-2.0/include;
  ${_IMPORT_PREFIX}/include/KF5"
  INTERFACE_LINK_LIBRARIES "Qt5::Core;Qt5::Network;Qt5::DBus"
)
...

```

(The absolute path in question is `/home/holger/data/Yocto/yocto-yoe/build/tmp/work/core2-32-ks-linux/networkmanager-qt/5.31.0-r0/recipe-sysroot/`).

This absolute path makes it impossible to use Yocto’s shared state cache  
feature, since at the point when the cache is re-used the old working copy to  
which the absolute paths point to may no longer be there.

A better approach would be to use the `CMAKE_SYSROOT` variable, like so:

```auto
set_target_properties(KF5::NetworkManagerQt PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/KF5/NetworkManagerQt;
  ${CMAKE_SYSROOT}/usr/include/libnm;
  ${CMAKE_SYSROOT}/usr/include/libmount;
  ${CMAKE_SYSROOT}/usr/include/blkid;
  ${CMAKE_SYSROOT}/usr/include/glib-2.0;
  ${CMAKE_SYSROOT}/usr/lib/glib-2.0/include;
  ${_IMPORT_PREFIX}/include/KF5"
  INTERFACE_LINK_LIBRARIES "Qt5::Core;Qt5::Network;Qt5::DBus"
)

```

Can this change be achieved in a clean way without patching CMake?  
(Patching NetworkManagerQt would be ok, though).

Best,  
Holger

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 26, 2020, 7:52pm UTC](https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246/2 "2020-11-26T19:52:32Z")

</div>

Looks like a problem in upstream I’d guess.

Around [this line](https://invent.kde.org/mtrescott/networkmanager-qt/-/blob/d3323ebc22a560db572332a2bf1a506f688b72a6/src/CMakeLists.txt#L154), I’d put some debugging statements to see if these expand to absolute paths and the figure out why they come out that way. I expect they should eventually show up as `${_IMPORT_PREFIX}/include/libnm` and the like.

Alternatively, the problem could be in the `FindNetworkManager.cmake` at the top. This should instead be converted over to an `IMPORTED` target, installed, and then `find_dependency(NetworkManager)` be added to the `Config.cmake` file. This sounds like the better solution since it is my gut feeling for where the absolute paths come from.

---

<div class="post-metadata">

### Author: ![Holger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@Holger](https://discourse.cmake.org/u/Holger)
#### Post date: [November 30, 2020, 1:28pm UTC](https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246/3 "2020-11-30T13:28:14Z")

</div>

Hi @ben.boeckel ,

I use the following versions:

networkmanager: 1.22.10  
networkmanager-qt: 5.31.0

Unfortunately, the version of `networkmanager` I use (respectively: is shipped  
with Yocto) does not provide a `FindNetworkManager.cmake`.

`networkmanager-qt` finds the package with the following command:

```auto
find_package(NetworkManager 0.9.10.0 REQUIRED)

```

This command sets the variable `NM-CORE_INCLUDE_DIRS` which  
includes the annoying absolute paths.

Is there a way to tweak `find_package` into using a SYSROOT-variable?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 30, 2020, 1:51pm UTC](https://discourse.cmake.org/t/problematic-absolute-paths-in-cmake-file-created-by-install-export/2246/4 "2020-11-30T13:51:35Z")

</div>

The `FindNetworkManager.cmake` file is inside of `networkmanager-qt`. I think you’ll just have to convert it to using imported targets rather than variables. [This commit](https://gitlab.kitware.com/cmake/cmake/-/commit/1aa7df411474cd183af7049f3a53c8ac6be75a61) shows how it was done for one module.
