From cc840534c04245345b4be92efb5e0a8d7d85410d Mon Sep 17 00:00:00 2001
From: Christian Kamm <mail@ckamm.de>
Date: Thu, 7 Mar 2019 10:58:40 +0100
Subject: [PATCH] Add PLUGINDIR cmake setting and define #7027

By default, plugins are only searched next to the binary or next to the
other Qt plugins. This optional build variable allows another path to be
configured.

The idea is that on linux the oC packaging probably wants the binary in
something like /opt/owncloud/bin and the plugins in
/opt/owncloud/lib/plugins.

Similarly, distribution packagers probably don't want the plugins next
to the binary or next to the other Qt plugins. This flag allows them to
configure another path that the executable will look in.
---
 CMakeLists.txt                        |  1 +
 config.h.in                           |  1 +
 src/gui/application.cpp               | 11 +++++++++++
 src/libsync/vfs/suffix/CMakeLists.txt |  4 ++--
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7da9f36de..be6b4319a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -105,6 +105,7 @@ if(WIN32)
 set(DATADIR "share")
 endif(WIN32)
 set(SHAREDIR ${DATADIR})
+set(PLUGINDIR "${CMAKE_INSTALL_FULL_LIBDIR}/${APPLICATION_SHORTNAME}/plugins" CACHE STRING "Extra path to look for Qt plugins like for VFS. May be relative to binary.")
 
 #####
 ## handle BUILD_OWNCLOUD_OSX_BUNDLE
diff --git a/config.h.in b/config.h.in
index c645c0be6..2dcf2d6f1 100644
--- a/config.h.in
+++ b/config.h.in
@@ -33,5 +33,6 @@
 
 #cmakedefine SYSCONFDIR "@SYSCONFDIR@"
 #cmakedefine SHAREDIR "@SHAREDIR@"
+#cmakedefine PLUGINDIR "@PLUGINDIR@"
 
 #endif
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index 90f81d45d..fed5c6388 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -269,6 +269,17 @@ Application::Application(int &argc, char **argv)
     if (!AbstractNetworkJob::httpTimeout)
         AbstractNetworkJob::httpTimeout = cfg.timeout();
 
+#ifdef PLUGINDIR
+    // Setup extra plugin search path
+    QString extraPluginPath = QStringLiteral(PLUGINDIR);
+    if (!extraPluginPath.isEmpty()) {
+        if (QDir::isRelativePath(extraPluginPath))
+            extraPluginPath = QDir(QApplication::applicationDirPath()).filePath(extraPluginPath);
+        qCInfo(lcApplication) << "Adding extra plugin search path:" << extraPluginPath;
+        addLibraryPath(extraPluginPath);
+    }
+#endif
+
     // Check vfs plugins
     if (Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() == Vfs::Off) {
         qCWarning(lcApplication) << "Theme wants to show vfs mode, but no vfs plugins are available";
diff --git a/src/libsync/vfs/suffix/CMakeLists.txt b/src/libsync/vfs/suffix/CMakeLists.txt
index d98347d50..28699dccf 100644
--- a/src/libsync/vfs/suffix/CMakeLists.txt
+++ b/src/libsync/vfs/suffix/CMakeLists.txt
@@ -14,7 +14,7 @@ set_target_properties("${synclib_NAME}_vfs_suffix" PROPERTIES
 )
 
 INSTALL(TARGETS "${synclib_NAME}_vfs_suffix"
-  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/plugins"
-  RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/plugins"
+  LIBRARY DESTINATION "${PLUGINDIR}"
+  RUNTIME DESTINATION "${PLUGINDIR}"
 )