Commit fd1bc295 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Change CMake code to enable building against Qt 5 or 6

- forward declaring QStringList doesn't work with Qt6, instead #include it
  (for Qt6 we could use 'using QStringList = QList<QString>' but that wouldn't
  work with Qt5, and it's not worth an #ifdef, QStringList is common in Qt
  and KDE code anyway)
- Add a copy constructor to PolkitQt1::Details, required because of QMetaType
  and the QESDP d-pointer

By default this builds with Qt5, to build with Qt6 pass -DQT_MAJOR_VERSION=6
to cmake.
parent 05ccd348
Pipeline #117180 passed with stage
in 28 seconds
......@@ -24,19 +24,23 @@ include(FeatureSummary)
set(REQUIRED_QT_VERSION 5.5.0)
set(CMAKE_CXX_STANDARD 11)
find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus Widgets)
if (NOT QT_MAJOR_VERSION)
set(QT_MAJOR_VERSION "5")
endif()
find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus Widgets)
find_package(PkgConfig REQUIRED)
set(POLKITQT-1_PCNAME "polkit-qt5-1")
set(POLKITQT-1_CORE_PCNAME "polkit-qt5-core-1")
set(POLKITQT-1_GUI_PCNAME "polkit-qt5-gui-1")
set(POLKITQT-1_AGENT_PCNAME "polkit-qt5-agent-1")
set(POLKITQT-1_CAMEL_NAME "PolkitQt5-1")
set(POLKITQT-1_EXAMPLE "polkit-example-qt5")
set(POLKITQT-1_EXAMPLE_HELPER "polkit-example-helper-qt5")
set(POLKITQT-1_AGENT_EXAMPLE "polkit-agent-example-qt5")
set(POLKITQT-1_INCLUDE_PATH "polkit-qt5-1")
set(POLKITQT-1_PCNAME "polkit-qt${QT_MAJOR_VERSION}-1")
set(POLKITQT-1_CORE_PCNAME "polkit-qt${QT_MAJOR_VERSION}-core-1")
set(POLKITQT-1_GUI_PCNAME "polkit-qt${QT_MAJOR_VERSION}-gui-1")
set(POLKITQT-1_AGENT_PCNAME "polkit-qt${QT_MAJOR_VERSION}-agent-1")
set(POLKITQT-1_CAMEL_NAME "PolkitQt${QT_MAJOR_VERSION}-1")
set(POLKITQT-1_EXAMPLE "polkit-example-qt${QT_MAJOR_VERSION}")
set(POLKITQT-1_EXAMPLE_HELPER "polkit-example-helper-qt${QT_MAJOR_VERSION}")
set(POLKITQT-1_AGENT_EXAMPLE "polkit-agent-example-qt${QT_MAJOR_VERSION}")
set(POLKITQT-1_INCLUDE_PATH "polkit-qt${QT_MAJOR_VERSION}-1")
pkg_check_modules(POLKIT_GOBJECT polkit-gobject-1 REQUIRED IMPORTED_TARGET)
pkg_check_modules(POLKIT_AGENT polkit-agent-1 REQUIRED IMPORTED_TARGET)
......@@ -168,13 +172,13 @@ install(EXPORT ${POLKITQT-1_CAMEL_NAME}Export FILE ${POLKITQT-1_CAMEL_NAME}Targe
option(BUILD_EXAMPLES "Builds a set of examples for polkit-qt-1" OFF)
if (BUILD_EXAMPLES)
find_package(Qt5Xml ${REQUIRED_QT_VERSION} REQUIRED)
find_package(Qt${QT_MAJOR_VERSION}Xml ${REQUIRED_QT_VERSION} REQUIRED)
add_subdirectory(examples)
endif (BUILD_EXAMPLES)
option(BUILD_TEST "Builds unit tests for polkit-qt-1" OFF)
if (BUILD_TEST)
find_package(Qt5Test ${REQUIRED_QT_VERSION} REQUIRED)
find_package(Qt${QT_MAJOR_VERSION}Test ${REQUIRED_QT_VERSION} REQUIRED)
add_subdirectory(test)
endif (BUILD_TEST)
......
......@@ -14,10 +14,10 @@ generate_export_header(${POLKITQT-1_AGENT_PCNAME}
target_link_libraries(${POLKITQT-1_AGENT_PCNAME}
PUBLIC
Qt5::Core
Qt${QT_MAJOR_VERSION}::Core
${POLKITQT-1_CORE_PCNAME}
PRIVATE
Qt5::Core
Qt${QT_MAJOR_VERSION}::Core
PkgConfig::POLKIT_AGENT
PkgConfig::GOBJECT
)
......
......@@ -17,9 +17,9 @@ generate_export_header(${POLKITQT-1_CORE_PCNAME}
target_link_libraries(${POLKITQT-1_CORE_PCNAME}
PUBLIC
Qt5::Core
Qt${QT_MAJOR_VERSION}::Core
PRIVATE
Qt5::DBus
Qt${QT_MAJOR_VERSION}::DBus
PkgConfig::POLKIT_GOBJECT
PkgConfig::GLIB2
PkgConfig::GOBJECT
......
......@@ -19,9 +19,9 @@
#include <QObject>
#include <QMetaType>
#include <QStringList>
typedef struct _PolkitAuthority PolkitAuthority;
class QStringList;
/**
* \namespace PolkitQt1 PolkitQt
......
......@@ -56,6 +56,8 @@ Details::~Details()
{
}
Details::Details(const Details &other) = default;
Details& Details::operator=(const PolkitQt1::Details& other)
{
d = other.d;
......
......@@ -48,6 +48,11 @@ public:
*/
explicit Details(PolkitDetails *pkDetails);
/**
* Copy constructor.
*/
Details(const Details &other);
~Details();
Details &operator=(const Details &other);
......
......@@ -11,9 +11,9 @@ target_sources(${POLKITQT-1_EXAMPLE} PRIVATE
)
target_link_libraries(${POLKITQT-1_EXAMPLE}
Qt5::Core
Qt5::DBus
Qt5::Widgets
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::DBus
Qt${QT_MAJOR_VERSION}::Widgets
${POLKITQT-1_GUI_PCNAME}
${POLKITQT-1_CORE_PCNAME}
)
......@@ -34,7 +34,7 @@ endmacro(dbus_add_activation_system_service _sources)
add_executable(${POLKITQT-1_EXAMPLE_HELPER})
qt5_add_dbus_adaptor(polkit_example_helper_dbus_SRCS
qt_add_dbus_adaptor(polkit_example_helper_dbus_SRCS
org.qt.policykit.examples.xml
PkExampleHelper.h
PkExampleHelper
......@@ -48,9 +48,9 @@ target_sources(${POLKITQT-1_EXAMPLE_HELPER} PRIVATE
# see our helper is pretty small :D
target_link_libraries(${POLKITQT-1_EXAMPLE_HELPER}
Qt5::Core
Qt5::Xml
Qt5::DBus
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::Xml
Qt${QT_MAJOR_VERSION}::DBus
${POLKITQT-1_GUI_PCNAME}
)
......
......@@ -7,8 +7,8 @@ target_sources(${POLKITQT-1_AGENT_EXAMPLE} PRIVATE
)
target_link_libraries(${POLKITQT-1_AGENT_EXAMPLE}
Qt5::Core
Qt5::Widgets
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::Widgets
${POLKITQT-1_AGENT_PCNAME}
${POLKITQT-1_CORE_PCNAME}
PkgConfig::POLKIT_AGENT
......
......@@ -15,10 +15,10 @@ generate_export_header(${POLKITQT-1_CORE_PCNAME}
target_link_libraries(${POLKITQT-1_GUI_PCNAME}
PUBLIC
${POLKITQT-1_CORE_PCNAME}
Qt5::Widgets
Qt${QT_MAJOR_VERSION}::Widgets
PRIVATE
Qt5::Core
Qt5::DBus
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::DBus
)
set_target_properties(${POLKITQT-1_GUI_PCNAME} PROPERTIES VERSION ${POLKITQT-1_LIBRARY_VERSION}
......
......@@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_AGENT_PCNAME@
Description: Convenience library for using polkit Agent with a Qt-styled API
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt5Core Qt5Gui
Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui
Libs: -L${libdir} -l@POLKITQT-1_AGENT_PCNAME@
Cflags: -I${includedir}
......@@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_CORE_PCNAME@
Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt5Core
Requires: Qt@QT_MAJOR_VERSION@Core
Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@
Cflags: -I${includedir}
......@@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_GUI_PCNAME@
Description: Convenience library for using polkit with a Qt-styled API, GUI classes
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt5Core Qt5Gui @POLKITQT-1_CORE_PCNAME@
Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui @POLKITQT-1_CORE_PCNAME@
Libs: -L${libdir} -l@POLKITQT-1_GUI_PCNAME@
Cflags: -I${includedir}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_PCNAME@
Description: Convenience library for using polkit with a Qt-styled API
Version: @POLKITQT-1_VERSION_STRING@
Requires: @POLKITQT-1_CORE_PCNAME@ @POLKITQT-1_GUI_PCNAME@ @POLKITQT-1_AGENT_PCNAME@
Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@ -l@POLKITQT-1_GUI_PCNAME@ -l@POLKITQT-1_AGENT_PCNAME@
Cflags: -I${includedir}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_AGENT_PCNAME@
Description: Convenience library for using polkit Agent with a Qt-styled API
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui
Libs: -L${libdir} -l@POLKITQT-1_AGENT_PCNAME@
Cflags: -I${includedir}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_CORE_PCNAME@
Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt@QT_MAJOR_VERSION@Core
Libs: -L${libdir} -l@POLKITQT-1_CORE_PCNAME@
Cflags: -I${includedir}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@
Name: @POLKITQT-1_GUI_PCNAME@
Description: Convenience library for using polkit with a Qt-styled API, GUI classes
Version: @POLKITQT-1_VERSION_STRING@
Requires: Qt@QT_MAJOR_VERSION@Core Qt@QT_MAJOR_VERSION@Gui @POLKITQT-1_CORE_PCNAME@
Libs: -L${libdir} -l@POLKITQT-1_GUI_PCNAME@
Cflags: -I${includedir}
......@@ -5,10 +5,10 @@ add_executable(polkit-qt-test
)
target_link_libraries(polkit-qt-test
Qt5::Core
Qt5::DBus
Qt5::Test
Qt5::Widgets
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::DBus
Qt${QT_MAJOR_VERSION}::Test
Qt${QT_MAJOR_VERSION}::Widgets
${POLKITQT-1_CORE_PCNAME}
${POLKITQT-1_AGENT_PCNAME}
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment