File: ECMFindQmlModule.cmake

package info (click to toggle)
kf6-extra-cmake-modules 6.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,524 kB
  • sloc: python: 668; cpp: 326; ansic: 291; xml: 182; sh: 62; makefile: 8
file content (70 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
# SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
#
# SPDX-License-Identifier: BSD-3-Clause

#[=======================================================================[.rst:
ECMFindQmlModule
----------------

Finds QML import modules to set them as runtime dependencies.

Because QML modules are not compile time requirements, they can be easy to miss
by packagers and developers, causing QML apps to fail to display.
Use this CMake module to ensure a QML module is installed at compile time
during CMake configuration.

Internally, this CMake module looks for the qmldir and, if needed, uses
qmlplugindump to find the plugins and set them up as runtime dependencies.

::

  ecm_find_qmlmodule(<module_name>
    <version> # Optional for Qt6 builds
    [REQUIRED] # Since 6.0
  )

Usage example:

.. code-block:: cmake

  ecm_find_qmlmodule(org.kde.kirigami 2.1)
  ecm_find_qmlmodule(org.kde.kirigami 2.1 REQUIRED) # CMake will fail if the required version is not found
  ecm_find_qmlmodule(org.kde.kirigami) # Find it without a given version
  ecm_find_qmlmodule(org.kde.kirigami REQUIRED) # CMake will fail if it is not found

Since 5.38.0.
#]=======================================================================]

cmake_policy(VERSION 3.16)

set(MODULES_DIR ${CMAKE_CURRENT_LIST_DIR})

function(ecm_find_qmlmodule MODULE_NAME)
    if (QT_MAJOR_VERSION STREQUAL 6)
      cmake_parse_arguments(ARG REQUIRED "" "" ${ARGN})
        if (ARG_UNPARSED_ARGUMENTS)
          list(GET ARG_UNPARSED_ARGUMENTS 0 VERSION) # If we have any unparsed args, that should be the version
        endif()
        set(ARGN "") # The find_package call below should not recieve arguments in KF6
    else()
        list(GET ARGN 0 VERSION)
        list(REMOVE_AT ARGN 0)
    endif()

    set(GENMODULE "${MODULE_NAME}-QMLModule")
    configure_file("${MODULES_DIR}/ECMFindQmlModule.cmake.in" "Find${GENMODULE}.cmake" @ONLY)
    set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}" ${CMAKE_MODULE_PATH})
    find_package(${GENMODULE} ${ARGN})

    if(COMMAND set_package_properties)
      if (ARG_REQUIRED)
        set(TYPE_STRING TYPE REQUIRED)
      else()
        set(TYPE_STRING TYPE RUNTIME)
      endif()
        set_package_properties(${GENMODULE} PROPERTIES
            DESCRIPTION "QML module '${MODULE_NAME}' is a runtime dependency."
            ${TYPE_STRING})
    endif()
endfunction()