• 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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/python.gni")
18import("$dir_pw_docgen/docs.gni")
19
20# IMPORTANT: The compilation flags in this file must be kept in sync with
21#            the CMake flags pw_build/CMakeLists.txt.
22
23config("colorize_output") {
24  cflags = [
25    # Colorize output. Ninja's Clang invocation disables color by default.
26    "-fdiagnostics-color",
27  ]
28  ldflags = cflags
29}
30
31config("debugging") {
32  # Enable debug symbol generation. This has no effect on final code size.
33  cflags = [ "-g" ]
34}
35
36config("extra_debugging") {
37  # Include things like macro expansion in debug info.
38  cflags = [ "-g3" ]
39}
40
41# Optimization levels
42config("optimize_debugging") {
43  cflags = [ "-Og" ]
44  ldflags = cflags
45}
46
47config("optimize_speed") {
48  cflags = [ "-O2" ]
49  ldflags = cflags
50}
51
52config("optimize_more_speed") {
53  cflags = [ "-O3" ]
54  ldflags = cflags
55}
56
57config("optimize_size") {
58  cflags = [ "-Os" ]
59  ldflags = cflags
60}
61
62# Standard compiler flags to reduce output binary size.
63config("reduced_size") {
64  cflags = [
65    "-fno-common",
66    "-fno-exceptions",
67    "-ffunction-sections",
68    "-fdata-sections",
69  ]
70  cflags_cc = [ "-fno-rtti" ]
71}
72
73config("strict_warnings") {
74  cflags = [
75    "-Wall",
76    "-Wextra",
77    "-Wimplicit-fallthrough",
78    "-Wcast-qual",
79    "-Wundef",
80    "-Wpointer-arith",
81
82    # Make all warnings errors, except for the exemptions below.
83    "-Werror",
84    "-Wno-error=cpp",  # preprocessor #warning statement
85    "-Wno-error=deprecated-declarations",  # [[deprecated]] attribute
86  ]
87  cflags_cc = [ "-Wnon-virtual-dtor" ]
88}
89
90# Thread safety warnings are only supported by Clang.
91config("clang_thread_safety_warnings") {
92  cflags = [ "-Wthread-safety" ]
93  defines = [ "_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1" ]
94}
95
96# This config contains warnings that we don't necessarily recommend projects
97# enable, but are enabled for upstream Pigweed for maximum project
98# compatibility.
99config("extra_strict_warnings") {
100  cflags = [
101    "-Wshadow",
102    "-Wredundant-decls",
103  ]
104  cflags_c = [ "-Wstrict-prototypes" ]
105}
106
107config("cpp11") {
108  cflags_cc = [ "-std=c++11" ]
109}
110
111config("cpp14") {
112  cflags_cc = [ "-std=c++14" ]
113}
114
115config("cpp17") {
116  cflags_cc = [
117    "-std=c++17",
118
119    # Allow uses of the register keyword, which may appear in C headers.
120    "-Wno-register",
121  ]
122}
123
124# This empty target is used as the default value for module configurations.
125# Projects may set pw_build_DEFAULT_MODULE_CONFIG to a different GN target that
126# overrides modules' configuration options via macro definitions or a header
127# forcibly included with `-include`.
128group("empty") {
129}
130
131pool("pip_pool") {
132  depth = 1
133}
134
135pool("copy_from_cipd_pool") {
136  depth = 1
137}
138
139# Requirements for the pw_python_package lint targets.
140pw_python_requirements("python_lint") {
141  requirements = [
142    "build",
143    "mypy==0.800",
144    "pylint==2.6.0",
145  ]
146}
147
148pw_doc_group("docs") {
149  sources = [
150    "docs.rst",
151    "python.rst",
152  ]
153}
154
155# Pool to limit a single thread to download external Go packages at a time.
156pool("go_download_pool") {
157  depth = 1
158}
159