blob: 0e12281a8ce03905d140280585346ab143074c85 [file] [log] [blame]
Alexis Hetu91f10e32016-06-07 19:53:42 -04001# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Peter Collingbourne8e67eb92018-01-24 18:42:02 -080015import("//build/config/c++/c++.gni")
Nicolas Capensd51e2162017-06-05 13:59:55 -040016import("//build/config/compiler/compiler.gni")
Milko Leporis05069822018-12-18 16:04:15 +010017import("//build/config/mips.gni")
Nicolas Capens5b36fbc2021-01-21 14:00:46 -050018import("//build/config/sysroot.gni")
Nicolas Capens282aa412020-11-16 11:37:29 -050019import("src/Reactor/reactor.gni")
Nicolas Capensd51e2162017-06-05 13:59:55 -040020
Alexis Hetu91f10e32016-06-07 19:53:42 -040021config("swiftshader_config") {
Alexis Hetu0def1022017-08-16 17:15:48 -040022 defines = []
Alexis Hetu2ddef882017-03-14 15:11:15 -040023
Alexis Hetu03b67af2016-08-31 17:25:40 -040024 if (is_win) {
25 cflags = [
Alexis Hetud6d10f92016-11-22 13:47:04 -050026 "/GS", # Detects some buffer overruns
Alexis Hetu03b67af2016-08-31 17:25:40 -040027 "/Zc:wchar_t",
Reid Klecknerd19db3d2017-11-29 10:45:53 -080028 "/EHs-c-", # Disable C++ exceptions
Alexis Hetu03b67af2016-08-31 17:25:40 -040029 "/nologo",
Alexis Hetud6d10f92016-11-22 13:47:04 -050030 "/Gd", # Default calling convention
Jamie Madillbbd8c422019-08-28 17:08:17 -040031 # Disable MSVC warnings about std::aligned_storage being broken before VS 2017 15.8
32 "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
Alexis Hetu2ddef882017-03-14 15:11:15 -040033 ]
34
Peter Collingbourne8e67eb92018-01-24 18:42:02 -080035 if (!use_custom_libcxx) {
36 # Disable EH usage in STL headers.
37 # libc++ uses a predefined macro to control whether to use exceptions, so
38 # defining this macro is unnecessary. Defining _HAS_EXCEPTIONS to 0 also
39 # breaks libc++ because it depends on MSVC headers that only provide
40 # certain declarations if _HAS_EXCEPTIONS is 1.
41 defines += [
42 "_HAS_EXCEPTIONS=0",
43 ]
44 }
45
Alexis Hetu2ddef882017-03-14 15:11:15 -040046 defines += [
47 "_CRT_SECURE_NO_DEPRECATE",
48 "NOMINMAX",
49 "_WINDLL",
Nicolas Capens506cc5e2017-07-24 11:30:55 -040050 "NO_SANITIZE_FUNCTION=",
Alexis Hetu03b67af2016-08-31 17:25:40 -040051 ]
Alexis Hetuc55dd842017-08-08 08:31:13 -040052
Robert Liaoe8d42ae2017-08-14 10:51:58 -070053 if (!is_debug) {
Alexis Hetuc55dd842017-08-08 08:31:13 -040054 defines += [ "ANGLE_DISABLE_TRACE" ]
55 }
Jamie Madill9746f8b2019-09-05 13:17:09 -040056
57 # Diable some MSVC warnings.
58 if (!is_clang) {
59 cflags += [
Jonah Ryan-Davis5fc197d2020-01-15 13:08:17 -050060 "/wd4065", # switch statement contains 'default' but no 'case' labels
Jamie Madill9746f8b2019-09-05 13:17:09 -040061 "/wd4309", # Truncation of constant value. See PixelRoutine.cpp casts of signed shorts.
62 ]
63 }
Nicolas Capensb3e5c442021-01-20 06:16:24 +000064
65 cflags_cc = [ "/std:c++17" ]
Alexis Hetu03b67af2016-08-31 17:25:40 -040066 } else {
Alexis Hetua11d03e2017-01-27 11:38:59 -050067 cflags = [
Alexis Hetu2c0546d2017-05-24 11:16:26 -040068 "-fno-exceptions",
Alexis Hetua11d03e2017-01-27 11:38:59 -050069 "-fno-operator-names",
Alexis Hetu2ddef882017-03-14 15:11:15 -040070 ]
Nicolas Capensb3e5c442021-01-20 06:16:24 +000071 cflags_cc = [ "-std=c++17" ]
Nicolas Capens3fe96b72021-01-22 11:32:21 -050072 # On macOS for the ARM architecture, some C++17 features require version 10.14,
73 # while Chrome must support 10.11 (El Capitan). However, the first 'Apple Silicon'
74 # devices launched with macOS 11.0 (Big Sur).
75 # TODO(b/174843857): Remove once Chrome demands macOS 10.14.
76 if (is_mac && current_cpu == "arm64") {
Nicolas Capens5b36fbc2021-01-21 14:00:46 -050077 cflags += [
78 "-isysroot",
79 rebase_path(sysroot, root_build_dir),
Nicolas Capens3fe96b72021-01-22 11:32:21 -050080 "-mmacosx-version-min=10.14.0",
Nicolas Capens5b36fbc2021-01-21 14:00:46 -050081 ]
82 }
Alexis Hetu2ddef882017-03-14 15:11:15 -040083
84 defines += [
85 "__STDC_CONSTANT_MACROS",
86 "__STDC_LIMIT_MACROS",
Nicolas Capens506cc5e2017-07-24 11:30:55 -040087 "NO_SANITIZE_FUNCTION=__attribute__((no_sanitize(\"function\")))",
Alexis Hetua11d03e2017-01-27 11:38:59 -050088 ]
Alexis Hetu91f10e32016-06-07 19:53:42 -040089
Alexis Hetuc55dd842017-08-08 08:31:13 -040090 if (is_debug) {
91 cflags += [
92 "-g",
93 "-g3",
94 ]
95 } else { # Release
96 # All Release builds use function/data sections to make the shared libraries smaller
97 cflags += [
98 "-ffunction-sections",
99 "-fdata-sections",
100 "-fomit-frame-pointer",
101 "-Os",
102 ]
103
104 defines += [
105 "ANGLE_DISABLE_TRACE",
106 "NDEBUG",
107 ]
108 }
109
Antonio Maiorano84785602020-02-21 15:37:37 -0500110 if (current_cpu == "x64") { # 64 bit version
Alexis Hetu91f10e32016-06-07 19:53:42 -0400111 cflags += [
112 "-m64",
113 "-fPIC",
Nicolas Capens0424edc2018-01-03 14:06:30 -0500114 "-march=x86-64",
115 "-mtune=generic",
Alexis Hetu91f10e32016-06-07 19:53:42 -0400116 ]
Antonio Maiorano84785602020-02-21 15:37:37 -0500117 } else if (current_cpu == "x86") { # 32 bit version
Alexis Hetua11d03e2017-01-27 11:38:59 -0500118 cflags += [
119 "-m32",
120 "-msse2",
Nicolas Capens0424edc2018-01-03 14:06:30 -0500121 "-mfpmath=sse",
122 "-march=pentium4",
123 "-mtune=generic",
Alexis Hetua11d03e2017-01-27 11:38:59 -0500124 ]
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200125 } else if (target_cpu == "mipsel" && current_cpu == target_cpu) {
126 cflags += [
Jiaxun Yang55275c32020-02-09 14:52:42 +0800127 "-EL",
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200128 "-fPIC",
129 "-mhard-float",
130 "-mfp32",
Jiaxun Yang55275c32020-02-09 14:52:42 +0800131 "-mxgot",
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200132 ]
Milko Leporis05069822018-12-18 16:04:15 +0100133 if (mips_arch_variant == "r1") {
134 cflags += [
Jiaxun Yang55275c32020-02-09 14:52:42 +0800135 "-march=mips32",
Milko Leporis05069822018-12-18 16:04:15 +0100136 ]
137 } else {
138 cflags += [
Jiaxun Yang55275c32020-02-09 14:52:42 +0800139 "-march=mips32r2",
Milko Leporis05069822018-12-18 16:04:15 +0100140 ]
141 }
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100142 } else if (target_cpu == "mips64el" && current_cpu == target_cpu) {
143 cflags += [
Jiaxun Yang55275c32020-02-09 14:52:42 +0800144 "-EL",
145 "-arch=mips64r2",
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100146 "-mabi=64",
147 "-fPIC",
Jiaxun Yang55275c32020-02-09 14:52:42 +0800148 "-mxgot",
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100149 ]
Alexis Hetu91f10e32016-06-07 19:53:42 -0400150 }
Alexis Hetua11d03e2017-01-27 11:38:59 -0500151
Hidehiko Abefe878de2020-09-11 16:12:25 +0900152 if (is_linux || is_chromeos) {
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200153 ldflags = [ "-Wl,--gc-sections" ]
154
Antonio Maiorano84785602020-02-21 15:37:37 -0500155 if (current_cpu == "mipsel") {
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200156 ldflags += [
157 "-Wl,--hash-style=sysv",
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200158 ]
Milko Leporis05069822018-12-18 16:04:15 +0100159 if (mips_arch_variant == "r1") {
160 ldflags += [
161 "-mips32",
162 ]
163 } else {
164 ldflags += [
165 "-mips32r2",
166 ]
167 }
Antonio Maiorano84785602020-02-21 15:37:37 -0500168 } else if (current_cpu == "mips64el") {
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100169 ldflags += [
170 "-Wl,--hash-style=sysv",
171 "-mips64r2",
172 ]
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200173 } else {
174 ldflags += [ "-Wl,--hash-style=both" ]
175 }
Alexis Hetu9441b072017-08-02 08:40:37 -0400176
Nicolas Capens0f7d4272017-06-05 13:24:09 -0400177 # A bug in the gold linker prevents using ICF on 32-bit (crbug.com/729532)
Antonio Maiorano84785602020-02-21 15:37:37 -0500178 if (use_gold && (current_cpu == "x86" || current_cpu == "mipsel")) {
Alexis Hetu9441b072017-08-02 08:40:37 -0400179 ldflags += [ "-Wl,--icf=none" ]
Nicolas Capens0f7d4272017-06-05 13:24:09 -0400180 }
Alexis Hetub1031c82017-01-30 13:46:08 -0500181 }
Alexis Hetu91f10e32016-06-07 19:53:42 -0400182 }
183}
184
Corentin Wallez57eb0632017-10-24 15:17:18 -0400185source_set("vertex_routine_fuzzer") {
186 sources = [
187 "tests/fuzzers/VertexRoutineFuzzer.cpp"
188 ]
Corentin Wallez6e27fea2017-10-27 13:40:18 -0400189 if (is_win) {
190 cflags = [
191 "/wd4201", # nameless struct/union
192 "/wd4065", # switch statement contains 'default' but no 'case' labels
193 "/wd5030", # attribute is not recognized
194 ]
195 }
Corentin Wallez57eb0632017-10-24 15:17:18 -0400196 include_dirs = [
197 "src/",
198 ]
199 deps = [
200 "src/OpenGL/libGLESv2:swiftshader_libGLESv2_static",
201 ]
202}
203
Alexis Hetu68f564d2016-07-06 17:43:22 -0400204group("swiftshader") {
Alexis Hetu996663b2016-09-21 13:47:42 -0400205 data_deps = [
206 "src/OpenGL/libGLESv2:swiftshader_libGLESv2",
207 "src/OpenGL/libEGL:swiftshader_libEGL",
208 ]
Alexis Hetua6e99c02016-11-16 13:53:57 -0500209}
210
Jamie Madillbbd8c422019-08-28 17:08:17 -0400211if (build_with_chromium) {
212 group("swiftshader_tests") {
213 testonly = true
Alexis Hetua6e99c02016-11-16 13:53:57 -0500214
Jamie Madillbbd8c422019-08-28 17:08:17 -0400215 data_deps = [
216 "tests/GLESUnitTests:swiftshader_unittests",
David 'Digit' Turnerc9fa9fe2019-08-13 19:05:01 +0200217 "tests/SystemUnitTests:swiftshader_system_unittests",
Jamie Madillbbd8c422019-08-28 17:08:17 -0400218 ]
Nicolas Capens282aa412020-11-16 11:37:29 -0500219
220 if (supports_llvm) {
221 data_deps += [ "tests/ReactorUnitTests:swiftshader_reactor_llvm_unittests" ]
222 }
223
224 if (supports_subzero) {
225 data_deps += [ "tests/ReactorUnitTests:swiftshader_reactor_subzero_unittests" ]
226 }
Jamie Madillbbd8c422019-08-28 17:08:17 -0400227 }
David 'Digit' Turnerc9fa9fe2019-08-13 19:05:01 +0200228}