blob: f228a42d206d256172f89a855ac483aca8225f78 [file] [log] [blame]
import("{{Repeat "../" .Depth}}../../../tint_overrides_with_defaults.gni")
import("${tint_src_dir}/tint.gni")
{{- if or ($.Project.Target $ "test") ($.Project.Target $ "test_cmd")}}
{{/* newline */}}
if (tint_build_unittests) {
import("//testing/test.gni")
}
{{- end}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "lib")}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "cmd")}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test")}}
{{- Eval "TargetIfNotEmpty" ($.Project.Target $ "test_cmd")}}
{{- /*
--------------------------------------------------------------------------------
-- Emits a GN source set if it contains any files
--------------------------------------------------------------------------------
*/ -}}
{{- define "TargetIfNotEmpty"}}
{{- if $}}
{{- if len $.SourceFiles}}{{Eval "Target" $}}{{end}}
{{- end}}
{{- end}}
{{- /*
--------------------------------------------------------------------------------
-- Emits a GN source set
--------------------------------------------------------------------------------
*/ -}}
{{- define "Target"}}
{{- if Contains (print $.Kind) "test"}}
if (tint_build_unittests) {
{{- end}}
{{- /* Target condition */}}
{{- if $.Condition}}
if({{$.Condition}}) {
{{- end}}
{{ if $.Kind.IsLib -}}
libtint_source_set("{{$.Directory.Name}}") {
{{- else if $.Kind.IsCmd -}}
executable("{{$.Directory.Name}}") {
{{- else if $.Kind.IsTest -}}
tint_unittests_source_set("unittests") {
testonly = true
{{- else if $.Kind.IsTestCmd -}}
test("{{$.Directory.Name}}") {
{{- else }}{{Error $.Kind}}
{{- end }}
{{- if $.OutputName }}
output_name = "{{$.OutputName}}"
{{- end}}
sources = [
{{- range $File := $.UnconditionalSourceFiles}}
"{{TrimPrefix $File.Name $.Directory.Path}}",
{{- end}}
]
deps = [
{{- /* Emit unconditional inernal dependencies */}}
{{- range $Dep := $.Dependencies.UnconditionalInternal}}
"{{Eval "Dependency" $Dep}}",
{{- end}}
{{- /* Emit unconditional external dependencies */}}
{{- range $Dep := $.Dependencies.UnconditionalExternal}}
{{Eval "ExternalDependencyTargets" $Dep}}
{{- end}}
]
{{- /* Emit conditional source files and dependencies */}}
{{- range $Cond := $.Conditionals}}
{{/* newline */}}
if ({{$Cond.Condition}}) {
{{- if $Cond.SourceFiles}}
sources += [
{{- range $File := $Cond.SourceFiles}}
"{{TrimPrefix $File.Name $.Directory.Path}}",
{{- end}}
]
{{- end}}
{{- if or $Cond.InternalDependencies $Cond.ExternalDependencies}}
deps += [
{{- range $Dep := $Cond.InternalDependencies}}
"{{Eval "Dependency" $Dep}}",
{{- end}}
{{- range $Dep := $Cond.ExternalDependencies}}
{{Eval "ExternalDependencyTargets" $Dep}}
{{- end}}
]
{{- end}}
}
{{- end}}
{{- if $.Dependencies.ContainsExternal "spirv-opt-internal"}}
public_configs = [ "${tint_spirv_tools_dir}/:spvtools_internal_config" ]
{{- end}}
{{- if $.Kind.IsTestCmd }}
testonly = true
configs += [ "${tint_src_dir}:tint_unittests_config" ]
if (build_with_chromium) {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
{{- end}}
}
{{- /* Target condition */}}
{{- if $.Condition}}}{{end}}
{{- /* if(tint_build_unittests) */}}
{{- if $.Kind.IsTestOrTestCmd}}}{{end}}
{{- end}}
{{- /*
--------------------------------------------------------------------------------
-- Emits a dependency target name
--------------------------------------------------------------------------------
*/ -}}
{{- define "Dependency"}}
{{- $Path := printf "${tint_src_dir}/%v" $.Directory.Path}}
{{- if $.Kind.IsLib }}{{$Path}}
{{- else if $.Kind.IsTest }}{{$Path}}:unittests
{{- else }}{{$Path}}:{{$.Kind}}
{{- end}}
{{- end}}
{{- /*
--------------------------------------------------------------------------------
-- Emits comma separated, quoted external dependency target name(s) with a trailing comma
-- External target names are declared in tools/src/cmd/gen/build/externals.json
--------------------------------------------------------------------------------
*/ -}}
{{- define "ExternalDependencyTargets"}}
{{- if eq $.Name "abseil" -}}"${tint_src_dir}:abseil",
{{- else if eq $.Name "gtest" -}}"${tint_src_dir}:gmock_and_gtest",
{{- else if eq $.Name "spirv-tools" -}}"${tint_spirv_tools_dir}:spvtools_headers", "${tint_spirv_tools_dir}:spvtools_val",
{{- else if eq $.Name "spirv-opt-internal" -}}"${tint_spirv_tools_dir}:spvtools", "${tint_spirv_tools_dir}:spvtools_opt",
{{- else if eq $.Name "spirv-headers" -}}"${tint_spirv_headers_dir}:spv_headers",
{{- else if eq $.Name "glslang" -}}"${tint_glslang_dir}:glslang_lib_sources",
{{- else if eq $.Name "glslang-res-limits" -}}"${tint_glslang_dir}:glslang_default_resource_limits_sources",
{{- else -}}{{Error (printf "unhandled external dependency '%v'" $)}}
{{- end}}
{{- end}}