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
# A custom target for building the qmltypes files manually.
18
if (NOT TARGET qmltypes)
19
add_custom_target(qmltypes)
22
# Creates a target for copying resource files into build dir and optionally installing them.
24
# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
25
# into ${DESTINATION}/${path}.
27
# Resource file names are matched against {*.{qml,js,jpg,png,sci,svg},qmldir}.
29
# export_qmlfiles(plugin path
30
# [SEARCH_PATH path] # Path to search for resources in (defaults to ${CMAKE_CURRENT_SOURCE_DIR})
33
# [TARGET_PREFIX string] # Will be prefixed to the target name
37
# - ${TARGET_PREFIX}${plugin}-qmlfiles - Copies resources into the binary dir.
39
macro(export_qmlfiles PLUGIN PATH)
40
set(single SEARCH_PATH BINARY_DIR DESTINATION TARGET_PREFIX)
41
cmake_parse_arguments(QMLFILES "" "${single}" "" ${ARGN})
43
if(NOT QMLFILES_SEARCH_PATH)
44
set(QMLFILES_SEARCH_PATH ${CMAKE_CURRENT_SOURCE_DIR})
47
if(QMLFILES_BINARY_DIR)
48
set(qmlfiles_dir ${QMLFILES_BINARY_DIR}/${PATH})
50
set(qmlfiles_dir ${CMAKE_CURRENT_BINARY_DIR})
54
${QMLFILES_SEARCH_PATH}/*.qml
55
${QMLFILES_SEARCH_PATH}/*.js
56
${QMLFILES_SEARCH_PATH}/*.jpg
57
${QMLFILES_SEARCH_PATH}/*.png
58
${QMLFILES_SEARCH_PATH}/*.sci
59
${QMLFILES_SEARCH_PATH}/*.svg
60
${QMLFILES_SEARCH_PATH}/*.qmltypes
61
${QMLFILES_SEARCH_PATH}/qmldir
64
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${qmlfiles_dir})
67
add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL
68
COMMAND cp ${QMLFILES} ${qmlfiles_dir}
73
if(QMLFILES_DESTINATION)
74
# install the qmlfiles file.
75
install(FILES ${QMLFILES}
76
DESTINATION ${QMLFILES_DESTINATION}/${PATH}
82
# Creates a target for generating the typeinfo file for a QML plugin and/or installs the plugin
85
# Files will be copied into ${BINARY_DIR}/${path} or ${CMAKE_CURRENT_BINARY_DIR} and installed
86
# into ${DESTINATION}/${path}. If you don't pass BINARY_DIR, it's assumed that current source
87
# path ends with ${path}.
89
# The generated file will be named after the last segment of the plugin name, e.g. Foo.qmltypes.
91
# export_qmlplugin(plugin version path
94
# [TARGET_PREFIX string] # Will be prefixed to the target name
95
# [ENVIRONMENT string] # Will be added to qmlplugindump's env
96
# [TARGETS target1 [target2 ...]] # Targets to depend on and install (e.g. the plugin shared object)
97
# [NO_TYPES] # Do not create the qmltypes target
101
# - ${TARGET_PREFIX}${plugin}-qmltypes - Generates the qmltypes file in the source dir.
102
# It will be made a dependency of the "qmltypes" target.
104
macro(export_qmlplugin PLUGIN VERSION PATH)
105
set(options NO_TYPES)
106
set(single BINARY_DIR DESTINATION TARGET_PREFIX ENVIRONMENT)
108
cmake_parse_arguments(QMLPLUGIN "${options}" "${single}" "${multi}" ${ARGN})
110
get_target_property(qmlplugindump_executable qmlplugindump LOCATION)
112
if(QMLPLUGIN_BINARY_DIR)
113
set(qmlplugin_dir ${QMLPLUGIN_BINARY_DIR}/${PATH})
115
# Find import path to point qmlplugindump at
116
string(REGEX REPLACE "/${PATH}$" "" QMLPLUGIN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
117
set(qmlplugin_dir ${CMAKE_CURRENT_BINARY_DIR})
120
if(NOT QMLPLUGIN_NO_TYPES)
121
# Relative path for the module
122
string(REPLACE "${CMAKE_BINARY_DIR}/" "" QMLPLUGIN_MODULE_DIR "${QMLPLUGIN_BINARY_DIR}")
124
# Find the last segment of the plugin name to use as qmltypes basename
125
string(REGEX MATCH "[^.]+$" plugin_suffix ${PLUGIN})
126
set(target_prefix ${QMLPLUGIN_TARGET_PREFIX}${PLUGIN})
127
set(qmltypes_path ${CMAKE_CURRENT_SOURCE_DIR}/${plugin_suffix}.qmltypes)
129
add_custom_target(${target_prefix}-qmltypes
130
COMMAND env ${QMLPLUGIN_ENVIRONMENT} ${qmlplugindump_executable} -notrelocatable
131
${PLUGIN} ${VERSION} ${QMLPLUGIN_MODULE_DIR} > ${qmltypes_path}
132
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
134
add_dependencies(${target_prefix}-qmltypes ${target_prefix}-qmlfiles ${QMLPLUGIN_TARGETS})
135
add_dependencies(qmltypes ${target_prefix}-qmltypes)
138
set_target_properties(${QMLPLUGIN_TARGETS} PROPERTIES
139
ARCHIVE_OUTPUT_DIRECTORY ${qmlplugin_dir}
140
LIBRARY_OUTPUT_DIRECTORY ${qmlplugin_dir}
141
RUNTIME_OUTPUT_DIRECTORY ${qmlplugin_dir}
144
if (QMLPLUGIN_DESTINATION)
145
# Install additional targets
146
install(TARGETS ${QMLPLUGIN_TARGETS}
147
DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}