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_build/relative_source_file_names.gni") 19import("$dir_pw_docgen/docs.gni") 20import("target_types.gni") 21 22# IMPORTANT: The compilation flags in this file must be kept in sync with 23# the CMake flags pw_build/CMakeLists.txt. 24 25config("colorize_output") { 26 cflags = [ 27 # Colorize output. Ninja's Clang invocation disables color by default. 28 "-fdiagnostics-color", 29 ] 30 ldflags = cflags 31} 32 33config("debugging") { 34 # Enable debug symbol generation. This has no effect on final code size. 35 cflags = [ "-g" ] 36} 37 38config("extra_debugging") { 39 # Include things like macro expansion in debug info. 40 cflags = [ "-g3" ] 41} 42 43# Optimization levels 44config("optimize_debugging") { 45 cflags = [ "-Og" ] 46 ldflags = cflags 47} 48 49config("optimize_speed") { 50 cflags = [ "-O2" ] 51 ldflags = cflags 52} 53 54config("optimize_more_speed") { 55 cflags = [ "-O3" ] 56 ldflags = cflags 57} 58 59config("optimize_size") { 60 cflags = [ "-Os" ] 61 ldflags = cflags 62} 63 64# Standard compiler flags to reduce output binary size. 65config("reduced_size") { 66 cflags = [ 67 "-fno-common", 68 "-fno-exceptions", 69 "-ffunction-sections", 70 "-fdata-sections", 71 ] 72 cflags_cc = [ "-fno-rtti" ] 73 74 if (current_os == "mac" || current_os == "ios") { 75 # Delete unreferenced sections. Helpful with -ffunction-sections. 76 ldflags = [ "-Wl,-dead_strip" ] 77 } else { 78 # Delete unreferenced sections. Helpful with -ffunction-sections. 79 ldflags = [ "-Wl,--gc-sections" ] 80 } 81} 82 83config("strict_warnings") { 84 cflags = [ 85 "-Wall", 86 "-Wextra", 87 "-Wimplicit-fallthrough", 88 "-Wcast-qual", 89 "-Wundef", 90 "-Wpointer-arith", 91 92 # Make all warnings errors, except for the exemptions below. 93 "-Werror", 94 "-Wno-error=cpp", # preprocessor #warning statement 95 "-Wno-error=deprecated-declarations", # [[deprecated]] attribute 96 ] 97 cflags_cc = [ "-Wnon-virtual-dtor" ] 98} 99 100# Thread safety warnings are only supported by Clang. 101config("clang_thread_safety_warnings") { 102 cflags = [ "-Wthread-safety" ] 103 defines = [ "_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1" ] 104} 105 106# This config contains warnings that we don't necessarily recommend projects 107# enable, but are enabled for upstream Pigweed for maximum project 108# compatibility. 109config("extra_strict_warnings") { 110 cflags = [ 111 "-Wshadow", 112 "-Wredundant-decls", 113 ] 114 cflags_c = [ "-Wstrict-prototypes" ] 115} 116 117config("cpp14") { 118 cflags_cc = [ "-std=c++14" ] 119} 120 121config("cpp17") { 122 cflags_cc = [ 123 "-std=c++17", 124 125 # Allow uses of the register keyword, which may appear in C headers. 126 "-Wno-register", 127 ] 128} 129 130# Removes system-dependent prefixes from macros like __FILE__ and debug symbols. 131config("relative_paths") { 132 _transformations = [ 133 # Remap absolute paths to the build directory to "out", in case absolute 134 # paths to files in the build directory are created. 135 # 136 # Clang and GCC apply these flags in opposite order. The build directory is 137 # often nested under //. To ensure that both compilers removed it before 138 # removing the absolute path to //, apply the option both first and last. 139 rebase_path(root_build_dir) + "=out", 140 141 # Remove absolute paths to the repo root. 142 rebase_path("//") + "=", 143 144 # Remove relative paths from the build directory to the source tree. 145 rebase_path("//", root_build_dir) + "=", 146 147 # Repeat option to remap absolute paths to the build directory. 148 rebase_path(root_build_dir) + "=out", 149 ] 150 cflags = [] 151 152 foreach(transform, _transformations) { 153 cflags += [ "-ffile-prefix-map=" + transform ] 154 } 155 156 # Write the transformations to a well known path so that other utilities 157 # that need to present file names that match the compiler's __FILE__ 158 # macro can apply the same transformation. 159 write_file(pw_build_RELATIVE_PATH_TRANSFORM_JSON, _transformations, "json") 160} 161 162# This group is linked into all pw_executable, pw_static_library, and 163# pw_shared_library targets. This makes it possible to ensure symbols are 164# defined without a dependency on them. 165# 166# pw_build_LINK_DEPS should only be used when necessary. For example, 167# pw_assert relies on pw_build_LINK_DEPS to avoid circular dependencies 168# in GN. In almost all other cases, build targets should explicitly depend on 169# the other targets they use. 170group("link_deps") { 171 deps = pw_build_LINK_DEPS 172} 173 174# This empty target is used as the default value for module configurations. 175# Projects may set pw_build_DEFAULT_MODULE_CONFIG to a different GN target that 176# overrides modules' configuration options via macro definitions or a header 177# forcibly included with `-include`. 178group("empty") { 179} 180 181# Requirements for the pw_python_package lint targets. 182pw_python_requirements("python_lint") { 183 requirements = [ 184 "build", 185 186 # NOTE: mypy needs to stay in sync with mypy-protobuf 187 # Currently using mypy 0.910 and mypy-protobuf 2.9 188 "mypy==0.910", 189 190 # typeshed packages (required by mypy > 0.9) 191 "types-setuptools", 192 "pylint==2.9.3", 193 ] 194} 195 196pw_doc_group("docs") { 197 sources = [ 198 "docs.rst", 199 "python.rst", 200 ] 201} 202