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


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:

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

This exported cmake-file contains absolute paths:

set_target_properties(KF5::NetworkManagerQt PROPERTIES
  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:

set_target_properties(KF5::NetworkManagerQt PROPERTIES
  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).


Looks like a problem in upstream I’d guess.

Around this line, 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.

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:

find_package(NetworkManager 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?

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 shows how it was done for one module.