1 # 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.
5 import("//build/config/compiler/compiler.gni")
7 template("split_static_library") {
8 assert(defined(invoker.split_count),
9 "Must define split_count for split_static_library")
11 # In many conditions the number of inputs will be 1 (because the
12 # count will be conditional on platform or configuration) and for
13 # some build configurations it's unnecessary to split libraries
14 # since the tooling will never create files of a problematic size.
15 if (invoker.split_count == 1 || use_lld) {
16 static_library(target_name) {
17 forward_variables_from(invoker, "*")
20 group_name = target_name
22 generated_static_libraries = []
23 current_library_index = 0
24 foreach(current_sources, split_list(invoker.sources, invoker.split_count)) {
25 current_name = "${target_name}_$current_library_index"
27 current_sources != [],
28 "Your values for splitting a static library generate one that has no sources.")
29 generated_static_libraries += [ ":$current_name" ]
31 static_library(current_name) {
32 # Generated static library shard gets everything but sources (which
33 # we're redefining) and visibility (which is set to be the group
35 forward_variables_from(invoker,
42 sources = current_sources
43 visibility = [ ":$group_name" ]
45 # When splitting a target's sources up into a series of static
46 # libraries, those targets will naturally include headers from each
47 # other arbitrarily. We could theoretically generate a web of
48 # dependencies and allow_circular_includes_from between all pairs of
49 # targets, but that's very cumbersome. Typical usage in Chrome is that
50 # only official Windows builds use split static libraries due to the
51 # Visual Studio size limits, and this means we'll still get header
52 # checking coverage for the other configurations.
53 check_includes = false
55 # Uniquify the output name if one is specified.
56 if (defined(invoker.output_name)) {
57 output_name = "${invoker.output_name}_$current_library_index"
61 current_library_index = current_library_index + 1
65 public_deps = generated_static_libraries
66 forward_variables_from(invoker,
76 set_defaults("split_static_library") {
77 configs = default_compiler_configs