• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15# IMPORTANT: The compilation flags in this file must be kept in sync with
16#            the GN flags //pw_build/BUILD.gn.
17
18include("$ENV{PW_ROOT}/pw_build/cc_blob_library.cmake")
19include("$ENV{PW_ROOT}/pw_build/pigweed.cmake")
20
21# Target that specifies the standard Pigweed build options.
22pw_add_library_generic(pw_build INTERFACE
23  PUBLIC_COMPILE_OPTIONS
24    -g
25    # Force the compiler use colorized output. This is required for Ninja.
26    $<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
27    $<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
28  PUBLIC_DEPS
29    pw_build.reduced_size
30)
31if(ZEPHYR_PIGWEED_MODULE_DIR)
32  target_link_libraries(pw_build INTERFACE zephyr_interface)
33endif()
34
35# Declare top-level targets for tests.
36add_custom_target(pw_tests.default)
37add_custom_target(pw_run_tests.default)
38
39add_custom_target(pw_tests DEPENDS pw_tests.default)
40add_custom_target(pw_run_tests DEPENDS pw_run_tests.default)
41
42# Define the standard Pigweed compile options.
43pw_add_library_generic(pw_build.reduced_size INTERFACE
44  PUBLIC_COMPILE_OPTIONS
45    "-fno-common"
46    "-fno-exceptions"
47    "-ffunction-sections"
48    "-fdata-sections"
49    $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
50)
51
52# Define the standard Pigweed compile options.
53#
54# The pw_build.warnings library is used by upstream Pigweed targets to add
55# compiler warnings to the build.
56#
57# Toolchains may override these warnings by setting pw_build_WARNINGS:
58#
59#   set(pw_build_WARNINGS my_warnings CACHE STRING "" FORCE)
60#
61set(pw_build_WARNINGS pw_build.strict_warnings
62    CACHE STRING "Warnings libraries to use for Pigweed upstream code")
63
64pw_add_library_generic(pw_build.warnings INTERFACE
65  PUBLIC_DEPS
66    ${pw_build_WARNINGS}
67)
68
69# TODO(hepler): These Zephyr exceptions should be made by overriding
70#     pw_build_WARNINGS.
71if(ZEPHYR_PIGWEED_MODULE_DIR)
72  # -Wtype-limits is incompatible with Kconfig at times, disable it for Zephyr
73  # builds.
74  set(strict_warnings_cond "-Wno-type-limits")
75else()
76  # Only include these flags if we're not building with Zephyr.
77  set(strict_warnings_cond "-Wundef")
78endif()
79
80pw_add_library_generic(pw_build.strict_warnings INTERFACE
81  PUBLIC_COMPILE_OPTIONS
82    "-Wall"
83    "-Wextra"
84    "-Wimplicit-fallthrough"
85    ${strict_warnings_cond}
86    "-Wpointer-arith"
87
88    # Make all warnings errors, except for the exemptions below.
89    "-Werror"
90    "-Wno-error=cpp"  # preprocessor #warning statement
91    "-Wno-error=deprecated-declarations"  # [[deprecated]] attribute
92
93    $<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>
94)
95
96if(NOT ZEPHYR_PIGWEED_MODULE_DIR)
97  # Only include these flags if we're not building with Zephyr.
98  set(extra_strict_warnings_cond "-Wredundant-decls")
99endif()
100
101pw_add_library_generic(pw_build.extra_strict_warnings INTERFACE
102  PUBLIC_COMPILE_OPTIONS
103    "-Wshadow"
104    ${extra_strict_warnings_cond}
105    $<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
106)
107
108pw_add_library_generic(pw_build.pedantic_warnings INTERFACE
109  PUBLIC_COMPILE_OPTIONS
110    # Enable -Wpedantic, but disable a few warnings.
111    "-Wpedantic"
112
113    # Allow designated initializers, which were added in C++20 but widely
114    # supported prior and permitted by the Google style guide.
115    "-Wno-c++20-designator"
116
117    # Allow empty ... arguments in macros, which are permitted in C++20 but
118    # widely supported prior.
119    "-Wno-gnu-zero-variadic-macro-arguments"
120
121    # TODO: b/333712899 - Enable C23 extension warnings.
122    "-Wno-c23-extensions"
123
124    # TODO: b/335021928 - Enable C++ 20 extension warnings.
125    "-Wno-c++20-extensions"
126
127    # TODO: b/335328444 - Enable C++ 20 extension warnings.
128    "-Wno-deprecated-pragma"
129)
130
131pw_add_library_generic(pw_build.cpp17 INTERFACE
132  PUBLIC_COMPILE_OPTIONS
133    $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
134    # Allow uses of the register keyword, which may appear in C headers.
135    $<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
136)
137
138# Create an empty C++ source file and library for general use.
139file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "")
140add_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "")
141
142pw_add_test(pw_build.cc_blob_library_test
143  SOURCES
144    cc_blob_library_test.cc
145  PRIVATE_DEPS
146    pw_build.test_blob
147  GROUPS
148    modules
149    pw_build
150)
151
152pw_cc_blob_library(pw_build.test_blob
153  HEADER
154    pw_build/test_blob.h
155  NAMESPACE
156    test::ns
157  BLOB
158    SYMBOL_NAME kFirstBlob0123
159    PATH test_blob_0123.bin
160    ALIGNAS 512
161  BLOB
162    SYMBOL_NAME kSecondBlob0123
163    PATH test_blob_0123.bin
164)
165