on xenial help sign in
Refactor export_qmlfiles and export_qmlplugins to be more generic.
commit0ed938e1ce6dcaf4531c2f91d498c6f4f256c186 authorMichał Sawicz <michal.sawicz@canonical.com> dateSat 3 May 2014, 00:57 (12 years ago) parentdb5700c
26 files changed+173−138
cmake/modules/Plugins.cmake−68 cmake/modules/QmlPlugins.cmake+135 plugins/AccountsService/CMakeLists.txt+1−4 plugins/AccountsService/qmldir+1−1 plugins/CMakeLists.txt+13 plugins/DashViews/CMakeLists.txt+1−6 plugins/DashViews/qmldir+1−1 plugins/HudClient/CMakeLists.txt+1−6 plugins/HudClient/qmldir+1−1 plugins/LightDM/CMakeLists.txt+1−6 plugins/LightDM/qmldir+1−1 plugins/Powerd/CMakeLists.txt+1−3 plugins/Powerd/qmldir+1−1 plugins/SessionBroadcast/CMakeLists.txt+1−4 plugins/SessionBroadcast/qmldir+1−1 plugins/Ubuntu/DownloadDaemonListener/CMakeLists.txt+1−6 plugins/Ubuntu/DownloadDaemonListener/qmldir+1−1 plugins/Ubuntu/Gestures/CMakeLists.txt+1−6 plugins/Ubuntu/Gestures/qmldir+1−1 plugins/Unity/Indicators/CMakeLists.txt+4−7 plugins/Unity/Indicators/qml/CMakeLists.txt−5 plugins/Unity/Indicators/qml/qmldir+1−1 plugins/Unity/Launcher/CMakeLists.txt+1−3 plugins/Unity/Launcher/qmldir+1−1 plugins/Utils/CMakeLists.txt+1−3 plugins/Utils/qmldir+1−1
cmake/modules/Plugins.cmakedeleted−68
@@ -1,68 +0,0 @@
1−find_program(qmlplugindump_exe qmlplugindump)
2−
3−if(NOT qmlplugindump_exe)
4− msg(FATAL_ERROR "Could not locate qmlplugindump.")
5−endif()
6−
7−# Creates target for copying and installing qmlfiles
8−#
9−# export_qmlfiles(plugin sub_path)
10−#
11−#
12−# Target to be created:
13−# - plugin-qmlfiles - Copies the qml files (*.qml, *.js, qmldir) into the shadow build folder.
14−
15−macro(export_qmlfiles PLUGIN PLUGIN_SUBPATH)
16−
17− file(GLOB QMLFILES
18− *.qml
19− *.js
20− qmldir
21− )
22−
23− # copy the qmldir file
24− add_custom_target(${PLUGIN}-qmlfiles ALL
25− COMMAND cp ${QMLFILES} ${CMAKE_BINARY_DIR}/plugins/${PLUGIN_SUBPATH}
26− DEPENDS ${QMLFILES}
27− SOURCES ${QMLFILES}
28− )
29−
30− # install the qmlfiles file.
31− install(FILES ${QMLFILES}
32− DESTINATION ${SHELL_INSTALL_QML}/${PLUGIN_SUBPATH}
33− )
34−endmacro(export_qmlfiles)
35−
36−
37−# Creates target for generating the qmltypes file for a plugin and installs plugin files
38−#
39−# export_qmlplugin(plugin version sub_path [TARGETS target1 [target2 ...]])
40−#
41−# TARGETS additional install targets (eg the plugin shared object)
42−#
43−# Target to be created:
44−# - plugin-qmltypes - Generates the qmltypes file in the shadow build folder.
45−
46−macro(export_qmlplugin PLUGIN VERSION PLUGIN_SUBPATH)
47− set(multi_value_keywords TARGETS)
48− cmake_parse_arguments(qmlplugin "" "" "${multi_value_keywords}" ${ARGN})
49−
50− # Only try to generate .qmltypes if not cross compiling
51− if(NOT CMAKE_CROSSCOMPILING)
52− # create the plugin.qmltypes file
53− add_custom_target(${PLUGIN}-qmltypes ALL
54− COMMAND ${qmlplugindump_exe} -notrelocatable ${PLUGIN} ${VERSION} ${CMAKE_BINARY_DIR}/plugins > ${CMAKE_BINARY_DIR}/plugins/${PLUGIN_SUBPATH}/plugin.qmltypes
55− )
56− add_dependencies(${PLUGIN}-qmltypes ${PLUGIN}-qmlfiles ${qmlplugin_TARGETS})
57−
58− # install the qmltypes file.
59− install(FILES ${CMAKE_BINARY_DIR}/plugins/${PLUGIN_SUBPATH}/plugin.qmltypes
60− DESTINATION ${SHELL_INSTALL_QML}/${PLUGIN_SUBPATH}
61− )
62− endif()
63−
64− # install the additional targets
65− install(TARGETS ${qmlplugin_TARGETS}
66− DESTINATION ${SHELL_INSTALL_QML}/${PLUGIN_SUBPATH}
67− )
68−endmacro(export_qmlplugin)
cmake/modules/QmlPlugins.cmakenew file+135
@@ -0,0 +1,135 @@
1+# If you need to override the qmlplugindump binary, create the qmlplugin executable
2+# target before loading this plugin.
3+
4+if(NOT TARGET qmlplugindump)
5+ find_program(qmlplugindump_exe qmlplugindump)
6+
7+ if(NOT qmlplugindump_exe)
8+ msg(FATAL_ERROR "Could not locate qmlplugindump.")
9+ endif()
10+
11+ add_executable(qmlplugindump IMPORTED)
12+ set_target_properties(qmlplugindump PROPERTIES IMPORTED_LOCATION ${qmlplugindump_exe})
13+endif()
14+
15+
16+# Creates a target for copying resource files into build dir and optionally installing them.
17+#
18+# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
19+# into ${DESTINATION}/${path}.
20+#
21+# Resource file names are matched against {*.{qml,js,jpg,png,sci,svg},qmldir}.
22+#
23+# export_qmlfiles(plugin path
24+# [SEARCH_PATH path] # Path to search for resources in (defaults to ${CMAKE_CURRENT_SOURCE_DIR})
25+# [BINARY_DIR path]
26+# [DESTINATION path]
27+# [TARGET_PREFIX string] # Will be prefixed to the target name
28+# )
29+#
30+# Created target:
31+# - ${TARGET_PREFIX}${plugin}-qmlfiles - Copies resources into the binary dir.
32+
33+macro(export_qmlfiles PLUGIN PATH)
34+ set(single SEARCH_PATH BINARY_DIR DESTINATION TARGET_PREFIX)
35+ cmake_parse_arguments(QMLFILES "" "${single}" "" ${ARGN})
36+
37+ if(NOT QMLFILES_SEARCH_PATH)
38+ set(QMLFILES_SEARCH_PATH ${CMAKE_CURRENT_SOURCE_DIR})
39+ endif()
40+
41+ if(QMLFILES_BINARY_DIR)
42+ set(qmlfiles_dir ${QMLFILES_BINARY_DIR}/${PATH})
43+ else()
44+ set(qmlfiles_dir ${CMAKE_CURRENT_BINARY_DIR})
45+ endif()
46+
47+ file(GLOB QMLFILES
48+ ${QMLFILES_SEARCH_PATH}/*.qml
49+ ${QMLFILES_SEARCH_PATH}/*.js
50+ ${QMLFILES_SEARCH_PATH}/*.jpg
51+ ${QMLFILES_SEARCH_PATH}/*.png
52+ ${QMLFILES_SEARCH_PATH}/*.sci
53+ ${QMLFILES_SEARCH_PATH}/*.svg
54+ ${QMLFILES_SEARCH_PATH}/qmldir
55+ )
56+
57+ # copy the files
58+ add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL
59+ COMMAND cp ${QMLFILES} ${qmlfiles_dir}
60+ DEPENDS ${QMLFILES}
61+ SOURCES ${QMLFILES}
62+ )
63+
64+ if(QMLFILES_DESTINATION)
65+ # install the qmlfiles file.
66+ install(FILES ${QMLFILES}
67+ DESTINATION ${QMLFILES_DESTINATION}/${PATH}
68+ )
69+ endif()
70+endmacro(export_qmlfiles)
71+
72+
73+# Creates a target for generating the typeinfo file for a QML plugin and optionally installs it
74+# and additional targets.
75+#
76+# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
77+# into ${DESTINATION}/${path}. If you don't pass BINARY_DIR, it's assumed that current source
78+# path ends with ${path}.
79+#
80+# The generated file will be named after the last segment of the plugin name, e.g. Foo.qmltypes.
81+#
82+# export_qmlplugin(plugin version path
83+# [BINARY_DIR path]
84+# [DESTINATION path]
85+# [TARGET_PREFIX string] # Will be prefixed to the target name
86+# [ENVIRONMENT string] # Will be added to qmlplugindump's env
87+# [TARGETS target1 [target2 ...]] # Targets to depend on and install (e.g. the plugin shared object)
88+# )
89+#
90+# Created target:
91+# - ${TARGET_PREFIX}${plugin}-qmltypes - Generates the qmltypes file in the binary dir.
92+
93+macro(export_qmlplugin PLUGIN VERSION PATH)
94+ set(single BINARY_DIR DESTINATION TARGET_PREFIX ENVIRONMENT)
95+ set(multi TARGETS)
96+ cmake_parse_arguments(QMLPLUGIN "" "${single}" "${multi}" ${ARGN})
97+
98+ get_target_property(qmlplugindump_executable qmlplugindump LOCATION)
99+
100+ if(QMLPLUGIN_BINARY_DIR)
101+ set(qmlplugin_dir ${QMLPLUGIN_BINARY_DIR}/${PATH})
102+ else()
103+ # Find import path to point qmlplugindump at
104+ string(REGEX REPLACE "${PATH}$" "" QMLPLUGIN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
105+ set(qmlplugin_dir ${CMAKE_CURRENT_BINARY_DIR})
106+ endif()
107+
108+ # Find the last segment of the plugin name to use as qmltypes basename
109+ string(REGEX MATCH "[^.]+$" plugin_suffix ${PLUGIN})
110+ set(target_prefix ${QMLPLUGIN_TARGET_PREFIX}${PLUGIN})
111+ set(qmltypes_path ${qmlplugin_dir}/${plugin_suffix}.qmltypes)
112+
113+ # Only generate typeinfo if not cross compiling
114+ if(NOT CMAKE_CROSSCOMPILING)
115+ add_custom_target(${target_prefix}-qmltypes ALL
116+ COMMAND env ${QMLPLUGIN_ENVIRONMENT} ${qmlplugindump_executable} -notrelocatable
117+ ${PLUGIN} ${VERSION} ${QMLPLUGIN_BINARY_DIR} > ${qmltypes_path}
118+ )
119+ add_dependencies(${target_prefix}-qmltypes ${target_prefix}-qmlfiles ${QMLPLUGIN_TARGETS})
120+
121+ if (QMLPLUGIN_DESTINATION)
122+ # Install the typeinfo file
123+ install(FILES ${qmltypes_path}
124+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}
125+ )
126+ endif()
127+ endif()
128+
129+ if (QMLPLUGIN_DESTINATION)
130+ # Install additional targets
131+ install(TARGETS ${QMLPLUGIN_TARGETS}
132+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}
133+ )
134+ endif()
135+endmacro()
plugins/AccountsService/CMakeLists.txt+1−4
@@ -1,5 +1,3 @@
1−include(Plugins)
2−
31add_definitions(-DSM_BUSNAME=systemBus)
42
53add_library(AccountsService-qml MODULE
@@ -10,8 +8,7 @@ add_library(AccountsService-qml MODULE
108
119qt5_use_modules(AccountsService-qml DBus Qml)
1210
13−export_qmlfiles(AccountsService AccountsService)
14−export_qmlplugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
11+add_unity8_plugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
1512
1613set(POLKIT_LIB_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/polkit-1")
1714set(POLKIT_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/polkit-1")
plugins/AccountsService/qmldir+1−1
@@ -1,3 +1,3 @@
11module AccountsService
22plugin AccountsService-qml
3−typeinfo plugin.qmltypes
3+typeinfo AccountsService.qmltypes
plugins/CMakeLists.txt+13
@@ -1,3 +1,16 @@
1+include(QmlPlugins)
2+
3+# Set up and install a plugin for unity8.
4+#
5+# add_unity8_plugin(plugin version path
6+# [...] # See export_qmlfiles and export_qmlplugin documentation for more options
7+# )
8+
9+macro(add_unity8_plugin PLUGIN VERSION PATH)
10+ export_qmlfiles(${PLUGIN} ${PATH} DESTINATION ${SHELL_INSTALL_QML} ${ARGN})
11+ export_qmlplugin(${PLUGIN} ${VERSION} ${PATH} DESTINATION ${SHELL_INSTALL_QML} ${ARGN})
12+endmacro()
13+
114add_subdirectory(AccountsService)
215add_subdirectory(HudClient)
316add_subdirectory(LightDM)
plugins/DashViews/CMakeLists.txt+1−6
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41# There's no cmake var for v8 include path :-/
52# so create one
63LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
@@ -41,6 +38,4 @@ target_link_libraries(DashViews-qml
4138
4239qt5_use_modules(DashViews-qml Qml Quick)
4340
44−# export the qmldir qmltypes and plugin files
45−export_qmlfiles(DashViews DashViews)
46−export_qmlplugin(DashViews 0.1 DashViews TARGETS DashViews-qml)
41+add_unity8_plugin(DashViews 0.1 DashViews TARGETS DashViews-qml)
plugins/DashViews/qmldir+1−1
@@ -1,3 +1,3 @@
11module DashViews
22plugin DashViews-qml
3−typeinfo plugin.qmltypes
3+typeinfo DashViews.qmltypes
plugins/HudClient/CMakeLists.txt+1−6
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41find_package(Qt5Core REQUIRED)
52find_package(Qt5Quick REQUIRED)
63pkg_search_module(DEE dee-1.0 REQUIRED)
@@ -38,6 +35,4 @@ target_link_libraries(HudClientQml
3835
3936qt5_use_modules(HudClientQml Qml)
4037
41−# export the qmldir qmltypes and plugin files
42−export_qmlfiles(HudClient HudClient)
43−export_qmlplugin(HudClient 0.1 HudClient TARGETS HudClientQml)
38+add_unity8_plugin(HudClient 0.1 HudClient TARGETS HudClientQml)
plugins/HudClient/qmldir+1−1
@@ -1,3 +1,3 @@
11module HudClient
22plugin HudClientQml
3−typeinfo plugin.qmltypes
3+typeinfo HudClient.qmltypes
plugins/LightDM/CMakeLists.txt+1−6
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41# Dependencies
52include(FindPkgConfig)
63pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
@@ -37,6 +34,4 @@ target_link_libraries(LightDM-qml
3734
3835qt5_use_modules(LightDM-qml DBus Gui Qml)
3936
40−# export the qmldir qmltypes and plugin files
41−export_qmlfiles(LightDM LightDM)
42−export_qmlplugin(LightDM 0.1 LightDM TARGETS LightDM-qml)
37+add_unity8_plugin(LightDM 0.1 LightDM TARGETS LightDM-qml)
plugins/LightDM/qmldir+1−1
@@ -1,3 +1,3 @@
11module LightDM
22plugin LightDM-qml
3−typeinfo plugin.qmltypes
3+typeinfo LightDM.qmltypes
plugins/Powerd/CMakeLists.txt+1−3
@@ -1,4 +1,3 @@
1−include(Plugins)
21include(FindPkgConfig)
32
43pkg_search_module(GIO REQUIRED gio-2.0)
@@ -17,5 +16,4 @@ add_library(Powerd-qml MODULE
1716qt5_use_modules(Powerd-qml DBus Qml)
1817target_link_libraries(Powerd-qml ${GIO_LDFLAGS})
1918
20−export_qmlfiles(Powerd Powerd)
21−export_qmlplugin(Powerd 0.1 Powerd TARGETS Powerd-qml)
19+add_unity8_plugin(Powerd 0.1 Powerd TARGETS Powerd-qml)
plugins/Powerd/qmldir+1−1
@@ -1,3 +1,3 @@
11module Powerd
22plugin Powerd-qml
3−typeinfo plugin.qmltypes
3+typeinfo Powerd.qmltypes
plugins/SessionBroadcast/CMakeLists.txt+1−4
@@ -1,5 +1,3 @@
1−include(Plugins)
2−
31add_definitions(-DSM_BUSNAME=systemBus)
42
53add_library(SessionBroadcast-qml MODULE
@@ -9,5 +7,4 @@ add_library(SessionBroadcast-qml MODULE
97
108qt5_use_modules(SessionBroadcast-qml DBus Qml)
119
12−export_qmlfiles(SessionBroadcast SessionBroadcast)
13−export_qmlplugin(SessionBroadcast 0.1 SessionBroadcast TARGETS SessionBroadcast-qml)
10+add_unity8_plugin(SessionBroadcast 0.1 SessionBroadcast TARGETS SessionBroadcast-qml)
plugins/SessionBroadcast/qmldir+1−1
@@ -1,3 +1,3 @@
11module SessionBroadcast
22plugin SessionBroadcast-qml
3−typeinfo plugin.qmltypes
3+typeinfo SessionBroadcast.qmltypes
plugins/Ubuntu/DownloadDaemonListener/CMakeLists.txt+1−6
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41include_directories(
52 ${CMAKE_CURRENT_SOURCE_DIR}
63 ${CMAKE_CURRENT_BINARY_DIR}
@@ -17,6 +14,4 @@ add_library(DownloadDaemonListener MODULE ${DOWNLOADDAEMONLISTENER_SOURCES})
1714
1815qt5_use_modules(DownloadDaemonListener Qml Quick DBus Core)
1916
20−# export the qmldir qmltypes and plugin files
21−export_qmlfiles(Ubuntu.DownloadDaemonListener Ubuntu/DownloadDaemonListener)
22−export_qmlplugin(Ubuntu.DownloadDaemonListener 0.1 Ubuntu/DownloadDaemonListener TARGETS DownloadDaemonListener)
17+add_unity8_plugin(Ubuntu.DownloadDaemonListener 0.1 Ubuntu/DownloadDaemonListener TARGETS DownloadDaemonListener)
plugins/Ubuntu/DownloadDaemonListener/qmldir+1−1
@@ -1,3 +1,3 @@
11module Ubuntu.DownloadDaemonListener
22plugin DownloadDaemonListener
3−typeinfo plugins.qmltypes
3+typeinfo DownloadDaemonListener.qmltypes
plugins/Ubuntu/Gestures/CMakeLists.txt+1−6
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41set(UbuntuGestureQml_SOURCES
52 plugin.cpp
63 AxisVelocityCalculator.cpp
@@ -19,6 +16,4 @@ qt5_use_modules(UbuntuGestureQml Core Quick)
1916# So that Foo.cpp can #include "Foo.moc"
2017include_directories(${CMAKE_CURRENT_BINARY_DIR})
2118
22−# export the qmldir qmltypes and plugin files
23−export_qmlfiles(Ubuntu.Gestures Ubuntu/Gestures)
24−export_qmlplugin(Ubuntu.Gestures 0.1 Ubuntu/Gestures TARGETS UbuntuGestureQml)
19+add_unity8_plugin(Ubuntu.Gestures 0.1 Ubuntu/Gestures TARGETS UbuntuGestureQml)
plugins/Ubuntu/Gestures/qmldir+1−1
@@ -1,3 +1,3 @@
11module Ubuntu.Gestures
22plugin UbuntuGestureQml
3−typeinfo plugin.qmltypes
3+typeinfo Gestures.qmltypes
plugins/Unity/Indicators/CMakeLists.txt+4−7
@@ -1,6 +1,3 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
41project(IndicatorsQml)
52
63pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
@@ -10,8 +7,6 @@ pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
107find_package(Qt5Core REQUIRED)
118find_package(Qt5Quick REQUIRED)
129
13−add_subdirectory(qml)
14−
1510include_directories(
1611 ${CMAKE_CURRENT_SOURCE_DIR}
1712 ${CMAKE_CURRENT_BINARY_DIR}
@@ -56,5 +51,7 @@ target_link_libraries(IndicatorsQml
5651
5752qt5_use_modules(IndicatorsQml Core Qml Quick)
5853
59−# export the qmltypes and plugin files
60−export_qmlplugin(Unity.Indicators 0.1 Unity/Indicators TARGETS IndicatorsQml)
54+add_unity8_plugin(Unity.Indicators 0.1 Unity/Indicators
55+ SEARCH_PATH qml
56+ TARGETS IndicatorsQml
57+)
plugins/Unity/Indicators/qml/CMakeLists.txtdeleted−5
@@ -1,5 +0,0 @@
1−# export_qmlplugin macro
2−include(Plugins)
3−
4−# export the qmldir, *.qml files.
5−export_qmlfiles(Unity.Indicators Unity/Indicators)
plugins/Unity/Indicators/qml/qmldir+1−1
@@ -1,6 +1,6 @@
11module Unity.Indicators
22plugin IndicatorsQml
3−typeinfo plugin.qmltypes
3+typeinfo Indicators.qmltypes
44
55CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
66IndicatorBase 0.1 IndicatorBase.qml
plugins/Unity/Launcher/CMakeLists.txt+1−3
@@ -32,6 +32,4 @@ target_link_libraries(UnityLauncher-qml ${GSETTINGS_QT_LDFLAGS})
3232
3333qt5_use_modules(UnityLauncher-qml DBus Qml)
3434
35−# export the qmldir and qmltypes files
36−export_qmlfiles(Unity.Launcher Unity/Launcher)
37−export_qmlplugin(Unity.Launcher 0.1 Unity/Launcher TARGETS UnityLauncher-qml)
35+add_unity8_plugin(Unity.Launcher 0.1 Unity/Launcher TARGETS UnityLauncher-qml)
plugins/Unity/Launcher/qmldir+1−1
@@ -1,3 +1,3 @@
11module Unity.Launcher
22plugin UnityLauncher-qml
3−typeinfo plugin.qmltypes
3+typeinfo Launcher.qmltypes
plugins/Utils/CMakeLists.txt+1−3
@@ -34,6 +34,4 @@ set_target_properties(Utils-qml PROPERTIES COMPILE_FLAGS -fvisibility=default)
3434
3535qt5_use_modules(Utils-qml Qml Quick DBus Network XmlPatterns Gui Concurrent)
3636
37−# export the qmldir qmltypes and plugin files
38−export_qmlfiles(Utils Utils)
39−export_qmlplugin(Utils 0.1 Utils TARGETS Utils-qml)
37+add_unity8_plugin(Utils 0.1 Utils TARGETS Utils-qml)
plugins/Utils/qmldir+1−1
@@ -1,3 +1,3 @@
11module Utils
22plugin Utils-qml
3−typeinfo plugin.qmltypes
3+typeinfo Utils.qmltypes