Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 1 | # Copyright 2019 The Dawn Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 15 | import("//build_overrides/build.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 16 | import("dawn_features.gni") |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 17 | import("dawn_overrides_with_defaults.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 18 | |
| 19 | ############################################################################### |
| 20 | # Template to produce a component for one of Dawn's libraries. |
| 21 | ############################################################################### |
| 22 | |
| 23 | # Template that produces static and shared versions of the same library as well |
| 24 | # as a target similar to Chromium's component targets. |
| 25 | # - The shared version exports symbols and has dependent import the symbols |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 26 | # as libdawn_${name}.so. If the target name matches the package directory |
| 27 | # name, then the shared library target will be named 'shared', otherwise |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 28 | # '${target_name}_shared'. |
| 29 | # - The static library doesn't export symbols nor make dependents import them. |
| 30 | # If the target name matches the package directory name, then the static |
| 31 | # library target will be named 'static', otherwise '${target_name}_static'. |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 32 | # - The libname target is similar to a Chromium component and is an alias for |
| 33 | # either the static or the shared library. |
| 34 | # |
| 35 | # The DEFINE_PREFIX must be provided and must match the respective "_export.h" |
| 36 | # file. |
| 37 | # |
| 38 | # Example usage: |
| 39 | # |
| 40 | # dawn_component("my_library") { |
| 41 | # // my_library_export.h must use the MY_LIBRARY_IMPLEMENTATION and |
| 42 | # // MY_LIBRARY_SHARED_LIBRARY macros. |
| 43 | # DEFINE_PREFIX = "MY_LIBRARY" |
| 44 | # |
| 45 | # sources = [...] |
| 46 | # deps = [...] |
| 47 | # configs = [...] |
| 48 | # } |
| 49 | # |
| 50 | # executable("foo") { |
| 51 | # deps = [ ":my_library_shared" ] // or :my_library for the same effect |
| 52 | # } |
| 53 | template("dawn_component") { |
| 54 | # Copy the target_name in the local scope so it doesn't get shadowed in the |
| 55 | # definition of targets. |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 56 | name = target_name |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 57 | |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 58 | prefix = "${name}_" |
| 59 | |
| 60 | # Remove prefix if the target name matches directory |
| 61 | if (get_label_info(get_label_info(":$target_name", "dir"), "name") == name) { |
| 62 | prefix = "" |
| 63 | } |
| 64 | |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 65 | # The config that will apply to dependents of the shared library so they know |
| 66 | # they should "import" the symbols |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 67 | config("${prefix}shared_public_config") { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 68 | defines = [ "${invoker.DEFINE_PREFIX}_SHARED_LIBRARY" ] |
| 69 | |
| 70 | # Executable needs an rpath to find our shared libraries on OSX and Linux |
| 71 | if (is_mac) { |
| 72 | ldflags = [ |
| 73 | "-rpath", |
| 74 | "@executable_path/", |
| 75 | ] |
| 76 | } |
Hidehiko Abe | 948b3a0 | 2020-09-11 02:24:16 +0000 | [diff] [blame] | 77 | if ((is_linux || is_chromeos) && dawn_has_build) { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 78 | configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] |
| 79 | } |
| 80 | } |
| 81 | |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 82 | shared_library("${prefix}shared") { |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 83 | # The "tool" for creating shared libraries will automatically add the "lib" prefix |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 84 | output_name = "dawn_${name}" |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 85 | |
| 86 | # Copy all variables except "configs", which has a default value |
| 87 | forward_variables_from(invoker, "*", [ "configs" ]) |
| 88 | if (defined(invoker.configs)) { |
| 89 | configs += invoker.configs |
| 90 | } |
| 91 | |
| 92 | # Tell dependents where to find this shared library |
| 93 | if (is_mac) { |
| 94 | ldflags = [ |
| 95 | "-install_name", |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 96 | "@rpath/lib${name}.dylib", |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 97 | ] |
| 98 | } |
| 99 | |
| 100 | # Use the config that makes the ${DEFINE_PREFIX}_EXPORT macro do something |
| 101 | if (!defined(public_configs)) { |
| 102 | public_configs = [] |
| 103 | } |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 104 | public_configs += [ ":${prefix}shared_public_config" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 105 | |
| 106 | # Tell sources of this library to export the symbols (and not import) |
| 107 | if (!defined(defines)) { |
| 108 | defines = [] |
| 109 | } |
| 110 | defines += [ "${invoker.DEFINE_PREFIX}_IMPLEMENTATION" ] |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 111 | |
| 112 | # Chromium adds a config that uses a special linker script that removes |
| 113 | # all symbols except JNI ones. Remove this config so that our |
| 114 | # shared_library symbols are visible. This matches what Chromium's |
| 115 | # component template does. |
| 116 | if (build_with_chromium && is_android) { |
| 117 | configs -= [ "//build/config/android:hide_all_but_jni_onload" ] |
| 118 | } |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 121 | static_library("${prefix}static") { |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 122 | output_name = "dawn_${name}_static" |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 123 | |
| 124 | complete_static_lib = dawn_complete_static_libs |
| 125 | |
| 126 | # Copy all variables except "configs", which has a default value |
| 127 | forward_variables_from(invoker, "*", [ "configs" ]) |
| 128 | if (defined(invoker.configs)) { |
| 129 | configs += invoker.configs |
| 130 | } |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 133 | group(name) { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 134 | if (is_component_build) { |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 135 | public_deps = [ ":${prefix}shared" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 136 | } else { |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 137 | public_deps = [ ":${prefix}static" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | } |