diff --git a/asteroidsyncservice/CMakeLists.txt b/asteroidsyncservice/CMakeLists.txt index 9fb6348..b4c7349 100644 --- a/asteroidsyncservice/CMakeLists.txt +++ b/asteroidsyncservice/CMakeLists.txt @@ -1,15 +1,16 @@ cmake_minimum_required(VERSION 3.15) -find_package(QT NAMES Qt5 COMPONENTS DBus Qml REQUIRED) -find_package(Qt${QT_VERSION_MAJOR} COMPONENTS DBus Qml REQUIRED) +find_package(Qt6 COMPONENTS DBus Qml) +if (NOT Qt6_FOUND) + find_package(Qt5 5.15 COMPONENTS DBus Qml REQUIRED) +endif() add_library(asteroidsyncserviceplugin SHARED syncservice_plugin.cpp watch.cpp watches.cpp ${PLATFORM_SOURCE_DIR}/servicecontrol.cpp) set_target_properties(asteroidsyncserviceplugin PROPERTIES AUTOMOC ON) target_include_directories(asteroidsyncserviceplugin PRIVATE ${PROJECT_BINARY_DIR} ${PLATFORM_SOURCE_DIR}) target_compile_features(asteroidsyncserviceplugin PUBLIC cxx_std_17) -target_link_libraries(asteroidsyncserviceplugin PRIVATE Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::Qml) +target_link_libraries(asteroidsyncserviceplugin PRIVATE Qt::DBus Qt::Qml) # Installation paths -get_target_property(REAL_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} - IMPORTED_LOCATION) +get_target_property(REAL_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) if (NOT QT_INSTALL_QML) execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_QML diff --git a/asteroidsyncserviced/CMakeLists.txt b/asteroidsyncserviced/CMakeLists.txt index 4f02b1d..3bb1e81 100644 --- a/asteroidsyncserviced/CMakeLists.txt +++ b/asteroidsyncserviced/CMakeLists.txt @@ -1,12 +1,21 @@ cmake_minimum_required(VERSION 3.15) -find_package(Qt5 COMPONENTS Core Bluetooth DBus Qml REQUIRED) +find_package(Qt6 COMPONENTS Core Bluetooth DBus Qml) +if (NOT Qt6_FOUND) + find_package(Qt5 COMPONENTS Core Bluetooth DBus Qml REQUIRED) +endif() add_subdirectory(libasteroid) if(NOT DEFINED Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR) include (CheckCXXSourceCompiles) - find_package(Qt5 COMPONENTS Core REQUIRED) - set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS}) - set(CMAKE_REQUIRED_LIBRARIES Qt5::Core) + find_package(Qt6 COMPONENTS Core) + if (Qt6_FOUND) + set(CMAKE_REQUIRED_INCLUDES ${Qt6Core_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES Qt6::Core) + else() + find_package(Qt5 COMPONENTS Core REQUIRED) + set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES Qt5::Core) + endif() set(Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR 0) check_cxx_source_compiles(" #include @@ -43,7 +52,7 @@ set_target_properties(asteroidsyncserviced PROPERTIES AUTOMOC ON) target_compile_features(asteroidsyncserviced PUBLIC cxx_std_17) add_compile_definitions(Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR=${Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR}) target_include_directories(asteroidsyncserviced PRIVATE ${PROJECT_BINARY_DIR} ${DAEMON_PLATFORM_SOURCE_DIR} libasteroid/src bluez) -target_link_libraries(asteroidsyncserviced PRIVATE Qt5::Bluetooth Qt5::Core Qt5::DBus Qt5::Qml asteroid) +target_link_libraries(asteroidsyncserviced PRIVATE Qt::Bluetooth Qt::Core Qt::DBus Qt::Qml asteroid) install(TARGETS asteroidsyncserviced) if (DESKTOP_PLATFORM) configure_file( diff --git a/asteroidsyncserviced/dbusinterface.cpp b/asteroidsyncserviced/dbusinterface.cpp index 3b87608..077438d 100644 --- a/asteroidsyncserviced/dbusinterface.cpp +++ b/asteroidsyncserviced/dbusinterface.cpp @@ -31,6 +31,7 @@ #include #include +#include /*! * \brief Convert JSON weather string to QList @@ -45,7 +46,12 @@ */ static QList parseWeatherJson(const QString &weatherJson) { - constexpr int maxWeatherDays{5}; + /* This looks complex, but it's really just a way to compensate for the fact + * that with Qt5, size() returned an int, and with Qt6, it returns a qsizetype. + * This automatically determines the type so the comparison within std::min() + * below does not trigger a compiler warning. + */ + static constexpr decltype(std::declval().size()) maxWeatherDays{5}; QList weatherDays; QJsonParseError parseError; auto json = QJsonDocument::fromJson(weatherJson.toUtf8(), &parseError);