eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.63k stars 382 forks source link

Exported packages are not relocateable #2230

Closed lms-ts closed 5 months ago

lms-ts commented 5 months ago

Required information

Operating system: E.g. Ubuntu 22.04 LTS

Compiler version: GCC 11.4.0

Eclipse iceoryx version: master branch

Observed result or behaviour: We created a Yocto recipe to cross-compile iceoryx:

#iceoryx_git.bb
SECTION = "iceoryx - true zero-copy inter-process-communication"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=46d6aa0ba1fa2ed247cd8d42f20b72f4"

SRC_URI = "git://github.com/eclipse/iceoryx.git;protocol=https;branch=master"
SRCREV = "1e17b23d50e7ac2243f43969d90e7f5e8b60afca"

PV = "2.0.5+git"

SRC_URI += "file://iceoryx-roudi.service"

inherit cmake systemd

S = "${WORKDIR}/git"

EXTRA_OECMAKE = " \
    -H${S}/iceoryx_meta \
"

PACKAGECONFIG ?= "bindingc ccache toml shared introspection"

PACKAGECONFIG[all] = "-DBUILD_ALL=ON,-DBUILD_ALL=OFF,ncurses"
PACKAGECONFIG[test] = "-DBUILD_TEST=ON,-DBUILD_TEST=OFF"
PACKAGECONFIG[shared] = "-DBUILD_SHARED_LIBS=ON,-DBUILD_SHARED_LIBS=OFF"
PACKAGECONFIG[bindingc] = "-DBINDING_C=ON,-DBINDINGC=OFF"
PACKAGECONFIG[examples] = "-DEXAMPLES=ON,-DEXAMPLES=OFF"
PACKAGECONFIG[introspection] = "-DINTROSPECTION=ON,-DINTROSPECTION=OFF,ncurses"
PACKAGECONFIG[toml] = "-DTOML_CONFIG=ON -DDOWNLOAD_TOML_LIB=ON,-DTOML_CONFIG=OFF -DDOWNLOAD_TOML_LIB=OFF"
PACKAGECONFIG[ccache] = "-DCCACHE=ON,-DCCACHE=OFF"

SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE:${PN} = "iceoryx-roudi.service"

do_install:append() {
    install -d ${D}${systemd_system_unitdir}
    install -m 0644 ${WORKDIR}/iceoryx-roudi.service ${D}${systemd_system_unitdir}
}

DEPENDS += "acl pkgconfig"
FILES:${PN} += "/usr/etc/* ${systemd_system_unitdir}/*"

It works but when installing the exported packages in an SDK and trying to use find_package() (e. g. find_package(iceoryx_posh CONFIG REQUIRED)) within CMakeLists.txt, it fails:

[cmake] CMake Error at /opt/sdk/sysroots/armv8a_tegra-lms-linux/usr/lib/cmake/iceoryx_platform/iceoryx_platformTargets.cmake:79 (message):
[cmake]   The imported target "iceoryx_platform::iceoryx_platform" references the
[cmake]   file
[cmake] 
[cmake]      "/usr/lib/libiceoryx_platform.so.2.90.0"
[cmake] 
[cmake]   but this file does not exist.

The underlying problem is that the _IMPORT_PREFIX in the target import files is fixed and not relative to the installation path, e. g.:

#iceoryx_platformTargets.cmake
set(_IMPORT_PREFIX "/usr/local")

Expected result or behaviour: Installed packages should be relocateable. The _IMPORT_PREFIX should be relative to the target import file.

Conditions where it occurred / Performed steps: Install iceoryx packages in a directory that differs from the standard installation directory used by the environment the project was built on.

elfenpiff commented 5 months ago

@lms-ts Could you please set the CMAKE_INSTALL_PREFIX in the cmake build command to the directory you would like to install iceoryx to and check if this solves your issue?

lms-ts commented 5 months ago

@elfenpiff No, that does not solve the underlying issue.

With CMAKE_INSTALL_PREFIX the _IMPORT_PREFIX can be changed correctly however, it is still fixed in *Targets.cmake: Example with -DCMAKE_INSTALL_PREFIX=/opt/sdk => set(_IMPORT_PREFIX "/opt/sdk") This makes the installed packages not relocateable.

With the linked pull request the _IMPORT_PREFIX is calculated relative to the *Targets.cmake file which makes the installation relocateable:

#iceoryx_platformTargets.cmake
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()