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