hyprwm / xdg-desktop-portal-hyprland

xdg-desktop-portal backend for Hyprland
BSD 3-Clause "New" or "Revised" License
305 stars 48 forks source link

[CMake] Fails to pass LDFLAGS with system sdbus-cpp #157

Closed jbeich closed 10 months ago

jbeich commented 10 months ago

Affects FreeBSD and other BSDs. Not sure why Nix isn't affected given it uses different prefix for each package. To reproduce install sdbus-cpp outside of /usr and /usr/local thus not part of default C compiler search path.

$ git clone https://github.com/Kistler-Group/sdbus-cpp
$ cd sdbus-cpp
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/tmp/sdbus-cpp_prefix -B /tmp/sdbus-cpp_build -G Ninja
$ cmake --build /tmp/sdbus-cpp_build
$ cmake --install /tmp/sdbus-cpp_build
$ export PKG_CONFIG_PATH=/tmp/sdbus-cpp_prefix/lib/pkgconfig

$ git clone https://github.com/hyprwm/xdg-desktop-portal-hyprland
$ cd xdg-desktop-portal-hyprland
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/tmp/xdg-desktop-portal-hyprland_prefix -B /tmp/xdg-desktop-portal-hyprland_build -G Ninja
$ cmake --build /tmp/xdg-desktop-portal-hyprland_build
[...]
ld: error: unable to find library -lsdbus-c++

$ pkg-config --libs-only-L sdbus-c++
-L/tmp/sdbus-cpp_prefix/lib

Looks like target_link_libraries uses plain sdbus-c++ instead of the imported target: https://github.com/hyprwm/xdg-desktop-portal-hyprland/blob/c0b606460a099efdea48347aeb40b01af3d9af1c/CMakeLists.txt#L45 https://github.com/hyprwm/xdg-desktop-portal-hyprland/blob/c0b606460a099efdea48347aeb40b01af3d9af1c/CMakeLists.txt#L61

fufexan commented 10 months ago

Yes, did that so that even if it's not found through pkg-config, we can still add it through the subproject. Should I try adding it conditionally with SDBUS using if?

jbeich commented 10 months ago

Why not add_library(PkgConifg::SDBUS ALIAS sdbus-c++) under if(NOT SDBUS_FOUND)?

fufexan commented 10 months ago

Didn't know about that, thanks! I'll add it now.

fufexan commented 10 months ago

https://github.com/hyprwm/xdg-desktop-portal-hyprland/commit/df8c154f5793e71796e76004812f2a03eba67e88 seems to work on Nix, I hope it also works for you.

jbeich commented 10 months ago

I confirm, builds fine.