abarth | 6fc8ff0 | 2016-07-15 15:15:15 -0700 | [diff] [blame] | 1 | # 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 Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 6 | template("third_party_config") { |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 7 | enabled = !defined(invoker.enabled) || invoker.enabled |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 8 | config(target_name) { |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 9 | if (enabled) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 10 | forward_variables_from(invoker, "*", [ "include_dirs" ]) |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 11 | cflags = [] |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 12 | if (is_win) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 13 | include_dirs = invoker.include_dirs |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 14 | if (is_clang) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 15 | foreach(dir, invoker.include_dirs) { |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 16 | cflags += [ |
| 17 | "/imsvc", |
| 18 | rebase_path(dir), |
| 19 | ] |
| 20 | } |
Mike Klein | 10af5ec | 2019-02-11 12:18:24 -0500 | [diff] [blame] | 21 | } |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 22 | } else { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 23 | foreach(dir, invoker.include_dirs) { |
Shachar Langbeheim | db610b3 | 2019-06-11 21:26:28 +0300 | [diff] [blame] | 24 | if (werror) { |
| 25 | cflags += [ |
| 26 | "-isystem", |
| 27 | rebase_path(dir), |
| 28 | ] |
| 29 | } else { |
| 30 | cflags += [ |
| 31 | "-I", |
| 32 | rebase_path(dir), |
| 33 | ] |
| 34 | } |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | } else { |
| 38 | not_needed(invoker, "*") |
Mike Klein | 4b167fc | 2016-10-11 18:13:53 -0400 | [diff] [blame] | 39 | } |
mtklein | 25c81d4 | 2016-07-27 13:55:26 -0700 | [diff] [blame] | 40 | } |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | template("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 Lubick | d5c6e16 | 2019-02-01 15:34:04 -0500 | [diff] [blame] | 55 | |
| 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 Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 65 | if (enabled) { |
| 66 | forward_variables_from(invoker, "*", [ "public_include_dirs" ]) |
| 67 | public_configs = [ ":" + target_name + "_public" ] |
abarth | 6fc8ff0 | 2016-07-15 15:15:15 -0700 | [diff] [blame] | 68 | |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 69 | # Warnings are just noise if we're not maintaining the code. |
| 70 | if (is_win) { |
Brian Osman | 63d3215 | 2019-12-30 10:11:13 -0500 | [diff] [blame] | 71 | cflags = [ "/w" ] |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 72 | } else { |
| 73 | cflags = [ "-w" ] |
| 74 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 75 | } |
mtklein | f037d48 | 2016-07-19 08:25:00 -0700 | [diff] [blame] | 76 | } |
| 77 | } |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 78 | |
| 79 | set_defaults("third_party") { |
Mike Klein | d84c1e6 | 2018-09-04 10:15:58 -0400 | [diff] [blame] | 80 | configs = default_configs |
| 81 | if (!is_official_build) { |
| 82 | # Official builds don't have warnings to begin with. |
| 83 | configs -= [ "//gn:warnings" ] |
| 84 | } |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 85 | |
Mike Klein | 7ea977b | 2018-09-19 13:44:43 -0400 | [diff] [blame] | 86 | if (is_debug) { |
| 87 | configs += [ "//gn:optimize" ] |
| 88 | } |
Mike Klein | c0c0522 | 2020-01-31 11:07:51 -0600 | [diff] [blame] | 89 | |
| 90 | if (sanitize == "ASAN") { |
| 91 | configs += [ "//gn:recover_pointer_overflow" ] |
| 92 | } |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 93 | } |
Mike Klein | 10d665d | 2016-11-01 11:46:10 -0400 | [diff] [blame] | 94 | |
| 95 | template("system") { |
| 96 | config(target_name + "_public") { |
| 97 | forward_variables_from(invoker, "*", []) |
| 98 | } |
| 99 | group(target_name) { |
| 100 | public_configs = [ ":" + target_name + "_public" ] |
| 101 | } |
| 102 | } |