Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_build / CMakeLists.txt
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
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"
74 )
75
76 add_library(pw_build.cpp17 INTERFACE)
77 target_compile_options(pw_build.cpp17
78   INTERFACE
79     $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
80     # Allow uses of the register keyword, which may appear in C headers.
81     $<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
82 )
83
84 # Create an empty source file and library for general use.
85 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "")
86 add_library(pw_build.empty OBJECT "${CMAKE_CURRENT_BINARY_DIR}/empty_file.c" "")