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/module_config.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_protobuf_compiler/proto.gni") 22import("$dir_pw_unit_test/test.gni") 23import("backend.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_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 30} 31 32config("public_include_path") { 33 include_dirs = [ "public" ] 34 visibility = [ ":*" ] 35} 36 37pw_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 44pw_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 61pw_facade("thread") { 62 backend = pw_thread_THREAD_BACKEND 63 public_configs = [ ":public_include_path" ] 64 public = [ 65 "public/pw_thread/detached_thread.h", 66 "public/pw_thread/thread.h", 67 ] 68 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" ] 78} 79 80pw_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 88pw_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" ] 99 deps = [ 100 ":config", 101 dir_pw_log, 102 ] 103} 104 105pw_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 132pw_source_set("test_threads") { 133 public_configs = [ ":public_include_path" ] 134 public = [ "public/pw_thread/test_threads.h" ] 135 public_deps = [ ":thread" ] 136} 137 138# 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 ] 152} 153 154pw_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 166pw_proto_library("protos") { 167 sources = [ "pw_thread_protos/thread.proto" ] 168 deps = [ "$dir_pw_tokenizer:proto" ] 169} 170 171pw_doc_group("docs") { 172 sources = [ "docs.rst" ] 173} 174