1*61c4878aSAndroid Build Coastguard Worker# Copyright 2020 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Worker# IMPORTANT: The compilation flags in this file must be kept in sync with 16*61c4878aSAndroid Build Coastguard Worker# the GN flags //pw_build/BUILD.gn. 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard Workerinclude("$ENV{PW_ROOT}/pw_build/cc_blob_library.cmake") 19*61c4878aSAndroid Build Coastguard Workerinclude("$ENV{PW_ROOT}/pw_build/pigweed.cmake") 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Worker# Target that specifies the standard Pigweed build options. 22*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build INTERFACE 23*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 24*61c4878aSAndroid Build Coastguard Worker -g 25*61c4878aSAndroid Build Coastguard Worker # Force the compiler use colorized output. This is required for Ninja. 26*61c4878aSAndroid Build Coastguard Worker $<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics> 27*61c4878aSAndroid Build Coastguard Worker $<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always> 28*61c4878aSAndroid Build Coastguard Worker PUBLIC_DEPS 29*61c4878aSAndroid Build Coastguard Worker pw_build.reduced_size 30*61c4878aSAndroid Build Coastguard Worker) 31*61c4878aSAndroid Build Coastguard Workerif(ZEPHYR_PIGWEED_MODULE_DIR) 32*61c4878aSAndroid Build Coastguard Worker target_link_libraries(pw_build INTERFACE zephyr_interface) 33*61c4878aSAndroid Build Coastguard Workerendif() 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard Worker# Declare top-level targets for tests. 36*61c4878aSAndroid Build Coastguard Workeradd_custom_target(pw_tests.default) 37*61c4878aSAndroid Build Coastguard Workeradd_custom_target(pw_run_tests.default) 38*61c4878aSAndroid Build Coastguard Worker 39*61c4878aSAndroid Build Coastguard Workeradd_custom_target(pw_tests DEPENDS pw_tests.default) 40*61c4878aSAndroid Build Coastguard Workeradd_custom_target(pw_run_tests DEPENDS pw_run_tests.default) 41*61c4878aSAndroid Build Coastguard Worker 42*61c4878aSAndroid Build Coastguard Worker# Define the standard Pigweed compile options. 43*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.reduced_size INTERFACE 44*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 45*61c4878aSAndroid Build Coastguard Worker "-fno-common" 46*61c4878aSAndroid Build Coastguard Worker "-fno-exceptions" 47*61c4878aSAndroid Build Coastguard Worker "-ffunction-sections" 48*61c4878aSAndroid Build Coastguard Worker "-fdata-sections" 49*61c4878aSAndroid Build Coastguard Worker $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> 50*61c4878aSAndroid Build Coastguard Worker) 51*61c4878aSAndroid Build Coastguard Worker 52*61c4878aSAndroid Build Coastguard Worker# Define the standard Pigweed compile options. 53*61c4878aSAndroid Build Coastguard Worker# 54*61c4878aSAndroid Build Coastguard Worker# The pw_build.warnings library is used by upstream Pigweed targets to add 55*61c4878aSAndroid Build Coastguard Worker# compiler warnings to the build. 56*61c4878aSAndroid Build Coastguard Worker# 57*61c4878aSAndroid Build Coastguard Worker# Toolchains may override these warnings by setting pw_build_WARNINGS: 58*61c4878aSAndroid Build Coastguard Worker# 59*61c4878aSAndroid Build Coastguard Worker# set(pw_build_WARNINGS my_warnings CACHE STRING "" FORCE) 60*61c4878aSAndroid Build Coastguard Worker# 61*61c4878aSAndroid Build Coastguard Workerset(pw_build_WARNINGS pw_build.strict_warnings 62*61c4878aSAndroid Build Coastguard Worker CACHE STRING "Warnings libraries to use for Pigweed upstream code") 63*61c4878aSAndroid Build Coastguard Worker 64*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.warnings INTERFACE 65*61c4878aSAndroid Build Coastguard Worker PUBLIC_DEPS 66*61c4878aSAndroid Build Coastguard Worker ${pw_build_WARNINGS} 67*61c4878aSAndroid Build Coastguard Worker) 68*61c4878aSAndroid Build Coastguard Worker 69*61c4878aSAndroid Build Coastguard Worker# TODO(hepler): These Zephyr exceptions should be made by overriding 70*61c4878aSAndroid Build Coastguard Worker# pw_build_WARNINGS. 71*61c4878aSAndroid Build Coastguard Workerif(ZEPHYR_PIGWEED_MODULE_DIR) 72*61c4878aSAndroid Build Coastguard Worker # -Wtype-limits is incompatible with Kconfig at times, disable it for Zephyr 73*61c4878aSAndroid Build Coastguard Worker # builds. 74*61c4878aSAndroid Build Coastguard Worker set(strict_warnings_cond "-Wno-type-limits") 75*61c4878aSAndroid Build Coastguard Workerelse() 76*61c4878aSAndroid Build Coastguard Worker # Only include these flags if we're not building with Zephyr. 77*61c4878aSAndroid Build Coastguard Worker set(strict_warnings_cond "-Wundef") 78*61c4878aSAndroid Build Coastguard Workerendif() 79*61c4878aSAndroid Build Coastguard Worker 80*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.strict_warnings INTERFACE 81*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 82*61c4878aSAndroid Build Coastguard Worker "-Wall" 83*61c4878aSAndroid Build Coastguard Worker "-Wextra" 84*61c4878aSAndroid Build Coastguard Worker "-Wimplicit-fallthrough" 85*61c4878aSAndroid Build Coastguard Worker ${strict_warnings_cond} 86*61c4878aSAndroid Build Coastguard Worker "-Wpointer-arith" 87*61c4878aSAndroid Build Coastguard Worker 88*61c4878aSAndroid Build Coastguard Worker # Make all warnings errors, except for the exemptions below. 89*61c4878aSAndroid Build Coastguard Worker "-Werror" 90*61c4878aSAndroid Build Coastguard Worker "-Wno-error=cpp" # preprocessor #warning statement 91*61c4878aSAndroid Build Coastguard Worker "-Wno-error=deprecated-declarations" # [[deprecated]] attribute 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker $<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor> 94*61c4878aSAndroid Build Coastguard Worker) 95*61c4878aSAndroid Build Coastguard Worker 96*61c4878aSAndroid Build Coastguard Workerif(NOT ZEPHYR_PIGWEED_MODULE_DIR) 97*61c4878aSAndroid Build Coastguard Worker # Only include these flags if we're not building with Zephyr. 98*61c4878aSAndroid Build Coastguard Worker set(extra_strict_warnings_cond "-Wredundant-decls") 99*61c4878aSAndroid Build Coastguard Workerendif() 100*61c4878aSAndroid Build Coastguard Worker 101*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.extra_strict_warnings INTERFACE 102*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 103*61c4878aSAndroid Build Coastguard Worker "-Wshadow" 104*61c4878aSAndroid Build Coastguard Worker ${extra_strict_warnings_cond} 105*61c4878aSAndroid Build Coastguard Worker $<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes> 106*61c4878aSAndroid Build Coastguard Worker) 107*61c4878aSAndroid Build Coastguard Worker 108*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.pedantic_warnings INTERFACE 109*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 110*61c4878aSAndroid Build Coastguard Worker # Enable -Wpedantic, but disable a few warnings. 111*61c4878aSAndroid Build Coastguard Worker "-Wpedantic" 112*61c4878aSAndroid Build Coastguard Worker 113*61c4878aSAndroid Build Coastguard Worker # Allow designated initializers, which were added in C++20 but widely 114*61c4878aSAndroid Build Coastguard Worker # supported prior and permitted by the Google style guide. 115*61c4878aSAndroid Build Coastguard Worker "-Wno-c++20-designator" 116*61c4878aSAndroid Build Coastguard Worker 117*61c4878aSAndroid Build Coastguard Worker # Allow empty ... arguments in macros, which are permitted in C++20 but 118*61c4878aSAndroid Build Coastguard Worker # widely supported prior. 119*61c4878aSAndroid Build Coastguard Worker "-Wno-gnu-zero-variadic-macro-arguments" 120*61c4878aSAndroid Build Coastguard Worker 121*61c4878aSAndroid Build Coastguard Worker # TODO: b/333712899 - Enable C23 extension warnings. 122*61c4878aSAndroid Build Coastguard Worker "-Wno-c23-extensions" 123*61c4878aSAndroid Build Coastguard Worker 124*61c4878aSAndroid Build Coastguard Worker # TODO: b/335021928 - Enable C++ 20 extension warnings. 125*61c4878aSAndroid Build Coastguard Worker "-Wno-c++20-extensions" 126*61c4878aSAndroid Build Coastguard Worker 127*61c4878aSAndroid Build Coastguard Worker # TODO: b/335328444 - Enable C++ 20 extension warnings. 128*61c4878aSAndroid Build Coastguard Worker "-Wno-deprecated-pragma" 129*61c4878aSAndroid Build Coastguard Worker 130*61c4878aSAndroid Build Coastguard Worker # TODO: b/356904203 - Unblock Clang roll. Missing template argument 131*61c4878aSAndroid Build Coastguard Worker # warning introduced by Clang produces warnings in third party code. 132*61c4878aSAndroid Build Coastguard Worker # Remove this warning suppression after addressing the root cause. 133*61c4878aSAndroid Build Coastguard Worker "-Wno-missing-template-arg-list-after-template-kw" 134*61c4878aSAndroid Build Coastguard Worker 135*61c4878aSAndroid Build Coastguard Worker # TODO: b/356689444 - Remove no-unknown-warning-option after Clang roll. 136*61c4878aSAndroid Build Coastguard Worker "-Wno-unknown-warning-option" 137*61c4878aSAndroid Build Coastguard Worker) 138*61c4878aSAndroid Build Coastguard Worker 139*61c4878aSAndroid Build Coastguard Workerpw_add_library_generic(pw_build.cpp17 INTERFACE 140*61c4878aSAndroid Build Coastguard Worker PUBLIC_COMPILE_OPTIONS 141*61c4878aSAndroid Build Coastguard Worker $<$<COMPILE_LANGUAGE:CXX>:-std=c++17> 142*61c4878aSAndroid Build Coastguard Worker # Allow uses of the register keyword, which may appear in C headers. 143*61c4878aSAndroid Build Coastguard Worker $<$<COMPILE_LANGUAGE:CXX>:-Wno-register> 144*61c4878aSAndroid Build Coastguard Worker) 145*61c4878aSAndroid Build Coastguard Worker 146*61c4878aSAndroid Build Coastguard Worker# Create an empty C++ source file and library for general use. 147*61c4878aSAndroid Build Coastguard Workerfile(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "") 148*61c4878aSAndroid Build Coastguard Workeradd_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "") 149*61c4878aSAndroid Build Coastguard Worker 150*61c4878aSAndroid Build Coastguard Workerpw_add_test(pw_build.cc_blob_library_test 151*61c4878aSAndroid Build Coastguard Worker SOURCES 152*61c4878aSAndroid Build Coastguard Worker cc_blob_library_test.cc 153*61c4878aSAndroid Build Coastguard Worker PRIVATE_DEPS 154*61c4878aSAndroid Build Coastguard Worker pw_build.test_blob 155*61c4878aSAndroid Build Coastguard Worker GROUPS 156*61c4878aSAndroid Build Coastguard Worker modules 157*61c4878aSAndroid Build Coastguard Worker pw_build 158*61c4878aSAndroid Build Coastguard Worker) 159*61c4878aSAndroid Build Coastguard Worker 160*61c4878aSAndroid Build Coastguard Workerpw_cc_blob_library(pw_build.test_blob 161*61c4878aSAndroid Build Coastguard Worker HEADER 162*61c4878aSAndroid Build Coastguard Worker pw_build/test_blob.h 163*61c4878aSAndroid Build Coastguard Worker NAMESPACE 164*61c4878aSAndroid Build Coastguard Worker test::ns 165*61c4878aSAndroid Build Coastguard Worker BLOB 166*61c4878aSAndroid Build Coastguard Worker SYMBOL_NAME kFirstBlob0123 167*61c4878aSAndroid Build Coastguard Worker PATH test_blob_0123.bin 168*61c4878aSAndroid Build Coastguard Worker ALIGNAS 512 169*61c4878aSAndroid Build Coastguard Worker BLOB 170*61c4878aSAndroid Build Coastguard Worker SYMBOL_NAME kSecondBlob0123 171*61c4878aSAndroid Build Coastguard Worker PATH test_blob_0123.bin 172*61c4878aSAndroid Build Coastguard Worker) 173*61c4878aSAndroid Build Coastguard Worker 174*61c4878aSAndroid Build Coastguard Workerpw_add_library(pw_build.must_place INTERFACE 175*61c4878aSAndroid Build Coastguard Worker HEADERS 176*61c4878aSAndroid Build Coastguard Worker public/pw_build/must_place.ld.h 177*61c4878aSAndroid Build Coastguard Worker PUBLIC_INCLUDES 178*61c4878aSAndroid Build Coastguard Worker public 179*61c4878aSAndroid Build Coastguard Worker) 180