Restore variadic macros in DevToolsEmbedderMessageDispatcher
[chromium-blink-merge.git] / third_party / sqlite / BUILD.gn
blob0daa5ee69daa7ae7d4315a5298673759152791dd
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 declare_args() {
6   # Controls whether the build should uses the version of sqlite3 library
7   # shipped with the system (currently only supported on iOS) or the one
8   # shipped with Chromium source.
9   use_system_sqlite = is_ios
12 if (!use_system_sqlite) {
13   config("sqlite_warnings") {
14     cflags = []
15     if (is_clang) {
16       # sqlite contains a few functions that are unused, at least on
17       # Windows with Chromium's sqlite patches applied
18       # (interiorCursorEOF fts3EvalDeferredPhrase
19       # fts3EvalSelectDeferred sqlite3Fts3InitHashTable
20       # sqlite3Fts3InitTok).
21       cflags += [ "-Wno-unused-function" ]
22     }
23     if (is_linux) {
24       cflags += [
25         # SQLite doesn"t believe in compiler warnings,
26         # preferring testing.
27         #   http://www.sqlite.org/faq.html#q17
28         "-Wno-int-to-pointer-cast",
29         "-Wno-pointer-to-int-cast",
30       ]
31     }
32   }
34   # "sqlite3" can cause conflicts with the system library.
35   component("chromium_sqlite3") {
36     visibility = [ ":*" ]
38     sources = [
39       "amalgamation/sqlite3.c",
40       "amalgamation/sqlite3.h",
41     ]
43     cflags = []
44     defines = [
45       "SQLITE_ENABLE_FTS3",
47       # New unicode61 tokenizer with built-in tables.
48       "SQLITE_DISABLE_FTS3_UNICODE",
50       # Chromium currently does not enable fts4, disable extra code.
51       "SQLITE_DISABLE_FTS4_DEFERRED",
52       "SQLITE_ENABLE_ICU",
53       "SQLITE_ENABLE_MEMORY_MANAGEMENT",
54       "SQLITE_SECURE_DELETE",
56       # Custom flag to tweak pcache pools.
57       # TODO(shess): This shouldn't use faux-SQLite naming.
58       "SQLITE_SEPARATE_CACHE_POOLS",
60       # TODO(shess): SQLite adds mutexes to protect structures which cross
61       # threads.  In theory Chromium should be able to turn this off for a
62       # slight speed boost.
63       "THREADSAFE",
65       # SQLite can spawn threads to sort in parallel if configured
66       # appropriately.  Chromium doesn't configure SQLite for that, and would
67       # prefer to control distribution to worker threads.
68       "SQLITE_MAX_WORKER_THREADS=0",
70       # Use a read-only memory map when mmap'ed I/O is enabled to prevent memory
71       # stompers from directly corrupting the database.
72       # TODO(shess): Upstream the ability to use this define.
73       "SQLITE_MMAP_READ_ONLY=1",
75       # NOTE(shess): Some defines can affect the amalgamation.  Those should be
76       # added to google_generate_amalgamation.sh, and the amalgamation
77       # re-generated.  Usually this involves disabling features which include
78       # keywords or syntax, for instance SQLITE_OMIT_VIRTUALTABLE omits the
79       # virtual table syntax entirely.  Missing an item usually results in
80       # syntax working but execution failing.  Review:
81       #   src/src/parse.py
82       #   src/tool/mkkeywordhash.c
83     ]
84     if (is_component_build) {
85       if (is_win) {
86         defines += [ "SQLITE_API=__declspec(dllexport)" ]
87       } else {
88         defines += [ "SQLITE_API=__attribute__((visibility(\"default\")))" ]
89       }
90     }
91     if (is_chromeos) {
92       defines += [
93         # Despite obvious warnings about not using this flag in deployment, we
94         # are turning off sync in ChromeOS and relying on the underlying
95         # journaling filesystem to do error recovery properly. It's much faster.
96         "SQLITE_NO_SYNC",
97       ]
98     }
99     if (is_posix) {
100       defines += [
101         # Allow xSleep() call on Unix to use usleep() rather than sleep(), so it
102         # will have microsecond precision.  Should only affect contended
103         # databases via the busy callback.  Browser profile databases are mostly
104         # exclusive, but renderer databases may allow for contention.
105         "HAVE_USLEEP=1",
107         # Use pread/pwrite directly rather than emulating them.
108         "USE_PREAD=1",
109       ]
110     }
111     if (is_linux || is_android) {
112       defines += [
113         # Linux provides fdatasync(), a faster equivalent of fsync().
114         "fdatasync=fdatasync",
115       ]
116     }
118     # SQLite wants to track malloc sizes.  On OSX it uses malloc_size(), on
119     # Windows _msize(), elsewhere it handles it manually by enlarging the malloc
120     # and injecting a field.  Enable malloc_usable_size() for Linux.
121     # NOTE(shess): Android does _not_ export malloc_usable_size().
122     if (is_linux) {
123       defines += [
124         "HAVE_MALLOC_H",
125         "HAVE_MALLOC_USABLE_SIZE",
126       ]
127     }
129     include_dirs = [ "amalgamation" ]
131     configs -= [ "//build/config/compiler:chromium_code" ]
132     configs += [
133       "//build/config/compiler:no_chromium_code",
135       # Must be after no_chromium_code for warning flags to be ordered
136       # correctly.
137       ":sqlite_warnings",
138     ]
140     if (is_linux) {
141       libs = [ "dl" ]
142     } else if (is_mac || is_ios) {
143       libs = [
144         "CoreFoundation.framework",
145         "CoreServices.framework",
146       ]
147     } else if (is_android) {
148       defines += [
149         "SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576",
150         "SQLITE_DEFAULT_AUTOVACUUM=1",
151         "SQLITE_TEMP_STORE=3",
152         "SQLITE_ENABLE_FTS3_BACKWARDS",
153         "DSQLITE_DEFAULT_FILE_FORMAT=4",
154       ]
155     }
157     deps = [
158       "//third_party/icu",
159     ]
160   }
162   config("sqlite_export") {
163     if (is_component_build && is_win) {
164       defines = [ "SQLITE_API=__declspec(dllimport)" ]
165     }
166   }
168   # This is used to allow the SQLITE_API definition to be different when
169   # building sqlite3.c than it is when clients include sqlite3.h.
170   group("sqlite") {
171     public_deps = [
172       ":chromium_sqlite3",
173     ]
174     public_configs = [ ":sqlite_export" ]
175   }
177   if (is_linux) {
178     executable("sqlite_shell") {
179       # So shell.c can find the correct sqlite3.h.
180       include_dirs = [ "amalgamation" ]
182       sources = [
183         "src/src/shell.c",
184         "src/src/shell_icu_linux.c",
186         # Include a dummy c++ file to force linking of libstdc++.
187         "build_as_cpp.cc",
188       ]
190       deps = [
191         ":sqlite",
192         "//build/config/sanitizers:deps",
193         "//third_party/icu",
194       ]
195     }
196   }
199 if (use_system_sqlite) {
200   # iOS uses the version of sqlite3 shipped with the system instead of the
201   # version shipped with Chromium. Export a "sqlite" target so the change
202   # can be localized to this file.
204   config("sqlite_config") {
205     defines = [ "USE_SYSTEM_SQLITE" ]
206     if (is_ios) {
207       libs = [ "sqlite3" ]
208     } else {
209       assert(false, "extra flags to use system sqlite3 library missing")
210     }
211   }
213   source_set("sqlite") {
214     public_configs = [ ":sqlite_config" ]
215     if (is_ios) {
216       deps = [
217         ":sqlite_regexp",
218       ]
219     }
220   }
222   if (is_ios) {
223     source_set("sqlite_regexp") {
224       defines = [
225         # Necessary to statically compile the extension.
226         "SQLITE_CORE",
227         "SQLITE_ENABLE_ICU",
228         "SQLITE_ENABLE_MEMORY_MANAGEMENT",
229       ]
230       sources = [
231         "src/ext/icu/icu.c",
232       ]
233       deps = [
234         "//third_party/icu",
235       ]
236       if (is_clang) {
237         # src/ext/icu/icu.c uses assert(!"string") which causes warnings about
238         # conversion from string literal to bool.
239         configs -= [ "//build/config/clang:extra_warnings" ]
240       }
241     }
242   }