1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("ffmpeg_options.gni")
6 import("ffmpeg_generated.gni")
8 # Path to platform configuration files.
10 "chromium/config/$ffmpeg_branding/$os_config/$ffmpeg_arch"
12 # Stub generator script and signatures of all functions used by Chrome.
13 generate_stubs_script = "//tools/generate_stubs/generate_stubs.py"
15 # Used by ffmpeg_generate_stubs and ffmpeg_generate_def
16 sig_files = [ "chromium/ffmpegsumo.sigs" ]
18 # TODO(ajwong): Should be in ffmpeg_generate_stubs if we could grab the
19 # outputs of an action via a function.
20 stubs_filename_root = "ffmpeg_stubs"
22 if (cpu_arch != "arm" && os_config != "linux-noasm") {
23 import("//third_party/yasm/yasm_assemble.gni")
24 yasm_assemble("ffmpeg_yasm") {
25 sources = ffmpeg_yasm_sources
27 # Ensure the architecture defines go in the command line before the -P
28 # file below, so don't use defines.
30 if (cpu_arch == "x86") {
31 yasm_flags += [ "-DARCH_X86_32" ]
32 } else if (cpu_arch == "x64") {
33 yasm_flags += [ "-DARCH_X86_64" ]
44 # Disable warnings, prevents log spam for things we won't fix.
47 "-P", rebase_path("$platform_config_root/config.asm", root_build_dir),
51 # Necessary to ensure symbols end up with a _ prefix; added by
52 # yasm_compile.gypi for Windows, but not Mac.
53 defines += [ "PREFIX" ]
58 # FFMpeg is dynamically loaded on all platforms but our code calls it
59 # as if it were directly linked. To make this work, the build system needs
60 # to generate stubs that indirect into the library calls.
62 # On Windows, this script calls the windows stub generator. Otherwise, assume
63 # this is a POSIX platform and generate our own wrapper stubs.
64 action("ffmpeg_generate_stubs") {
65 extra_header = "chromium/ffmpeg_stub_headers.fragment"
67 script = generate_stubs_script
69 inputs = [ extra_header ]
72 if (build_cpu_arch == "x64") {
73 outfile_type = "windows_lib_x64"
75 outfile_type = "windows_lib"
78 # TODO(ajwong): these need to be in the ffmpeg build.
80 "$target_gen_dir/$stubs_filename_root.lib",
84 # TODO(ajwong): In gyp, this uses different directories for the
85 # windows build. We should think this through.
86 "-i", rebase_path(target_gen_dir, root_build_dir),
87 "-o", rebase_path(target_gen_dir, root_build_dir),
91 # If it's not windows, clearly it must be posix.
93 # TODO(ajwong): these need to be included in the ffmpeg build.
95 "$target_gen_dir/$stubs_filename_root.cc",
96 "$target_gen_dir/$stubs_filename_root.h",
99 # TODO(ajwong): IN gyp, this used to output the .h file into a shared
100 # directory that other targets could reference. The .cc ends up in a
101 # special generated directory that gyp would guaranteed that no one else
102 # could look at. Now we're dumping both into the generated directory.
103 # Verify what the best + simplest behavior is here and use that.
104 "-i", rebase_path(target_gen_dir, root_build_dir),
105 "-o", rebase_path(target_gen_dir, root_build_dir),
107 "-e", rebase_path(extra_header, root_build_dir),
108 "-s", stubs_filename_root,
109 "-p", "third_party/ffmpeg",
113 args += rebase_path(sources, root_build_dir)
116 if (build_ffmpegsumo) {
117 shared_library("ffmpegsumo") {
118 # TODO(gyp): Add version number to dll.
119 sources = ffmpeg_c_sources + ffmpeg_gas_sources + [
120 "$platform_config_root/config.h",
121 "$platform_config_root/libavutil/avconfig.h",
124 platform_config_root,
129 "_POSIX_C_SOURCE=200112",
132 # Disable deprecated features which generate spammy warnings.
133 "FF_API_PIX_FMT_DESC=0",
134 "FF_API_OLD_DECODE_AUDIO=0",
135 "FF_API_DESTRUCT_PACKET=0",
136 "FF_API_GET_BUFFER=0",
139 # So we can append below and assume they're defined.
145 configs -= [ "//build/config/compiler:chromium_code" ]
146 configs += [ "//build/config/compiler:no_chromium_code" ]
148 # Since we are not often debugging FFmpeg, and performance is
149 # unacceptable without optimization, freeze the optimizations to -O2.
150 # If someone really wants -O1 , they can change these in their checkout.
151 # If you want -O0, see the Gotchas in README.Chromium for why that
154 # In addition to the above reasons, /Od optimization won't remove symbols
155 # that are under "if (0)" style sections. Which lead to link time errors
156 # when for example it tries to link an ARM symbol on X86.
158 configs -= [ "//build/config/compiler:no_optimize" ]
160 configs -= [ "//build/config/compiler:optimize" ]
163 # Setting the optimizations to 'speed' or to 'max' on Windows results in
164 # a lot of unresolved symbols. The only supported mode is 'size' (see
166 configs += [ "//build/config/compiler:optimize" ]
168 configs += [ "//build/config/compiler:optimize_max" ]
174 "-fomit-frame-pointer",
175 # ffmpeg uses its own deprecated functions.
176 "-Wno-deprecated-declarations",
181 "-Wno-absolute-value",
182 "-Wno-incompatible-pointer-types",
183 "-Wno-logical-op-parentheses",
189 # gcc doesn't have flags for specific warnings, so disable them
193 if (cpu_arch == "x86") {
194 # Turn off valgrind build option that breaks ffmpeg builds.
195 # TODO(ajwong): The gyp file had special removals for
196 # debug_extra_cflags and release_extra_cflags. Do we care?
197 #cflags -= [ "-fno-omit-frame-pointer" ]
198 } else if (cpu_arch == "arm") {
199 # TODO(ihf): See the long comment in build_ffmpeg.sh
200 # We want to be consistent with CrOS and have configured
201 # ffmpeg for thumb. Protect yourself from -marm.
203 cflags += [ "-marm" ]
211 if (arm_float_abi == "hard") {
212 cflags += [ "-DHAVE_VFP_ARGS=1" ]
214 cflags += [ "-DHAVE_VFP_ARGS=0" ]
216 } else if (cpu_arch == "mipsel") {
224 if (is_posix && !is_mac) {
228 # BUG(ihf): ffmpeg compiles with this define. But according to
229 # ajwong: I wouldn't change _FILE_OFFSET_BITS. That's a scary change
230 # cause it affects the default length of off_t, and fpos_t,
231 # which can cause strange problems if the loading code doesn't
232 # have it set and you start passing FILE*s or file descriptors
233 # between symbol contexts.
234 # "_FILE_OFFSET_BITS=64",
241 "-fno-tree-vectorize",
242 "-fomit-frame-pointer",
244 # Ensure the symbols are exported.
246 # TODO(ajwong): Manually tag the API that we use to be
248 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
251 "-L", rebase_path(target_gen_dir, root_build_dir),
254 # TODO(ajwong): How to handle openbsd? Especially w/o the is_posix?
256 # # OpenBSD's gcc (4.2.1) does not support this flag
257 # cflags -= [ "-fno-signed-zeros" ]
261 defines += [ "_DARWIN_C_SOURCE" ]
263 # TODO(ajwong): What does this do in mac? There isn't anything in ffmpeg.gyp that
265 # ['mac_breakpad == 1', {
267 # # A real .dSYM is needed for dump_syms to operate on.
268 # 'mac_real_dsym': 1,
271 if (cpu_arch != "x64") {
272 # This is needed because even though FFmpeg now builds
273 # with -fPIC, it's not quite a complete PIC build, only
274 # partial :( Thus we need to instruct the linker to allow
275 # relocations for read-only segments for this target to be
276 # able to generated the shared library on Mac.
278 #TODO(ajwong): Check if this can be cpu_arch == "x86"
279 # Note -read_only_relocs cannot be used in x86_64
281 # This makes Mark sad, but he's okay with it since it is
282 # isolated to this module. When Mark finds this in the
283 # future, and has forgotten this conversation, this
284 # comment should remind him that the world is still nice
285 # and butterflies still exist...as do rainbows, sunshine,
286 # tulips, etc., etc...but not kittens. Those went away
289 "-Wl,-read_only_relocs,suppress",
292 # TODO(ajwong): How to handle SDKROOT?
294 # '$(SDKROOT)/usr/lib/libz.dylib',
296 # Ensure the symbols are exported.
298 # TODO(ajwong): Manually tag the API that we use to be exported.
300 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
302 # TODO(ajwong): How to handle @loader_path?
303 # 'xcode_settings': {
304 # 'DYLIB_INSTALL_NAME_BASE': '@loader_path',
306 lib_dirs = [ target_gen_dir ]
314 "strtod=avpriv_strtod",
315 "snprintf=avpriv_snprintf",
316 "_snprintf=avpriv_snprintf",
317 "vsnprintf=avpriv_vsnprintf",
321 "chromium/include/win"
323 # TODO(dalecurtis): We should fix these. http://crbug.com/154421
325 "/wd4996", # 'function': was declared deprecated
326 "/wd4018", # 'expression': signed/unsigned mismatch
327 "/wd4090", # 'operation' : different 'modifier' qualifiers
328 "/wd4305", # 'identifier': truncation from 'type1' to 'type2'
329 "/wd4133", # 'type' : incompatible types - from 'type1' to 'type2'
330 "/wd4146", # unary minus operator applied to unsigned type, result
332 "/wd4554", # 'operator' : check operator precedence for possible
333 # error; use parentheses to clarify precedence
334 "/wd4028", # formal parameter 'number' different from declaration
335 "/wd4334", # 'operator' : result of 32-bit shift implicitly
336 # converted to 64 bits (was 64-bit shift intended?)
337 "/wd4101", # 'identifier' : unreferenced local variable
338 "/wd4102", # 'label' : unreferenced label
339 "/wd4116", # unnamed type definition in parentheses
340 "/wd4307", # 'operator' : integral constant overflow
341 "/wd4273", # 'function' : inconsistent DLL linkage
342 "/wd4005", # 'identifier' : macro redefinition
343 "/wd4056", # overflow in floating point constant arithmetic
344 "/wd4756", # overflow in constant arithmetic
346 # TODO(ajwong): Verify this is true.
347 # Ignore warnings about a local symbol being inefficiently imported,
348 # upstream is working on a fix.
350 "/ignore:4049", # locally defined symbol 'symbol' imported
351 "/ignore:4217", # locally defined symbol 'symbol' imported in
352 # function 'function'
354 if (cpu_arch == "x64") {
355 # TODO(wolenetz): We should fix this. http://crbug.com/171009
357 "/wd4267" # Conversion from size_t to 'type'.
360 deps += [ ":ffmpeg_generate_def" ]
363 if (cpu_arch != "arm" && cpu_arch != "mipsel" && os_config != "linux-noasm") {
364 deps += [ ":ffmpeg_yasm" ]
370 config("ffmpeg_win_dependent_config") {
372 platform_config_root,
373 "chromium/include/win",
376 libs = [ "$target_out_dir/ffmpegsumo.lib" ]
377 ldflags = [ "/DELAYLOAD:ffmpegsumo.dll" ]
380 action("ffmpeg_generate_def") {
381 script = generate_stubs_script
383 outputs = [ "$target_gen_dir/ffmpegsumo.def" ]
385 # TODO(ajwong): This was -i <(INTERMEDIATE_DIR). What next?
386 "-i", rebase_path(target_out_dir, root_build_dir),
387 "-o", rebase_path(target_gen_dir, root_build_dir),
389 "-m", "ffmpegsumo.dll",
390 ] + rebase_path(sources, root_build_dir)
394 public_configs = [ ":ffmpeg_win_dependent_config" ]
396 ":ffmpeg_generate_stubs",
401 config("ffmpeg_posix_dependent_config") {
403 platform_config_root,
407 component("ffmpeg") {
409 "$target_gen_dir/$stubs_filename_root.cc",
410 "$target_gen_dir/$stubs_filename_root.h",
412 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
414 "__STDC_CONSTANT_MACROS", # FFmpeg uses INT64_C.
418 platform_config_root,
422 public_configs = [ ":ffmpeg_posix_dependent_config" ]
423 deps = [ ":ffmpeg_generate_stubs", ":ffmpegsumo" ]