@@ -0,0 +1,135 @@
1+# If you need to override the qmlplugindump binary, create the qmlplugin executable
2+# target before loading this plugin.
4+if(NOT TARGET qmlplugindump)
5+ find_program(qmlplugindump_exe qmlplugindump)
7+ if(NOT qmlplugindump_exe)
8+ msg(FATAL_ERROR "Could not locate qmlplugindump.")
11+ add_executable(qmlplugindump IMPORTED)
12+ set_target_properties(qmlplugindump PROPERTIES IMPORTED_LOCATION ${qmlplugindump_exe})
16+# Creates a target for copying resource files into build dir and optionally installing them.
18+# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
19+# into ${DESTINATION}/${path}.
21+# Resource file names are matched against {*.{qml,js,jpg,png,sci,svg},qmldir}.
23+# export_qmlfiles(plugin path
24+# [SEARCH_PATH path] # Path to search for resources in (defaults to ${CMAKE_CURRENT_SOURCE_DIR})
27+# [TARGET_PREFIX string] # Will be prefixed to the target name
31+# - ${TARGET_PREFIX}${plugin}-qmlfiles - Copies resources into the binary dir.
33+macro(export_qmlfiles PLUGIN PATH)
34+ set(single SEARCH_PATH BINARY_DIR DESTINATION TARGET_PREFIX)
35+ cmake_parse_arguments(QMLFILES "" "${single}" "" ${ARGN})
37+ if(NOT QMLFILES_SEARCH_PATH)
38+ set(QMLFILES_SEARCH_PATH ${CMAKE_CURRENT_SOURCE_DIR})
41+ if(QMLFILES_BINARY_DIR)
42+ set(qmlfiles_dir ${QMLFILES_BINARY_DIR}/${PATH})
44+ set(qmlfiles_dir ${CMAKE_CURRENT_BINARY_DIR})
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
58+ add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL
59+ COMMAND cp ${QMLFILES} ${qmlfiles_dir}
64+ if(QMLFILES_DESTINATION)
65+ # install the qmlfiles file.
66+ install(FILES ${QMLFILES}
67+ DESTINATION ${QMLFILES_DESTINATION}/${PATH}
70+endmacro(export_qmlfiles)
73+# Creates a target for generating the typeinfo file for a QML plugin and optionally installs it
74+# and additional targets.
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}.
80+# The generated file will be named after the last segment of the plugin name, e.g. Foo.qmltypes.
82+# export_qmlplugin(plugin version 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)
91+# - ${TARGET_PREFIX}${plugin}-qmltypes - Generates the qmltypes file in the binary dir.
93+macro(export_qmlplugin PLUGIN VERSION PATH)
94+ set(single BINARY_DIR DESTINATION TARGET_PREFIX ENVIRONMENT)
96+ cmake_parse_arguments(QMLPLUGIN "" "${single}" "${multi}" ${ARGN})
98+ get_target_property(qmlplugindump_executable qmlplugindump LOCATION)
100+ if(QMLPLUGIN_BINARY_DIR)
101+ set(qmlplugin_dir ${QMLPLUGIN_BINARY_DIR}/${PATH})
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})
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)
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}
119+ add_dependencies(${target_prefix}-qmltypes ${target_prefix}-qmlfiles ${QMLPLUGIN_TARGETS})
121+ if (QMLPLUGIN_DESTINATION)
122+ # Install the typeinfo file
123+ install(FILES ${qmltypes_path}
124+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}
129+ if (QMLPLUGIN_DESTINATION)
130+ # Install additional targets
131+ install(TARGETS ${QMLPLUGIN_TARGETS}
132+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}