• 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
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.
19add_library(pw_build INTERFACE)
20target_compile_options(pw_build INTERFACE "-g")
21target_link_libraries(pw_build
22  INTERFACE
23    pw_build.reduced_size
24    pw_build.cpp17
25)
26target_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.
34add_custom_target(pw_tests.default)
35add_custom_target(pw_run_tests.default)
36
37add_custom_target(pw_tests DEPENDS pw_tests.default)
38add_custom_target(pw_run_tests DEPENDS pw_run_tests.default)
39
40# Define the standard Pigweed compile options.
41add_library(pw_build.reduced_size INTERFACE)
42target_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
51add_library(pw_build.strict_warnings INTERFACE)
52target_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
69add_library(pw_build.extra_strict_warnings INTERFACE)
70target_compile_options(pw_build.extra_strict_warnings
71  INTERFACE
72    "-Wshadow"
73    "-Wredundant-decls"
74    $<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
75)
76
77add_library(pw_build.cpp17 INTERFACE)
78target_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.
86file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "")
87add_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "")
88