on 6ca9421 help sign in
unity8/cmake/modules/QmlPlugins.cmake
148 lines 5.5 kB history raw
1# If you need to override the qmlplugindump binary, create the qmlplugin executable
2# target before loading this plugin.
4if(NOT TARGET qmlplugindump)
5 find_program(qmlplugindump_exe qmlplugindump)
7 if(NOT qmlplugindump_exe)
8 msg(FATAL_ERROR "Could not locate qmlplugindump.")
9 endif()
11 add_executable(qmlplugindump IMPORTED)
12 set_target_properties(qmlplugindump PROPERTIES IMPORTED_LOCATION ${qmlplugindump_exe})
13endif()
16# A custom target for building the qmltypes files manually.
18if (NOT TARGET qmltypes)
19 add_custom_target(qmltypes)
20endif()
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})
31# [BINARY_DIR path]
32# [DESTINATION path]
33# [TARGET_PREFIX string] # Will be prefixed to the target name
34# )
36# Created target:
37# - ${TARGET_PREFIX}${plugin}-qmlfiles - Copies resources into the binary dir.
39macro(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})
45 endif()
47 if(QMLFILES_BINARY_DIR)
48 set(qmlfiles_dir ${QMLFILES_BINARY_DIR}/${PATH})
49 else()
50 set(qmlfiles_dir ${CMAKE_CURRENT_BINARY_DIR})
51 endif()
53 file(GLOB QMLFILES
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
62 )
64 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${qmlfiles_dir})
66 # copy the files
67 add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL
68 COMMAND cp ${QMLFILES} ${qmlfiles_dir}
69 DEPENDS ${QMLFILES}
70 SOURCES ${QMLFILES}
71 )
73 if(QMLFILES_DESTINATION)
74 # install the qmlfiles file.
75 install(FILES ${QMLFILES}
76 DESTINATION ${QMLFILES_DESTINATION}/${PATH}
77 )
78 endif()
79endmacro()
82# Creates a target for generating the typeinfo file for a QML plugin and/or installs the plugin
83# targets.
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
92# [BINARY_DIR path]
93# [DESTINATION 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
98# )
100# Created 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.
104macro(export_qmlplugin PLUGIN VERSION PATH)
105 set(options NO_TYPES)
106 set(single BINARY_DIR DESTINATION TARGET_PREFIX ENVIRONMENT)
107 set(multi TARGETS)
108 cmake_parse_arguments(QMLPLUGIN "${options}" "${single}" "${multi}" ${ARGN})
110 if(QMLPLUGIN_BINARY_DIR)
111 set(qmlplugin_dir ${QMLPLUGIN_BINARY_DIR}/${PATH})
112 else()
113 # Find import path to point qmlplugindump at
114 string(REGEX REPLACE "/${PATH}$" "" QMLPLUGIN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
115 set(qmlplugin_dir ${CMAKE_CURRENT_BINARY_DIR})
116 endif()
118 if(NOT QMLPLUGIN_NO_TYPES)
119 # Relative path for the module
120 string(REPLACE "${CMAKE_BINARY_DIR}/" "" QMLPLUGIN_MODULE_DIR "${QMLPLUGIN_BINARY_DIR}")
122 # Find the last segment of the plugin name to use as qmltypes basename
123 string(REGEX MATCH "[^.]+$" plugin_suffix ${PLUGIN})
124 set(target_prefix ${QMLPLUGIN_TARGET_PREFIX}${PLUGIN})
125 set(qmltypes_path ${CMAKE_CURRENT_SOURCE_DIR}/${plugin_suffix}.qmltypes)
127 add_custom_target(${target_prefix}-qmltypes
128 COMMAND env ${QMLPLUGIN_ENVIRONMENT} $<TARGET_FILE:qmlplugindump> -notrelocatable
129 ${PLUGIN} ${VERSION} ${QMLPLUGIN_MODULE_DIR} > ${qmltypes_path}
130 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
131 )
132 add_dependencies(${target_prefix}-qmltypes ${target_prefix}-qmlfiles ${QMLPLUGIN_TARGETS})
133 add_dependencies(qmltypes ${target_prefix}-qmltypes)
134 endif()
136 set_target_properties(${QMLPLUGIN_TARGETS} PROPERTIES
137 ARCHIVE_OUTPUT_DIRECTORY ${qmlplugin_dir}
138 LIBRARY_OUTPUT_DIRECTORY ${qmlplugin_dir}
139 RUNTIME_OUTPUT_DIRECTORY ${qmlplugin_dir}
140 )
142 if (QMLPLUGIN_DESTINATION)
143 # Install additional targets
144 install(TARGETS ${QMLPLUGIN_TARGETS}
145 DESTINATION ${QMLPLUGIN_DESTINATION}/${PATH}
146 )
147 endif()
148endmacro()