meganz / MEGAsync

Easy automated syncing between your computers and your MEGA Cloud Drive
Other
1.62k stars 279 forks source link

Linux: Don't link against libstdc++fs if GCC version in 9 or newer #458

Open tinywrkb opened 4 years ago

tinywrkb commented 4 years ago

GCC 9 adds C++17 std::filesystem support in libstdc++, from GGC 9 release notes

Using the types and functions in does not require linking with -lstdc++fs now.

src/MEGASync/mega/src/autocomplete.cpp has a test to use std::filesystem namespace instead of std::experimental::filesystem in case that CPP 17 is found.

This means that static linking against libstdc++fs.a is not needed if GCC version is 9 or newer, so I'm suggesting a change like the following.

diff --git a/src/MEGASync/MEGASync.pro b/src/MEGASync/MEGASync.pro
index d0517a7a..28bebaa3 100644
--- a/src/MEGASync/MEGASync.pro
+++ b/src/MEGASync/MEGASync.pro
@@ -109,7 +109,7 @@ include(qtlockedfile/qtlockedfile.pri)

 unix:!macx {
     GCC_VERSION = $$system("g++ -dumpversion")
-    lessThan(GCC_VERSION, 5) {
+    lessThan(GCC_VERSION, 5) | !lessThan(GCC_VERSION, 9) {
         LIBS -= -lstdc++fs
     }
 }

The application seems to build and run fine with this change on Arch Linux and also when built as a Flatpak package with KDE 5.14 runtime.

This change needed for Flatpak as libstdc++fs.a is not shipped with the latest KDE 5.14 runtime.

tinywrkb commented 4 years ago

And I didn't need to use QMAKE_CXXFLAGS+=-std=c++17.