aboutsummaryrefslogtreecommitdiff
path: root/pw_build/CMakeLists.txt
blob: 62a310549a127de22e4fe4bee94c4eb1ba9c9607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# IMPORTANT: The compilation flags in this file must be kept in sync with
#            the GN flags //pw_build/BUILD.gn.

include("$ENV{PW_ROOT}/pw_build/cc_blob_library.cmake")
include("$ENV{PW_ROOT}/pw_build/pigweed.cmake")

# Target that specifies the standard Pigweed build options.
pw_add_library_generic(pw_build INTERFACE
  PUBLIC_COMPILE_OPTIONS
    -g
    # Force the compiler use colorized output. This is required for Ninja.
    $<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
    $<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
  PUBLIC_DEPS
    pw_build.reduced_size
    pw_build.cpp17
)
if(ZEPHYR_PIGWEED_MODULE_DIR)
  target_link_libraries(pw_build INTERFACE zephyr_interface)
endif()

# Declare top-level targets for tests.
add_custom_target(pw_tests.default)
add_custom_target(pw_run_tests.default)

add_custom_target(pw_tests DEPENDS pw_tests.default)
add_custom_target(pw_run_tests DEPENDS pw_run_tests.default)

# Define the standard Pigweed compile options.
pw_add_library_generic(pw_build.reduced_size INTERFACE
  PUBLIC_COMPILE_OPTIONS
    "-fno-common"
    "-fno-exceptions"
    "-ffunction-sections"
    "-fdata-sections"
    $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)

# Define the standard Pigweed compile options.
#
# The pw_build.warnings library is used by upstream Pigweed targets to add
# compiler warnings to the build.
#
# Toolchains may override these warnings by setting pw_build_WARNINGS:
#
#   set(pw_build_WARNINGS my_warnings CACHE STRING "" FORCE)
#
set(pw_build_WARNINGS pw_build.strict_warnings
    CACHE STRING "Warnings libraries to use for Pigweed upstream code")

pw_add_library_generic(pw_build.warnings INTERFACE
  PUBLIC_DEPS
    ${pw_build_WARNINGS}
)

# TODO(hepler): These Zephyr exceptions should be made by overriding
#     pw_build_WARNINGS.
if(ZEPHYR_PIGWEED_MODULE_DIR)
  # -Wtype-limits is incompatible with Kconfig at times, disable it for Zephyr
  # builds.
  set(strict_warnings_cond "-Wno-type-limits")
else()
  # Only include these flags if we're not building with Zephyr.
  set(strict_warnings_cond "-Wundef")
endif()

pw_add_library_generic(pw_build.strict_warnings INTERFACE
  PUBLIC_COMPILE_OPTIONS
    "-Wall"
    "-Wextra"
    "-Wimplicit-fallthrough"
    ${strict_warnings_cond}
    "-Wpointer-arith"

    # Make all warnings errors, except for the exemptions below.
    "-Werror"
    "-Wno-error=cpp"  # preprocessor #warning statement
    "-Wno-error=deprecated-declarations"  # [[deprecated]] attribute

    $<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>
)

if(NOT ZEPHYR_PIGWEED_MODULE_DIR)
  # Only include these flags if we're not building with Zephyr.
  set(extra_strict_warnings_cond "-Wredundant-decls")
endif()

pw_add_library_generic(pw_build.extra_strict_warnings INTERFACE
  PUBLIC_COMPILE_OPTIONS
    "-Wshadow"
    ${extra_strict_warnings_cond}
    $<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
)

pw_add_library_generic(pw_build.pedantic_warnings INTERFACE
  PUBLIC_COMPILE_OPTIONS
    # Enable -Wpedantic, but disable a few warnings.
    "-Wpedantic"

    # Allow designated initializers, which were added in C++20 but widely
    # supported prior and permitted by the Google style guide.
    "-Wno-c++20-designator"

    # Allow empty ... arguments in macros, which are permitted in C++20 but
    # widely supported prior.
    "-Wno-gnu-zero-variadic-macro-arguments"
)

pw_add_library_generic(pw_build.cpp17 INTERFACE
  PUBLIC_COMPILE_OPTIONS
    $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
    # Allow uses of the register keyword, which may appear in C headers.
    $<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
)

# Create an empty C++ source file and library for general use.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "")
add_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.cc" "")

pw_add_test(pw_build.cc_blob_library_test
  SOURCES
    cc_blob_library_test.cc
  PRIVATE_DEPS
    pw_build.test_blob
  GROUPS
    modules
    pw_build
)

pw_cc_blob_library(pw_build.test_blob
  HEADER
    pw_build/test_blob.h
  NAMESPACE
    test::ns
  BLOB
    SYMBOL_NAME kFirstBlob0123
    PATH test_blob_0123.bin
    ALIGNAS 512
  BLOB
    SYMBOL_NAME kSecondBlob0123
    PATH test_blob_0123.bin
)