Debian Codegraph @

cmake/3rdparty/extra-cmake-modules/find-modules/FindWaylandScanner.cmake

raw
1 #.rst:
2 # FindWaylandScanner
3 # ------------------
4 #
5 # Try to find wayland-scanner.
6 #
7 # If the wayland-scanner executable is not in your PATH, you can provide
8 # an alternative name or full path location with the ``WaylandScanner_EXECUTABLE``
9 # variable.
10 #
11 # This will define the following variables:
12 #
13 # ``WaylandScanner_FOUND``
14 # True if wayland-scanner is available.
15 #
16 # ``WaylandScanner_EXECUTABLE``
17 # The wayland-scanner executable.
18 #
19 # If ``WaylandScanner_FOUND`` is TRUE, it will also define the following imported
20 # target:
21 #
22 # ``Wayland::Scanner``
23 # The wayland-scanner executable.
24 #
25 # This module provides the following functions to generate C protocol
26 # implementations:
27 #
28 # - ``ecm_add_wayland_client_protocol``
29 # - ``ecm_add_wayland_server_protocol``
30 #
31 # ::
32 #
33 # ecm_add_wayland_client_protocol(<source_files_var>
34 # PROTOCOL <xmlfile>
35 # BASENAME <basename>)
36 #
37 # Generate Wayland client protocol files from ``<xmlfile>`` XML
38 # definition for the ``<basename>`` interface and append those files
39 # to ``<source_files_var>``.
40 #
41 # ::
42 #
43 # ecm_add_wayland_server_protocol(<source_files_var>
44 # PROTOCOL <xmlfile>
45 # BASENAME <basename>)
46 #
47 # Generate Wayland server protocol files from ``<xmlfile>`` XML
48 # definition for the ``<basename>`` interface and append those files
49 # to ``<source_files_var>``.
50 #
51 # Since 1.4.0.
52
53 #=============================================================================
54 # Copyright 2012-2014 Pier Luigi Fiorini <[email protected]>
55 #
56 # Redistribution and use in source and binary forms, with or without
57 # modification, are permitted provided that the following conditions
58 # are met:
59 #
60 # 1. Redistributions of source code must retain the copyright
61 # notice, this list of conditions and the following disclaimer.
62 # 2. Redistributions in binary form must reproduce the copyright
63 # notice, this list of conditions and the following disclaimer in the
64 # documentation and/or other materials provided with the distribution.
65 # 3. The name of the author may not be used to endorse or promote products
66 # derived from this software without specific prior written permission.
67 #
68 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
69 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
71 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
72 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
73 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
77 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 #=============================================================================
79
80 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
81
82 ecm_find_package_version_check(WaylandScanner)
83
84 # Find wayland-scanner
85 find_program(WaylandScanner_EXECUTABLE NAMES wayland-scanner)
86
87 include(FindPackageHandleStandardArgs)
88 find_package_handle_standard_args(WaylandScanner
89 FOUND_VAR
90 WaylandScanner_FOUND
91 REQUIRED_VARS
92 WaylandScanner_EXECUTABLE
93 )
94
95 mark_as_advanced(WaylandScanner_EXECUTABLE)
96
97 if(NOT TARGET Wayland::Scanner AND WaylandScanner_FOUND)
98 add_executable(Wayland::Scanner IMPORTED)
99 set_target_properties(Wayland::Scanner PROPERTIES
100 IMPORTED_LOCATION "${WaylandScanner_EXECUTABLE}"
101 )
102 endif()
103
104 include(FeatureSummary)
105 set_package_properties(WaylandScanner PROPERTIES
106 URL "https://wayland.freedesktop.org/"
107 DESCRIPTION "Executable that converts XML protocol files to C code"
108 )
109
110 function(ecm_add_wayland_client_protocol out_var)
111 # Parse arguments
112 set(oneValueArgs PROTOCOL BASENAME)
113 cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
114
115 if(ARGS_UNPARSED_ARGUMENTS)
116 message(FATAL_ERROR "Unknown keywords given to ecm_add_wayland_client_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
117 endif()
118
119 get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
120 set(_client_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-client-protocol.h")
121 set(_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-protocol.c")
122
123 set_source_files_properties(${_client_header} GENERATED)
124 set_source_files_properties(${_code} GENERATED)
125 set_property(SOURCE ${_client_header} PROPERTY SKIP_AUTOMOC ON)
126
127 add_custom_command(OUTPUT "${_client_header}"
128 COMMAND ${WaylandScanner_EXECUTABLE} client-header ${_infile} ${_client_header}
129 DEPENDS ${WaylandScanner_EXECUTABLE} ${_infile}
130 VERBATIM
131 )
132
133 add_custom_command(OUTPUT "${_code}"
134 COMMAND ${WaylandScanner_EXECUTABLE} code ${_infile} ${_code}
135 DEPENDS ${WaylandScanner_EXECUTABLE} ${_infile} ${_client_header}
136 VERBATIM
137 )
138
139 list(APPEND ${out_var} "${_client_header}" "${_code}")
140 set(${out_var} ${${out_var}} PARENT_SCOPE)
141 endfunction()
142
143
144 function(ecm_add_wayland_server_protocol out_var)
145 # Parse arguments
146 set(oneValueArgs PROTOCOL BASENAME)
147 cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})
148
149 if(ARGS_UNPARSED_ARGUMENTS)
150 message(FATAL_ERROR "Unknown keywords given to ecm_add_wayland_server_protocol(): \"${ARGS_UNPARSED_ARGUMENTS}\"")
151 endif()
152
153 ecm_add_wayland_client_protocol(${out_var}
154 PROTOCOL ${ARGS_PROTOCOL}
155 BASENAME ${ARGS_BASENAME})
156
157 get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
158 set(_server_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${ARGS_BASENAME}-server-protocol.h")
159 set_property(SOURCE ${_server_header} PROPERTY SKIP_AUTOMOC ON)
160 set_source_files_properties(${_server_header} GENERATED)
161
162 add_custom_command(OUTPUT "${_server_header}"
163 COMMAND ${WaylandScanner_EXECUTABLE} server-header ${_infile} ${_server_header}
164 DEPENDS ${WaylandScanner_EXECUTABLE} ${_infile}
165 VERBATIM
166 )
167
168 list(APPEND ${out_var} "${_server_header}")
169 set(${out_var} ${${out_var}} PARENT_SCOPE)
170 endfunction()