• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_chrono/backend.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_protobuf_compiler/proto.gni")
21import("$dir_pw_unit_test/test.gni")
22
23config("public_include_path") {
24  include_dirs = [ "public" ]
25  visibility = [ ":*" ]
26}
27
28pw_source_set("epoch") {
29  public = [ "public/pw_chrono/epoch.h" ]
30  public_configs = [ ":public_include_path" ]
31}
32
33pw_facade("system_clock") {
34  backend = pw_chrono_SYSTEM_CLOCK_BACKEND
35  public_configs = [ ":public_include_path" ]
36  public = [
37    "public/pw_chrono/internal/system_clock_macros.h",
38    "public/pw_chrono/system_clock.h",
39  ]
40  public_deps = [
41    ":epoch",
42    "$dir_pw_preprocessor",
43  ]
44  sources = [ "system_clock.cc" ]
45}
46
47pw_facade("system_timer") {
48  backend = pw_chrono_SYSTEM_TIMER_BACKEND
49  public_configs = [ ":public_include_path" ]
50  public = [ "public/pw_chrono/system_timer.h" ]
51  public_deps = [
52    ":system_clock",
53    "$dir_pw_function",
54  ]
55}
56
57# Dependency injectable implementation of pw::chrono::SystemClock::Interface.
58pw_source_set("simulated_system_clock") {
59  public_configs = [ ":public_include_path" ]
60  public = [ "public/pw_chrono/simulated_system_clock.h" ]
61  public_deps = [
62    ":system_clock",
63    "$dir_pw_sync:interrupt_spin_lock",
64  ]
65}
66
67pw_test_group("tests") {
68  tests = [
69    ":simulated_system_clock_test",
70    ":system_clock_facade_test",
71    ":system_timer_facade_test",
72  ]
73}
74
75pw_test("simulated_system_clock_test") {
76  enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
77  sources = [ "simulated_system_clock_test.cc" ]
78  deps = [ ":simulated_system_clock" ]
79}
80
81pw_test("system_clock_facade_test") {
82  enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
83  sources = [
84    "system_clock_facade_test.cc",
85    "system_clock_facade_test_c.c",
86  ]
87  deps = [
88    ":system_clock",
89    "$dir_pw_preprocessor",
90    pw_chrono_SYSTEM_CLOCK_BACKEND,
91  ]
92}
93
94pw_test("system_timer_facade_test") {
95  enable_if = pw_chrono_SYSTEM_TIMER_BACKEND != ""
96  sources = [ "system_timer_facade_test.cc" ]
97  deps = [
98    ":system_timer",
99    "$dir_pw_sync:thread_notification",
100    pw_chrono_SYSTEM_TIMER_BACKEND,
101  ]
102}
103
104# The ":time" target wraps the time() and gettimeofday(), which are
105# commonly used by TLS libraries for expiration check.
106config("time_wrap") {
107  # Link options that wrap C time calls.
108  ldflags = [
109    "-Wl,--wrap=time",
110    "-Wl,--wrap=gettimeofday",
111  ]
112  visibility = [ ":*" ]
113}
114
115# The build time is obtained with a python script and put in a generated header
116# file. The header file is included in build_time.cc
117pw_python_action("generate_build_time_header") {
118  header_output = "$target_gen_dir/pw_chrono/build_time.h"
119  script = "generate_build_time_header.py"
120  outputs = [ header_output ]
121  args = [ rebase_path(header_output) ]
122}
123
124# The target provides a backend to :time that returns build time.
125pw_source_set("wrap_time_build_time") {
126  all_dependent_configs = [ ":time_wrap" ]
127  include_dirs =
128      [ get_label_info(":generate_build_time_header", "target_gen_dir") ]
129  sources = [ "wrap_time_build_time.cc" ]
130  deps = [ ":generate_build_time_header" ]
131}
132
133pw_source_set("wrap_time_system_clock") {
134  all_dependent_configs = [ ":time_wrap" ]
135  sources = [ "wrap_time_system_clock.cc" ]
136  deps = [ ":system_clock" ]
137}
138
139pw_proto_library("protos") {
140  sources = [ "chrono.proto" ]
141  prefix = "pw_chrono_protos"
142}
143
144pw_doc_group("docs") {
145  sources = [
146    "backends.rst",
147    "docs.rst",
148  ]
149}
150