blob: aedc658c30c4a5627e0bef435c318e4c83623d4b [file] [log] [blame]
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("dav1d_generated.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//third_party/nasm/nasm_assemble.gni")
# MemorySanitizer can't handle assembly, https://crbug.com/928357.
enable_nasm = (current_cpu == "x86" || current_cpu == "x64") && !is_msan
if (is_win) {
platform_config_root = "config/win/$current_cpu"
} else if (is_msan) {
assert(current_cpu == "x64" && is_linux, "Only Linux X64 MSAN is supported")
platform_config_root = "config/linux-noasm/$current_cpu"
} else {
# Linux configuration files seem to work on Mac, so just reuse them.
platform_config_root = "config/linux/$current_cpu"
}
# Clang LTO doesn't respect stack alignment and clang-cl doesn't support setting
# the stack alignment, so we must use the platform's default alignment in those
# cases; https://crbug.com/928743.
if (current_cpu == "x86" || current_cpu == "x64") {
if (use_thin_lto || is_win) {
needs_stack_alignment = false
# The defaults are stack_alignment=4 for x86 and stack_alignment=16 for x64.
} else {
needs_stack_alignment = true
if (current_cpu == "x86") {
stack_alignment = 16
} else if (current_cpu == "x64") {
stack_alignment = 32
}
}
} else {
needs_stack_alignment = false
}
config("dav1d_config") {
include_dirs = [
"version",
"libdav1d",
"libdav1d/include",
"libdav1d/include/dav1d",
platform_config_root,
]
# Disable internal dav1d logs in the official build to save storage.
if (is_official_build) {
defines = [ "CONFIG_LOG=0" ]
} else {
defines = [ "CONFIG_LOG=1" ]
}
if (needs_stack_alignment) {
defines += [ "STACK_ALIGNMENT=$stack_alignment" ]
}
# Don't let dav1d export any symbols. Otherwise the verify_order step on macOS
# can fail since these exports end up in the final Chromium binary.
defines += [ "DAV1D_API=" ]
}
dav1d_copts = [
"-D_FILE_OFFSET_BITS=64",
"-D_POSIX_C_SOURCE=200112L",
]
if (!is_win) {
dav1d_copts += [ "-std=c99" ]
if (needs_stack_alignment) {
dav1d_copts += [ "-mstack-alignment=$stack_alignment" ]
}
}
if (enable_nasm) {
nasm_assemble("dav1d_asm") {
sources = x86_asm_sources
inputs = [
"libdav1d/src/ext/x86/x86inc.asm",
"$platform_config_root/config.asm",
]
include_dirs = [
"libdav1d/src/",
platform_config_root,
]
nasm_flags = [
"-P",
rebase_path("$platform_config_root/config.asm", root_build_dir),
]
if (needs_stack_alignment) {
defines = [ "STACK_ALIGNMENT=$stack_alignment" ]
}
# Necessary to ensure macOS symbols end up with a _ prefix.
if (is_mac) {
defines += [ "PREFIX" ]
}
}
}
static_library("dav1d_entrypoints") {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
sources = entry_point_sources
# TODO(dalecurtis): Fix arm compiler options...
cflags = dav1d_copts
if (is_win) {
sources += [ "libdav1d/src/win32/thread.c" ]
}
if (needs_stack_alignment) {
cflags += [ "-mstackrealign" ]
}
}
static_library("dav1d_8bit") {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
sources = template_sources
if (current_cpu == "x86" || current_cpu == "x64") {
sources += x86_template_sources
} else if (current_cpu == "arm") {
sources += arm_template_sources + arm32_asm_sources
} else if (current_cpu == "arm64") {
sources += arm_template_sources + arm64_asm_sources
}
# TODO(dalecurtis): Fix arm compiler options...
cflags = dav1d_copts
cflags += [ "-DBITDEPTH=8" ]
}
static_library("dav1d_10bit") {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
sources = template_sources
if (current_cpu == "x86" || current_cpu == "x64") {
sources += x86_template_sources
} else if (current_cpu == "arm") {
sources += arm_template_sources + arm32_asm_sources
} else if (current_cpu == "arm64") {
sources += arm_template_sources + arm64_asm_sources
}
# TODO(dalecurtis): Fix arm compiler options...
cflags = dav1d_copts
cflags += [ "-DBITDEPTH=16" ]
}
if (current_cpu == "x86" || current_cpu == "x64") {
static_library("dav1d_x86") {
sources = [
"libdav1d/src/x86/cpu.c",
"libdav1d/src/x86/cpu.h",
]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
cflags = dav1d_copts
}
} else if (current_cpu == "arm" || current_cpu == "arm64") {
static_library("dav1d_arm") {
sources = [
"libdav1d/src/arm/cpu.c",
"libdav1d/src/arm/cpu.h",
]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
# TODO(dalecurtis): Fix arm compiler options...
cflags = dav1d_copts
}
}
static_library("dav1d") {
sources = c_sources
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":dav1d_config",
]
cflags = dav1d_copts
deps = [
":dav1d_10bit",
":dav1d_8bit",
":dav1d_entrypoints",
]
if (current_cpu == "x86" || current_cpu == "x64") {
deps += [ ":dav1d_x86" ]
if (enable_nasm) {
deps += [ ":dav1d_asm" ]
}
} else if (current_cpu == "arm" || current_cpu == "arm64") {
deps += [ ":dav1d_arm" ]
}
}