summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell-plugins/CMakeLists.txt
blob: a7e88fa7474e1d3b8a8e293554b9f3c7c1537cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
set(INSTALL_QMLDIR "" CACHE STRING "QML install dir")
set(INSTALL_QML_PREFIX "" CACHE STRING "QML install prefix")

# There doesn't seem to be a standard cross-distro qml install path.
if ("${INSTALL_QMLDIR}" STREQUAL "" AND "${INSTALL_QML_PREFIX}" STREQUAL "")
	message(WARNING "Neither INSTALL_QMLDIR nor INSTALL_QML_PREFIX is set. QML modules will not be installed.")
else()
	if ("${INSTALL_QMLDIR}" STREQUAL "")
		set(QML_FULL_INSTALLDIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_QML_PREFIX}")
	else()
		set(QML_FULL_INSTALLDIR "${INSTALL_QMLDIR}")
	endif()

	message(STATUS "QML install dir: ${QML_FULL_INSTALLDIR}")
endif()

# Install a given target as a QML module. This is mostly pulled from ECM, as there does not seem
# to be an official way to do it.
# see https://github.com/KDE/extra-cmake-modules/blob/fe0f606bf7f222e36f7560fd7a2c33ef993e23bb/modules/ECMQmlModule6.cmake#L160
function(install_qml_module arg_TARGET)
	if (NOT DEFINED QML_FULL_INSTALLDIR)
		return()
	endif()

	qt_query_qml_module(${arg_TARGET}
		URI module_uri
		VERSION module_version
		PLUGIN_TARGET module_plugin_target
		TARGET_PATH module_target_path
		QMLDIR module_qmldir
		TYPEINFO module_typeinfo
		QML_FILES module_qml_files
		RESOURCES module_resources
	)

  set(module_dir "${QML_FULL_INSTALLDIR}/${module_target_path}")

  if (NOT TARGET "${module_plugin_target}")
    message(FATAL_ERROR "install_qml_modules called for a target without a plugin")
  endif()

	get_target_property(target_type "${arg_TARGET}" TYPE)
	if (NOT "${target_type}" STREQUAL "STATIC_LIBRARY")
		install(
			TARGETS "${arg_TARGET}"
			LIBRARY DESTINATION "${module_dir}"
			RUNTIME DESTINATION "${module_dir}"
		)

		install(
			TARGETS "${module_plugin_target}"
			LIBRARY DESTINATION "${module_dir}"
			RUNTIME DESTINATION "${module_dir}"
		)
	endif()

  install(FILES "${module_qmldir}" DESTINATION "${module_dir}")
  install(FILES "${module_typeinfo}" DESTINATION "${module_dir}")

  # Install QML files
  list(LENGTH module_qml_files num_files)
  if (NOT "${module_qml_files}" MATCHES "NOTFOUND" AND ${num_files} GREATER 0)
    qt_query_qml_module(${arg_TARGET} QML_FILES_DEPLOY_PATHS qml_files_deploy_paths)

    math(EXPR last_index "${num_files} - 1")
    foreach(i RANGE 0 ${last_index})
      list(GET module_qml_files       ${i} src_file)
      list(GET qml_files_deploy_paths ${i} deploy_path)
      get_filename_component(dst_name "${deploy_path}" NAME)
      get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
      install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
    endforeach()
  endif()

  # Install resources
  list(LENGTH module_resources num_files)
  if (NOT "${module_resources}" MATCHES "NOTFOUND" AND ${num_files} GREATER 0)
    qt_query_qml_module(${arg_TARGET} RESOURCES_DEPLOY_PATHS resources_deploy_paths)

    math(EXPR last_index "${num_files} - 1")
    foreach(i RANGE 0 ${last_index})
      list(GET module_resources       ${i} src_file)
      list(GET resources_deploy_paths ${i} deploy_path)
      get_filename_component(dst_name "${deploy_path}" NAME)
      get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
      install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
    endforeach()
  endif()
endfunction()


cmake_minimum_required(VERSION 3.20)
project(custom LANGUAGES CXX)

find_package(Qt6 REQUIRED COMPONENTS Core Qml DBus)

qt_standard_project_setup(REQUIRES 6.6)

qt6_policy(SET QTP0001 NEW)
qt6_add_qml_module(customplugin
    URI "Custom"
    PLUGIN_TARGET customplugin
)

set_source_files_properties(org.keepassxc.KeePassXC.MainWindow.xml PROPERTIES
	CLASSNAME DBusKeePassXC
	NO_NAMESPACE TRUE
)

qt_add_dbus_interface(DBUS_INTERFACES
	org.keepassxc.KeePassXC.MainWindow.xml
	dbus_keepassxc
)

include_directories(${CMAKE_SOURCE_DIR}/build)

target_compile_features(customplugin PUBLIC cxx_std_26)

target_link_libraries(customplugin PRIVATE
    Qt6::Core
    Qt6::Qml
    Qt6::DBus
)

target_sources(customplugin PRIVATE
    Chrono.cpp Chrono.hpp
    FileSelector.cpp FileSelector.hpp
    KeePassXC.cpp KeePassXC.hpp
    Systemd.cpp Systemd.hpp
    ${DBUS_INTERFACES}
)

install_qml_module(customplugin)