flathub / org.qbittorrent.qBittorrent

https://flathub.org/apps/details/org.qbittorrent.qBittorrent
9 stars 11 forks source link

Fix LTO build #97

Closed Erick555 closed 1 year ago

Erick555 commented 1 year ago

The https://github.com/flathub/org.qbittorrent.qBittorrent/pull/96 (Build with LTO) change has unwanted side-effect - it overwrites all default cflags/ldflags that come from flatpak runtime (mostly binary hardening stuff).

Using CMAKE_INTERPROCEDURAL_OPTIMIZATION variable is canonical approach for using LTO with cmake and it results with -flto=auto being appended to the default build flag set instead of replacing them.

cc: @Chocobo1

flathubbot commented 1 year ago

Started test build 15051

flathubbot commented 1 year ago

Build 15051 successful To test this build, install it from the testing repository:

flatpak install --user https://dl.flathub.org/build-repo/127473/org.qbittorrent.qBittorrent.flatpakref
Chocobo1 commented 1 year ago

Some notes for myself.

it overwrites all default cflags/ldflags that come from flatpak runtime (mostly binary hardening stuff).

https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html

Using CMAKE_INTERPROCEDURAL_OPTIMIZATION variable is canonical approach for using LTO with cmake and it results with -flto=auto being appended to the default build flag set instead of replacing them.

https://github.com/Kitware/CMake/blob/d183038b68330ac115ee996006049bf1fba7ffc1/Modules/Compiler/GNU.cmake#L84

Chocobo1 commented 1 year ago

@Erick555 A follow up question, what if I really need to add flags to CMAKE_CXX_FLAGS? Will this work -DCMAKE_CXX_FLAGS="$CXXFLAGS -flto=auto"?

Erick555 commented 1 year ago

@Chocobo1 there is dedicated manifest option for adding build flags to the default set:

    build-options:
      cflags: -flto=auto
      cxxflags: -flto=auto
      ldflags: -flto=auto

Example use in manifest: https://github.com/flathub/org.radare.iaito/blob/6b72b2e51b9871460d10595e9a87896a143ee50e/org.radare.iaito.yaml#L41-L42

Those will be added to CFLAGS/CXXGLAGS/LDFLAGS env variables which are honored by cmake when CMAKE_<XXX>_FLAGS aren't set.

I think variables like -DCMAKE_CXX_FLAGS="$CXXFLAGS -flto=auto aren't expanded outside buildsystem: simple so $CXXFLAGS would be literal $CXXFLAGS garbage string in your example.