blob: ea378e38dd7a789155e41353a96b4602ab08df0b [file] [log] [blame]
brettwf760b442016-06-29 18:57:281# Copyright 2016 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.
4
5template("split_static_library") {
6 assert(defined(invoker.split_count),
7 "Must define split_count for split_static_library")
8
9 # In many conditions the number of inputs will be 1 (because the count will
10 # be conditional on platform or configuration) so optimize that.
11 if (invoker.split_count == 1) {
12 static_library(target_name) {
13 forward_variables_from(invoker, "*")
14 }
15 } else {
16 group_name = target_name
17
18 generated_static_libraries = []
19 current_library_index = 0
20 foreach(current_sources, split_list(invoker.sources, invoker.split_count)) {
21 current_name = "${target_name}_$current_library_index"
22 assert(
23 current_sources != [],
24 "Your values for splitting a static library generate one that has no sources.")
25 generated_static_libraries += [ ":$current_name" ]
26
27 static_library(current_name) {
28 # Generated static library shard gets everything but sources (which
29 # we're redefining) and visibility (which is set to be the group
30 # below).
31 forward_variables_from(invoker,
32 "*",
33 [
brettwb3e60142016-09-23 19:55:0134 "check_includes",
brettwf760b442016-06-29 18:57:2835 "sources",
36 "visibility",
37 ])
38 sources = current_sources
39 visibility = [ ":$group_name" ]
brettw251c55182016-07-15 18:21:2640
brettwb3e60142016-09-23 19:55:0141 # When splitting a target's sources up into a series of static
42 # libraries, those targets will naturally include headers from each
43 # other arbitrarily. We could theoretically generate a web of
44 # dependencies and allow_circular_includes_from between all pairs of
45 # targets, but that's very cumbersome. Typical usage in Chrome is that
46 # only official Windows builds use split static libraries due to the
47 # Visual Studio size limits, and this means we'll still get header
48 # checking coverage for the other configurations.
49 check_includes = false
50
brettw251c55182016-07-15 18:21:2651 # Uniquify the output name if one is specified.
52 if (defined(invoker.output_name)) {
53 output_name = "${invoker.output_name}_$current_library_index"
54 }
brettwf760b442016-06-29 18:57:2855 }
56
57 current_library_index = current_library_index + 1
58 }
59
60 group(group_name) {
61 public_deps = generated_static_libraries
62 forward_variables_from(invoker,
63 [
64 "testonly",
65 "visibility",
66 ])
67 }
68 }
69}
brettwedb6ecc2016-07-14 23:37:0370
71set_defaults("split_static_library") {
72 configs = default_compiler_configs
73}