fd1bc295.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. From fd1bc29594c6dee8b65c294c1c8595349f5cfdb2 Mon Sep 17 00:00:00 2001
  2. From: Ahmad Samir <a.samirh78@gmail.com>
  3. Date: Sun, 5 Dec 2021 20:41:08 +0200
  4. Subject: [PATCH] Change CMake code to enable building against Qt 5 or 6
  5. - forward declaring QStringList doesn't work with Qt6, instead #include it
  6. (for Qt6 we could use 'using QStringList = QList<QString>' but that wouldn't
  7. work with Qt5, and it's not worth an #ifdef, QStringList is common in Qt
  8. and KDE code anyway)
  9. - Add a copy constructor to PolkitQt1::Details, required because of QMetaType
  10. and the QESDP d-pointer
  11. By default this builds with Qt5, to build with Qt6 pass -DQT_MAJOR_VERSION=6
  12. to cmake.
  13. ---
  14. CMakeLists.txt | 28 ++++++++++++++++------------
  15. agent/CMakeLists.txt | 4 ++--
  16. core/CMakeLists.txt | 4 ++--
  17. core/polkitqt1-authority.h | 2 +-
  18. core/polkitqt1-details.cpp | 2 ++
  19. core/polkitqt1-details.h | 5 +++++
  20. examples/CMakeLists.txt | 14 +++++++-------
  21. examples/agent/CMakeLists.txt | 4 ++--
  22. gui/CMakeLists.txt | 6 +++---
  23. polkit-qt5-agent-1.pc.cmake | 2 +-
  24. polkit-qt5-core-1.pc.cmake | 2 +-
  25. polkit-qt5-gui-1.pc.cmake | 2 +-
  26. polkit-qt6-1.pc.cmake | 11 +++++++++++
  27. polkit-qt6-agent-1.pc.cmake | 11 +++++++++++
  28. polkit-qt6-core-1.pc.cmake | 11 +++++++++++
  29. polkit-qt6-gui-1.pc.cmake | 11 +++++++++++
  30. test/CMakeLists.txt | 8 ++++----
  31. 17 files changed, 91 insertions(+), 36 deletions(-)
  32. create mode 100644 polkit-qt6-1.pc.cmake
  33. create mode 100644 polkit-qt6-agent-1.pc.cmake
  34. create mode 100644 polkit-qt6-core-1.pc.cmake
  35. create mode 100644 polkit-qt6-gui-1.pc.cmake
  36. diff --git a/CMakeLists.txt b/CMakeLists.txt
  37. index dd0977e..166c177 100644
  38. --- a/CMakeLists.txt
  39. +++ b/CMakeLists.txt
  40. @@ -24,19 +24,23 @@ include(FeatureSummary)
  41. set(REQUIRED_QT_VERSION 5.5.0)
  42. set(CMAKE_CXX_STANDARD 11)
  43. -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus Widgets)
  44. +if (NOT QT_MAJOR_VERSION)
  45. + set(QT_MAJOR_VERSION "5")
  46. +endif()
  47. +
  48. +find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus Widgets)
  49. find_package(PkgConfig REQUIRED)
  50. -set(POLKITQT-1_PCNAME "polkit-qt5-1")
  51. -set(POLKITQT-1_CORE_PCNAME "polkit-qt5-core-1")
  52. -set(POLKITQT-1_GUI_PCNAME "polkit-qt5-gui-1")
  53. -set(POLKITQT-1_AGENT_PCNAME "polkit-qt5-agent-1")
  54. -set(POLKITQT-1_CAMEL_NAME "PolkitQt5-1")
  55. -set(POLKITQT-1_EXAMPLE "polkit-example-qt5")
  56. -set(POLKITQT-1_EXAMPLE_HELPER "polkit-example-helper-qt5")
  57. -set(POLKITQT-1_AGENT_EXAMPLE "polkit-agent-example-qt5")
  58. -set(POLKITQT-1_INCLUDE_PATH "polkit-qt5-1")
  59. +set(POLKITQT-1_PCNAME "polkit-qt${QT_MAJOR_VERSION}-1")
  60. +set(POLKITQT-1_CORE_PCNAME "polkit-qt${QT_MAJOR_VERSION}-core-1")
  61. +set(POLKITQT-1_GUI_PCNAME "polkit-qt${QT_MAJOR_VERSION}-gui-1")
  62. +set(POLKITQT-1_AGENT_PCNAME "polkit-qt${QT_MAJOR_VERSION}-agent-1")
  63. +set(POLKITQT-1_CAMEL_NAME "PolkitQt${QT_MAJOR_VERSION}-1")
  64. +set(POLKITQT-1_EXAMPLE "polkit-example-qt${QT_MAJOR_VERSION}")
  65. +set(POLKITQT-1_EXAMPLE_HELPER "polkit-example-helper-qt${QT_MAJOR_VERSION}")
  66. +set(POLKITQT-1_AGENT_EXAMPLE "polkit-agent-example-qt${QT_MAJOR_VERSION}")
  67. +set(POLKITQT-1_INCLUDE_PATH "polkit-qt${QT_MAJOR_VERSION}-1")
  68. pkg_check_modules(POLKIT_GOBJECT polkit-gobject-1 REQUIRED IMPORTED_TARGET)
  69. pkg_check_modules(POLKIT_AGENT polkit-agent-1 REQUIRED IMPORTED_TARGET)
  70. @@ -168,13 +172,13 @@ install(EXPORT ${POLKITQT-1_CAMEL_NAME}Export FILE ${POLKITQT-1_CAMEL_NAME}Targe
  71. option(BUILD_EXAMPLES "Builds a set of examples for polkit-qt-1" OFF)
  72. if (BUILD_EXAMPLES)
  73. - find_package(Qt5Xml ${REQUIRED_QT_VERSION} REQUIRED)
  74. + find_package(Qt${QT_MAJOR_VERSION}Xml ${REQUIRED_QT_VERSION} REQUIRED)
  75. add_subdirectory(examples)
  76. endif (BUILD_EXAMPLES)
  77. option(BUILD_TEST "Builds unit tests for polkit-qt-1" OFF)
  78. if (BUILD_TEST)
  79. - find_package(Qt5Test ${REQUIRED_QT_VERSION} REQUIRED)
  80. + find_package(Qt${QT_MAJOR_VERSION}Test ${REQUIRED_QT_VERSION} REQUIRED)
  81. add_subdirectory(test)
  82. endif (BUILD_TEST)
  83. diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt
  84. index 1a86cd8..ba95bfe 100644
  85. --- a/agent/CMakeLists.txt
  86. +++ b/agent/CMakeLists.txt
  87. @@ -14,10 +14,10 @@ generate_export_header(${POLKITQT-1_AGENT_PCNAME}
  88. target_link_libraries(${POLKITQT-1_AGENT_PCNAME}
  89. PUBLIC
  90. - Qt5::Core
  91. + Qt${QT_MAJOR_VERSION}::Core
  92. ${POLKITQT-1_CORE_PCNAME}
  93. PRIVATE
  94. - Qt5::Core
  95. + Qt${QT_MAJOR_VERSION}::Core
  96. PkgConfig::POLKIT_AGENT
  97. PkgConfig::GOBJECT
  98. )
  99. diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
  100. index 8225871..29bccc7 100644
  101. --- a/core/CMakeLists.txt
  102. +++ b/core/CMakeLists.txt
  103. @@ -17,9 +17,9 @@ generate_export_header(${POLKITQT-1_CORE_PCNAME}
  104. target_link_libraries(${POLKITQT-1_CORE_PCNAME}
  105. PUBLIC
  106. - Qt5::Core
  107. + Qt${QT_MAJOR_VERSION}::Core
  108. PRIVATE
  109. - Qt5::DBus
  110. + Qt${QT_MAJOR_VERSION}::DBus
  111. PkgConfig::POLKIT_GOBJECT
  112. PkgConfig::GLIB2
  113. PkgConfig::GOBJECT
  114. diff --git a/core/polkitqt1-authority.h b/core/polkitqt1-authority.h
  115. index 43527b0..d2d66ba 100644
  116. --- a/core/polkitqt1-authority.h
  117. +++ b/core/polkitqt1-authority.h
  118. @@ -19,9 +19,9 @@
  119. #include <QObject>
  120. #include <QMetaType>
  121. +#include <QStringList>
  122. typedef struct _PolkitAuthority PolkitAuthority;
  123. -class QStringList;
  124. /**
  125. * \namespace PolkitQt1 PolkitQt
  126. diff --git a/core/polkitqt1-details.cpp b/core/polkitqt1-details.cpp
  127. index 50568ff..b5be7ee 100644
  128. --- a/core/polkitqt1-details.cpp
  129. +++ b/core/polkitqt1-details.cpp
  130. @@ -56,6 +56,8 @@ Details::~Details()
  131. {
  132. }
  133. +Details::Details(const Details &other) = default;
  134. +
  135. Details& Details::operator=(const PolkitQt1::Details& other)
  136. {
  137. d = other.d;
  138. diff --git a/core/polkitqt1-details.h b/core/polkitqt1-details.h
  139. index 7fb8448..59dfcb6 100644
  140. --- a/core/polkitqt1-details.h
  141. +++ b/core/polkitqt1-details.h
  142. @@ -48,6 +48,11 @@ public:
  143. */
  144. explicit Details(PolkitDetails *pkDetails);
  145. + /**
  146. + * Copy constructor.
  147. + */
  148. + Details(const Details &other);
  149. +
  150. ~Details();
  151. Details &operator=(const Details &other);
  152. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
  153. index 229e97a..32577af 100644
  154. --- a/examples/CMakeLists.txt
  155. +++ b/examples/CMakeLists.txt
  156. @@ -11,9 +11,9 @@ target_sources(${POLKITQT-1_EXAMPLE} PRIVATE
  157. )
  158. target_link_libraries(${POLKITQT-1_EXAMPLE}
  159. - Qt5::Core
  160. - Qt5::DBus
  161. - Qt5::Widgets
  162. + Qt${QT_MAJOR_VERSION}::Core
  163. + Qt${QT_MAJOR_VERSION}::DBus
  164. + Qt${QT_MAJOR_VERSION}::Widgets
  165. ${POLKITQT-1_GUI_PCNAME}
  166. ${POLKITQT-1_CORE_PCNAME}
  167. )
  168. @@ -34,7 +34,7 @@ endmacro(dbus_add_activation_system_service _sources)
  169. add_executable(${POLKITQT-1_EXAMPLE_HELPER})
  170. -qt5_add_dbus_adaptor(polkit_example_helper_dbus_SRCS
  171. +qt_add_dbus_adaptor(polkit_example_helper_dbus_SRCS
  172. org.qt.policykit.examples.xml
  173. PkExampleHelper.h
  174. PkExampleHelper
  175. @@ -48,9 +48,9 @@ target_sources(${POLKITQT-1_EXAMPLE_HELPER} PRIVATE
  176. # see our helper is pretty small :D
  177. target_link_libraries(${POLKITQT-1_EXAMPLE_HELPER}
  178. - Qt5::Core
  179. - Qt5::Xml
  180. - Qt5::DBus
  181. + Qt${QT_MAJOR_VERSION}::Core
  182. + Qt${QT_MAJOR_VERSION}::Xml
  183. + Qt${QT_MAJOR_VERSION}::DBus
  184. ${POLKITQT-1_GUI_PCNAME}
  185. )
  186. diff --git a/examples/agent/CMakeLists.txt b/examples/agent/CMakeLists.txt
  187. index 020c686..130ac4e 100644
  188. --- a/examples/agent/CMakeLists.txt
  189. +++ b/examples/agent/CMakeLists.txt
  190. @@ -7,8 +7,8 @@ target_sources(${POLKITQT-1_AGENT_EXAMPLE} PRIVATE
  191. )
  192. target_link_libraries(${POLKITQT-1_AGENT_EXAMPLE}
  193. - Qt5::Core
  194. - Qt5::Widgets
  195. + Qt${QT_MAJOR_VERSION}::Core
  196. + Qt${QT_MAJOR_VERSION}::Widgets
  197. ${POLKITQT-1_AGENT_PCNAME}
  198. ${POLKITQT-1_CORE_PCNAME}
  199. PkgConfig::POLKIT_AGENT
  200. diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
  201. index c22deba..69ec1f6 100644
  202. --- a/gui/CMakeLists.txt
  203. +++ b/gui/CMakeLists.txt
  204. @@ -15,10 +15,10 @@ generate_export_header(${POLKITQT-1_CORE_PCNAME}
  205. target_link_libraries(${POLKITQT-1_GUI_PCNAME}
  206. PUBLIC
  207. ${POLKITQT-1_CORE_PCNAME}
  208. - Qt5::Widgets
  209. + Qt${QT_MAJOR_VERSION}::Widgets
  210. PRIVATE
  211. - Qt5::Core
  212. - Qt5::DBus
  213. + Qt${QT_MAJOR_VERSION}::Core
  214. + Qt${QT_MAJOR_VERSION}::DBus
  215. )
  216. set_target_properties(${POLKITQT-1_GUI_PCNAME} PROPERTIES VERSION ${POLKITQT-1_LIBRARY_VERSION}
  217. diff --git a/polkit-qt5-agent-1.pc.cmake b/polkit-qt5-agent-1.pc.cmake
  218. index 709a24e..60b22d5 100644
  219. --- a/polkit-qt5-agent-1.pc.cmake
  220. +++ b/polkit-qt5-agent-1.pc.cmake
  221. @@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  222. Name: @POLKITQT-1_AGENT_PCNAME@
  223. Description: Convenience library for using polkit Agent with a Qt-styled API
  224. Version: @POLKITQT-1_VERSION_STRING@
  225. -Requires: Qt5Core Qt5Gui
  226. +Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui
  227. Libs: -L${libdir} -l@POLKITQT-1_AGENT_PCNAME@
  228. Cflags: -I${includedir}
  229. diff --git a/polkit-qt5-core-1.pc.cmake b/polkit-qt5-core-1.pc.cmake
  230. index 588f267..2f5d562 100644
  231. --- a/polkit-qt5-core-1.pc.cmake
  232. +++ b/polkit-qt5-core-1.pc.cmake
  233. @@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  234. Name: @POLKITQT-1_CORE_PCNAME@
  235. Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
  236. Version: @POLKITQT-1_VERSION_STRING@
  237. -Requires: Qt5Core
  238. +Requires: Qt@QT_MAJOR_VERSION@Core
  239. Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@
  240. Cflags: -I${includedir}
  241. diff --git a/polkit-qt5-gui-1.pc.cmake b/polkit-qt5-gui-1.pc.cmake
  242. index 1c012dd..1d208fb 100644
  243. --- a/polkit-qt5-gui-1.pc.cmake
  244. +++ b/polkit-qt5-gui-1.pc.cmake
  245. @@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  246. Name: @POLKITQT-1_GUI_PCNAME@
  247. Description: Convenience library for using polkit with a Qt-styled API, GUI classes
  248. Version: @POLKITQT-1_VERSION_STRING@
  249. -Requires: Qt5Core Qt5Gui @POLKITQT-1_CORE_PCNAME@
  250. +Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui @POLKITQT-1_CORE_PCNAME@
  251. Libs: -L${libdir} -l@POLKITQT-1_GUI_PCNAME@
  252. Cflags: -I${includedir}
  253. diff --git a/polkit-qt6-1.pc.cmake b/polkit-qt6-1.pc.cmake
  254. new file mode 100644
  255. index 0000000..ba8e46e
  256. --- /dev/null
  257. +++ b/polkit-qt6-1.pc.cmake
  258. @@ -0,0 +1,11 @@
  259. +prefix=@CMAKE_INSTALL_PREFIX@
  260. +exec_prefix=@CMAKE_INSTALL_PREFIX@
  261. +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
  262. +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  263. +
  264. +Name: @POLKITQT-1_PCNAME@
  265. +Description: Convenience library for using polkit with a Qt-styled API
  266. +Version: @POLKITQT-1_VERSION_STRING@
  267. +Requires: @POLKITQT-1_CORE_PCNAME@ @POLKITQT-1_GUI_PCNAME@ @POLKITQT-1_AGENT_PCNAME@
  268. +Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@ -l@POLKITQT-1_GUI_PCNAME@ -l@POLKITQT-1_AGENT_PCNAME@
  269. +Cflags: -I${includedir}
  270. diff --git a/polkit-qt6-agent-1.pc.cmake b/polkit-qt6-agent-1.pc.cmake
  271. new file mode 100644
  272. index 0000000..60b22d5
  273. --- /dev/null
  274. +++ b/polkit-qt6-agent-1.pc.cmake
  275. @@ -0,0 +1,11 @@
  276. +prefix=@CMAKE_INSTALL_PREFIX@
  277. +exec_prefix=@CMAKE_INSTALL_PREFIX@
  278. +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
  279. +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  280. +
  281. +Name: @POLKITQT-1_AGENT_PCNAME@
  282. +Description: Convenience library for using polkit Agent with a Qt-styled API
  283. +Version: @POLKITQT-1_VERSION_STRING@
  284. +Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui
  285. +Libs: -L${libdir} -l@POLKITQT-1_AGENT_PCNAME@
  286. +Cflags: -I${includedir}
  287. diff --git a/polkit-qt6-core-1.pc.cmake b/polkit-qt6-core-1.pc.cmake
  288. new file mode 100644
  289. index 0000000..2f5d562
  290. --- /dev/null
  291. +++ b/polkit-qt6-core-1.pc.cmake
  292. @@ -0,0 +1,11 @@
  293. +prefix=@CMAKE_INSTALL_PREFIX@
  294. +exec_prefix=@CMAKE_INSTALL_PREFIX@
  295. +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
  296. +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  297. +
  298. +Name: @POLKITQT-1_CORE_PCNAME@
  299. +Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
  300. +Version: @POLKITQT-1_VERSION_STRING@
  301. +Requires: Qt@QT_MAJOR_VERSION@Core
  302. +Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@
  303. +Cflags: -I${includedir}
  304. diff --git a/polkit-qt6-gui-1.pc.cmake b/polkit-qt6-gui-1.pc.cmake
  305. new file mode 100644
  306. index 0000000..1d208fb
  307. --- /dev/null
  308. +++ b/polkit-qt6-gui-1.pc.cmake
  309. @@ -0,0 +1,11 @@
  310. +prefix=@CMAKE_INSTALL_PREFIX@
  311. +exec_prefix=@CMAKE_INSTALL_PREFIX@
  312. +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
  313. +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
  314. +
  315. +Name: @POLKITQT-1_GUI_PCNAME@
  316. +Description: Convenience library for using polkit with a Qt-styled API, GUI classes
  317. +Version: @POLKITQT-1_VERSION_STRING@
  318. +Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui @POLKITQT-1_CORE_PCNAME@
  319. +Libs: -L${libdir} -l@POLKITQT-1_GUI_PCNAME@
  320. +Cflags: -I${includedir}
  321. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
  322. index 8403d7b..d587034 100644
  323. --- a/test/CMakeLists.txt
  324. +++ b/test/CMakeLists.txt
  325. @@ -5,10 +5,10 @@ add_executable(polkit-qt-test
  326. )
  327. target_link_libraries(polkit-qt-test
  328. - Qt5::Core
  329. - Qt5::DBus
  330. - Qt5::Test
  331. - Qt5::Widgets
  332. + Qt${QT_MAJOR_VERSION}::Core
  333. + Qt${QT_MAJOR_VERSION}::DBus
  334. + Qt${QT_MAJOR_VERSION}::Test
  335. + Qt${QT_MAJOR_VERSION}::Widgets
  336. ${POLKITQT-1_CORE_PCNAME}
  337. ${POLKITQT-1_AGENT_PCNAME}
  338. )
  339. --
  340. GitLab