aboutsummaryrefslogtreecommitdiff
path: root/pw_tokenizer/CMakeLists.txt
blob: 1ceecbc2ae7b4534e25908899adfca912d1e4d91 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Copyright 2020 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_protobuf_compiler/proto.cmake)

pw_add_module_config(pw_tokenizer_CONFIG)

pw_add_module_library(pw_tokenizer.config
  HEADERS
    public/pw_tokenizer/config.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    ${pw_tokenizer_CONFIG}
)

pw_add_module_library(pw_tokenizer
  HEADERS
    public/pw_tokenizer/encode_args.h
    public/pw_tokenizer/hash.h
    public/pw_tokenizer/tokenize.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_containers
    pw_polyfill.span
    pw_preprocessor
    pw_tokenizer.config
  SOURCES
    encode_args.cc
    hash.cc
    public/pw_tokenizer/internal/argument_types.h
    public/pw_tokenizer/internal/argument_types_macro_4_byte.h
    public/pw_tokenizer/internal/argument_types_macro_8_byte.h
    public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h
    public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_256_hash_macro.h
    public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h
    public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h
    public/pw_tokenizer/internal/tokenize_string.h
    tokenize.cc
  PRIVATE_DEPS
    pw_varint
)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "")
  target_link_options(pw_tokenizer
    PUBLIC
      "-T${CMAKE_CURRENT_SOURCE_DIR}/pw_tokenizer_linker_sections.ld"
  )
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
  target_link_options(pw_tokenizer
    PUBLIC
      "-T${CMAKE_CURRENT_SOURCE_DIR}/add_tokenizer_sections_to_default_script.ld"
      "-L${CMAKE_CURRENT_SOURCE_DIR}"
  )
endif()

pw_add_module_library(pw_tokenizer.base64
  HEADERS
    public/pw_tokenizer/base64.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_base64
    pw_polyfill.cstddef
    pw_polyfill.span
    pw_tokenizer
    pw_tokenizer.config
  SOURCES
    base64.cc
)

pw_add_module_library(pw_tokenizer.decoder
  HEADERS
    public/pw_tokenizer/detokenize.h
    public/pw_tokenizer/token_database.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_polyfill.span
    pw_tokenizer
  SOURCES
    decode.cc
    detokenize.cc
    public/pw_tokenizer/internal/decode.h
    token_database.cc
  PRIVATE_DEPS
    pw_varint
)

pw_add_facade(pw_tokenizer.global_handler
  DEFAULT_BACKEND
    pw_build.empty  # Default to an empty backend so the tests can run.
  HEADERS
    public/pw_tokenizer/tokenize_to_global_handler.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_preprocessor
    pw_tokenizer
  SOURCES
    tokenize_to_global_handler.cc
)

pw_add_facade(pw_tokenizer.global_handler_with_payload
  DEFAULT_BACKEND
    pw_build.empty  # Default to an empty backend so the tests can run.
  HEADERS
    public/pw_tokenizer/tokenize_to_global_handler_with_payload.h
  PUBLIC_INCLUDES
    public
  PUBLIC_DEPS
    pw_preprocessor
    pw_tokenizer
  SOURCES
    tokenize_to_global_handler_with_payload.cc
)

pw_proto_library(pw_tokenizer.proto
  SOURCES
    options.proto
  PREFIX
    pw_tokenizer/proto
)

# Executable for generating test data for the C++ and Python detokenizers. This
# target should only be built for the host.
add_executable(pw_tokenizer.generate_decoding_test_data EXCLUDE_FROM_ALL
    generate_decoding_test_data.cc)
target_link_libraries(pw_tokenizer.generate_decoding_test_data PRIVATE
    pw_varint pw_tokenizer)
target_compile_options(pw_tokenizer.generate_decoding_test_data PRIVATE
    -Wall -Werror)

# Executable for generating a test ELF file for elf_reader_test.py. A host
# version of this binary is checked in for use in elf_reader_test.py.
add_executable(pw_tokenizer.elf_reader_test_binary EXCLUDE_FROM_ALL
    py/elf_reader_test_binary.c)
target_link_libraries(pw_tokenizer.elf_reader_test_binary PRIVATE
    -Wl,--unresolved-symbols=ignore-all)  # main is not defined
set_target_properties(pw_tokenizer.elf_reader_test_binary PROPERTIES
    OUTPUT_NAME elf_reader_test_binary.elf)

pw_add_test(pw_tokenizer.argument_types_test
  SOURCES
    argument_types_test_c.c
    argument_types_test.cc
  DEPS
    pw_tokenizer
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.base64_test
  SOURCES
    base64_test.cc
  DEPS
    pw_tokenizer.base64
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.decode_test
  SOURCES
    decode_test.cc
  DEPS
    pw_varint
    pw_tokenizer.decoder
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.detokenize_test
  SOURCES
    detokenize_test.cc
  DEPS
    pw_tokenizer.decoder
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.global_handlers_test
  SOURCES
    global_handlers_test_c.c
    global_handlers_test.cc
  DEPS
    pw_tokenizer.global_handler
    pw_tokenizer.global_handler_with_payload
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.hash_test
  SOURCES
    hash_test.cc
  DEPS
    pw_tokenizer
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.token_database_test
  SOURCES
    token_database_test.cc
  DEPS
    pw_tokenizer.decoder
  GROUPS
    modules
    pw_tokenizer
)

pw_add_test(pw_tokenizer.tokenize_test
  SOURCES
    tokenize_test_c.c
    tokenize_test.cc
  DEPS
    pw_varint
    pw_tokenizer
  GROUPS
    modules
    pw_tokenizer
)