xref: /aosp_15_r20/external/pigweed/pw_thread_threadx/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/error.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_chrono/backend.gni")
21import("$dir_pw_docgen/docs.gni")
22import("$dir_pw_thread/backend.gni")
23import("$dir_pw_unit_test/test.gni")
24
25declare_args() {
26  # The build target that overrides the default configuration options for this
27  # module. This should point to a source set that provides defines through a
28  # public config (which may -include a file or add defines directly).
29  pw_thread_threadx_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30}
31
32config("public_include_path") {
33  include_dirs = [ "public" ]
34  visibility = [ ":*" ]
35}
36
37config("backend_config") {
38  include_dirs = [ "public_overrides" ]
39  visibility = [ ":*" ]
40}
41
42pw_source_set("config") {
43  public = [ "public/pw_thread_threadx/config.h" ]
44  public_configs = [ ":public_include_path" ]
45  public_deps = [
46    "$dir_pw_third_party/threadx",
47    pw_thread_threadx_CONFIG,
48  ]
49}
50
51config("id_public_overrides") {
52  include_dirs = [ "id_public_overrides" ]
53  visibility = [ ":*" ]
54}
55
56# This target provides the backend for pw::Thread::id.
57pw_source_set("id") {
58  public_configs = [
59    ":public_include_path",
60    ":id_public_overrides",
61  ]
62  public_deps = [
63    "$dir_pw_assert",
64    "$dir_pw_interrupt:context",
65    "$dir_pw_third_party/threadx",
66  ]
67  public = [
68    "$dir_pw_thread:thread.facade",
69    "id_public_overrides/pw_thread_backend/id_inline.h",
70    "id_public_overrides/pw_thread_backend/id_native.h",
71    "public/pw_thread_threadx/id_inline.h",
72    "public/pw_thread_threadx/id_native.h",
73  ]
74}
75
76if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") {
77  pw_build_assert("check_system_clock_backend") {
78    condition =
79        pw_thread_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK ||
80        pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_threadx:system_clock"
81    message = "The ThreadX pw::this_thread::sleep_{for,until} backend only " +
82              "works with the ThreadX pw::chrono::SystemClock backend."
83  }
84
85  config("sleep_public_overrides") {
86    include_dirs = [ "sleep_public_overrides" ]
87    visibility = [ ":*" ]
88  }
89
90  # This target provides the backend for pw::this_thread::sleep_{for,until}.
91  pw_source_set("sleep") {
92    public_configs = [
93      ":public_include_path",
94      ":sleep_public_overrides",
95    ]
96    public = [
97      "public/pw_thread_threadx/sleep_inline.h",
98      "sleep_public_overrides/pw_thread_backend/sleep_inline.h",
99    ]
100    public_deps = [ "$dir_pw_chrono:system_clock" ]
101    sources = [ "sleep.cc" ]
102    deps = [
103      ":check_system_clock_backend",
104      "$dir_pw_assert",
105      "$dir_pw_chrono_threadx:system_clock",
106      "$dir_pw_third_party/threadx",
107      "$dir_pw_thread:thread",
108    ]
109  }
110}
111
112config("thread_public_overrides") {
113  include_dirs = [ "thread_public_overrides" ]
114  visibility = [ ":*" ]
115}
116
117# This target provides the backend for pw::Thread and the headers needed for
118# thread creation.
119pw_source_set("thread") {
120  public_configs = [
121    ":public_include_path",
122    ":thread_public_overrides",
123  ]
124  public_deps = [
125    ":config",
126    "$dir_pw_assert",
127    "$dir_pw_string",
128    "$dir_pw_third_party/threadx",
129    "$dir_pw_thread:thread.facade",
130    dir_pw_function,
131    dir_pw_span,
132  ]
133  public = [
134    "public/pw_thread_threadx/context.h",
135    "public/pw_thread_threadx/options.h",
136    "public/pw_thread_threadx/thread_inline.h",
137    "public/pw_thread_threadx/thread_native.h",
138    "thread_public_overrides/pw_thread_backend/thread_inline.h",
139    "thread_public_overrides/pw_thread_backend/thread_native.h",
140  ]
141  allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ]
142  sources = [ "thread.cc" ]
143}
144
145config("yield_public_overrides") {
146  include_dirs = [ "yield_public_overrides" ]
147  visibility = [ ":*" ]
148}
149
150# This target provides the backend for pw::this_thread::yield.
151pw_source_set("yield") {
152  public_configs = [
153    ":public_include_path",
154    ":yield_public_overrides",
155  ]
156  public = [
157    "public/pw_thread_threadx/yield_inline.h",
158    "yield_public_overrides/pw_thread_backend/yield_inline.h",
159  ]
160  public_deps = [
161    "$dir_pw_assert",
162    "$dir_pw_third_party/threadx",
163    "$dir_pw_thread:thread",
164  ]
165  deps = [ "$dir_pw_thread:yield.facade" ]
166}
167
168pw_source_set("util") {
169  public_configs = [ ":public_include_path" ]
170  public_deps = [
171    "$dir_pw_third_party/threadx",
172    dir_pw_function,
173    dir_pw_status,
174  ]
175  public = [ "public/pw_thread_threadx/util.h" ]
176  sources = [ "util.cc" ]
177}
178
179pw_source_set("snapshot") {
180  public_configs = [ ":public_include_path" ]
181  public_deps = [
182    ":config",
183    "$dir_pw_third_party/threadx",
184    "$dir_pw_thread:protos.pwpb",
185    "$dir_pw_thread:snapshot",
186    dir_pw_bytes,
187    dir_pw_function,
188    dir_pw_log,
189    dir_pw_protobuf,
190    dir_pw_status,
191  ]
192  public = [ "public/pw_thread_threadx/snapshot.h" ]
193  sources = [ "snapshot.cc" ]
194  deps = [
195    ":util",
196    dir_pw_log,
197  ]
198}
199
200pw_test_group("tests") {
201  tests = [ ":thread_backend_test" ]
202}
203
204pw_source_set("non_portable_test_thread_options") {
205  public_deps = [ "$dir_pw_thread:non_portable_test_thread_options" ]
206  sources = [ "test_threads.cc" ]
207  deps = [
208    "$dir_pw_chrono:system_clock",
209    "$dir_pw_thread:sleep",
210    "$dir_pw_thread:thread",
211    dir_pw_assert,
212    dir_pw_log,
213  ]
214}
215
216pw_test("thread_backend_test") {
217  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_threadx:thread"
218  deps = [
219    ":non_portable_test_thread_options",
220    "$dir_pw_thread:thread_facade_test",
221  ]
222}
223
224pw_doc_group("docs") {
225  sources = [ "docs.rst" ]
226}
227