Wyatt Hepler | ae222dc | 2020-10-14 10:46:27 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Pigweed Authors |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 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 | |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | import("//build_overrides/pigweed.gni") |
Rob Mohr | 49de492 | 2019-12-10 20:10:41 -0800 | [diff] [blame] | 16 | |
Wyatt Hepler | a2970c5 | 2021-02-02 14:47:22 -0800 | [diff] [blame] | 17 | import("$dir_pw_build/python.gni") |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 18 | import("$dir_pw_docgen/docs.gni") |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame^] | 19 | import("target_types.gni") |
Wyatt Hepler | d49f8fe | 2020-10-15 10:13:47 -0700 | [diff] [blame] | 20 | |
Wyatt Hepler | 0a6f763 | 2020-10-29 09:08:19 -0700 | [diff] [blame] | 21 | # IMPORTANT: The compilation flags in this file must be kept in sync with |
| 22 | # the CMake flags pw_build/CMakeLists.txt. |
| 23 | |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 24 | config("colorize_output") { |
| 25 | cflags = [ |
| 26 | # Colorize output. Ninja's Clang invocation disables color by default. |
| 27 | "-fdiagnostics-color", |
Wyatt Hepler | b9db09f | 2020-01-27 17:40:08 -0800 | [diff] [blame] | 28 | ] |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 29 | ldflags = cflags |
Wyatt Hepler | b9db09f | 2020-01-27 17:40:08 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | config("debugging") { |
| 33 | # Enable debug symbol generation. This has no effect on final code size. |
| 34 | cflags = [ "-g" ] |
| 35 | } |
| 36 | |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 37 | config("extra_debugging") { |
| 38 | # Include things like macro expansion in debug info. |
| 39 | cflags = [ "-g3" ] |
| 40 | } |
| 41 | |
| 42 | # Optimization levels |
| 43 | config("optimize_debugging") { |
| 44 | cflags = [ "-Og" ] |
| 45 | ldflags = cflags |
| 46 | } |
| 47 | |
| 48 | config("optimize_speed") { |
| 49 | cflags = [ "-O2" ] |
| 50 | ldflags = cflags |
| 51 | } |
| 52 | |
| 53 | config("optimize_more_speed") { |
| 54 | cflags = [ "-O3" ] |
| 55 | ldflags = cflags |
| 56 | } |
| 57 | |
| 58 | config("optimize_size") { |
| 59 | cflags = [ "-Os" ] |
| 60 | ldflags = cflags |
| 61 | } |
| 62 | |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 63 | # Standard compiler flags to reduce output binary size. |
| 64 | config("reduced_size") { |
| 65 | cflags = [ |
| 66 | "-fno-common", |
| 67 | "-fno-exceptions", |
| 68 | "-ffunction-sections", |
| 69 | "-fdata-sections", |
| 70 | ] |
| 71 | cflags_cc = [ "-fno-rtti" ] |
| 72 | } |
| 73 | |
| 74 | config("strict_warnings") { |
| 75 | cflags = [ |
| 76 | "-Wall", |
| 77 | "-Wextra", |
Ewout van Bekkum | b4f9598 | 2020-10-15 11:10:51 -0700 | [diff] [blame] | 78 | "-Wimplicit-fallthrough", |
Ewout van Bekkum | 7a436e0 | 2020-10-16 11:49:32 -0700 | [diff] [blame] | 79 | "-Wcast-qual", |
Ewout van Bekkum | e4d7b69 | 2020-10-15 13:12:30 -0700 | [diff] [blame] | 80 | "-Wundef", |
Ewout van Bekkum | c9759dc | 2020-10-15 21:22:08 -0700 | [diff] [blame] | 81 | "-Wpointer-arith", |
Keir Mierle | 243e32a | 2019-11-05 10:29:26 -0800 | [diff] [blame] | 82 | |
Wyatt Hepler | 979890d | 2019-11-06 17:17:45 -0800 | [diff] [blame] | 83 | # Make all warnings errors, except for the exemptions below. |
| 84 | "-Werror", |
| 85 | "-Wno-error=cpp", # preprocessor #warning statement |
| 86 | "-Wno-error=deprecated-declarations", # [[deprecated]] attribute |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 87 | ] |
Wyatt Hepler | 1919c64 | 2019-12-06 10:06:13 -0800 | [diff] [blame] | 88 | cflags_cc = [ "-Wnon-virtual-dtor" ] |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Ewout van Bekkum | cc9ef83 | 2021-04-08 08:51:16 -0700 | [diff] [blame] | 91 | # Thread safety warnings are only supported by Clang. |
| 92 | config("clang_thread_safety_warnings") { |
| 93 | cflags = [ "-Wthread-safety" ] |
| 94 | defines = [ "_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1" ] |
| 95 | } |
| 96 | |
Armando Montanez | 888370d | 2020-05-01 18:29:22 -0700 | [diff] [blame] | 97 | # This config contains warnings that we don't necessarily recommend projects |
| 98 | # enable, but are enabled for upstream Pigweed for maximum project |
| 99 | # compatibility. |
| 100 | config("extra_strict_warnings") { |
Ewout van Bekkum | 2c62283 | 2020-10-16 13:49:57 -0700 | [diff] [blame] | 101 | cflags = [ |
| 102 | "-Wshadow", |
| 103 | "-Wredundant-decls", |
| 104 | ] |
Wyatt Hepler | 5a14a66 | 2021-03-08 11:22:02 -0800 | [diff] [blame] | 105 | cflags_c = [ "-Wstrict-prototypes" ] |
Armando Montanez | 888370d | 2020-05-01 18:29:22 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Wyatt Hepler | 818e331 | 2020-01-16 14:19:21 -0800 | [diff] [blame] | 108 | config("cpp11") { |
| 109 | cflags_cc = [ "-std=c++11" ] |
| 110 | } |
| 111 | |
| 112 | config("cpp14") { |
| 113 | cflags_cc = [ "-std=c++14" ] |
| 114 | } |
| 115 | |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 116 | config("cpp17") { |
Wyatt Hepler | 979890d | 2019-11-06 17:17:45 -0800 | [diff] [blame] | 117 | cflags_cc = [ |
| 118 | "-std=c++17", |
| 119 | |
| 120 | # Allow uses of the register keyword, which may appear in C headers. |
| 121 | "-Wno-register", |
| 122 | ] |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame^] | 125 | # This group is linked into all pw_executable, pw_static_library, and |
| 126 | # pw_shared_library targets. This makes it possible to ensure symbols are |
| 127 | # defined without a dependency on them. |
| 128 | # |
| 129 | # pw_build_LINK_DEPS should only be used when necessary. For example, |
| 130 | # pw_assert relies on pw_build_LINK_DEPS to avoid circular dependencies |
| 131 | # in GN. In almost all other cases, build targets should explicitly depend on |
| 132 | # the other targets they use. |
| 133 | group("link_deps") { |
| 134 | deps = pw_build_LINK_DEPS |
| 135 | } |
| 136 | |
Wyatt Hepler | ae222dc | 2020-10-14 10:46:27 -0700 | [diff] [blame] | 137 | # This empty target is used as the default value for module configurations. |
| 138 | # Projects may set pw_build_DEFAULT_MODULE_CONFIG to a different GN target that |
| 139 | # overrides modules' configuration options via macro definitions or a header |
| 140 | # forcibly included with `-include`. |
| 141 | group("empty") { |
| 142 | } |
| 143 | |
Wyatt Hepler | d7dc655 | 2020-10-21 16:16:21 -0700 | [diff] [blame] | 144 | pool("pip_pool") { |
| 145 | depth = 1 |
| 146 | } |
| 147 | |
Rob Mohr | 0cf27cb | 2021-03-08 12:13:54 -0800 | [diff] [blame] | 148 | pool("copy_from_cipd_pool") { |
| 149 | depth = 1 |
| 150 | } |
| 151 | |
Wyatt Hepler | a2970c5 | 2021-02-02 14:47:22 -0800 | [diff] [blame] | 152 | # Requirements for the pw_python_package lint targets. |
| 153 | pw_python_requirements("python_lint") { |
| 154 | requirements = [ |
Wyatt Hepler | af853ea | 2021-03-09 19:09:54 -0800 | [diff] [blame] | 155 | "build", |
Wyatt Hepler | a2970c5 | 2021-02-02 14:47:22 -0800 | [diff] [blame] | 156 | "mypy==0.800", |
| 157 | "pylint==2.6.0", |
| 158 | ] |
| 159 | } |
| 160 | |
Rob Mohr | 49de492 | 2019-12-10 20:10:41 -0800 | [diff] [blame] | 161 | pw_doc_group("docs") { |
Wyatt Hepler | b3ea980 | 2021-02-23 09:46:09 -0800 | [diff] [blame] | 162 | sources = [ |
| 163 | "docs.rst", |
| 164 | "python.rst", |
| 165 | ] |
Rob Mohr | 49de492 | 2019-12-10 20:10:41 -0800 | [diff] [blame] | 166 | } |
Alexei Frolov | c15a988 | 2019-12-23 14:29:02 -0800 | [diff] [blame] | 167 | |
| 168 | # Pool to limit a single thread to download external Go packages at a time. |
| 169 | pool("go_download_pool") { |
| 170 | depth = 1 |
| 171 | } |