1# 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")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_unit_test/test.gni")
21import("backend.gni")
22
23config("public_include_path") {
24  include_dirs = [ "public" ]
25  visibility = [ ":*" ]
26}
27
28pw_facade("id") {
29  backend = pw_thread_ID_BACKEND
30  public_configs = [ ":public_include_path" ]
31  public = [ "public/pw_thread/id.h" ]
32}
33
34pw_facade("sleep") {
35  backend = pw_thread_SLEEP_BACKEND
36  public_configs = [ ":public_include_path" ]
37  public = [ "public/pw_thread/sleep.h" ]
38  public_deps = [
39    "$dir_pw_chrono:system_clock",
40    "$dir_pw_preprocessor",
41  ]
42  sources = [ "sleep.cc" ]
43}
44
45pw_facade("thread") {
46  backend = pw_thread_THREAD_BACKEND
47  public_configs = [ ":public_include_path" ]
48  public = [ "public/pw_thread/thread.h" ]
49  public_deps = [
50    ":id",
51    ":thread_core",
52  ]
53  sources = [ "thread.cc" ]
54}
55
56pw_source_set("thread_core") {
57  public_configs = [ ":public_include_path" ]
58  public = [ "public/pw_thread/thread_core.h" ]
59}
60
61pw_facade("yield") {
62  backend = pw_thread_YIELD_BACKEND
63  public_configs = [ ":public_include_path" ]
64  public = [ "public/pw_thread/yield.h" ]
65  public_deps = [ "$dir_pw_preprocessor" ]
66  sources = [ "yield.cc" ]
67}
68
69pw_test_group("tests") {
70  tests = [
71    ":id_facade_test",
72    ":sleep_facade_test",
73    ":yield_facade_test",
74  ]
75}
76
77pw_test("id_facade_test") {
78  enable_if = pw_thread_ID_BACKEND != ""
79  sources = [ "id_facade_test.cc" ]
80  deps = [ ":id" ]
81}
82
83pw_test("sleep_facade_test") {
84  enable_if = pw_thread_SLEEP_BACKEND != "" && pw_thread_ID_BACKEND != ""
85  sources = [
86    "sleep_facade_test.cc",
87    "sleep_facade_test_c.c",
88  ]
89  deps = [
90    ":id",
91    ":sleep",
92    "$dir_pw_chrono:system_clock",
93  ]
94}
95
96if (pw_thread_THREAD_BACKEND != "") {
97  pw_source_set("test_threads") {
98    public_configs = [ ":public_include_path" ]
99    public = [ "public/pw_thread/test_threads.h" ]
100    public_deps = [ ":thread" ]
101  }
102
103  # To instantiate this facade test based on a selected backend to provide
104  # test_threads you can create a pw_test target which depends on this
105  # pw_source_set and a pw_source_set which provides the implementation of
106  # test_threads. See "$dir_pw_thread_stl:thread_backend_test" as an example.
107  pw_source_set("thread_facade_test") {
108    sources = [ "thread_facade_test.cc" ]
109    deps = [
110      ":id",
111      ":sleep",
112      ":test_threads",
113      ":thread",
114      "$dir_pw_sync:binary_semaphore",
115      dir_pw_unit_test,
116    ]
117  }
118}
119
120pw_test("yield_facade_test") {
121  enable_if = pw_thread_YIELD_BACKEND != "" && pw_thread_ID_BACKEND != ""
122  sources = [
123    "yield_facade_test.cc",
124    "yield_facade_test_c.c",
125  ]
126  deps = [
127    ":id",
128    ":yield",
129  ]
130}
131
132pw_doc_group("docs") {
133  sources = [ "docs.rst" ]
134}
135