Changeset View
Changeset View
Standalone View
Standalone View
modules/ECMInstallQmlModules.cmake
- This file was added.
1 | #.rst: | ||||
---|---|---|---|---|---|
2 | # ECMInstallQmlModules | ||||
3 | # -------------------- | ||||
4 | # | ||||
5 | # Installs a QML C++ plugin, while generating and installing also a matching | ||||
6 | # "qmldir" file. | ||||
7 | # | ||||
8 | # :: | ||||
9 | # | ||||
10 | # ecm_install_qmlplugin(<plugin_target> | ||||
11 | # IDENTIFIER <module_identifier> | ||||
12 | # DESTINATION <plugin_base_install_dir> | ||||
13 | # [DEPENDS <depend1> [<depend2> [...]]] | ||||
14 | # [DESIGNERSUPPORTED]) | ||||
15 | # | ||||
16 | # ``IDENTIFIER`` specifies the module identifier of the module implemented | ||||
17 | # by the plugin. | ||||
18 | # | ||||
19 | # ``DESTINATION`` specifies the directory on disk to which the module plugin | ||||
20 | # will be installed, without the module-specific sub-path. | ||||
21 | # If using the :kde-module:`KDEInstallDirs` module, one passes | ||||
22 | # ``${KDE_INSTALL_QMLDIR}`` as value usually. | ||||
23 | # | ||||
24 | # ``DEPENDS`` specifies dependencies which should be noted in the "qmldir" | ||||
25 | # file. Each ``<depend>`` argument is a string with both the module identifier | ||||
26 | # of the dependency and its version (e.g. ``"bar.example 1.0"``). | ||||
27 | # | ||||
28 | # ``DESIGNERSUPPORTED`` specifies that the "qmldir" file should get the | ||||
29 | # ``designersupported`` flag added. | ||||
30 | # | ||||
31 | # Example usage: | ||||
32 | # | ||||
33 | # .. code-block:: cmake | ||||
34 | # | ||||
35 | # add_library(fooexampleplugin SHARED ${fooexampleplugin_SRCS}) | ||||
36 | # | ||||
37 | # target_link_libraries(fooexampleplugin | ||||
38 | # Qt5::Qml | ||||
39 | # ) | ||||
40 | # | ||||
41 | # ecm_install_qmlplugin(fooexampleplugin | ||||
42 | # IDENTIFIER foo.example | ||||
43 | # DESTINATION "${KDE_INSTALL_QMLDIR}" | ||||
44 | # DEPENDS | ||||
45 | # "bar.example 42.0" | ||||
46 | # DESIGNERSUPPORTED | ||||
47 | # ) | ||||
48 | # | ||||
49 | # Since 5.59.0. | ||||
50 | | ||||
51 | | ||||
52 | #============================================================================= | ||||
53 | # Copyright 2019 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
54 | # | ||||
55 | # Redistribution and use in source and binary forms, with or without | ||||
56 | # modification, are permitted provided that the following conditions | ||||
57 | # are met: | ||||
58 | # | ||||
59 | # 1. Redistributions of source code must retain the copyright | ||||
60 | # notice, this list of conditions and the following disclaimer. | ||||
61 | # 2. Redistributions in binary form must reproduce the copyright | ||||
62 | # notice, this list of conditions and the following disclaimer in the | ||||
63 | # documentation and/or other materials provided with the distribution. | ||||
64 | # 3. The name of the author may not be used to endorse or promote products | ||||
65 | # derived from this software without specific prior written permission. | ||||
66 | # | ||||
67 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
68 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
69 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
70 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
71 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
72 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
73 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
74 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
75 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
76 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
77 | | ||||
78 | | ||||
79 | function(ecm_install_qmlplugin _target) | ||||
80 | set(options | ||||
81 | DESIGNERSUPPORTED | ||||
82 | ) | ||||
83 | set(oneValueArgs | ||||
84 | DESTINATION | ||||
85 | IDENTIFIER | ||||
86 | ) | ||||
87 | set(multiValueArgs | ||||
88 | DEPENDS | ||||
89 | ) | ||||
90 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||||
91 | | ||||
92 | # check args | ||||
93 | if (NOT TARGET ${_target}) | ||||
94 | message(FATAL_ERROR "No known target passed to ecm_install_qmlmodule: ${_target}") | ||||
95 | endif() | ||||
96 | if(ARGS_UNPARSED_ARGUMENTS) | ||||
97 | message(FATAL_ERROR "Unexpected arguments to ecm_install_qmlmodule: ${ARGS_UNPARSED_ARGUMENTS}") | ||||
98 | endif() | ||||
99 | if(NOT ARGS_DESTINATION) | ||||
100 | message(FATAL_ERROR "No DESTINATION argument given to ecm_install_qmlmodule") | ||||
101 | endif() | ||||
102 | if(NOT ARGS_IDENTIFIER) | ||||
103 | message(FATAL_ERROR "No IDENTIFIER argument given to ecm_install_qmlmodule") | ||||
104 | endif() | ||||
105 | | ||||
106 | # generate qmldir file | ||||
107 | set(qmldir_FILE "${CMAKE_CURRENT_BINARY_DIR}/qmldir") # TODO: support multiple in same dir? | ||||
108 | file(WRITE ${qmldir_FILE} "module ${ARGS_IDENTIFIER}\n") | ||||
109 | | ||||
110 | # TODO: is there a way to directly get the effective name? | ||||
111 | get_target_property(_plugin_name ${_target} LIBRARY_OUTPUT_NAME) | ||||
112 | if(NOT _plugin_name) | ||||
113 | get_target_property(_plugin_name ${_target} OUTPUT_NAME) | ||||
114 | endif() | ||||
115 | if(NOT _plugin_name) | ||||
116 | set(_plugin_name ${_target}) | ||||
117 | endif() | ||||
118 | file(APPEND ${qmldir_FILE} "plugin ${_plugin_name}\n") | ||||
119 | | ||||
120 | list(TRANSFORM ARGS_DEPENDS PREPEND "depends ") | ||||
121 | list(JOIN ARGS_DEPENDS "\n" _depends) | ||||
122 | if (_depends) | ||||
123 | file(APPEND ${qmldir_FILE} "${_depends}\n") | ||||
124 | endif() | ||||
125 | | ||||
126 | if(ARGS_DESIGNERSUPPORTED) | ||||
127 | file(APPEND ${qmldir_FILE} "designersupported\n") | ||||
128 | endif() | ||||
129 | | ||||
130 | # install | ||||
131 | string(REPLACE "." "/" _module_path ${ARGS_IDENTIFIER}) | ||||
132 | set(_install_dir "${ARGS_DESTINATION}/${_module_path}") | ||||
133 | | ||||
134 | install(TARGETS ${_target} DESTINATION ${_install_dir}) | ||||
135 | install(FILES ${qmldir_FILE} DESTINATION ${_install_dir}) | ||||
136 | endfunction() |