From cd58bbf4923c3b241bf0a8ce5b768cf95a4fdd91 Mon Sep 17 00:00:00 2001
From: Bart Ribbers <bribbers@disroot.org>
Date: Sun, 18 Apr 2021 17:22:02 +0200
Subject: [PATCH] Port to CMake

qmake is slowly being deprecated by Qt (they don't use it themselves
anymore from Qt6 and onwards) and they recommend using CMake instead.
---
 .gitignore                                    |  7 +-
 CMakeLists.txt                                | 51 ++++++++++++++
 calendar.pro                                  |  7 --
 lightweight/CMakeLists.txt                    |  2 +
 .../calendardataservice/CMakeLists.txt        | 23 ++++++
 .../calendardataservice.pro                   | 45 ------------
 .../calendareventsmodel/CMakeLists.txt        | 23 ++++++
 .../calendareventsmodel.pro                   | 34 ---------
 lightweight/lightweight.pro                   |  2 -
 src/CMakeLists.txt                            | 62 ++++++++++++++++
 src/src.pro                                   | 70 -------------------
 tests/CMakeLists.txt                          |  5 ++
 tests/common.pri                              |  9 ---
 tests/tests.pro                               | 11 ---
 tests/tests.xml                               | 16 -----
 tests/tst_calendaragendamodel/CMakeLists.txt  | 15 ++++
 .../tst_calendaragendamodel.pro               |  4 --
 tests/tst_calendarevent/CMakeLists.txt        | 17 +++++
 .../test_plugin/CMakeLists.txt                | 13 ++++
 .../test_plugin/test_plugin.pro               | 16 -----
 tests/tst_calendarevent/tst_calendarevent.pro |  4 --
 .../tst_calendareventbin.pro                  |  5 --
 tests/tst_calendarmanager/CMakeLists.txt      | 15 ++++
 .../tst_calendarmanager.pro                   |  4 --
 tools/CMakeLists.txt                          |  1 +
 tools/icalconverter/CMakeLists.txt            | 10 +++
 tools/icalconverter/icalconverter.pro         | 10 ---
 tools/tools.pro                               |  2 -
 28 files changed, 238 insertions(+), 245 deletions(-)
 create mode 100644 CMakeLists.txt
 delete mode 100644 calendar.pro
 create mode 100644 lightweight/CMakeLists.txt
 create mode 100644 lightweight/calendardataservice/CMakeLists.txt
 delete mode 100644 lightweight/calendardataservice/calendardataservice.pro
 create mode 100644 lightweight/calendareventsmodel/CMakeLists.txt
 delete mode 100644 lightweight/calendareventsmodel/calendareventsmodel.pro
 delete mode 100644 lightweight/lightweight.pro
 create mode 100644 src/CMakeLists.txt
 delete mode 100644 src/src.pro
 create mode 100644 tests/CMakeLists.txt
 delete mode 100644 tests/common.pri
 delete mode 100644 tests/tests.pro
 delete mode 100644 tests/tests.xml
 create mode 100644 tests/tst_calendaragendamodel/CMakeLists.txt
 delete mode 100644 tests/tst_calendaragendamodel/tst_calendaragendamodel.pro
 create mode 100644 tests/tst_calendarevent/CMakeLists.txt
 create mode 100644 tests/tst_calendarevent/test_plugin/CMakeLists.txt
 delete mode 100644 tests/tst_calendarevent/test_plugin/test_plugin.pro
 delete mode 100644 tests/tst_calendarevent/tst_calendarevent.pro
 delete mode 100644 tests/tst_calendarevent/tst_calendareventbin.pro
 create mode 100644 tests/tst_calendarmanager/CMakeLists.txt
 delete mode 100644 tests/tst_calendarmanager/tst_calendarmanager.pro
 create mode 100644 tools/CMakeLists.txt
 create mode 100644 tools/icalconverter/CMakeLists.txt
 delete mode 100644 tools/icalconverter/icalconverter.pro
 delete mode 100644 tools/tools.pro

diff --git a/.gitignore b/.gitignore
index 7fdc54b..2d578b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,8 @@
 # Build artefacts
 *.o
 *.so
-/lightweight/calendardataservice/calendardataservice
-/tests/tst_calendarevent/tst_calendarevent
-/tests/tst_calendarmanager/tst_calendarmanager
-/tests/tst_calendaragendamodel/tst_calendaragendamodel
-/tests/tst_calendarevent/Makefile.tst_calendareventbin
-/tools/icalconverter/icalconverter
 /RPMS
+build
 
 # Generated sources
 Makefile
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..97c268c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,51 @@
+cmake_minimum_required(VERSION 3.16.0)
+
+project(nemo-qml-plugin-calendar)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(FindPkgConfig)
+include(FeatureSummary)
+include(GNUInstallDirs)
+include(CTest)
+
+set(INSTALL_QML_IMPORT_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/qt/qml"
+	CACHE PATH "Custom QML import installation directory")
+
+find_package(PkgConfig REQUIRED)
+find_package(ECM REQUIRED NO_MODULE)
+set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
+
+set(QT_MIN_VERSION "5.6.0")
+find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS DBus Gui Qml Concurrent Test REQUIRED)
+find_package(KF5 COMPONENTS CalendarCore REQUIRED)
+
+pkg_check_modules(MKCAL libmkcal-qt5 IMPORTED_TARGET REQUIRED)
+set_property(GLOBAL APPEND PROPERTY _CMAKE_libmkcal-qt5_TYPE REQUIRED)
+pkg_check_modules(ACCOUNTS accounts-qt5 IMPORTED_TARGET REQUIRED)
+set_property(GLOBAL APPEND PROPERTY _CMAKE_accounts-qt5_TYPE REQUIRED)
+
+if(MKCAL_FOUND)
+	set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND libmkcal-qt5)
+else()
+	set_property(GLOBAL APPEND PROPERTY PACKAGES_NOT_FOUND libmkcal-qt5)
+endif()
+if(ACCOUNTS_FOUND)
+	set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND accounts-qt5)
+else()
+	set_property(GLOBAL APPEND PROPERTY PACKAGES_NOT_FOUND accounts-qt5)
+endif()
+
+add_subdirectory(src)
+add_subdirectory(lightweight)
+add_subdirectory(tools)
+
+if(BUILD_TESTING)
+	add_subdirectory(tests)
+endif()
+
+feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/calendar.pro b/calendar.pro
deleted file mode 100644
index 588555a..0000000
--- a/calendar.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = src tests lightweight tools
-
-tests.depends = src
-tools.depends = src
-
-OTHER_FILES += rpm/*
diff --git a/lightweight/CMakeLists.txt b/lightweight/CMakeLists.txt
new file mode 100644
index 0000000..4fff204
--- /dev/null
+++ b/lightweight/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(calendardataservice)
+add_subdirectory(calendareventsmodel)
diff --git a/lightweight/calendardataservice/CMakeLists.txt b/lightweight/calendardataservice/CMakeLists.txt
new file mode 100644
index 0000000..36425cf
--- /dev/null
+++ b/lightweight/calendardataservice/CMakeLists.txt
@@ -0,0 +1,23 @@
+set(SRC
+	main.cpp
+	calendardataservice.cpp
+	calendardataserviceadaptor.cpp
+	../common/eventdata.cpp)
+set(HEADERS
+	calendardataservice.h
+	calendardataserviceadaptor.h
+	../common/eventdata.h)
+
+add_executable(calendardataservice ${SRC} ${HEADERS})
+target_link_libraries(calendardataservice
+	Qt5::Qml
+	Qt5::DBus
+	KF5::CalendarCore
+	mkcal-qt5
+	accounts-qt5
+	nemocalendar)
+
+install(TARGETS calendardataservice
+	DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(FILES org.nemomobile.calendardataservice.service
+	DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services)
diff --git a/lightweight/calendardataservice/calendardataservice.pro b/lightweight/calendardataservice/calendardataservice.pro
deleted file mode 100644
index a311951..0000000
--- a/lightweight/calendardataservice/calendardataservice.pro
+++ /dev/null
@@ -1,45 +0,0 @@
-TEMPLATE = app
-TARGET = calendardataservice
-target.path = /usr/bin
-
-QT += qml dbus
-QT -= gui
-
-CONFIG += link_pkgconfig
-PKGCONFIG += KF5CalendarCore libmkcal-qt5 accounts-qt5
-
-HEADERS += \
-    calendardataservice.h \
-    calendardataserviceadaptor.h \
-    ../common/eventdata.h \
-    ../../src/calendaragendamodel.h \
-    ../../src/calendareventlistmodel.h \
-    ../../src/calendarmanager.h \
-    ../../src/calendarworker.h \
-    ../../src/calendareventoccurrence.h \
-    ../../src/calendarevent.h \
-    ../../src/calendareventquery.h \
-    ../../src/calendarinvitationquery.h \
-    ../../src/calendarutils.h
-
-SOURCES += \
-    calendardataservice.cpp \
-    calendardataserviceadaptor.cpp \
-    ../common/eventdata.cpp \
-    ../../src/calendaragendamodel.cpp \
-    ../../src/calendareventlistmodel.cpp \
-    ../../src/calendarmanager.cpp \
-    ../../src/calendarworker.cpp \
-    ../../src/calendareventoccurrence.cpp \
-    ../../src/calendarevent.cpp \
-    ../../src/calendareventquery.cpp \
-    ../../src/calendarinvitationquery.cpp \
-    ../../src/calendarutils.cpp \
-    main.cpp
-
-dbus_service.path = /usr/share/dbus-1/services/
-dbus_service.files = org.nemomobile.calendardataservice.service
-
-INSTALLS += target dbus_service
-
-OTHER_FILES += *.service *.xml
diff --git a/lightweight/calendareventsmodel/CMakeLists.txt b/lightweight/calendareventsmodel/CMakeLists.txt
new file mode 100644
index 0000000..c29c1dd
--- /dev/null
+++ b/lightweight/calendareventsmodel/CMakeLists.txt
@@ -0,0 +1,23 @@
+set(PLUGIN_IMPORT_PATH ${INSTALL_QML_IMPORT_DIR}/org/nemomobile/calendar/lightweight)
+
+set(SRC
+	calendardataserviceproxy.cpp
+	calendareventsmodel.cpp
+	plugin.cpp
+	../common/eventdata.cpp)
+set(HEADERS
+	calendardataserviceproxy.h
+	calendareventsmodel.h
+	../common/eventdata.h)
+
+add_library(calendareventsmodel SHARED ${SRC} ${HEADERS})
+
+target_link_libraries(calendareventsmodel
+	Qt5::Gui
+	Qt5::Qml
+	Qt5::DBus)
+
+install(TARGETS calendareventsmodel
+	DESTINATION ${PLUGIN_IMPORT_PATH})
+install(FILES qmldir plugins.qmltypes
+	DESTINATION ${PLUGIN_IMPORT_PATH})
diff --git a/lightweight/calendareventsmodel/calendareventsmodel.pro b/lightweight/calendareventsmodel/calendareventsmodel.pro
deleted file mode 100644
index 1016304..0000000
--- a/lightweight/calendareventsmodel/calendareventsmodel.pro
+++ /dev/null
@@ -1,34 +0,0 @@
-TARGET = nemocalendarwidget
-PLUGIN_IMPORT_PATH = org/nemomobile/calendar/lightweight
-
-TEMPLATE = lib
-CONFIG += qt plugin hide_symbols
-
-QT += qml dbus
-
-target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
-INSTALLS += target
-
-qmldir.files += qmldir plugins.qmltypes
-qmldir.path +=  $$target.path
-INSTALLS += qmldir
-
-qmltypes.commands = qmlplugindump -nonrelocatable org.nemomobile.calendar.lightweight 1.0 > $$PWD/plugins.qmltypes
-QMAKE_EXTRA_TARGETS += qmltypes
-
-isEmpty(SRCDIR) SRCDIR = "."
-SOURCES += \
-    calendardataserviceproxy.cpp \
-    calendareventsmodel.cpp \
-    ../common/eventdata.cpp \
-    plugin.cpp
-
-HEADERS += \
-    calendardataserviceproxy.h \
-    calendareventsmodel.h \
-    ../common/eventdata.h
-
-OTHER_FILES += qmldir
-
-MOC_DIR = $$PWD/.moc
-OBJECTS_DIR = $$PWD/.obj
diff --git a/lightweight/lightweight.pro b/lightweight/lightweight.pro
deleted file mode 100644
index 6fe91a6..0000000
--- a/lightweight/lightweight.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = calendardataservice calendareventsmodel
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..901c1dd
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,62 @@
+set(PLUGIN_IMPORT_PATH ${INSTALL_QML_IMPORT_DIR}/org/nemomobile/calendar)
+set(CMAKE_INSTALL_RPATH "${PLUGIN_IMPORT_PATH}")
+
+set(SRC
+	plugin.cpp
+	calendarevent.cpp
+	calendareventoccurrence.cpp
+	calendaragendamodel.cpp
+	calendarapi.cpp
+	calendareventquery.cpp
+	calendarinvitationquery.cpp
+	calendarnotebookmodel.cpp
+	calendarmanager.cpp
+	calendarworker.cpp
+	calendarnotebookquery.cpp
+	calendareventmodification.cpp	
+	calendarutils.cpp
+	calendarimportmodel.cpp
+	calendarimportevent.cpp
+	calendarcontactmodel.cpp
+	calendarattendeemodel.cpp
+	calendareventlistmodel.cpp)
+set(HEADERS
+	calendarevent.h
+	calendareventoccurrence.h
+	calendaragendamodel.h
+	calendarapi.h
+	calendareventquery.h
+	calendarinvitationquery.h
+	calendarnotebookmodel.h
+	calendarmanager.h
+	calendarworker.h
+	calendardata.h
+	calendarnotebookquery.h
+	calendareventmodification.h	
+	calendarutils.h
+	calendarimportmodel.h
+	calendarimportevent.h
+	calendarcontactmodel.h
+	calendarattendeemodel.h
+	calendareventlistmodel.h)
+
+add_library(nemocalendar SHARED ${SRC} ${HEADERS})
+
+set(TARGET_MOC_DIR ${CMAKE_CURRENT_BINARY_DIR}/calendar_autogen)
+set_target_properties(nemocalendar PROPERTIES AUTOGEN_BUILD_DIR ${TARGET_MOC_DIR})
+
+# For use in other parts of the build
+set(TARGET_MOC_DIR ${TARGET_MOC_DIR}/include PARENT_SCOPE)
+
+target_link_libraries(nemocalendar
+	Qt5::Qml
+	Qt5::Concurrent
+	KF5::CalendarCore
+	PkgConfig::MKCAL
+	PkgConfig::ACCOUNTS)
+
+# Install the library
+install(TARGETS nemocalendar
+	LIBRARY DESTINATION ${PLUGIN_IMPORT_PATH})
+install(FILES qmldir plugins.qmltypes
+	DESTINATION ${PLUGIN_IMPORT_PATH})
diff --git a/src/src.pro b/src/src.pro
deleted file mode 100644
index a6de4e5..0000000
--- a/src/src.pro
+++ /dev/null
@@ -1,70 +0,0 @@
-TARGET = nemocalendar
-PLUGIN_IMPORT_PATH = org/nemomobile/calendar
-
-TEMPLATE = lib
-CONFIG += qt plugin hide_symbols
-
-QT += qml concurrent
-QT -= gui
-QMAKE_CXXFLAGS += -Werror
-
-target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
-PKGCONFIG += KF5CalendarCore libmkcal-qt5 accounts-qt5
-
-INSTALLS += target
-
-qmldir.files += qmldir plugins.qmltypes
-qmldir.path +=  $$target.path
-INSTALLS += qmldir
-
-qmltypes.commands = qmlplugindump -noinstantiate -nonrelocatable org.nemomobile.calendar 1.0 > $$PWD/plugins.qmltypes
-QMAKE_EXTRA_TARGETS += qmltypes
-
-CONFIG += link_pkgconfig
-
-isEmpty(SRCDIR) SRCDIR = "."
-
-SOURCES += \
-    $$SRCDIR/plugin.cpp \
-    $$SRCDIR/calendarevent.cpp \
-    $$SRCDIR/calendareventoccurrence.cpp \
-    $$SRCDIR/calendaragendamodel.cpp \
-    $$SRCDIR/calendareventlistmodel.cpp \
-    $$SRCDIR/calendarapi.cpp \
-    $$SRCDIR/calendareventquery.cpp \
-    $$SRCDIR/calendarinvitationquery.cpp \
-    $$SRCDIR/calendarnotebookmodel.cpp \
-    $$SRCDIR/calendarmanager.cpp \
-    $$SRCDIR/calendarworker.cpp \
-    $$SRCDIR/calendarnotebookquery.cpp \
-    $$SRCDIR/calendareventmodification.cpp \
-    $$SRCDIR/calendarutils.cpp \
-    $$SRCDIR/calendarimportmodel.cpp \
-    $$SRCDIR/calendarimportevent.cpp \
-    $$SRCDIR/calendarcontactmodel.cpp \
-    $$SRCDIR/calendarattendeemodel.cpp
-
-HEADERS += \
-    $$SRCDIR/calendarevent.h \
-    $$SRCDIR/calendareventoccurrence.h \
-    $$SRCDIR/calendaragendamodel.h \
-    $$SRCDIR/calendareventlistmodel.h \
-    $$SRCDIR/calendarapi.h \
-    $$SRCDIR/calendareventquery.h \
-    $$SRCDIR/calendarinvitationquery.h \
-    $$SRCDIR/calendarnotebookmodel.h \
-    $$SRCDIR/calendarmanager.h \
-    $$SRCDIR/calendarworker.h \
-    $$SRCDIR/calendardata.h \
-    $$SRCDIR/calendarnotebookquery.h \
-    $$SRCDIR/calendareventmodification.h \
-    $$SRCDIR/calendarutils.h \
-    $$SRCDIR/calendarimportmodel.h \
-    $$SRCDIR/calendarimportevent.h \
-    $$SRCDIR/calendarcontactmodel.h \
-    $$SRCDIR/calendarattendeemodel.h
-
-OTHER_FILES += qmldir
-
-MOC_DIR = $$PWD/.moc
-OBJECTS_DIR = $$PWD/.obj
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..b0f453b
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,5 @@
+enable_testing()
+
+add_subdirectory(tst_calendarevent)
+add_subdirectory(tst_calendarmanager)
+add_subdirectory(tst_calendaragendamodel)
diff --git a/tests/common.pri b/tests/common.pri
deleted file mode 100644
index bab74e7..0000000
--- a/tests/common.pri
+++ /dev/null
@@ -1,9 +0,0 @@
-SRCDIR = ../../src/
-include(../src/src.pro)
-INCLUDEPATH += $$SRCDIR
-DEPENDPATH = $$INCLUDEPATH
-QT += testlib
-TEMPLATE = app
-CONFIG -= app_bundle
-
-target.path = /opt/tests/nemo-qml-plugins-qt5/calendar
diff --git a/tests/tests.pro b/tests/tests.pro
deleted file mode 100644
index 8405ea0..0000000
--- a/tests/tests.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = \
-    tst_calendarmanager \
-    tst_calendarevent \
-    tst_calendaragendamodel
-
-tests_xml.path = /opt/tests/nemo-qml-plugins-qt5/calendar
-tests_xml.files = tests.xml
-INSTALLS += tests_xml
-
-OTHER_FILES += tests.xml
diff --git a/tests/tests.xml b/tests/tests.xml
deleted file mode 100644
index 2b91b34..0000000
--- a/tests/tests.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<testdefinition version="1.0">
-  <suite name="nemo-qml-plugins-calendar-qt5-tests" domain="mw">
-    <set name="unit-tests" feature="calendar mw">
-      <case manual="false" name="calendarmanager">
-        <step>rm -f /tmp/testdb; SQLITESTORAGEDB=/tmp/testdb /usr/sbin/run-blts-root /bin/su $USER -g privileged -c /opt/tests/nemo-qml-plugins-qt5/calendar/tst_calendarmanager</step>
-      </case>
-      <case manual="false" name="calendarevent">
-        <step>rm -f /tmp/testdb; SQLITESTORAGEDB=/tmp/testdb MKCAL_PLUGIN_DIR=/opt/tests/nemo-qml-plugins-qt5/calendar/plugins /usr/sbin/run-blts-root /bin/su $USER -g privileged -c /opt/tests/nemo-qml-plugins-qt5/calendar/tst_calendarevent</step>
-      </case>
-      <case manual="false" name="calendaragendamodel">
-        <step>rm -f /tmp/testdb; SQLITESTORAGEDB=/tmp/testdb /usr/sbin/run-blts-root /bin/su $USER -g privileged -c /opt/tests/nemo-qml-plugins-qt5/calendar/tst_calendaragendamodel</step>
-      </case>
-    </set>
-  </suite>
-</testdefinition>
diff --git a/tests/tst_calendaragendamodel/CMakeLists.txt b/tests/tst_calendaragendamodel/CMakeLists.txt
new file mode 100644
index 0000000..09cfa06
--- /dev/null
+++ b/tests/tst_calendaragendamodel/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(SRC tst_calendaragendamodel.cpp)
+
+add_executable(tst_calendaragendamodel ${SRC})
+
+target_include_directories(tst_calendaragendamodel PRIVATE
+	${PROJECT_SOURCE_DIR}/src
+	${TARGET_MOC_DIR})
+
+target_link_libraries(tst_calendaragendamodel
+	Qt5::Qml
+	Qt5::Test
+	KF5::CalendarCore
+	nemocalendar)
+
+add_test(tst_calendaragendamodel tst_calendaragendamodel)
diff --git a/tests/tst_calendaragendamodel/tst_calendaragendamodel.pro b/tests/tst_calendaragendamodel/tst_calendaragendamodel.pro
deleted file mode 100644
index d9b67f3..0000000
--- a/tests/tst_calendaragendamodel/tst_calendaragendamodel.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-include(../common.pri)
-
-TARGET = tst_calendaragendamodel
-SOURCES += tst_calendaragendamodel.cpp
diff --git a/tests/tst_calendarevent/CMakeLists.txt b/tests/tst_calendarevent/CMakeLists.txt
new file mode 100644
index 0000000..50f49f5
--- /dev/null
+++ b/tests/tst_calendarevent/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(SRC tst_calendarevent.cpp)
+
+add_executable(tst_calendarevent ${SRC})
+
+target_include_directories(tst_calendarevent PRIVATE
+	${PROJECT_SOURCE_DIR}/src
+	${TARGET_MOC_DIR})
+
+target_link_libraries(tst_calendarevent
+	Qt5::Qml
+	Qt5::Test
+	KF5::CalendarCore
+	nemocalendar)
+
+add_test(tst_calendarevent tst_calendarevent)
+
+add_subdirectory(test_plugin)
diff --git a/tests/tst_calendarevent/test_plugin/CMakeLists.txt b/tests/tst_calendarevent/test_plugin/CMakeLists.txt
new file mode 100644
index 0000000..9188446
--- /dev/null
+++ b/tests/tst_calendarevent/test_plugin/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(SRC test_plugin.cpp)
+
+add_library(tst_calendarevent_plugin ${SRC})
+
+target_include_directories(tst_calendarevent_plugin PRIVATE
+	${PROJECT_SOURCE_DIR}/src
+	${TARGET_MOC_DIR})
+
+target_link_libraries(tst_calendarevent_plugin
+	Qt5::Qml
+	Qt5::Test
+	KF5::CalendarCore
+	PkgConfig::MKCAL)
diff --git a/tests/tst_calendarevent/test_plugin/test_plugin.pro b/tests/tst_calendarevent/test_plugin/test_plugin.pro
deleted file mode 100644
index 0ec993f..0000000
--- a/tests/tst_calendarevent/test_plugin/test_plugin.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TARGET = testplugin
-
-TEMPLATE = lib
-CONFIG += qt plugin hide_symbols
-
-QT -= gui
-
-target.path = /opt/tests/nemo-qml-plugins-qt5/calendar/plugins
-PKGCONFIG += KF5CalendarCore libmkcal-qt5
-
-INSTALLS += target
-
-CONFIG += link_pkgconfig
-
-SOURCES += test_plugin.cpp
-HEADERS += test_plugin.h
diff --git a/tests/tst_calendarevent/tst_calendarevent.pro b/tests/tst_calendarevent/tst_calendarevent.pro
deleted file mode 100644
index a2d5722..0000000
--- a/tests/tst_calendarevent/tst_calendarevent.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = \
-    test_plugin \
-    tst_calendareventbin.pro
diff --git a/tests/tst_calendarevent/tst_calendareventbin.pro b/tests/tst_calendarevent/tst_calendareventbin.pro
deleted file mode 100644
index b52729e..0000000
--- a/tests/tst_calendarevent/tst_calendareventbin.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-include(../common.pri)
-
-TARGET = tst_calendarevent
-SOURCES += tst_calendarevent.cpp
-HEADERS += test_plugin_interface.h
diff --git a/tests/tst_calendarmanager/CMakeLists.txt b/tests/tst_calendarmanager/CMakeLists.txt
new file mode 100644
index 0000000..66c959f
--- /dev/null
+++ b/tests/tst_calendarmanager/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(SRC tst_calendarmanager.cpp)
+
+add_executable(tst_calendarmanager ${SRC})
+
+target_include_directories(tst_calendarmanager PRIVATE
+	${PROJECT_SOURCE_DIR}/src
+	${TARGET_MOC_DIR})
+
+target_link_libraries(tst_calendarmanager
+	Qt5::Qml
+	Qt5::Test
+	KF5::CalendarCore
+	nemocalendar)
+
+add_test(tst_calendarmanager tst_calendarmanager)
diff --git a/tests/tst_calendarmanager/tst_calendarmanager.pro b/tests/tst_calendarmanager/tst_calendarmanager.pro
deleted file mode 100644
index ace2f6d..0000000
--- a/tests/tst_calendarmanager/tst_calendarmanager.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-include(../common.pri)
-
-TARGET = tst_calendarmanager
-SOURCES += tst_calendarmanager.cpp
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 0000000..7d81e07
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(icalconverter)
diff --git a/tools/icalconverter/CMakeLists.txt b/tools/icalconverter/CMakeLists.txt
new file mode 100644
index 0000000..aa094ff
--- /dev/null
+++ b/tools/icalconverter/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(SRC main.cpp)
+
+add_executable(icalconverter ${SRC})
+
+target_link_libraries(icalconverter
+	KF5::CalendarCore
+	PkgConfig::MKCAL)
+
+install(TARGETS icalconverter
+	DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/tools/icalconverter/icalconverter.pro b/tools/icalconverter/icalconverter.pro
deleted file mode 100644
index fa373c2..0000000
--- a/tools/icalconverter/icalconverter.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-TEMPLATE=app
-TARGET=icalconverter
-QT-=gui
-CONFIG += link_pkgconfig
-PKGCONFIG += KF5CalendarCore libmkcal-qt5
-QMAKE_CXXFLAGS += -fPIE -fvisibility=hidden -fvisibility-inlines-hidden
-SOURCES+=main.cpp
-
-target.path = $$INSTALL_ROOT/usr/bin/
-INSTALLS+=target
diff --git a/tools/tools.pro b/tools/tools.pro
deleted file mode 100644
index 1827543..0000000
--- a/tools/tools.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-TEMPLATE=subdirs
-SUBDIRS+=icalconverter
