@@ -0,0 +1,143 @@
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
57+ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${qmlfiles_dir})
60+ add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL
61+ COMMAND cp ${QMLFILES} ${qmlfiles_dir}
66+ if(QMLFILES_DESTINATION)
67+ # install the qmlfiles file.
68+ install(FILES ${QMLFILES}
69+ DESTINATION ${QMLFILES_DESTINATION}/${PATH}
72+endmacro(export_qmlfiles)
75+# Creates a target for generating the typeinfo file for a QML plugin and optionally installs it
76+# and additional targets.
78+# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
79+# into ${DESTINATION}/${path}. If you don't pass BINARY_DIR, it's assumed that current source
80+# path ends with ${path}.
82+# The generated file will be named after the last segment of the plugin name, e.g. Foo.qmltypes.
84+# export_qmlplugin(plugin version path
87+# [TARGET_PREFIX string] # Will be prefixed to the target name
88+# [ENVIRONMENT string] # Will be added to qmlplugindump's env
89+# [TARGETS target1 [target2 ...]] # Targets to depend on and install (e.g. the plugin shared object)
93+# - ${TARGET_PREFIX}${plugin}-qmltypes - Generates the qmltypes file in the binary dir.
95+macro(export_qmlplugin PLUGIN VERSION PATH)
96+ set(single BINARY_DIR DESTINATION TARGET_PREFIX ENVIRONMENT)
98+ cmake_parse_arguments(QMLPLUGIN "" "${single}" "${multi}" ${ARGN})
100+ get_target_property(qmlplugindump_executable qmlplugindump LOCATION)
102+ if(QMLPLUGIN_BINARY_DIR)
103+ set(qmlplugin_dir ${QMLPLUGIN_BINARY_DIR}/${PATH})
105+ # Find import path to point qmlplugindump at
106+ string(REGEX REPLACE "${PATH}$" "" QMLPLUGIN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
107+ set(qmlplugin_dir ${CMAKE_CURRENT_BINARY_DIR})
110+ # Find the last segment of the plugin name to use as qmltypes basename
111+ string(REGEX MATCH "[^.]+$" plugin_suffix ${PLUGIN})
112+ set(target_prefix ${QMLPLUGIN_TARGET_PREFIX}${PLUGIN})
113+ set(qmltypes_path ${qmlplugin_dir}/${plugin_suffix}.qmltypes)
115+ # Only generate typeinfo if not cross compiling
116+ if(NOT CMAKE_CROSSCOMPILING)
117+ add_custom_target(${target_prefix}-qmltypes ALL
118+ COMMAND env ${QMLPLUGIN_ENVIRONMENT} ${qmlplugindump_executable} -notrelocatable
119+ ${PLUGIN} ${VERSION} ${QMLPLUGIN_BINARY_DIR} > ${qmltypes_path}
121+ add_dependencies(${target_prefix}-qmltypes ${target_prefix}-qmlfiles ${QMLPLUGIN_TARGETS})
123+ if (QMLPLUGIN_DESTINATION)
124+ # Install the typeinfo file
125+ install(FILES ${qmltypes_path}
126+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}
131+ set_target_properties(${QMLPLUGIN_TARGETS} PROPERTIES
132+ ARCHIVE_OUTPUT_DIRECTORY ${qmlplugin_dir}
133+ LIBRARY_OUTPUT_DIRECTORY ${qmlplugin_dir}
134+ RUNTIME_OUTPUT_DIRECTORY ${qmlplugin_dir}
137+ if (QMLPLUGIN_DESTINATION)
138+ # Install additional targets
139+ install(TARGETS ${QMLPLUGIN_TARGETS}
140+ DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}