mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
BUILD.gn: Split dawn_component/generator in their own files
This will allow follow up commits to use them from the different parts of the split-off BUILD.gn file. BUG=dawn:61 Change-Id: I767f6c97c06ee73290d3df482880d1a2df92e187 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5301 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
1cc386687c
commit
abc753c9c9
123
scripts/dawn_component.gni
Normal file
123
scripts/dawn_component.gni
Normal file
@@ -0,0 +1,123 @@
|
||||
# Copyright 2019 The Dawn Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("dawn_overrides_with_defaults.gni")
|
||||
import("dawn_features.gni")
|
||||
|
||||
###############################################################################
|
||||
# Template to produce a component for one of Dawn's libraries.
|
||||
###############################################################################
|
||||
|
||||
# Template that produces static and shared versions of the same library as well
|
||||
# as a target similar to Chromium's component targets.
|
||||
# - The shared version exports symbols and has dependent import the symbols
|
||||
# as libname.so with target name libname_shared
|
||||
# - The static library doesn't export symbols nor make dependents import them
|
||||
# - The libname target is similar to a Chromium component and is an alias for
|
||||
# either the static or the shared library.
|
||||
#
|
||||
# The DEFINE_PREFIX must be provided and must match the respective "_export.h"
|
||||
# file.
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# dawn_component("my_library") {
|
||||
# // my_library_export.h must use the MY_LIBRARY_IMPLEMENTATION and
|
||||
# // MY_LIBRARY_SHARED_LIBRARY macros.
|
||||
# DEFINE_PREFIX = "MY_LIBRARY"
|
||||
#
|
||||
# sources = [...]
|
||||
# deps = [...]
|
||||
# configs = [...]
|
||||
# }
|
||||
#
|
||||
# executable("foo") {
|
||||
# deps = [ ":my_library_shared" ] // or :my_library for the same effect
|
||||
# }
|
||||
template("dawn_component") {
|
||||
# Copy the target_name in the local scope so it doesn't get shadowed in the
|
||||
# definition of targets.
|
||||
libname = target_name
|
||||
|
||||
# The config that will apply to dependents of the shared library so they know
|
||||
# they should "import" the symbols
|
||||
config("${libname}_shared_public_config") {
|
||||
defines = [ "${invoker.DEFINE_PREFIX}_SHARED_LIBRARY" ]
|
||||
|
||||
# Executable needs an rpath to find our shared libraries on OSX and Linux
|
||||
if (is_mac) {
|
||||
ldflags = [
|
||||
"-rpath",
|
||||
"@executable_path/",
|
||||
]
|
||||
}
|
||||
if (is_linux) {
|
||||
configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
|
||||
}
|
||||
}
|
||||
|
||||
shared_library("${libname}_shared") {
|
||||
output_name = libname
|
||||
|
||||
# Copy all variables except "configs", which has a default value
|
||||
forward_variables_from(invoker, "*", [ "configs" ])
|
||||
if (defined(invoker.configs)) {
|
||||
configs += invoker.configs
|
||||
}
|
||||
|
||||
# Tell dependents where to find this shared library
|
||||
if (is_mac) {
|
||||
ldflags = [
|
||||
"-install_name",
|
||||
"@rpath/${libname}.dylib",
|
||||
]
|
||||
}
|
||||
|
||||
# Use the config that makes the ${DEFINE_PREFIX}_EXPORT macro do something
|
||||
if (!defined(public_configs)) {
|
||||
public_configs = []
|
||||
}
|
||||
public_configs += [ ":${libname}_shared_public_config" ]
|
||||
|
||||
# Tell sources of this library to export the symbols (and not import)
|
||||
if (!defined(defines)) {
|
||||
defines = []
|
||||
}
|
||||
defines += [ "${invoker.DEFINE_PREFIX}_IMPLEMENTATION" ]
|
||||
}
|
||||
|
||||
static_library("${libname}_static") {
|
||||
output_name = libname
|
||||
|
||||
complete_static_lib = dawn_complete_static_libs
|
||||
|
||||
# Copy all variables except "configs", which has a default value
|
||||
forward_variables_from(invoker, "*", [ "configs" ])
|
||||
if (defined(invoker.configs)) {
|
||||
configs += invoker.configs
|
||||
}
|
||||
}
|
||||
|
||||
group(libname) {
|
||||
if (is_component_build) {
|
||||
public_deps = [
|
||||
":${libname}_shared",
|
||||
]
|
||||
} else {
|
||||
public_deps = [
|
||||
":${libname}_static",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user