Warning, /frameworks/extra-cmake-modules/find-modules/FindWaylandScanner.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 FindWaylandScanner
0007 ------------------
0008 
0009 Try to find wayland-scanner.
0010 
0011 If the wayland-scanner executable is not in your PATH, you can provide
0012 an alternative name or full path location with the ``WaylandScanner_EXECUTABLE``
0013 variable.
0014 
0015 This will define the following variables:
0016 
0017 ``WaylandScanner_FOUND``
0018     True if wayland-scanner is available.
0019 
0020 ``WaylandScanner_EXECUTABLE``
0021     The wayland-scanner executable.
0022 
0023 If ``WaylandScanner_FOUND`` is TRUE, it will also define the following imported
0024 target:
0025 
0026 ``Wayland::Scanner``
0027     The wayland-scanner executable.
0028 
0029 This module provides the following functions to generate C protocol
0030 implementations:
0031 
0032   - ``ecm_add_wayland_client_protocol``
0033   - ``ecm_add_wayland_server_protocol``
0034 
0035 ::
0036 
0037   ecm_add_wayland_client_protocol(<target>
0038                                   PROTOCOL <xmlfile>
0039                                   BASENAME <basename>)
0040 
0041   ecm_add_wayland_client_protocol(<source_files_var>
0042                                   PROTOCOL <xmlfile>
0043                                   BASENAME <basename>)
0044 
0045 Generate Wayland client protocol files from ``<xmlfile>`` XML
0046 definition for the ``<basename>`` interface and append those files
0047 to ``<source_files_var>`` or ``<target>``.
0048 
0049 ::
0050 
0051   ecm_add_wayland_server_protocol(<target>
0052                                   PROTOCOL <xmlfile>
0053                                   BASENAME <basename>)
0054 
0055   ecm_add_wayland_server_protocol(<source_files_var>
0056                                   PROTOCOL <xmlfile>
0057                                   BASENAME <basename>)
0058 
0059 Generate Wayland server protocol files from ``<xmlfile>`` XML
0060 definition for the ``<basename>`` interface and append those files
0061 to ``<source_files_var>`` or ``<target>``.
0062 
0063 Since 1.4.0.
0064 #]=======================================================================]
0065 
0066 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
0067 
0068 ecm_find_package_version_check(WaylandScanner)
0069 
0070 # Find wayland-scanner
0071 find_program(WaylandScanner_EXECUTABLE NAMES wayland-scanner)
0072 
0073 include(FindPackageHandleStandardArgs)
0074 find_package_handle_standard_args(WaylandScanner
0075     FOUND_VAR
0076         WaylandScanner_FOUND
0077     REQUIRED_VARS
0078         WaylandScanner_EXECUTABLE
0079 )
0080 
0081 mark_as_advanced(WaylandScanner_EXECUTABLE)
0082 
0083 if(NOT TARGET Wayland::Scanner AND WaylandScanner_FOUND)
0084     add_executable(Wayland::Scanner IMPORTED)
0085     set_target_properties(Wayland::Scanner PROPERTIES
0086         IMPORTED_LOCATION "${WaylandScanner_EXECUTABLE}"
0087     )
0088 endif()
0089 
0090 include(FeatureSummary)
0091 set_package_properties(WaylandScanner PROPERTIES
0092     URL "https://wayland.freedesktop.org/"
0093     DESCRIPTION "Executable that converts XML protocol files to C code"
0094 )
0095 
0096 function(ecm_add_wayland_client_protocol target_or_sources_var)
0097     # Parse arguments
0098     set(oneValueArgs PROTOCOL BASENAME)
0099     cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
0100 
0101     if(ARGS_UNPARSED_ARGUMENTS)
0102         message(FATAL_ERROR "Unknown keywords given to ecm_add_wayland_client_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
0103     endif()
0104 
0105     get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
0106     set(_client_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-client-protocol.h")
0107     set(_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-protocol.c")
0108 
0109     set_source_files_properties(${_client_header} GENERATED)
0110     set_source_files_properties(${_code} GENERATED)
0111     set_property(SOURCE ${_client_header} ${_code} PROPERTY SKIP_AUTOMOC ON)
0112 
0113     add_custom_command(OUTPUT "${_client_header}"
0114         COMMAND ${WaylandScanner_EXECUTABLE} client-header ${_infile} ${_client_header}
0115         DEPENDS ${_infile} VERBATIM)
0116 
0117     add_custom_command(OUTPUT "${_code}"
0118         COMMAND ${WaylandScanner_EXECUTABLE} public-code ${_infile} ${_code}
0119         DEPENDS ${_infile} ${_client_header} VERBATIM)
0120 
0121     if (TARGET ${target_or_sources_var})
0122         target_sources(${target_or_sources_var} PRIVATE "${_client_header}" "${_code}")
0123     else()
0124         list(APPEND ${target_or_sources_var} "${_client_header}" "${_code}")
0125         set(${target_or_sources_var} ${${target_or_sources_var}} PARENT_SCOPE)
0126     endif()
0127 endfunction()
0128 
0129 
0130 function(ecm_add_wayland_server_protocol target_or_sources_var)
0131     # Parse arguments
0132     set(oneValueArgs PROTOCOL BASENAME)
0133     cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
0134 
0135     if(ARGS_UNPARSED_ARGUMENTS)
0136         message(FATAL_ERROR "Unknown keywords given to ecm_add_wayland_server_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
0137     endif()
0138 
0139     ecm_add_wayland_client_protocol(${target_or_sources_var}
0140                                     PROTOCOL ${ARGS_PROTOCOL}
0141                                     BASENAME ${ARGS_BASENAME})
0142 
0143     get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
0144     set(_server_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-server-protocol.h")
0145     set(_server_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-protocol.c")
0146     set_property(SOURCE ${_server_header} ${_server_code} PROPERTY SKIP_AUTOMOC ON)
0147     set_source_files_properties(${_server_header} GENERATED)
0148 
0149     add_custom_command(OUTPUT "${_server_header}"
0150         COMMAND ${WaylandScanner_EXECUTABLE} server-header ${_infile} ${_server_header}
0151         DEPENDS ${_infile} VERBATIM)
0152 
0153     if (TARGET ${target_or_sources_var})
0154         target_sources(${target_or_sources_var} PRIVATE "${_server_header}")
0155     else()
0156         list(APPEND ${target_or_sources_var} "${_server_header}")
0157         set(${target_or_sources_var} ${${target_or_sources_var}} PARENT_SCOPE)
0158     endif()
0159 endfunction()