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
15include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
16
17pw_add_module_library(pw_tokenizer
18  SOURCES
19    encode_args.cc
20    hash.cc
21    tokenize.cc
22  PUBLIC_DEPS
23    pw_polyfill.overrides
24    pw_preprocessor
25    pw_span
26  PRIVATE_DEPS
27    pw_varint
28)
29
30if("${CMAKE_SYSTEM_NAME}" STREQUAL "")
31  target_link_options(pw_tokenizer
32    PUBLIC
33      "-T${CMAKE_CURRENT_SOURCE_DIR}/pw_tokenizer_linker_sections.ld"
34  )
35elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
36  target_link_options(pw_tokenizer
37    PUBLIC
38      "-T${CMAKE_CURRENT_SOURCE_DIR}/add_tokenizer_sections_to_default_script.ld"
39      "-L${CMAKE_CURRENT_SOURCE_DIR}"
40  )
41endif()
42
43pw_add_module_library(pw_tokenizer.base64
44  SOURCES
45    base64.cc
46  PUBLIC_DEPS
47    pw_base64
48    pw_containers
49    pw_polyfill.overrides
50    pw_preprocessor
51    pw_span
52)
53
54pw_add_module_library(pw_tokenizer.decoder
55  SOURCES
56    decode.cc
57    detokenize.cc
58    token_database.cc
59  PUBLIC_DEPS
60    pw_span
61    pw_tokenizer
62  PRIVATE_DEPS
63    pw_varint
64)
65
66pw_add_facade(pw_tokenizer.global_handler
67  SOURCES
68    tokenize_to_global_handler.cc
69  PUBLIC_DEPS
70    pw_tokenizer
71  DEFAULT_BACKEND
72    pw_build.empty  # Default to an empty backend so the tests can run.
73)
74
75pw_add_facade(pw_tokenizer.global_handler_with_payload
76  SOURCES
77    tokenize_to_global_handler_with_payload.cc
78  PUBLIC_DEPS
79    pw_tokenizer
80  DEFAULT_BACKEND
81    pw_build.empty  # Default to an empty backend so the tests can run.
82)
83
84# Executable for generating test data for the C++ and Python detokenizers. This
85# target should only be built for the host.
86add_executable(pw_tokenizer.generate_decoding_test_data EXCLUDE_FROM_ALL
87    generate_decoding_test_data.cc)
88target_link_libraries(pw_tokenizer.generate_decoding_test_data PRIVATE
89    pw_varint pw_tokenizer)
90target_compile_options(pw_tokenizer.generate_decoding_test_data PRIVATE
91    -Wall -Werror)
92
93# Executable for generating a test ELF file for elf_reader_test.py. A host
94# version of this binary is checked in for use in elf_reader_test.py.
95add_executable(pw_tokenizer.elf_reader_test_binary EXCLUDE_FROM_ALL
96    py/elf_reader_test_binary.c)
97target_link_libraries(pw_tokenizer.elf_reader_test_binary PRIVATE
98    -Wl,--unresolved-symbols=ignore-all)  # main is not defined
99set_target_properties(pw_tokenizer.elf_reader_test_binary PROPERTIES
100    OUTPUT_NAME elf_reader_test_binary.elf)
101
102pw_add_test(pw_tokenizer.argument_types_test
103  SOURCES
104    argument_types_test_c.c
105    argument_types_test.cc
106  DEPS
107    pw_tokenizer
108  GROUPS
109    modules
110    pw_tokenizer
111)
112
113pw_add_test(pw_tokenizer.base64_test
114  SOURCES
115    base64_test.cc
116  DEPS
117    pw_tokenizer.base64
118  GROUPS
119    modules
120    pw_tokenizer
121)
122
123pw_add_test(pw_tokenizer.decode_test
124  SOURCES
125    decode_test.cc
126  DEPS
127    pw_varint
128    pw_tokenizer.decoder
129  GROUPS
130    modules
131    pw_tokenizer
132)
133
134pw_add_test(pw_tokenizer.detokenize_test
135  SOURCES
136    detokenize_test.cc
137  DEPS
138    pw_tokenizer.decoder
139  GROUPS
140    modules
141    pw_tokenizer
142)
143
144pw_add_test(pw_tokenizer.global_handlers_test
145  SOURCES
146    global_handlers_test_c.c
147    global_handlers_test.cc
148  DEPS
149    pw_tokenizer.global_handler
150    pw_tokenizer.global_handler_with_payload
151  GROUPS
152    modules
153    pw_tokenizer
154)
155
156pw_add_test(pw_tokenizer.hash_test
157  SOURCES
158    hash_test.cc
159  DEPS
160    pw_tokenizer
161  GROUPS
162    modules
163    pw_tokenizer
164)
165
166pw_add_test(pw_tokenizer.token_database_test
167  SOURCES
168    token_database_test.cc
169  DEPS
170    pw_tokenizer.decoder
171  GROUPS
172    modules
173    pw_tokenizer
174)
175
176pw_add_test(pw_tokenizer.tokenize_test
177  SOURCES
178    tokenize_test_c.c
179    tokenize_test.cc
180  DEPS
181    pw_varint
182    pw_tokenizer
183  GROUPS
184    modules
185    pw_tokenizer
186)
187