blob: e35c3ecd884738fe90cbe5e14c80217d1e476d5f [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
mtkleinf037d482016-07-19 08:25:00 -07006template("third_party") {
Brian Osmanc069a572018-06-19 16:05:09 -04007 enabled = !defined(invoker.enabled) || invoker.enabled
mtklein25c81d42016-07-27 13:55:26 -07008 config(target_name + "_public") {
Brian Osmanc069a572018-06-19 16:05:09 -04009 if (enabled) {
10 cflags = []
11 if (defined(invoker.public_defines)) {
12 defines = invoker.public_defines
13 }
Mike Klein10af5ec2019-02-11 12:18:24 -050014 if (is_win && !is_clang) {
Brian Osmanc069a572018-06-19 16:05:09 -040015 include_dirs = invoker.public_include_dirs
Mike Klein10af5ec2019-02-11 12:18:24 -050016 } else if (is_win && is_clang) {
17 foreach(dir, invoker.public_include_dirs) {
18 cflags += [
19 "/imsvc",
20 rebase_path(dir),
21 ]
22 }
Brian Osmanc069a572018-06-19 16:05:09 -040023 } else {
24 foreach(dir, invoker.public_include_dirs) {
25 cflags += [
26 "-isystem",
27 rebase_path(dir),
28 ]
29 }
30 }
31 } else {
32 not_needed(invoker, "*")
Mike Klein4b167fc2016-10-11 18:13:53 -040033 }
mtklein25c81d42016-07-27 13:55:26 -070034 }
Kevin Lubickd5c6e162019-02-01 15:34:04 -050035
36 # You can't make a static_library() without object files to archive,
37 # but we can treat targets without object files as a source_set().
38 if (defined(invoker.sources)) {
39 _mode = "static_library"
40 } else {
41 _mode = "source_set"
42 }
43
44 target(_mode, target_name) {
Brian Osmanc069a572018-06-19 16:05:09 -040045 if (enabled) {
46 forward_variables_from(invoker, "*", [ "public_include_dirs" ])
47 public_configs = [ ":" + target_name + "_public" ]
abarth6fc8ff02016-07-15 15:15:15 -070048
Brian Osmanc069a572018-06-19 16:05:09 -040049 # Warnings are just noise if we're not maintaining the code.
50 if (is_win) {
51 cflags = [ "/w" ]
52 } else {
53 cflags = [ "-w" ]
54 }
herbb6318bf2016-09-16 13:29:57 -070055 }
mtkleinf037d482016-07-19 08:25:00 -070056 }
57}
halcanary19a97202016-08-03 15:08:04 -070058
59set_defaults("third_party") {
Mike Kleind84c1e62018-09-04 10:15:58 -040060 configs = default_configs
61 if (!is_official_build) {
62 # Official builds don't have warnings to begin with.
63 configs -= [ "//gn:warnings" ]
64 }
Brian Osman50ea3c02019-02-04 10:01:53 -050065
66 # Don't want to to deal with this (especially /RTCc)
67 if (sanitize == "MSVC") {
68 configs -= [ "//gn:msvc_rtc" ]
69 }
Mike Klein7ea977b2018-09-19 13:44:43 -040070 if (is_debug) {
71 configs += [ "//gn:optimize" ]
72 }
halcanary19a97202016-08-03 15:08:04 -070073}
Mike Klein10d665d2016-11-01 11:46:10 -040074
75template("system") {
76 config(target_name + "_public") {
77 forward_variables_from(invoker, "*", [])
78 }
79 group(target_name) {
80 public_configs = [ ":" + target_name + "_public" ]
81 }
82}