diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c75bc0..bce14f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,151 +1,150 @@ cmake_minimum_required(VERSION 3.5) set(KF5_VERSION "5.54.0") # handled by release scripts set(KF5_DEP_VERSION "5.54.0") # handled by release scripts project(KNotifications VERSION ${KF5_VERSION}) # ECM setup include(FeatureSummary) find_package(ECM 5.54.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMQtDeclareLoggingCategory) include(ECMPoQmTools) include(ECMAddQch) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") ecm_setup_version(PROJECT VARIABLE_PREFIX KNOTIFICATIONS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/knotifications_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5NotificationsConfigVersion.cmake" SOVERSION 5) # Dependencies set(REQUIRED_QT_VERSION 5.10.0) set(CMAKE_AUTORCC TRUE) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets) if (NOT ANDROID) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED DBus) else () find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED AndroidExtras) - find_package(Java REQUIRED) - include(UseJava) + find_package(Gradle REQUIRED) endif() find_package(Qt5 ${REQUIRED_QT_VERSION} QUIET OPTIONAL_COMPONENTS TextToSpeech) set_package_properties(Qt5TextToSpeech PROPERTIES DESCRIPTION "Qt text to speech module" TYPE OPTIONAL PURPOSE "Required to build text to speech notification support") if (Qt5TextToSpeech_FOUND) add_definitions(-DHAVE_SPEECH) endif() include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) if (NOT APPLE AND NOT WIN32) find_package(X11) endif() set(HAVE_X11 ${X11_FOUND}) set(HAVE_XTEST ${X11_XTest_FOUND}) if(X11_FOUND) find_package(Qt5X11Extras ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE) endif() if(APPLE) find_package(Qt5MacExtras ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE) endif() find_package(KF5WindowSystem ${KF5_DEP_VERSION} REQUIRED) find_package(KF5Config ${KF5_DEP_VERSION} REQUIRED) find_package(KF5Codecs ${KF5_DEP_VERSION} REQUIRED) find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED) find_package(Canberra) set_package_properties(Canberra PROPERTIES DESCRIPTION "Library for generating event sounds" PURPOSE "Needed to build audio notification support" URL "http://0pointer.de/lennart/projects/libcanberra" TYPE OPTIONAL) if (CANBERRA_FOUND) add_definitions(-DHAVE_CANBERRA) else() find_package(Phonon4Qt5 4.6.60 NO_MODULE) set_package_properties(Phonon4Qt5 PROPERTIES DESCRIPTION "Qt-based audio library" PURPOSE "Needed to build audio notification support when Canberra isn't available") if (NOT ANDROID) # This is REQUIRED since you cannot tell CMake "either one of those two optional ones are required" set_package_properties(Phonon4Qt5 PROPERTIES TYPE REQUIRED) endif() if (Phonon4Qt5_FOUND) add_definitions(-DHAVE_PHONON4QT5) endif() endif() remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(tests) add_subdirectory(autotests) endif() # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Notifications") if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5Notifications_QCH FILE KF5NotificationsQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5NotificationsQchTargets.cmake\")") endif() include(CMakePackageConfigHelpers) set(HAVE_DBUS FALSE) if (TARGET Qt5::DBus) set(HAVE_DBUS TRUE) endif() configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5NotificationsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5NotificationsConfig.cmake" PATH_VARS KDE_INSTALL_DBUSINTERFACEDIR INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5NotificationsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5NotificationsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5NotificationsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5NotificationsTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/knotifications_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) install(FILES knotifications.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/modules/FindGradle.cmake b/cmake/modules/FindGradle.cmake new file mode 100644 index 0000000..4bd772d --- /dev/null +++ b/cmake/modules/FindGradle.cmake @@ -0,0 +1,106 @@ +#.rst: +# FindGradle +# ---------- +# +# Provides the ability to build Android AAR libraries using Gradle. +# +# This relies on the Qt provided Gradle, so a Qt for Android installation +# is required. +# +# gradle_add_aar( +# BUIDLFILE build.gradle +# NAME ) +# +# This builds an Android AAR library using the given ``build.gradle`` file. +# +# gradle_install_aar( +# DESTINATION ) +# +# Installs a Android AAR library that has been created with ``gradle_add_aar``. + +#============================================================================= +# Copyright (c) 2019 Volker Krause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +include(CMakeParseArguments) +include(FindPackageHandleStandardArgs) + +find_package(Qt5Core REQUIRED) + +if (NOT WIN32) + set(Gradle_EXECUTABLE ${CMAKE_BINARY_DIR}/gradle/gradlew) +else() + set(Gradle_EXECUTABLE ${CMAKE_BINARY_DIR}/gradle/gradlew.bat) +endif() + +get_target_property(_qt_core_location Qt5::Core LOCATION) +get_filename_component(_qt_install_root ${_qt_core_location} DIRECTORY) +get_filename_component(_qt_install_root ${_qt_install_root}/../ ABSOLUTE) + +set(_gradle_template_dir ${CMAKE_CURRENT_LIST_DIR}) + +add_custom_command(OUTPUT ${Gradle_EXECUTABLE} + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/gradle + COMMAND ${CMAKE_COMMAND} -E copy_directory ${_qt_install_root}/src/3rdparty/gradle ${CMAKE_BINARY_DIR}/gradle +) +add_custom_target(gradle DEPENDS ${Gradle_EXECUTABLE}) + +find_package_handle_standard_args(Gradle DEFAULT_MSG Gradle_EXECUTABLE) + +function(gradle_add_aar target) + cmake_parse_arguments(ARG "" "BUILDFILE;NAME" "" ${ARGN}) + + set(_build_root ${CMAKE_CURRENT_BINARY_DIR}/gradle_build/${ARG_NAME}) + configure_file(${_gradle_template_dir}/local.properties.in ${_build_root}/local.properties) + configure_file(${_gradle_template_dir}/settings.gradle.in ${_build_root}/settings.gradle) + configure_file(${ARG_BUILDFILE} ${_build_root}/build.gradle) + + if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(_aar_suffix "-debug") + set(_aar_gradleCmd "assembleDebug") + else() + set(_aar_suffix "-release") + set(_aar_gradleCmd "assembleRelease") + endif() + + add_custom_command( + OUTPUT ${_build_root}/build/outputs/aar/${ARG_NAME}${_aar_suffix}.aar + COMMAND ${Gradle_EXECUTABLE} ${_aar_gradleCmd} + DEPENDS ${Gradle_EXECUTABLE} + DEPENDS gradle + WORKING_DIRECTORY ${_build_root} + ) + add_custom_target(${target} ALL DEPENDS ${_build_root}/build/outputs/aar/${ARG_NAME}${_aar_suffix}.aar) + set_target_properties(${target} PROPERTIES LOCATION ${_build_root}/build/outputs/aar/${ARG_NAME}${_aar_suffix}.aar) + set_target_properties(${target} PROPERTIES OUTPUT_NAME ${ARG_NAME}) +endfunction() + +function(gradle_install_aar target) + cmake_parse_arguments(ARG "" "DESTINATION" "" ${ARGN}) + get_target_property(_loc ${target} LOCATION) + get_target_property(_name ${target} OUTPUT_NAME) + install(FILES ${_loc} DESTINATION ${ARG_DESTINATION} RENAME ${_name}.aar) +endfunction() diff --git a/cmake/modules/local.properties.in b/cmake/modules/local.properties.in new file mode 100644 index 0000000..4f14cc3 --- /dev/null +++ b/cmake/modules/local.properties.in @@ -0,0 +1 @@ +sdk.dir=@ANDROID_SDK_ROOT@ diff --git a/cmake/modules/settings.gradle.in b/cmake/modules/settings.gradle.in new file mode 100644 index 0000000..6628d9e --- /dev/null +++ b/cmake/modules/settings.gradle.in @@ -0,0 +1 @@ +rootProject.name = '@ARG_NAME@' diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9db613b..4cc3892 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,218 +1,209 @@ if (Phonon4Qt5_FOUND) include_directories(${PHONON_INCLUDE_DIR}) endif() if (CANBERRA_FOUND) include_directories(${CANBERRA_INCLUDE_DIRS}) endif() ecm_create_qm_loader(knotifications_QM_LOADER knotifications5_qt) set(knotifications_SRCS knotification.cpp knotificationmanager.cpp kpassivepopup.cpp knotifyconfig.cpp knotificationplugin.cpp notifybypopupgrowl.cpp notifybyexecute.cpp notifybylogfile.cpp notifybytaskbar.cpp ${knotifications_QM_LOADER} ) if (TARGET Qt5::DBus) list(APPEND knotifications_SRCS kstatusnotifieritem.cpp kstatusnotifieritemdbus_p.cpp knotificationrestrictions.cpp imageconverter.cpp #needed to marshal images for sending over dbus by NotifyByPopup notifybypopup.cpp notifybyportal.cpp ) endif() if (ANDROID) if (NOT CMAKE_ANDROID_API VERSION_LESS 23) + add_subdirectory(android) list(APPEND knotifications_SRCS notifybyandroid.cpp knotifications.qrc) - # see qtbase/mkspecs/features/java.prf - set(CMAKE_JAVA_COMPILE_FLAGS -source 6 -target 6) - add_jar(knotifications_jar - SOURCES - org/kde/knotifications/KNotification.java - org/kde/knotifications/NotifyByAndroid.java - INCLUDE_JARS ${ANDROID_SDK_ROOT}/platforms/android-${CMAKE_ANDROID_API}/android.jar - OUTPUT_NAME KF5Notifications - ) else() message(WARNING "Android notification backend needs at least API level 23!") endif() endif() ecm_qt_declare_logging_category(knotifications_SRCS HEADER debug_p.h IDENTIFIER LOG_KNOTIFICATIONS CATEGORY_NAME org.kde.knotifications) if (CANBERRA_FOUND) set(knotifications_SRCS ${knotifications_SRCS} notifybyaudio_canberra.cpp) elseif (Phonon4Qt5_FOUND) set(knotifications_SRCS ${knotifications_SRCS} notifybyaudio_phonon.cpp) endif() if (Qt5TextToSpeech_FOUND) set(knotifications_SRCS ${knotifications_SRCS} notifybytts.cpp) endif() find_package(dbusmenu-qt5 CONFIG) set_package_properties(dbusmenu-qt5 PROPERTIES DESCRIPTION "DBusMenuQt" URL "https://launchpad.net/libdbusmenu-qt" TYPE OPTIONAL PURPOSE "Support for notification area menus via the DBusMenu protocol") if (dbusmenu-qt5_FOUND) message("dbusmenu-qt5_FOUND") set(HAVE_DBUSMENUQT 1) include_directories(${dbusmenu-qt5_INCLUDE_DIRS}) else() set(HAVE_DBUSMENUQT 0) endif() if (TARGET Qt5::DBus) qt5_add_dbus_adaptor(knotifications_SRCS org.kde.StatusNotifierItem.xml kstatusnotifieritemdbus_p.h KStatusNotifierItemDBus) set(statusnotifierwatcher_xml org.kde.StatusNotifierWatcher.xml) qt5_add_dbus_interface(knotifications_SRCS ${statusnotifierwatcher_xml} statusnotifierwatcher_interface) set(notifications_xml org.freedesktop.Notifications.xml) qt5_add_dbus_interface(knotifications_SRCS ${notifications_xml} notifications_interface) endif() configure_file(config-knotifications.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-knotifications.h ) add_library(KF5Notifications ${knotifications_SRCS}) generate_export_header(KF5Notifications BASE_NAME KNotifications) add_library(KF5::Notifications ALIAS KF5Notifications) target_include_directories(KF5Notifications INTERFACE "$") target_link_libraries(KF5Notifications PUBLIC Qt5::Widgets ) if (TARGET Qt5::DBus) target_link_libraries(KF5Notifications PUBLIC Qt5::DBus) endif() target_link_libraries(KF5Notifications PRIVATE KF5::CoreAddons KF5::ConfigCore KF5::WindowSystem KF5::Codecs ) if (Phonon4Qt5_FOUND) target_link_libraries(KF5Notifications PRIVATE ${PHONON_LIBRARIES}) endif() if (CANBERRA_FOUND) target_link_libraries(KF5Notifications PRIVATE ${CANBERRA_LIBRARIES}) endif() if (Qt5TextToSpeech_FOUND) target_link_libraries(KF5Notifications PRIVATE Qt5::TextToSpeech) endif() if(X11_FOUND) target_link_libraries(KF5Notifications PRIVATE ${X11_X11_LIB} Qt5::X11Extras) endif() if(APPLE) target_link_libraries(KF5Notifications PRIVATE Qt5::MacExtras) endif() if(X11_XTest_FOUND) target_link_libraries(KF5Notifications PRIVATE ${X11_XTest_LIB}) endif() if(HAVE_DBUSMENUQT) target_link_libraries(KF5Notifications PRIVATE dbusmenu-qt5) endif() if (ANDROID) target_link_libraries(KF5Notifications PRIVATE Qt5::AndroidExtras) endif() set_target_properties(KF5Notifications PROPERTIES VERSION ${KNOTIFICATIONS_VERSION_STRING} SOVERSION ${KNOTIFICATIONS_SOVERSION} EXPORT_NAME Notifications ) ecm_generate_headers(KNotifications_HEADERS HEADER_NAMES KNotification KPassivePopup KStatusNotifierItem KNotificationRestrictions KNotificationPlugin KNotifyConfig REQUIRED_HEADERS KNotifications_HEADERS ) install(TARGETS KF5Notifications EXPORT KF5NotificationsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/knotifications_export.h ${KNotifications_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KNotifications COMPONENT Devel ) if(BUILD_QCH) ecm_add_qch( KF5Notifications_QCH NAME KNotifications BASE_NAME KF5Notifications VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${KNotifications_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" IMAGE_DIRS "${CMAKE_SOURCE_DIR}/docs/pics" LINK_QCHS Qt5Widgets_QCH BLANK_MACROS KNOTIFICATIONS_EXPORT KNOTIFICATIONS_DEPRECATED KNOTIFICATIONS_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() if (TARGET Qt5::DBus) install(FILES org.kde.StatusNotifierItem.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} RENAME kf5_org.kde.StatusNotifierItem.xml) install(FILES org.kde.StatusNotifierWatcher.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} RENAME kf5_org.kde.StatusNotifierWatcher.xml) endif() install(FILES knotificationplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KNotifications LIB_NAME KF5Notifications DEPS "widgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KNotifications) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) if (ANDROID AND NOT ANDROID_API_LEVEL VERSION_LESS 23) - install_jar(knotifications_jar DESTINATION jar) install(FILES KF5Notifications-android-dependencies.xml DESTINATION ${KDE_INSTALL_LIBDIR}) endif() diff --git a/src/KF5Notifications-android-dependencies.xml b/src/KF5Notifications-android-dependencies.xml index 62e4b0a..42bd71b 100644 --- a/src/KF5Notifications-android-dependencies.xml +++ b/src/KF5Notifications-android-dependencies.xml @@ -1,9 +1,9 @@ - + diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml new file mode 100644 index 0000000..e627147 --- /dev/null +++ b/src/android/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/src/android/CMakeLists.txt b/src/android/CMakeLists.txt new file mode 100644 index 0000000..58b5908 --- /dev/null +++ b/src/android/CMakeLists.txt @@ -0,0 +1,2 @@ +gradle_add_aar(knotifications_aar BUILDFILE ${CMAKE_CURRENT_SOURCE_DIR}/build.gradle NAME KF5Notifications) +gradle_install_aar(knotifications_aar DESTINATION jar) diff --git a/src/android/build.gradle b/src/android/build.gradle new file mode 100644 index 0000000..26b2557 --- /dev/null +++ b/src/android/build.gradle @@ -0,0 +1,37 @@ +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.2.0' + } +} + +repositories { + google() + jcenter() +} + +apply plugin: 'com.android.library' + +dependencies { + implementation 'androidx.core:core:1.0.1' +} + +android { + compileSdkVersion 28 + buildToolsVersion '28.0.2' + + sourceSets { + main { + manifest.srcFile '@CMAKE_CURRENT_SOURCE_DIR@/AndroidManifest.xml' + java.srcDirs = ['@CMAKE_CURRENT_SOURCE_DIR@/org'] + } + } + + lintOptions { + abortOnError false + } +} diff --git a/src/org/kde/knotifications/KNotification.java b/src/android/org/kde/knotifications/KNotification.java similarity index 100% rename from src/org/kde/knotifications/KNotification.java rename to src/android/org/kde/knotifications/KNotification.java diff --git a/src/org/kde/knotifications/NotifyByAndroid.java b/src/android/org/kde/knotifications/NotifyByAndroid.java similarity index 100% rename from src/org/kde/knotifications/NotifyByAndroid.java rename to src/android/org/kde/knotifications/NotifyByAndroid.java