123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- # 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 || is_chromeos),
- "Only Linux X64 MSAN is supported")
- platform_config_root = "config/linux-noasm/$current_cpu"
- } else if (current_cpu == "riscv64") {
- 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 {
- # The compiler flags, as well as the stack alignment values, all mirror
- # upstream's meson.build setup:
- # https://chromium.googlesource.com/external/github.com/videolan/dav1d/+/master/meson.build
- needs_stack_alignment = true
- if (current_cpu == "x86") {
- stack_alignment = 16
- if (!is_clang) {
- # Values used by GCC.
- preferred_stack_boundary = 4
- incoming_stack_boundary = 2
- }
- } else if (current_cpu == "x64") {
- stack_alignment = 32
- if (!is_clang) {
- # Values used by GCC.
- preferred_stack_boundary = 5
- incoming_stack_boundary = 4
- }
- }
- if (is_clang) {
- stackalign_flag = "-mstack-alignment=$stack_alignment"
- stackrealign_flag = "-mstackrealign"
- } else {
- # Assume GCC for now.
- stackalign_flag = "-mpreferred-stack-boundary=$preferred_stack_boundary"
- stackrealign_flag = "-mincoming-stack-boundary=$incoming_stack_boundary"
- }
- }
- } else {
- needs_stack_alignment = false
- }
- config("public_dav1d_config") {
- include_dirs = [ "version" ]
- # 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" ]
- }
- if (!is_android && !is_win) {
- defines += [ "HAVE_PTHREAD_GETAFFINITY_NP=1" ]
- }
- # 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=" ]
- }
- config("dav1d_config") {
- configs = [ ":public_dav1d_config" ]
- include_dirs = [
- "libdav1d",
- "libdav1d/include",
- "libdav1d/include/dav1d",
- platform_config_root,
- ]
- if (is_win && !is_clang) {
- include_dirs += [ "libdav1d/include/compat/msvc" ]
- }
- }
- dav1d_copts = [
- "-D_FILE_OFFSET_BITS=64",
- "-D_POSIX_C_SOURCE=200112L",
- ]
- if (is_win) {
- if (!is_clang) {
- dav1d_copts += [ "/wd4028" ]
- }
- } else {
- dav1d_copts += [ "-std=c99" ]
- if (needs_stack_alignment) {
- dav1d_copts += [ stackalign_flag ]
- }
- if (is_mac || is_ios) {
- dav1d_copts += [ "-D_DARWIN_C_SOURCE" ]
- }
- if (is_linux || is_chromeos || is_android || current_os == "aix") {
- if (!is_clang) {
- dav1d_copts += [ "-D_GNU_SOURCE" ]
- }
- }
- }
- 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),
- ]
- defines = []
- if (needs_stack_alignment) {
- defines += [ "STACK_ALIGNMENT=$stack_alignment" ]
- }
- # Necessary to ensure macOS symbols end up with a _ prefix.
- if (is_mac || is_ios) {
- defines += [ "PREFIX" ]
- }
- }
- }
- source_set("dav1d_headers") {
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":dav1d_config",
- ]
- sources = c_headers
- }
- static_library("dav1d_entrypoints") {
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":dav1d_config",
- ]
- sources = entry_point_sources
- cflags = dav1d_copts
- if (is_win) {
- sources += [ "libdav1d/src/win32/thread.c" ]
- }
- if (needs_stack_alignment) {
- cflags += [ stackrealign_flag ]
- }
- deps = [ ":dav1d_headers" ]
- }
- 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
- } else if (current_cpu == "arm64") {
- sources += arm_template_sources
- } else if (current_cpu == "ppc64") {
- sources += ppc64_template_sources
- }
- cflags = dav1d_copts
- cflags += [ "-DBITDEPTH=8" ]
- deps = [ ":dav1d_headers" ]
- }
- static_library("dav1d_10bit") {
- configs -= [
- "//build/config/compiler:chromium_code",
- # Disable coverage for the 10 bit version to avoid confusing the
- # instrumentation about which version of the library is being run.
- # dav1d_10 bit was selected for this, as it's less used than dav1d_8bit,
- # which still has coverage enabled. See crbug.com/1030350.
- "//build/config/coverage:default_coverage",
- ]
- 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
- } else if (current_cpu == "arm64") {
- sources += arm_template_sources
- } else if (current_cpu == "ppc64") {
- sources += ppc64_template_sources
- }
- cflags = dav1d_copts
- cflags += [ "-DBITDEPTH=16" ]
- deps = [ ":dav1d_headers" ]
- }
- if (current_cpu == "x86" || current_cpu == "x64") {
- static_library("dav1d_x86") {
- sources = [
- "libdav1d/src/x86/cpu.c",
- "libdav1d/src/x86/cpu.h",
- "libdav1d/src/x86/refmvs_init.c",
- ]
- # x86/msac.h redefines macros in msac.h if x86/msac.h is included and
- # HAVE_ASM is 0, so we must exclude msac_init.c if !enable_nasm. Also, it
- # is only used for x64.
- if (enable_nasm && current_cpu == "x64") {
- sources += [ "libdav1d/src/x86/msac_init.c" ]
- }
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":dav1d_config",
- ]
- cflags = dav1d_copts
- deps = [ ":dav1d_headers" ]
- allow_circular_includes_from = [ ":dav1d_headers" ]
- }
- } else if (current_cpu == "arm" || current_cpu == "arm64") {
- static_library("dav1d_arm") {
- sources = [
- "libdav1d/src/arm/cpu.c",
- "libdav1d/src/arm/cpu.h",
- "libdav1d/src/arm/refmvs_init.c",
- ]
- # These are not template based so should only be built once.
- if (current_cpu == "arm") {
- sources += arm32_asm_sources
- } else if (current_cpu == "arm64") {
- sources += arm64_asm_sources
- }
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":dav1d_config",
- ]
- # Necessary to ensure macOS symbols end up with a _ prefix.
- if (is_mac || is_ios) {
- defines = [ "PREFIX" ]
- }
- cflags = dav1d_copts
- deps = [ ":dav1d_headers" ]
- allow_circular_includes_from = [ ":dav1d_headers" ]
- }
- } else if (current_cpu == "ppc64") {
- static_library("dav1d_ppc64") {
- sources = [
- "libdav1d/src/ppc/cpu.c",
- "libdav1d/src/ppc/cpu.h",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":dav1d_config",
- ]
- cflags = dav1d_copts
- deps = [ ":dav1d_headers" ]
- allow_circular_includes_from = [ ":dav1d_headers" ]
- }
- }
- 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",
- ":dav1d_headers",
- ]
- public_configs = [ ":public_dav1d_config" ]
- 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" ]
- } else if (current_cpu == "ppc64") {
- deps += [ ":dav1d_ppc64" ]
- }
- }
|