Wyatt Hepler | 0a6f763 | 2020-10-29 09:08:19 -0700 | [diff] [blame] | 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 | |
| 18 | # Target that specifies the standard Pigweed build options. |
| 19 | add_library(pw_build INTERFACE) |
| 20 | target_compile_options(pw_build INTERFACE "-g") |
| 21 | target_link_libraries(pw_build |
| 22 | INTERFACE |
| 23 | pw_build.reduced_size |
Wyatt Hepler | 0a6f763 | 2020-10-29 09:08:19 -0700 | [diff] [blame] | 24 | pw_build.cpp17 |
| 25 | ) |
| 26 | target_compile_options(pw_build |
| 27 | INTERFACE |
| 28 | # Force the compiler use colorized output. This is required for Ninja. |
| 29 | $<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics> |
| 30 | $<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always> |
| 31 | ) |
| 32 | |
| 33 | # Declare top-level targets for tests. |
| 34 | add_custom_target(pw_tests.default) |
| 35 | add_custom_target(pw_run_tests.default) |
| 36 | |
| 37 | add_custom_target(pw_tests DEPENDS pw_tests.default) |
| 38 | add_custom_target(pw_run_tests DEPENDS pw_run_tests.default) |
| 39 | |
| 40 | # Define the standard Pigweed compile options. |
| 41 | add_library(pw_build.reduced_size INTERFACE) |
| 42 | target_compile_options(pw_build.reduced_size |
| 43 | INTERFACE |
| 44 | "-fno-common" |
| 45 | "-fno-exceptions" |
| 46 | "-ffunction-sections" |
| 47 | "-fdata-sections" |
| 48 | $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> |
| 49 | ) |
| 50 | |
| 51 | add_library(pw_build.strict_warnings INTERFACE) |
| 52 | target_compile_options(pw_build.strict_warnings |
| 53 | INTERFACE |
| 54 | "-Wall" |
| 55 | "-Wextra" |
| 56 | "-Wimplicit-fallthrough" |
| 57 | "-Wcast-qual" |
| 58 | "-Wundef" |
| 59 | "-Wpointer-arith" |
| 60 | |
| 61 | # Make all warnings errors, except for the exemptions below. |
| 62 | "-Werror" |
| 63 | "-Wno-error=cpp" # preprocessor #warning statement |
| 64 | "-Wno-error=deprecated-declarations" # [[deprecated]] attribute |
| 65 | |
| 66 | $<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor> |
| 67 | ) |
| 68 | |
| 69 | add_library(pw_build.extra_strict_warnings INTERFACE) |
| 70 | target_compile_options(pw_build.extra_strict_warnings |
| 71 | INTERFACE |
| 72 | "-Wshadow" |
| 73 | "-Wredundant-decls" |
Wyatt Hepler | 5a14a66 | 2021-03-08 11:22:02 -0800 | [diff] [blame] | 74 | $<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes> |
Wyatt Hepler | 0a6f763 | 2020-10-29 09:08:19 -0700 | [diff] [blame] | 75 | ) |
| 76 | |
| 77 | add_library(pw_build.cpp17 INTERFACE) |
| 78 | target_compile_options(pw_build.cpp17 |
| 79 | INTERFACE |
| 80 | $<$<COMPILE_LANGUAGE:CXX>:-std=c++17> |
| 81 | # Allow uses of the register keyword, which may appear in C headers. |
| 82 | $<$<COMPILE_LANGUAGE:CXX>:-Wno-register> |
| 83 | ) |
| 84 | |
| 85 | # Create an empty source file and library for general use. |
| 86 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "") |
| 87 | add_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "") |