@@ -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()