xref: /aosp_15_r20/external/pigweed/third_party/chre/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker# Copyright 2023 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker#
3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker# the License at
6*61c4878aSAndroid Build Coastguard Worker#
7*61c4878aSAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker#
9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker# the License.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Workerimport("//build_overrides/pigweed.gni")
16*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/error.gni")
17*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/target_types.gni")
18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_chrono/backend.gni")
19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_docgen/docs.gni")
20*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_unit_test/test.gni")
21*61c4878aSAndroid Build Coastguard Workerimport("chre.gni")
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard Worker# This file defines a GN source_set for an external installation of chre.
24*61c4878aSAndroid Build Coastguard Worker# To use, checkout the chre source into a directory, then set the build arg
25*61c4878aSAndroid Build Coastguard Worker# dir_pw_third_party_chre to point to that directory. The chre library
26*61c4878aSAndroid Build Coastguard Worker# will be available in GN at "$dir_pw_third_party/chre".
27*61c4878aSAndroid Build Coastguard Workerif (dir_pw_third_party_chre == "") {
28*61c4878aSAndroid Build Coastguard Worker} else {
29*61c4878aSAndroid Build Coastguard Worker  config("disable_warnings") {
30*61c4878aSAndroid Build Coastguard Worker    cflags = [
31*61c4878aSAndroid Build Coastguard Worker      "-Wno-cast-qual",
32*61c4878aSAndroid Build Coastguard Worker      "-Wno-int-in-bool-context",
33*61c4878aSAndroid Build Coastguard Worker      "-Wno-thread-safety-analysis",
34*61c4878aSAndroid Build Coastguard Worker      "-Wno-vla",
35*61c4878aSAndroid Build Coastguard Worker    ]
36*61c4878aSAndroid Build Coastguard Worker    visibility = [ ":*" ]
37*61c4878aSAndroid Build Coastguard Worker  }
38*61c4878aSAndroid Build Coastguard Worker
39*61c4878aSAndroid Build Coastguard Worker  config("default_chre_config_defines") {
40*61c4878aSAndroid Build Coastguard Worker    cflags = [
41*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_MESSAGE_TO_HOST_MAX_SIZE=2048",
42*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_DEBUG",
43*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_ASSERTIONS_DISABLED",
44*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_FILENAME=__FILE__",
45*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_PATCH_VERSION=1",
46*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_PLATFORM_ID=1",
47*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_FIRST_SUPPORTED_API_VERSION=CHRE_API_VERSION_1_1",
48*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST",
49*61c4878aSAndroid Build Coastguard Worker      "-DCHRE_NANOAPP_INTERNAL",
50*61c4878aSAndroid Build Coastguard Worker    ]
51*61c4878aSAndroid Build Coastguard Worker  }
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Worker  pw_source_set("default_chre_config") {
54*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":default_chre_config_defines" ]
55*61c4878aSAndroid Build Coastguard Worker  }
56*61c4878aSAndroid Build Coastguard Worker
57*61c4878aSAndroid Build Coastguard Worker  pw_source_set("config") {
58*61c4878aSAndroid Build Coastguard Worker    public_deps = [ pw_chre_CONFIG ]
59*61c4878aSAndroid Build Coastguard Worker  }
60*61c4878aSAndroid Build Coastguard Worker
61*61c4878aSAndroid Build Coastguard Worker  config("public_includes") {
62*61c4878aSAndroid Build Coastguard Worker    include_dirs = [
63*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/include",
64*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/chre_api/include",
65*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/chre_api/include/chre_api",
66*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/pal/include",
67*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/include",
68*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/include",
69*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/include",
70*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/include",
71*61c4878aSAndroid Build Coastguard Worker    ]
72*61c4878aSAndroid Build Coastguard Worker    visibility = [ ":*" ]
73*61c4878aSAndroid Build Coastguard Worker  }
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard Worker  pw_source_set("chre_headers") {
76*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":public_includes" ]
77*61c4878aSAndroid Build Coastguard Worker    public_deps = [ ":config" ]
78*61c4878aSAndroid Build Coastguard Worker  }
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard Worker  pw_source_set("shared_platform") {
81*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":disable_warnings" ]
82*61c4878aSAndroid Build Coastguard Worker    sources = [
83*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/chre_api_core.cc",
84*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/chre_api_re.cc",
85*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/chre_api_user_settings.cc",
86*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/chre_api_version.cc",
87*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/memory_manager.cc",
88*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/nanoapp/nanoapp_dso_util.cc",
89*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared/system_time.cc",
90*61c4878aSAndroid Build Coastguard Worker    ]
91*61c4878aSAndroid Build Coastguard Worker
92*61c4878aSAndroid Build Coastguard Worker    # CHRE does not compile on MacOS, so work around this.
93*61c4878aSAndroid Build Coastguard Worker    if (current_os == "mac") {
94*61c4878aSAndroid Build Coastguard Worker      sources += [ "version.cc" ]
95*61c4878aSAndroid Build Coastguard Worker    } else {
96*61c4878aSAndroid Build Coastguard Worker      sources += [ "$dir_pw_third_party_chre/platform/shared/version.cc" ]
97*61c4878aSAndroid Build Coastguard Worker    }
98*61c4878aSAndroid Build Coastguard Worker
99*61c4878aSAndroid Build Coastguard Worker    public_deps = [
100*61c4878aSAndroid Build Coastguard Worker      ":chre_headers",
101*61c4878aSAndroid Build Coastguard Worker      "$pw_chre_PLATFORM_BACKEND_HEADERS",
102*61c4878aSAndroid Build Coastguard Worker    ]
103*61c4878aSAndroid Build Coastguard Worker    remove_configs = [ "$dir_pw_build:internal_strict_warnings" ]
104*61c4878aSAndroid Build Coastguard Worker  }
105*61c4878aSAndroid Build Coastguard Worker
106*61c4878aSAndroid Build Coastguard Worker  pw_source_set("chre") {
107*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":disable_warnings" ]
108*61c4878aSAndroid Build Coastguard Worker    sources = [
109*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/debug_dump_manager.cc",
110*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/event.cc",
111*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/event_loop.cc",
112*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/event_loop_manager.cc",
113*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/event_ref_queue.cc",
114*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/host_comms_manager.cc",
115*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/init.cc",
116*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/log.cc",
117*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/nanoapp.cc",
118*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/settings.cc",
119*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/static_nanoapps.cc",
120*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/core/timer_pool.cc",
121*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/buffer_base.cc",
122*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/dynamic_vector_base.cc",
123*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/system/debug_dump.cc",
124*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/system/event_callbacks.cc",
125*61c4878aSAndroid Build Coastguard Worker    ]
126*61c4878aSAndroid Build Coastguard Worker
127*61c4878aSAndroid Build Coastguard Worker    public_deps = [
128*61c4878aSAndroid Build Coastguard Worker      ":chre_headers",
129*61c4878aSAndroid Build Coastguard Worker      "$pw_chre_PLATFORM_BACKEND",
130*61c4878aSAndroid Build Coastguard Worker    ]
131*61c4878aSAndroid Build Coastguard Worker    remove_configs = [ "$dir_pw_build:internal_strict_warnings" ]
132*61c4878aSAndroid Build Coastguard Worker  }
133*61c4878aSAndroid Build Coastguard Worker
134*61c4878aSAndroid Build Coastguard Worker  pw_source_set("example_apps") {
135*61c4878aSAndroid Build Coastguard Worker    sources = [
136*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/debug_dump_world/debug_dump_world.cc",
137*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/hello_world/hello_world.cc",
138*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/message_world/message_world.cc",
139*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/spammer/spammer.cc",
140*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/timer_world/timer_world.cc",
141*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/apps/unload_tester/unload_tester.cc",
142*61c4878aSAndroid Build Coastguard Worker    ]
143*61c4878aSAndroid Build Coastguard Worker    public_deps = [ ":chre" ]
144*61c4878aSAndroid Build Coastguard Worker  }
145*61c4878aSAndroid Build Coastguard Worker
146*61c4878aSAndroid Build Coastguard Worker  config("test_includes") {
147*61c4878aSAndroid Build Coastguard Worker    include_dirs = [
148*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/platform/shared",
149*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/test/simulation/inc",
150*61c4878aSAndroid Build Coastguard Worker    ]
151*61c4878aSAndroid Build Coastguard Worker    visibility = [ ":*" ]
152*61c4878aSAndroid Build Coastguard Worker  }
153*61c4878aSAndroid Build Coastguard Worker
154*61c4878aSAndroid Build Coastguard Worker  config("tests_disable_warnings") {
155*61c4878aSAndroid Build Coastguard Worker    cflags = [ "-Wno-sign-compare" ]
156*61c4878aSAndroid Build Coastguard Worker    visibility = [ ":*" ]
157*61c4878aSAndroid Build Coastguard Worker  }
158*61c4878aSAndroid Build Coastguard Worker
159*61c4878aSAndroid Build Coastguard Worker  pw_test("unit_tests") {
160*61c4878aSAndroid Build Coastguard Worker    enable_if =
161*61c4878aSAndroid Build Coastguard Worker        dir_pw_third_party_chre != "" && pw_chrono_SYSTEM_CLOCK_BACKEND != ""
162*61c4878aSAndroid Build Coastguard Worker    sources = [
163*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/blocking_queue_test.cc",
164*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/buffer_test.cc",
165*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/conditional_lock_guard_test.cc",
166*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/debug_dump_test.cc",
167*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/lock_guard_test.cc",
168*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/optional_test.cc",
169*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/ref_base_test.cc",
170*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/shared_ptr_test.cc",
171*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/singleton_test.cc",
172*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/time_test.cc",
173*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/util/tests/unique_ptr_test.cc",
174*61c4878aSAndroid Build Coastguard Worker    ]
175*61c4878aSAndroid Build Coastguard Worker    public_deps = [ ":chre" ]
176*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":tests_disable_warnings" ]
177*61c4878aSAndroid Build Coastguard Worker    remove_configs = [ "$dir_pw_build:internal_strict_warnings" ]
178*61c4878aSAndroid Build Coastguard Worker  }
179*61c4878aSAndroid Build Coastguard Worker
180*61c4878aSAndroid Build Coastguard Worker  pw_test("integration_tests") {
181*61c4878aSAndroid Build Coastguard Worker    enable_if =
182*61c4878aSAndroid Build Coastguard Worker        dir_pw_third_party_chre != "" && pw_chrono_SYSTEM_CLOCK_BACKEND != ""
183*61c4878aSAndroid Build Coastguard Worker    sources = [
184*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/test/simulation/memory_test.cc",
185*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/test/simulation/test_util.cc",
186*61c4878aSAndroid Build Coastguard Worker      "$dir_pw_third_party_chre/test/simulation/timer_test.cc",
187*61c4878aSAndroid Build Coastguard Worker      "integration_test.cc",
188*61c4878aSAndroid Build Coastguard Worker    ]
189*61c4878aSAndroid Build Coastguard Worker
190*61c4878aSAndroid Build Coastguard Worker    public_deps = [ ":chre" ]
191*61c4878aSAndroid Build Coastguard Worker    public_configs = [
192*61c4878aSAndroid Build Coastguard Worker      ":test_includes",
193*61c4878aSAndroid Build Coastguard Worker      ":tests_disable_warnings",
194*61c4878aSAndroid Build Coastguard Worker    ]
195*61c4878aSAndroid Build Coastguard Worker    remove_configs = [ "$dir_pw_build:internal_strict_warnings" ]
196*61c4878aSAndroid Build Coastguard Worker  }
197*61c4878aSAndroid Build Coastguard Worker}
198