blob: b0d106718d2f0394b11dd6aeac08e9970c4a5f3e [file] [log] [blame]
abarth6fc8ff02016-07-15 15:15:15 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
Ben Wagner36e67aa2020-04-02 17:17:05 -04006template("third_party_config") {
Brian Osmanc069a572018-06-19 16:05:09 -04007 enabled = !defined(invoker.enabled) || invoker.enabled
Ben Wagner36e67aa2020-04-02 17:17:05 -04008 config(target_name) {
Brian Osmanc069a572018-06-19 16:05:09 -04009 if (enabled) {
Ben Wagner36e67aa2020-04-02 17:17:05 -040010 forward_variables_from(invoker, "*", [ "include_dirs" ])
Brian Osmanc069a572018-06-19 16:05:09 -040011 cflags = []
Brian Osman8cdf5b62019-05-08 15:22:55 -040012 if (is_win) {
Ben Wagner36e67aa2020-04-02 17:17:05 -040013 include_dirs = invoker.include_dirs
Brian Osman8cdf5b62019-05-08 15:22:55 -040014 if (is_clang) {
Ben Wagner36e67aa2020-04-02 17:17:05 -040015 foreach(dir, invoker.include_dirs) {
Brian Osman8cdf5b62019-05-08 15:22:55 -040016 cflags += [
17 "/imsvc",
18 rebase_path(dir),
19 ]
20 }
Mike Klein10af5ec2019-02-11 12:18:24 -050021 }
Brian Osmanc069a572018-06-19 16:05:09 -040022 } else {
Ben Wagner36e67aa2020-04-02 17:17:05 -040023 foreach(dir, invoker.include_dirs) {
Shachar Langbeheimdb610b32019-06-11 21:26:28 +030024 if (werror) {
25 cflags += [
26 "-isystem",
27 rebase_path(dir),
28 ]
29 } else {
30 cflags += [
31 "-I",
32 rebase_path(dir),
33 ]
34 }
Brian Osmanc069a572018-06-19 16:05:09 -040035 }
36 }
37 } else {
38 not_needed(invoker, "*")
Mike Klein4b167fc2016-10-11 18:13:53 -040039 }
mtklein25c81d42016-07-27 13:55:26 -070040 }
Ben Wagner36e67aa2020-04-02 17:17:05 -040041}
42
43template("third_party") {
44 enabled = !defined(invoker.enabled) || invoker.enabled
45 third_party_config(target_name + "_public") {
46 if (enabled) {
47 if (defined(invoker.public_defines)) {
48 defines = invoker.public_defines
49 }
50 include_dirs = invoker.public_include_dirs
51 } else {
52 not_needed(invoker, "*")
53 }
54 }
Kevin Lubickd5c6e162019-02-01 15:34:04 -050055
56 # You can't make a static_library() without object files to archive,
57 # but we can treat targets without object files as a source_set().
58 if (defined(invoker.sources)) {
59 _mode = "static_library"
60 } else {
61 _mode = "source_set"
62 }
63
64 target(_mode, target_name) {
Brian Osmanc069a572018-06-19 16:05:09 -040065 if (enabled) {
66 forward_variables_from(invoker, "*", [ "public_include_dirs" ])
67 public_configs = [ ":" + target_name + "_public" ]
abarth6fc8ff02016-07-15 15:15:15 -070068
Brian Osmanc069a572018-06-19 16:05:09 -040069 # Warnings are just noise if we're not maintaining the code.
70 if (is_win) {
Brian Osman63d32152019-12-30 10:11:13 -050071 cflags = [ "/w" ]
Brian Osmanc069a572018-06-19 16:05:09 -040072 } else {
73 cflags = [ "-w" ]
74 }
herbb6318bf2016-09-16 13:29:57 -070075 }
mtkleinf037d482016-07-19 08:25:00 -070076 }
77}
halcanary19a97202016-08-03 15:08:04 -070078
79set_defaults("third_party") {
Mike Kleind84c1e62018-09-04 10:15:58 -040080 configs = default_configs
81 if (!is_official_build) {
82 # Official builds don't have warnings to begin with.
83 configs -= [ "//gn:warnings" ]
84 }
Brian Osman50ea3c02019-02-04 10:01:53 -050085
Mike Klein7ea977b2018-09-19 13:44:43 -040086 if (is_debug) {
87 configs += [ "//gn:optimize" ]
88 }
Mike Kleinc0c05222020-01-31 11:07:51 -060089
90 if (sanitize == "ASAN") {
91 configs += [ "//gn:recover_pointer_overflow" ]
92 }
halcanary19a97202016-08-03 15:08:04 -070093}
Mike Klein10d665d2016-11-01 11:46:10 -040094
95template("system") {
96 config(target_name + "_public") {
97 forward_variables_from(invoker, "*", [])
98 }
99 group(target_name) {
100 public_configs = [ ":" + target_name + "_public" ]
101 }
102}