blob: a7d1404816d3bc97c422095b9aed1c71e1b2c4ec [file] [log] [blame]
# Copyright 2017 The Fuchsia 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("ffmpeg_options.gni")
import("ffmpeg_generated.gni")
# Path to configuration files.
ffmpeg_config_root = "fuchsia/config/$ffmpeg_profile/$current_cpu"
has_yasm_deps = ffmpeg_yasm_sources != [] && current_cpu == "x64"
if (has_yasm_deps) {
import("//third_party/yasm/yasm_assemble.gni")
yasm_assemble("ffmpeg_yasm") {
sources = ffmpeg_yasm_sources
# Ensure the architecture defines go in the command line before the -P
# file below, so don't use defines.
yasm_flags = []
if (current_cpu == "x86") {
yasm_flags += [ "-DARCH_X86_32" ]
} else if (current_cpu == "x64") {
yasm_flags += [ "-DARCH_X86_64" ]
}
inputs = [
# Sets visibility hidden for cglobal functions. Explicitly included
# to avoid overlooking changes to this file in incremental builds.
"libavutil/x86/x86inc.asm",
]
defines = [ "PIC" ]
include_dirs = [
ffmpeg_config_root,
"libavcodec/x86",
"libavutil/x86",
".",
]
# Disable warnings, prevents log spam for things we won't fix.
yasm_flags += [
"-w",
"-P",
rebase_path("$ffmpeg_config_root/config.asm", root_build_dir),
]
if (is_mac) {
# Necessary to ensure symbols end up with a _ prefix; added by
# yasm_assemble.gni for Windows, but not Mac.
defines += [ "PREFIX" ]
}
}
}
config("ffmpeg_dependent_config") {
include_dirs = [
ffmpeg_config_root,
".",
]
}
# gn orders flags on a target before flags from configs. The default config
# adds -Wall, and these flags have to be after -Wall -- so they need to come
# from a config and can't be on the target directly.
config("ffmpegsumo_warnings") {
cflags = [
"-Wno-absolute-value",
# ffmpeg uses its own deprecated functions.
"-Wno-deprecated-declarations",
# ffmpeg doesn't care about pointer constness.
"-Wno-incompatible-pointer-types",
# ffmpeg doesn't follow usual parentheses conventions.
"-Wno-logical-op-parentheses",
# ffmpeg doesn't care about pointer signedness.
"-Wno-parentheses",
# ffmpeg doesn't care about pointer signedness.
"-Wno-pointer-sign",
# ffmpeg doesn't believe in exhaustive switch statements.
"-Wno-switch",
# matroskadec.c has a "failed:" label that's only used if some
# CONFIG_ flags we don't set are set.
"-Wno-unused-label",
# ffmpeg has a lot of unused variables.
"-Wno-unused-variable",
# This fires on `av_assert0(!"valid element size")` in utils.c
"-Wno-string-conversion",
# This fires on `pos_min` and `pos_max` in
# autorename_libavformat_utils.c
"-Wno-sometimes-uninitialized",
# ffmpeg contains static functions in header files, which lead
# to unused function warnings. There are a few legit unused
# functions too.
"-Wno-unused-function",
# vp3data.h's vp31_inter_dequant stores '128' in an int8_t array.
"-Wno-constant-conversion",
"-Wno-string-plus-int",
# ffmpeg compares ints and floats.
"-Wno-implicit-int-float-conversion",
# fmmpeg may have questionable indentation. We should come back later
# to confirm if this indentation is expected.
"-Wno-misleading-indentation",
]
}
config("ffmpeg_warnings") {
cflags = [
"-Wno-sign-compare",
"-Wno-missing-field-initializers",
"-Wno-pointer-bool-conversion",
"-Wno-implicit-int-float-conversion",
"-Wno-string-plus-int",
"-Wno-misleading-indentation",
]
}
shared_library("ffmpeg") {
sources = ffmpeg_c_sources + ffmpeg_gas_sources + [
"$ffmpeg_config_root/config.h",
"$ffmpeg_config_root/libavutil/avconfig.h",
]
public_configs = [ ":ffmpeg_dependent_config" ]
defines = [
"HAVE_AV_CONFIG_H",
"_POSIX_C_SOURCE=200112",
"_XOPEN_SOURCE=600",
"PIC",
# Disable deprecated features that generate spammy warnings.
"FF_API_CONVERGENCE_DURATION=0",
# Upstream libavcodec/utils.c still uses the deprecated
# av_dup_packet(), avcodec_encode_{audio,video}2(), and
# libavformat/utils.c still accesses the deprecated AVStream.codec,
# causing deprecation warnings.
# The normal fix for such things is to disable the features like setting
# "FF_API_AVPACKET_OLD_API=0", but the upstream code does not yet compile
# with it disabled (in the case of av_dup_packet()), and has no FF_API*
# gate for avcodec_encode_{audio,video}2() or AVStream.codec. In the
# meantime, we directly disable those warnings locally in the C files.
]
# So we can append below and assume they're defined.
cflags = []
ldflags = []
libs = []
deps = [
"//third_party/opus",
]
configs += [
":ffmpeg_warnings",
":ffmpegsumo_warnings",
]
# Since we are not often debugging FFmpeg, and performance is
# unacceptable without optimization, freeze the optimizations to -O2.
# If someone really wants -O1 , they can change these in their checkout.
# If you want -O0, see the Gotchas in README.fuchsia for why that
# won't work.
#
# In addition to the above reasons, /Od optimization won't remove symbols
# that are under "if (0)" style sections. Which lead to link time errors
# when for example it tries to link an ARM symbol on X86.
if (is_debug) {
configs -= [ "//build/config:debug" ]
configs += [ "//build/config:release" ]
}
# Make all symbols visible.
configs -= [ "//build/config:symbol_visibility_hidden" ]
cflags += [
# ffmpeg uses its own deprecated functions.
"-Wno-deprecated-declarations",
]
if (current_cpu == "arm64") {
asmflags = []
if (arm_float_abi == "hard") {
asmflags += [ "-DHAVE_VFP_ARGS=1" ]
} else {
asmflags += [ "-DHAVE_VFP_ARGS=0" ]
}
}
defines += [
"_ISOC99_SOURCE",
"_LARGEFILE_SOURCE",
]
cflags += [
"-std=c99",
"-pthread",
"-fno-math-errno",
"-fno-signed-zeros",
"-fno-tree-vectorize",
"-fomit-frame-pointer",
]
ldflags = [
# Avoid PIC relocation errors from assembly code.
"-Wl,-Bsymbolic",
"-L",
rebase_path(target_gen_dir, root_build_dir),
]
if (has_yasm_deps) {
deps += [ ":ffmpeg_yasm" ]
}
# TODO(46940): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
configs += [ "//build/config:temporarily_disable_ubsan_do_not_use" ]
}
group("ffmpeg_variants") {
deps = []
foreach(variant, select_variant) {
deps += [ ":ffmpeg(${toolchain_variant.base}-${variant}-shared)" ]
}
}