aboutsummaryrefslogtreecommitdiff
path: root/pw_thread/CMakeLists.txt
blob: dc16136bd031aab205fad918457fb07b0164b731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright 2022 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
include($ENV{PW_ROOT}/pw_thread/backend.cmake)

pw_add_module_config(pw_thread_CONFIG)

pw_add_library(pw_thread.config INTERFACE
  HEADERS
    public/pw_thread/config.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    ${pw_thread_CONFIG}
)

pw_add_facade(pw_thread.id INTERFACE
  BACKEND
    pw_thread.id_BACKEND
  HEADERS
    public/pw_thread/id.h
  PUBLIC_INCLUDES
    public
)

pw_add_facade(pw_thread.sleep STATIC
  BACKEND
    pw_thread.sleep_BACKEND
  HEADERS
    public/pw_thread/sleep.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_chrono.system_clock
    pw_preprocessor
  SOURCES
    sleep.cc
)

pw_add_facade(pw_thread.thread STATIC
  BACKEND
    pw_thread.thread_BACKEND
  HEADERS
    public/pw_thread/detached_thread.h
    public/pw_thread/thread.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_thread.thread_core
    pw_thread.id
  SOURCES
    thread.cc
)

pw_add_library(pw_thread.thread_core INTERFACE
  HEADERS
    public/pw_thread/thread_core.h
  PUBLIC_INCLUDES
    public
)

pw_add_facade(pw_thread.yield STATIC
  BACKEND
    pw_thread.yield_BACKEND
  HEADERS
    public/pw_thread/yield.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_preprocessor
  SOURCES
    yield.cc
)

pw_add_library(pw_thread.snapshot STATIC
  HEADERS
    public/pw_thread/snapshot.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_bytes
    pw_function
    pw_protobuf
    pw_status
    pw_thread.protos.pwpb
  SOURCES
    snapshot.cc
  PRIVATE_DEPS
    pw_thread.config
    pw_log
)

pw_proto_library(pw_thread.protos
  SOURCES
    pw_thread_protos/thread.proto
  DEPS
    pw_tokenizer.proto
)

if(NOT "${pw_thread.id_BACKEND}" STREQUAL "")
  pw_add_test(pw_thread.id_facade_test
    SOURCES
      id_facade_test.cc
    PRIVATE_DEPS
      pw_thread.id
    GROUPS
      modules
      pw_thread
  )
endif()

if((NOT "${pw_thread.id_BACKEND}" STREQUAL "") AND
   (NOT "${pw_thread.sleep_BACKEND}" STREQUAL ""))
  pw_add_test(pw_thread.sleep_facade_test
    SOURCES
      sleep_facade_test.cc
      sleep_facade_test_c.c
    PRIVATE_DEPS
      pw_chrono.system_clock
      pw_thread.id
      pw_thread.sleep
    GROUPS
      modules
      pw_thread
  )
endif()

pw_add_library(pw_thread.test_threads INTERFACE
  HEADERS
    public/pw_thread/test_threads.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_thread.thread
)

# To instantiate this facade test based on a selected backend to provide
# test_threads you can create a pw_add_test target which depends on this
# target and a target which provides the implementation of
# test_threads. See pw_thread_stl.thread_backend_test as an example.
pw_add_library(pw_thread.thread_facade_test STATIC
  SOURCES
    thread_facade_test.cc
  PRIVATE_DEPS
    pw_thread.id
    pw_thread.sleep
    pw_thread.test_threads
    pw_thread.thread
    pw_sync.binary_semaphore
    pw_unit_test
)

if((NOT "${pw_thread.id_BACKEND}" STREQUAL "") AND
   (NOT "${pw_thread.yield_BACKEND}" STREQUAL ""))
  pw_add_test(pw_thread.yield_facade_test
    SOURCES
      yield_facade_test.cc
      yield_facade_test_c.c
    PRIVATE_DEPS
      pw_thread.id
      pw_thread.yield
    GROUPS
      modules
      pw_thread
  )
endif()