blob: c7b63ffe112fa06f6dd0dd858a2955ecee501d61 [file] [log] [blame]
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +09001# Copyright 2018 The Chromium OS 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.
4
5import("//common-mk/pkg_config.gni")
6
7group("all") {
8 deps = [
9 ":libchrome",
10 ":libchrome-test",
11 ]
12}
13
14# Suppressing warning in base/strings/stringprintf.cc.
15config("base_core_config") {
Hidehiko Abe49419512018-12-15 00:36:33 +090016 cflags = [
17 "-Wno-format-nonliteral",
18 # This is for _exit(1) in base/debug/debugger_posix.cc.
19 "-Wno-unreachable-code",
20 ]
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +090021}
22
23libbase_sublibs = [
24 {
25 name = "base-core"
26 output_name = name + "-${libbase_ver}"
27 libs = [ "pthread", "rt", "modp_b64" ]
28 pkg_deps = [ "glib-2.0", "libevent" ]
29 configs = [ ":base_core_config" ]
30 sources = [
31 "base/allocator/allocator_extension.cc",
32 "base/allocator/allocator_shim.cc",
33 "base/allocator/allocator_shim_default_dispatch_to_glibc.cc",
34 "base/at_exit.cc",
35 "base/base64.cc",
36 "base/base64url.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +090037 "base/base_paths.cc",
38 "base/base_paths_posix.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +090039 "base/base_switches.cc",
40 "base/bind_helpers.cc",
41 "base/build_time.cc",
42 "base/callback_helpers.cc",
43 "base/callback_internal.cc",
44 "base/command_line.cc",
45 "base/cpu.cc",
46 "base/debug/activity_tracker.cc",
47 "base/debug/alias.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +090048 "base/debug/debugger.cc",
49 "base/debug/debugger_posix.cc",
50 "base/debug/dump_without_crashing.cc",
51 "base/debug/stack_trace.cc",
52 "base/debug/stack_trace_posix.cc",
53 "base/debug/task_annotator.cc",
54 "base/environment.cc",
55 "base/feature_list.cc",
56 "base/files/file.cc",
57 "base/files/file_descriptor_watcher_posix.cc",
58 "base/files/file_enumerator.cc",
59 "base/files/file_enumerator_posix.cc",
60 "base/files/file_path.cc",
61 "base/files/file_path_constants.cc",
62 "base/files/file_path_watcher.cc",
63 "base/files/file_path_watcher_linux.cc",
64 "base/files/file_posix.cc",
65 "base/files/file_tracing.cc",
66 "base/files/file_util.cc",
67 "base/files/file_util_linux.cc",
68 "base/files/file_util_posix.cc",
69 "base/files/important_file_writer.cc",
70 "base/files/memory_mapped_file.cc",
71 "base/files/memory_mapped_file_posix.cc",
72 "base/files/scoped_file.cc",
73 "base/files/scoped_temp_dir.cc",
74 "base/guid.cc",
75 "base/hash.cc",
76 "base/json/json_file_value_serializer.cc",
77 "base/json/json_parser.cc",
78 "base/json/json_reader.cc",
79 "base/json/json_string_value_serializer.cc",
80 "base/json/json_value_converter.cc",
81 "base/json/json_writer.cc",
82 "base/json/string_escape.cc",
83 "base/lazy_instance.cc",
84 "base/location.cc",
85 "base/logging.cc",
86 "base/md5.cc",
87 "base/memory/aligned_memory.cc",
88 "base/memory/ref_counted.cc",
89 "base/memory/ref_counted_memory.cc",
90 "base/memory/shared_memory_helper.cc",
91 "base/memory/shared_memory_posix.cc",
92 "base/memory/shared_memory_tracker.cc",
93 "base/memory/singleton.cc",
94 "base/memory/weak_ptr.cc",
95 "base/message_loop/incoming_task_queue.cc",
96 "base/message_loop/message_loop.cc",
97 "base/message_loop/message_loop_task_runner.cc",
98 "base/message_loop/message_pump.cc",
99 "base/message_loop/message_pump_default.cc",
100 "base/message_loop/message_pump_glib.cc",
101 "base/message_loop/message_pump_libevent.cc",
102 "base/metrics/bucket_ranges.cc",
103 "base/metrics/field_trial.cc",
104 "base/metrics/field_trial_param_associator.cc",
105 "base/metrics/metrics_hashes.cc",
106 "base/metrics/histogram_base.cc",
107 "base/metrics/histogram.cc",
108 "base/metrics/histogram_samples.cc",
109 "base/metrics/histogram_snapshot_manager.cc",
110 "base/metrics/persistent_histogram_allocator.cc",
111 "base/metrics/persistent_memory_allocator.cc",
112 "base/metrics/persistent_sample_map.cc",
113 "base/metrics/sample_map.cc",
114 "base/metrics/sample_vector.cc",
115 "base/metrics/sparse_histogram.cc",
116 "base/metrics/statistics_recorder.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +0900117 "base/path_service.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900118 "base/pending_task.cc",
119 "base/pickle.cc",
120 "base/posix/file_descriptor_shuffle.cc",
121 "base/posix/global_descriptors.cc",
122 "base/posix/safe_strerror.cc",
123 "base/posix/unix_domain_socket_linux.cc",
124 "base/process/internal_linux.cc",
125 "base/process/kill.cc",
126 "base/process/kill_posix.cc",
127 "base/process/launch.cc",
128 "base/process/launch_posix.cc",
129 "base/process/memory.cc",
130 "base/process/memory_linux.cc",
131 "base/process/process_handle.cc",
132 "base/process/process_handle_linux.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +0900133 "base/process/process_handle_posix.cc",
134 "base/process/process_info_linux.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900135 "base/process/process_iterator.cc",
136 "base/process/process_iterator_linux.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900137 "base/process/process_metrics.cc",
138 "base/process/process_metrics_linux.cc",
139 "base/process/process_metrics_posix.cc",
140 "base/process/process_posix.cc",
141 "base/profiler/scoped_profile.cc",
142 "base/profiler/scoped_tracker.cc",
143 "base/profiler/tracked_time.cc",
144 "base/rand_util.cc",
145 "base/rand_util_posix.cc",
146 "base/run_loop.cc",
147 "base/sequence_checker_impl.cc",
148 "base/sequenced_task_runner.cc",
149 "base/sequence_token.cc",
150 "base/sha1.cc",
151 "base/strings/pattern.cc",
152 "base/strings/safe_sprintf.cc",
153 "base/strings/string16.cc",
154 "base/strings/string_number_conversions.cc",
155 "base/strings/string_piece.cc",
156 "base/strings/stringprintf.cc",
157 "base/strings/string_split.cc",
158 "base/strings/string_util.cc",
159 "base/strings/string_util_constants.cc",
160 "base/strings/sys_string_conversions_posix.cc",
161 "base/strings/utf_string_conversions.cc",
162 "base/strings/utf_string_conversion_utils.cc",
163 "base/synchronization/atomic_flag.cc",
164 "base/synchronization/condition_variable_posix.cc",
165 "base/synchronization/lock.cc",
166 "base/synchronization/lock_impl_posix.cc",
167 "base/synchronization/read_write_lock_posix.cc",
168 "base/synchronization/waitable_event_posix.cc",
169 "base/synchronization/waitable_event_watcher_posix.cc",
170 "base/sync_socket_posix.cc",
171 "base/sys_info.cc",
172 "base/sys_info_chromeos.cc",
173 "base/sys_info_linux.cc",
174 "base/sys_info_posix.cc",
175 "base/task_runner.cc",
176 "base/task/cancelable_task_tracker.cc",
177 "base/task_scheduler/scheduler_lock_impl.cc",
178 "base/task_scheduler/scoped_set_task_priority_for_current_thread.cc",
179 "base/task_scheduler/sequence.cc",
180 "base/task_scheduler/sequence_sort_key.cc",
181 "base/task_scheduler/task.cc",
182 "base/task_scheduler/task_traits.cc",
183 "base/third_party/dynamic_annotations/dynamic_annotations.c",
184 "base/third_party/icu/icu_utf.cc",
185 "base/third_party/nspr/prtime.cc",
186 "base/threading/non_thread_safe_impl.cc",
187 "base/threading/platform_thread_internal_posix.cc",
188 "base/threading/platform_thread_linux.cc",
189 "base/threading/platform_thread_posix.cc",
190 "base/threading/post_task_and_reply_impl.cc",
191 "base/threading/sequenced_task_runner_handle.cc",
192 "base/threading/sequenced_worker_pool.cc",
193 "base/threading/simple_thread.cc",
194 "base/threading/thread.cc",
195 "base/threading/thread_checker_impl.cc",
196 "base/threading/thread_collision_warner.cc",
197 "base/threading/thread_id_name_manager.cc",
198 "base/threading/thread_local_storage.cc",
199 "base/threading/thread_local_storage_posix.cc",
200 "base/threading/thread_restrictions.cc",
201 "base/threading/thread_task_runner_handle.cc",
202 "base/threading/worker_pool.cc",
203 "base/threading/worker_pool_posix.cc",
204 "base/timer/elapsed_timer.cc",
205 "base/timer/timer.cc",
206 "base/time/clock.cc",
207 "base/time/default_clock.cc",
208 "base/time/default_tick_clock.cc",
209 "base/time/tick_clock.cc",
210 "base/time/time.cc",
211 "base/time/time_posix.cc",
212 "base/trace_event/category_registry.cc",
213 "base/trace_event/event_name_filter.cc",
214 "base/trace_event/malloc_dump_provider.cc",
215 "base/trace_event/heap_profiler_allocation_context.cc",
216 "base/trace_event/heap_profiler_allocation_context_tracker.cc",
217 "base/trace_event/heap_profiler_allocation_register.cc",
218 "base/trace_event/heap_profiler_allocation_register_posix.cc",
219 "base/trace_event/heap_profiler_event_filter.cc",
220 "base/trace_event/heap_profiler_heap_dump_writer.cc",
221 "base/trace_event/heap_profiler_stack_frame_deduplicator.cc",
222 "base/trace_event/heap_profiler_type_name_deduplicator.cc",
223 "base/trace_event/memory_allocator_dump.cc",
224 "base/trace_event/memory_allocator_dump_guid.cc",
225 "base/trace_event/memory_dump_manager.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +0900226 "base/trace_event/memory_dump_provider_info.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900227 "base/trace_event/memory_dump_request_args.cc",
228 "base/trace_event/memory_dump_scheduler.cc",
229 "base/trace_event/memory_dump_session_state.cc",
230 "base/trace_event/memory_infra_background_whitelist.cc",
231 "base/trace_event/process_memory_dump.cc",
232 "base/trace_event/process_memory_maps.cc",
233 "base/trace_event/process_memory_totals.cc",
234 "base/trace_event/trace_buffer.cc",
235 "base/trace_event/trace_config.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +0900236 "base/trace_event/trace_config_category_filter.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900237 "base/trace_event/trace_event_argument.cc",
238 "base/trace_event/trace_event_filter.cc",
239 "base/trace_event/trace_event_impl.cc",
240 "base/trace_event/trace_event_memory_overhead.cc",
241 "base/trace_event/trace_event_synthetic_delay.cc",
242 "base/trace_event/trace_log.cc",
243 "base/trace_event/trace_log_constants.cc",
244 "base/tracked_objects.cc",
245 "base/tracking_info.cc",
Hidehiko Abe780c6a92018-12-21 19:27:08 +0900246 "base/unguessable_token.cc",
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900247 "base/values.cc",
248 "base/version.cc",
249 "base/vlog.cc",
250 ]
251 },
252
253 {
254 name = "base-dl"
255 output_name = name + "-${libbase_ver}"
256 deps = [ ":base-core" ]
257 libs = [ "dl" ]
258 sources = [ "base/native_library_posix.cc" ]
259 },
260
261 {
262 name = "base-policy"
263 output_name = name + "-${libbase_ver}"
264 deps = [ ":base-core" ]
265 sources = [
266 "components/policy/core/common/policy_load_status.cc",
267 "components/policy/core/common/registry_dict.cc",
268 ]
269 },
270
271 {
272 name = "base-base_test_support"
273 output_name = name + "-${libbase_ver}"
274 testonly = true
275 sources = [
276 "base/test/fuzzed_data_provider.cc",
277 "base/test/simple_test_clock.cc",
278 "base/test/simple_test_tick_clock.cc",
279 "base/test/test_file_util.cc",
280 "base/test/test_file_util_linux.cc",
281 "base/test/test_switches.cc",
282 "base/test/test_timeouts.cc",
283 ]
284 }
285]
286
287if (use.crypto) {
288 libbase_sublibs += [
289 {
290 name = "base-crypto"
291 output_name = name + "-${libbase_ver}"
292 deps = [ ":base-core", ":base-dl" ]
293 pkg_deps = [ "nss", "openssl" ]
294 sources = [
295 "crypto/hmac.cc",
296 "crypto/hmac_nss.cc",
297 "crypto/nss_key_util.cc",
298 "crypto/nss_util.cc",
299 "crypto/openssl_util.cc",
300 "crypto/p224.cc",
301 "crypto/p224_spake.cc",
302 "crypto/random.cc",
303 "crypto/rsa_private_key.cc",
304 "crypto/rsa_private_key_nss.cc",
305 "crypto/scoped_test_nss_db.cc",
306 "crypto/secure_hash.cc",
307 "crypto/secure_util.cc",
308 "crypto/sha2.cc",
309 "crypto/signature_creator_nss.cc",
310 "crypto/signature_verifier_nss.cc",
311 "crypto/symmetric_key_nss.cc",
312 "crypto/third_party/nss/rsawrapr.c",
313 "crypto/third_party/nss/sha512.cc",
314 ]
315 }
316 ]
317}
318
319if (use.dbus) {
320 libbase_sublibs += [
321 {
322 name = "base-dbus"
323 output_name = name + "-${libbase_ver}"
324 deps = [ ":base-core" ]
325 pkg_deps = [ "dbus-1", "protobuf-lite" ]
326 sources = [
327 "dbus/bus.cc",
328 "dbus/dbus_statistics.cc",
329 "dbus/exported_object.cc",
330 "dbus/message.cc",
331 "dbus/object_manager.cc",
332 "dbus/object_path.cc",
333 "dbus/object_proxy.cc",
334 "dbus/property.cc",
335 "dbus/scoped_dbus_error.cc",
336 "dbus/string_util.cc",
337 "dbus/util.cc",
338 "dbus/values_util.cc",
339 ]
340 },
341
342 {
343 name = "base-dbus_test_support"
344 output_name = name + "-${libbase_ver}"
345 testonly = true
346 pkg_deps = [ "dbus-1", "protobuf-lite" ]
347 sources = [
348 "dbus/mock_bus.cc",
349 "dbus/mock_exported_object.cc",
350 "dbus/mock_object_manager.cc",
351 "dbus/mock_object_proxy.cc",
352 ]
353 },
354 ]
355}
356
357if (use.timers) {
358 libbase_sublibs += [
359 {
360 name = "base-timers"
361 output_name = name + "-${libbase_ver}"
362 deps = [ ":base-core" ]
363 sources = [ "components/timers/alarm_timer_chromeos.cc" ]
364 },
365
366 {
367 name = "base-timer_test_support"
368 output_name = name + "-${libbase_ver}"
369 testonly = true
370 sources = [ "base/timer/mock_timer.cc" ]
371 },
372 ]
373}
374
375# Generate static/shared libraries.
376foreach(attr, libbase_sublibs) {
377 if (defined(attr.pkg_deps)) {
378 # If it depends on external packages, introduces -pkg-config config.
379 pkg_config(attr.name + "-pkg-config") {
380 pkg_deps = attr.pkg_deps
381 }
382 }
383
384 if (defined(attr.testonly) && attr.testonly) {
385 buildtype = "static_library"
386 } else {
387 buildtype = "shared_library"
388 }
389 target(buildtype, attr.name) {
390 output_name = attr.output_name
391 sources = attr.sources
392 if (defined(attr.deps)) {
393 deps = attr.deps
394 }
395
396 # TODO(hidehiko): Consolidate with build_config.h.
397 defines = [
398 "OS_CHROMEOS",
399 "USE_NSS_CERTS",
400 "USE_SYSTEM_LIBEVENT",
401 "NO_TCMALLOC",
402 ]
403 include_dirs = [ "." ]
404 cflags = [
405 "-Wno-deprecated-register",
406 "-Wno-narrowing",
407 "-Wno-unused-local-typedefs",
408 "-Xclang-only=-Wno-char-subscripts",
409 ]
410 # Address sanitizer builds do not support -z,defs.
411 if (!use.asan) {
412 ldflags = [ "-Wl,-z,defs" ]
413 }
414
415 if (defined(attr.libs)) {
416 libs = attr.libs
417 }
418
419 if (defined(attr.pkg_deps)) {
420 configs += [ ":" + attr.name + "-pkg-config" ]
421 }
422 configs += [ "//common-mk:visibility_default" ]
Hidehiko Abe6fea5a42018-12-18 04:26:55 +0900423 if (buildtype == "static_library") {
424 configs -= [ "//common-mk:use_thin_archive" ]
425 configs += [ "//common-mk:nouse_thin_archive" ]
426 }
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900427 if (defined(attr.configs)) {
428 configs += attr.configs
429 }
430 }
431}
432
433action("base") {
434 deps = []
435 foreach(attr, libbase_sublibs) {
436 if (!defined(attr.testonly) || !attr.testonly) {
437 deps += [ ":" + attr.name ]
438 }
439 }
440
441 script = "//common-mk/write_args.py"
442 outputs = [ "${root_out_dir}/lib/lib${target_name}-${libbase_ver}.so" ]
443 args = [ "--output" ] + outputs + [ "--" ] + [
444 "GROUP", "(", "AS_NEEDED", "(",
445 ]
446 foreach(attr, libbase_sublibs) {
447 if (!defined(attr.testonly) || !attr.testonly) {
448 args += [ "-l" + attr.output_name ]
449 }
450 }
451 args += [ ")", ")" ]
452}
453
454libchrome_exported_cflags = [
455 "-I/usr/include/base-${libbase_ver}",
456 "-Wno-unused-local-typedefs",
457 "-DBASE_VER=${libbase_ver}",
458]
459
460generate_pkg_config("libchrome") {
461 deps = [ ":base" ]
462 output_name = "libchrome-${libbase_ver}"
463 description = "chrome base library"
464 version = "${libbase_ver}"
465 requires_private = []
466 foreach(attr, libbase_sublibs) {
467 if ((!defined(attr.testonly) || !attr.testonly)
468 && defined(attr.pkg_deps)) {
469 requires_private += attr.pkg_deps
470 }
471 }
Hidehiko Abee1f598f2019-01-15 01:32:39 +0900472 libs = [ "-lbase-${libbase_ver}" ]
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900473 libs_private = []
474 foreach(attr, libbase_sublibs) {
475 if (!defined(attr.testonly) || !attr.testonly) {
Hidehiko Abee1f598f2019-01-15 01:32:39 +0900476 libs_private += [ "-l" + attr.output_name ]
477 if (defined(attr.libs)) {
478 foreach(lib, attr.libs) {
479 libs_private += [ "-l" + lib ]
480 }
481 }
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900482 }
483 }
484 cflags = libchrome_exported_cflags
485}
486
487action("base-test") {
488 deps = []
489 foreach(attr, libbase_sublibs) {
490 if (defined(attr.testonly) && attr.testonly) {
491 deps += [ ":" + attr.name ]
492 }
493 }
494
495 script = "//common-mk/write_args.py"
496 outputs = [ "${root_out_dir}/lib${target_name}-${libbase_ver}.a" ]
497 args = [ "--output" ] + outputs + [ "--" ] + [
498 "GROUP", "(", "AS_NEEDED", "(",
499 ]
500 foreach(attr, libbase_sublibs) {
501 if (defined(attr.testonly) && attr.testonly) {
502 args += [ "-l" + attr.output_name ]
503 }
504 }
505 args += [ ")", ")" ]
506}
507
508generate_pkg_config("libchrome-test") {
509 deps = [ ":base-test" ]
510 output_name = "libchrome-test-${libbase_ver}"
511 description = "chrome base test library"
512 version = "${libbase_ver}"
513 requires_private = []
514 foreach(attr, libbase_sublibs) {
515 if (defined(attr.testonly) && attr.testonly && defined(attr.pkg_deps)) {
516 requires_private += attr.pkg_deps
517 }
518 }
Hidehiko Abee1f598f2019-01-15 01:32:39 +0900519 libs = [ "-lbase-test-${libbase_ver}" ]
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900520 libs_private = []
521 foreach(attr, libbase_sublibs) {
522 if (defined(attr.testonly) && attr.testonly) {
Hidehiko Abee1f598f2019-01-15 01:32:39 +0900523 libs_private += [ "-l" + attr.output_name ]
524 if (defined(attr.libs)) {
525 libs_private += [ "-l" + lib ]
526 }
Hidehiko Abe6ddb2e02018-12-02 23:24:50 +0900527 }
528 }
529 cflags = libchrome_exported_cflags
530}