Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / build / chip / linux / gdbus_library.gni
1 # Copyright (c) 2020 Project CHIP Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 glib_config = rebase_path(":glib")
16 gen_dbus_wrapper = rebase_path("gen_gdbus_wrapper.py")
17
18 # Runs gdbus-codegen and defines the resulting library.
19 #
20 # Parameters:
21 #   sources - The dbux XML files.
22 #   dbus_out_dir - Subdirectory for generated files within root_gen_dir.
23 #   replace_config_header - Replace the config header.
24 template("gdbus_library") {
25   library_name = target_name
26   visibility = [ ":${library_name}" ]
27
28   assert(defined(invoker.sources), "Please specify sources")
29   assert(defined(invoker.dbus_out_dir), "Please specify dbus_out_dir")
30
31   dbus_out_dir = invoker.dbus_out_dir
32   dbus_gen_dir = "${root_gen_dir}/${dbus_out_dir}"
33
34   config("${library_name}_config") {
35     include_dirs = [ root_gen_dir ]
36   }
37
38   dbus_sources = []
39   foreach(xml, invoker.sources) {
40     name = get_path_info(xml, "name")
41     dbus_sources += [
42       "${dbus_gen_dir}/${name}.c",
43       "${dbus_gen_dir}/${name}.h",
44     ]
45   }
46
47   action_foreach("${library_name}_gen") {
48     script = gen_dbus_wrapper
49
50     sources = invoker.sources
51
52     source_file = "$dbus_gen_dir/{{source_name_part}}.c"
53     header_file = "$dbus_gen_dir/{{source_name_part}}.h"
54
55     outputs = [
56       source_file,
57       header_file,
58     ]
59
60     args = [
61       "--input",
62       "{{source}}",
63       "--output_c",
64       rebase_path(source_file, root_build_dir),
65       "--output_h",
66       rebase_path(header_file, root_build_dir),
67     ]
68
69     if (defined(invoker.c_namespace)) {
70       args += [
71         "--c-namespace",
72         invoker.c_namespace,
73       ]
74     }
75
76     if (defined(invoker.interface_prefix)) {
77       args += [
78         "--interface-prefix",
79         invoker.interface_prefix,
80       ]
81     }
82
83     if (invoker.c_generate_object_manager) {
84       args += [ "--c-generate-object-manager" ]
85     }
86   }
87
88   static_library(library_name) {
89     forward_variables_from(invoker,
90                            [
91                              "defines",
92                              "testonly",
93                            ])
94     sources = dbus_sources
95     deps = [ ":${library_name}_gen" ]
96
97     public_configs = [
98       ":${library_name}_config",
99       glib_config,
100     ]
101
102     visibility = []
103     if (defined(invoker.visibility)) {
104       visibility = invoker.visibility
105     } else {
106       visibility = [ "*" ]
107     }
108   }
109 }