blob: 69a9c864d0ea7e3ae340f57eb3366c85ecff555e [file] [log] [blame]
Ewout van Bekkume3b56032020-12-22 12:00:18 -08001# Copyright 2020 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/facade.gni")
Armando Montanez5f10ff82021-08-13 13:47:39 -070018import("$dir_pw_build/module_config.gni")
Ewout van Bekkume3b56032020-12-22 12:00:18 -080019import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
Armando Montanez179aa8e2021-03-10 11:46:35 -080021import("$dir_pw_protobuf_compiler/proto.gni")
Ewout van Bekkume3b56032020-12-22 12:00:18 -080022import("$dir_pw_unit_test/test.gni")
23import("backend.gni")
24
Armando Montanez5f10ff82021-08-13 13:47:39 -070025declare_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_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30}
31
Ewout van Bekkume3b56032020-12-22 12:00:18 -080032config("public_include_path") {
33 include_dirs = [ "public" ]
34 visibility = [ ":*" ]
35}
36
Armando Montanez5f10ff82021-08-13 13:47:39 -070037pw_source_set("config") {
38 public_deps = [ pw_thread_CONFIG ]
39 public = [ "public/pw_thread/config.h" ]
40 public_configs = [ ":public_include_path" ]
41 visibility = [ ":*" ]
42}
43
Ewout van Bekkume3b56032020-12-22 12:00:18 -080044pw_facade("id") {
45 backend = pw_thread_ID_BACKEND
46 public_configs = [ ":public_include_path" ]
47 public = [ "public/pw_thread/id.h" ]
48}
49
50pw_facade("sleep") {
51 backend = pw_thread_SLEEP_BACKEND
52 public_configs = [ ":public_include_path" ]
53 public = [ "public/pw_thread/sleep.h" ]
54 public_deps = [
55 "$dir_pw_chrono:system_clock",
56 "$dir_pw_preprocessor",
57 ]
58 sources = [ "sleep.cc" ]
59}
60
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -080061pw_facade("thread") {
62 backend = pw_thread_THREAD_BACKEND
63 public_configs = [ ":public_include_path" ]
Ewout van Bekkum19e753a2021-04-28 18:06:55 -070064 public = [
65 "public/pw_thread/detached_thread.h",
66 "public/pw_thread/thread.h",
67 ]
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -070068 public_deps = [
69 ":id",
70 ":thread_core",
71 ]
72 sources = [ "thread.cc" ]
73}
74
75pw_source_set("thread_core") {
76 public_configs = [ ":public_include_path" ]
77 public = [ "public/pw_thread/thread_core.h" ]
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -080078}
79
Ewout van Bekkume3b56032020-12-22 12:00:18 -080080pw_facade("yield") {
81 backend = pw_thread_YIELD_BACKEND
82 public_configs = [ ":public_include_path" ]
83 public = [ "public/pw_thread/yield.h" ]
84 public_deps = [ "$dir_pw_preprocessor" ]
85 sources = [ "yield.cc" ]
86}
87
Armando Montanezfec572b2021-06-28 12:13:57 -070088pw_source_set("snapshot") {
89 public_configs = [ ":public_include_path" ]
90 public_deps = [
91 "$dir_pw_thread:protos.pwpb",
92 dir_pw_bytes,
93 dir_pw_function,
94 dir_pw_protobuf,
95 dir_pw_status,
96 ]
97 public = [ "public/pw_thread/snapshot.h" ]
98 sources = [ "snapshot.cc" ]
Armando Montanez5f10ff82021-08-13 13:47:39 -070099 deps = [
100 ":config",
101 dir_pw_log,
102 ]
Armando Montanezfec572b2021-06-28 12:13:57 -0700103}
104
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800105pw_test_group("tests") {
106 tests = [
107 ":id_facade_test",
108 ":sleep_facade_test",
109 ":yield_facade_test",
110 ]
111}
112
113pw_test("id_facade_test") {
114 enable_if = pw_thread_ID_BACKEND != ""
115 sources = [ "id_facade_test.cc" ]
116 deps = [ ":id" ]
117}
118
119pw_test("sleep_facade_test") {
120 enable_if = pw_thread_SLEEP_BACKEND != "" && pw_thread_ID_BACKEND != ""
121 sources = [
122 "sleep_facade_test.cc",
123 "sleep_facade_test_c.c",
124 ]
125 deps = [
126 ":id",
127 ":sleep",
128 "$dir_pw_chrono:system_clock",
129 ]
130}
131
Rob Mohr4663d472021-09-08 11:29:07 -0700132pw_source_set("test_threads") {
133 public_configs = [ ":public_include_path" ]
134 public = [ "public/pw_thread/test_threads.h" ]
135 public_deps = [ ":thread" ]
136}
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800137
Rob Mohr4663d472021-09-08 11:29:07 -0700138# To instantiate this facade test based on a selected backend to provide
139# test_threads you can create a pw_test target which depends on this
140# pw_source_set and a pw_source_set which provides the implementation of
141# test_threads. See "$dir_pw_thread_stl:thread_backend_test" as an example.
142pw_source_set("thread_facade_test") {
143 sources = [ "thread_facade_test.cc" ]
144 deps = [
145 ":id",
146 ":sleep",
147 ":test_threads",
148 ":thread",
149 "$dir_pw_sync:binary_semaphore",
150 dir_pw_unit_test,
151 ]
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800152}
153
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800154pw_test("yield_facade_test") {
155 enable_if = pw_thread_YIELD_BACKEND != "" && pw_thread_ID_BACKEND != ""
156 sources = [
157 "yield_facade_test.cc",
158 "yield_facade_test_c.c",
159 ]
160 deps = [
161 ":id",
162 ":yield",
163 ]
164}
165
Armando Montanez179aa8e2021-03-10 11:46:35 -0800166pw_proto_library("protos") {
167 sources = [ "pw_thread_protos/thread.proto" ]
Armando Montanez89314302021-07-28 10:32:53 -0700168 deps = [ "$dir_pw_tokenizer:proto" ]
Armando Montanez179aa8e2021-03-10 11:46:35 -0800169}
170
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800171pw_doc_group("docs") {
172 sources = [ "docs.rst" ]
173}