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 | |
Mike Klein | 29cb9f9 | 2020-06-19 16:25:12 -0500 | [diff] [blame] | 6 | declare_args() { |
| 7 | third_party_isystem = true |
| 8 | } |
| 9 | |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 10 | template("third_party_config") { |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 11 | enabled = !defined(invoker.enabled) || invoker.enabled |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 12 | config(target_name) { |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 13 | if (enabled) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 14 | forward_variables_from(invoker, "*", [ "include_dirs" ]) |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 15 | cflags = [] |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 16 | if (is_win) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 17 | include_dirs = invoker.include_dirs |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 18 | if (is_clang) { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 19 | foreach(dir, invoker.include_dirs) { |
Brian Osman | 8cdf5b6 | 2019-05-08 15:22:55 -0400 | [diff] [blame] | 20 | cflags += [ |
| 21 | "/imsvc", |
| 22 | rebase_path(dir), |
| 23 | ] |
| 24 | } |
Mike Klein | 10af5ec | 2019-02-11 12:18:24 -0500 | [diff] [blame] | 25 | } |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 26 | } else { |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 27 | foreach(dir, invoker.include_dirs) { |
Mike Klein | 29cb9f9 | 2020-06-19 16:25:12 -0500 | [diff] [blame] | 28 | if (third_party_isystem) { |
Shachar Langbeheim | db610b3 | 2019-06-11 21:26:28 +0300 | [diff] [blame] | 29 | cflags += [ |
| 30 | "-isystem", |
| 31 | rebase_path(dir), |
| 32 | ] |
| 33 | } else { |
| 34 | cflags += [ |
| 35 | "-I", |
| 36 | rebase_path(dir), |
| 37 | ] |
| 38 | } |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | } else { |
| 42 | not_needed(invoker, "*") |
Mike Klein | 4b167fc | 2016-10-11 18:13:53 -0400 | [diff] [blame] | 43 | } |
mtklein | 25c81d4 | 2016-07-27 13:55:26 -0700 | [diff] [blame] | 44 | } |
Ben Wagner | 36e67aa | 2020-04-02 17:17:05 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | template("third_party") { |
| 48 | enabled = !defined(invoker.enabled) || invoker.enabled |
| 49 | third_party_config(target_name + "_public") { |
| 50 | if (enabled) { |
| 51 | if (defined(invoker.public_defines)) { |
| 52 | defines = invoker.public_defines |
| 53 | } |
| 54 | include_dirs = invoker.public_include_dirs |
| 55 | } else { |
| 56 | not_needed(invoker, "*") |
| 57 | } |
| 58 | } |
Kevin Lubick | d5c6e16 | 2019-02-01 15:34:04 -0500 | [diff] [blame] | 59 | |
| 60 | # You can't make a static_library() without object files to archive, |
| 61 | # but we can treat targets without object files as a source_set(). |
| 62 | if (defined(invoker.sources)) { |
| 63 | _mode = "static_library" |
| 64 | } else { |
| 65 | _mode = "source_set" |
| 66 | } |
| 67 | |
| 68 | target(_mode, target_name) { |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 69 | if (enabled) { |
Ben Wagner | 3d9ab7e | 2021-03-16 14:29:20 -0400 | [diff] [blame] | 70 | # set_defaults(_mode) might not exist or set configs |
| 71 | if (!defined(configs)) { |
| 72 | configs = [] |
| 73 | } |
| 74 | if (is_debug) { |
| 75 | configs += [ "//gn/skia:optimize" ] |
| 76 | } |
| 77 | if (sanitize == "ASAN") { |
| 78 | configs += [ "//gn/skia:recover_pointer_overflow" ] |
| 79 | } |
| 80 | |
| 81 | # "*" clobbers the current scope; append to existing configs |
| 82 | forward_variables_from(invoker, |
| 83 | "*", |
| 84 | [ |
| 85 | "public_include_dirs", |
| 86 | "configs", |
| 87 | ]) |
| 88 | if (defined(invoker.configs)) { |
| 89 | configs += invoker.configs |
| 90 | } |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 91 | public_configs = [ ":" + target_name + "_public" ] |
abarth | 6fc8ff0 | 2016-07-15 15:15:15 -0700 | [diff] [blame] | 92 | |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 93 | # Warnings are just noise if we're not maintaining the code. |
| 94 | if (is_win) { |
Brian Osman | 63d3215 | 2019-12-30 10:11:13 -0500 | [diff] [blame] | 95 | cflags = [ "/w" ] |
Brian Osman | c069a57 | 2018-06-19 16:05:09 -0400 | [diff] [blame] | 96 | } else { |
| 97 | cflags = [ "-w" ] |
| 98 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 99 | } |
mtklein | f037d48 | 2016-07-19 08:25:00 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 102 | |
Mike Klein | 10d665d | 2016-11-01 11:46:10 -0400 | [diff] [blame] | 103 | template("system") { |
| 104 | config(target_name + "_public") { |
| 105 | forward_variables_from(invoker, "*", []) |
| 106 | } |
| 107 | group(target_name) { |
| 108 | public_configs = [ ":" + target_name + "_public" ] |
| 109 | } |
| 110 | } |