xref: /aosp_15_r20/external/pigweed/pw_assert/CMakeLists.txt (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
15include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
16include($ENV{PW_ROOT}/pw_assert/backend.cmake)
17
18pw_add_module_config(pw_assert_CONFIG)
19
20pw_add_library(pw_assert INTERFACE
21  PUBLIC_DEPS
22    pw_assert.check
23    pw_assert.assert
24    pw_assert.config
25)
26
27pw_add_library(pw_assert.config INTERFACE
28  HEADERS
29    public/pw_assert/config.h
30  PUBLIC_INCLUDES
31    public
32  PUBLIC_DEPS
33    ${pw_assert_CONFIG}
34)
35
36pw_add_facade(pw_assert.assert INTERFACE
37  BACKEND
38    pw_assert.assert_BACKEND
39  HEADERS
40    public/pw_assert/assert.h
41  PUBLIC_INCLUDES
42    public
43  PUBLIC_DEPS
44    pw_assert.config
45)
46
47pw_add_facade(pw_assert.check INTERFACE
48  BACKEND
49    pw_assert.check_BACKEND
50  HEADERS
51    public/pw_assert/check.h
52    public/pw_assert/internal/check_impl.h
53    public/pw_assert/short.h
54  PUBLIC_INCLUDES
55    public
56  PUBLIC_DEPS
57    pw_assert.config
58    pw_preprocessor
59)
60
61# Warning: The assert facade is in a transitional state, and this target is
62# likely to be removed as the pw_assert API is reassessed. (b/235149326)
63pw_add_library(pw_assert.assert_compatibility_backend INTERFACE
64  HEADERS
65    assert_compatibility_public_overrides/pw_assert_backend/assert_backend.h
66  PUBLIC_INCLUDES
67    assert_compatibility_public_overrides
68  PUBLIC_DEPS
69    pw_preprocessor
70)
71
72pw_add_library(pw_assert.libc_assert INTERFACE
73  HEADERS
74    libc_assert_public_overrides/assert.h
75    libc_assert_public_overrides/cassert
76    public/pw_assert/internal/libc_assert.h
77  PUBLIC_INCLUDES
78    public
79    libc_assert_public_overrides
80  PUBLIC_DEPS
81    pw_assert.assert
82    pw_preprocessor
83)
84
85pw_add_library(pw_assert.print_and_abort INTERFACE
86  HEADERS
87    public/pw_assert/internal/print_and_abort.h
88  PUBLIC_INCLUDES
89    public
90  PUBLIC_DEPS
91    pw_assert.config
92)
93
94# This backend to pw_assert's PW_CHECK()/PW_DCHECK() macros prints the assert
95# expression, evaluated expression, file/line number, function, and user message
96# with printf, then aborts. It is intended for use with host builds.
97pw_add_library(pw_assert.print_and_abort_check_backend INTERFACE
98  HEADERS
99    print_and_abort_check_public_overrides/pw_assert_backend/check_backend.h
100  PUBLIC_INCLUDES
101    print_and_abort_check_public_overrides
102  PUBLIC_DEPS
103    pw_assert.print_and_abort
104)
105
106# This backend to pw_assert's PW_ASSERT()/PW_DASSERT() macros prints the assert
107# expression, file/line number, and function with printf, then aborts. It is
108# intended for use with host builds.
109pw_add_library(pw_assert.print_and_abort_assert_backend INTERFACE
110  HEADERS
111    print_and_abort_assert_public_overrides/pw_assert_backend/assert_backend.h
112  PUBLIC_INCLUDES
113    print_and_abort_assert_public_overrides
114  PUBLIC_DEPS
115    pw_assert.config
116    pw_assert.print_and_abort
117)
118
119pw_add_test(pw_assert.assert_facade_test
120  SOURCES
121    assert_facade_test.cc
122    fake_backend.cc
123    public/pw_assert/internal/check_impl.h
124    pw_assert_test/fake_backend.h
125  PRIVATE_DEPS
126    pw_assert
127    pw_compilation_testing._pigweed_only_negative_compilation
128    pw_status
129    pw_string
130  GROUPS
131    modules
132    pw_assert
133)
134
135if((NOT "${pw_assert.assert_BACKEND}" STREQUAL "") AND
136   (NOT "${pw_assert.check_BACKEND}" STREQUAL ""))
137  pw_add_test(pw_assert.assert_backend_compile_test
138    SOURCES
139      assert_backend_compile_test.cc
140      assert_backend_compile_test_c.c
141    PRIVATE_DEPS
142      pw_assert
143      pw_status
144    GROUPS
145      modules
146      pw_assert
147  )
148endif()
149