Warning, /frameworks/extra-cmake-modules/find-modules/FindQtWaylandScanner.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2012-2014 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 
0005 #[=======================================================================[.rst:
0006 FindQtWaylandScanner
0007 --------------------
0008 
0009 Try to find qtwaylandscanner.
0010 
0011 If the qtwaylandscanner executable is not in your PATH, you can provide
0012 an alternative name or full path location with the ``QtWaylandScanner_EXECUTABLE``
0013 variable.
0014 
0015 This will define the following variables:
0016 
0017 ``QtWaylandScanner_FOUND``
0018     True if qtwaylandscanner is available
0019 
0020 ``QtWaylandScanner_EXECUTABLE``
0021     The qtwaylandscanner executable.
0022 
0023 If ``QtWaylandScanner_FOUND`` is TRUE, it will also define the following imported
0024 target:
0025 
0026 ``Wayland::QtScanner``
0027     The qtwaylandscanner executable.
0028 
0029 This module provides the following functions to generate C++ protocol
0030 implementations:
0031 
0032   - ``ecm_add_qtwayland_client_protocol``
0033   - ``ecm_add_qtwayland_server_protocol``
0034 
0035 ::
0036 
0037   ecm_add_qtwayland_client_protocol(<target>
0038                                     PROTOCOL <xmlfile>
0039                                     BASENAME <basename>
0040                                     [PREFIX <prefix>])
0041 
0042   ecm_add_qtwayland_client_protocol(<source_files_var>
0043                                     PROTOCOL <xmlfile>
0044                                     BASENAME <basename>
0045                                     [PREFIX <prefix>])
0046 
0047 Generate C++ wrapper to Wayland client protocol files from ``<xmlfile>``
0048 XML definition for the ``<basename>`` interface and append those files
0049 to ``<source_files_var>`` or ``<target>``.  Pass the ``<prefix>`` argument if the interface
0050 names don't start with ``qt_`` or ``wl_``.
0051 
0052 WaylandScanner is required and will be searched for.
0053 
0054 ::
0055 
0056   ecm_add_qtwayland_server_protocol(<target>
0057                                     PROTOCOL <xmlfile>
0058                                     BASENAME <basename>
0059                                     [PREFIX <prefix>])
0060 
0061   ecm_add_qtwayland_server_protocol(<source_files_var>
0062                                     PROTOCOL <xmlfile>
0063                                     BASENAME <basename>
0064                                     [PREFIX <prefix>])
0065 
0066 Generate C++ wrapper to Wayland server protocol files from ``<xmlfile>``
0067 XML definition for the ``<basename>`` interface and append those files
0068 to ``<source_files_var>`` or ``<target>``.  Pass the ``<prefix>`` argument if the interface
0069 names don't start with ``qt_`` or ``wl_``.
0070 
0071 WaylandScanner is required and will be searched for.
0072 
0073 Since 1.4.0.
0074 #]=======================================================================]
0075 
0076 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
0077 include("${ECM_MODULE_DIR}/ECMQueryQt.cmake")
0078 
0079 ecm_find_package_version_check(QtWaylandScanner)
0080 
0081 if (QT_MAJOR_VERSION STREQUAL "5")
0082     ecm_query_qt(qtwaylandscanner_dir QT_HOST_BINS)
0083 else()
0084     ecm_query_qt(qtwaylandscanner_dir QT_HOST_LIBEXECS)
0085 endif()
0086 
0087 # Find qtwaylandscanner
0088 find_program(QtWaylandScanner_EXECUTABLE NAMES qtwaylandscanner HINTS ${qtwaylandscanner_dir})
0089 
0090 include(FindPackageHandleStandardArgs)
0091 find_package_handle_standard_args(QtWaylandScanner
0092     FOUND_VAR
0093         QtWaylandScanner_FOUND
0094     REQUIRED_VARS
0095         QtWaylandScanner_EXECUTABLE
0096 )
0097 
0098 mark_as_advanced(QtWaylandScanner_EXECUTABLE)
0099 
0100 if(NOT TARGET Wayland::QtScanner AND QtWaylandScanner_FOUND)
0101     add_executable(Wayland::QtScanner IMPORTED)
0102     set_target_properties(Wayland::QtScanner PROPERTIES
0103         IMPORTED_LOCATION "${QtWaylandScanner_EXECUTABLE}"
0104     )
0105 endif()
0106 
0107 include(FeatureSummary)
0108 set_package_properties(QtWaylandScanner PROPERTIES
0109     URL "https://qt.io/"
0110     DESCRIPTION "Executable that converts XML protocol files to C++ code"
0111 )
0112 
0113 function(ecm_add_qtwayland_client_protocol target_or_sources_var)
0114     # Parse arguments
0115     set(oneValueArgs PROTOCOL BASENAME PREFIX)
0116     cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
0117 
0118     if(ARGS_UNPARSED_ARGUMENTS)
0119         message(FATAL_ERROR "Unknown keywords given to ecm_add_qtwayland_client_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
0120     endif()
0121 
0122     set(_prefix "${ARGS_PREFIX}")
0123 
0124     find_package(WaylandScanner REQUIRED QUIET)
0125     ecm_add_wayland_client_protocol(${target_or_sources_var}
0126                                     PROTOCOL ${ARGS_PROTOCOL}
0127                                     BASENAME ${ARGS_BASENAME})
0128 
0129     get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
0130     set(_header "${CMAKE_CURRENT_BINARY_DIR}/qwayland-${ARGS_BASENAME}.h")
0131     set(_code "${CMAKE_CURRENT_BINARY_DIR}/qwayland-${ARGS_BASENAME}.cpp")
0132 
0133     set_source_files_properties(${_header} ${_code} GENERATED)
0134 
0135     add_custom_command(OUTPUT "${_header}"
0136         COMMAND ${QtWaylandScanner_EXECUTABLE} client-header ${_infile} "" ${_prefix} > ${_header}
0137         DEPENDS ${_infile} ${_cheader} VERBATIM)
0138 
0139     add_custom_command(OUTPUT "${_code}"
0140         COMMAND ${QtWaylandScanner_EXECUTABLE} client-code ${_infile} "" ${_prefix} > ${_code}
0141         DEPENDS ${_infile} ${_header} VERBATIM)
0142 
0143     set_property(SOURCE ${_header} ${_code} PROPERTY SKIP_AUTOMOC ON)
0144 
0145     if (TARGET ${target_or_sources_var})
0146         target_sources(${target_or_sources_var} PRIVATE "${_code}")
0147     else()
0148         list(APPEND ${target_or_sources_var} "${_code}")
0149         set(${target_or_sources_var} ${${target_or_sources_var}} PARENT_SCOPE)
0150     endif()
0151 endfunction()
0152 
0153 
0154 function(ecm_add_qtwayland_server_protocol target_or_sources_var)
0155     # Parse arguments
0156     set(oneValueArgs PROTOCOL BASENAME PREFIX)
0157     cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
0158 
0159     if(ARGS_UNPARSED_ARGUMENTS)
0160         message(FATAL_ERROR "Unknown keywords given to ecm_add_qtwayland_server_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
0161     endif()
0162 
0163     set(_prefix "${ARGS_PREFIX}")
0164 
0165     find_package(WaylandScanner REQUIRED QUIET)
0166     ecm_add_wayland_server_protocol(${target_or_sources_var}
0167                                     PROTOCOL ${ARGS_PROTOCOL}
0168                                     BASENAME ${ARGS_BASENAME})
0169 
0170     get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
0171     set(_header "${CMAKE_CURRENT_BINARY_DIR}/qwayland-server-${ARGS_BASENAME}.h")
0172     set(_code "${CMAKE_CURRENT_BINARY_DIR}/qwayland-server-${ARGS_BASENAME}.cpp")
0173 
0174     set_source_files_properties(${_header} ${_code} GENERATED)
0175 
0176     add_custom_command(OUTPUT "${_header}"
0177         COMMAND ${QtWaylandScanner_EXECUTABLE} server-header ${_infile} "" ${_prefix} > ${_header}
0178         DEPENDS ${_infile} VERBATIM)
0179 
0180     add_custom_command(OUTPUT "${_code}"
0181         COMMAND ${QtWaylandScanner_EXECUTABLE} server-code ${_infile} "" ${_prefix} > ${_code}
0182         DEPENDS ${_infile} ${_header} VERBATIM)
0183 
0184     set_property(SOURCE ${_header} ${_code} PROPERTY SKIP_AUTOMOC ON)
0185 
0186     if (TARGET ${target_or_sources_var})
0187         target_sources(${target_or_sources_var} PRIVATE "${_code}")
0188     else()
0189         list(APPEND ${target_or_sources_var} "${_code}")
0190         set(${target_or_sources_var} ${${target_or_sources_var}} PARENT_SCOPE)
0191     endif()
0192 endfunction()