summaryrefslogtreecommitdiff
path: root/BUILD.gn
blob: 4fdc2938b5489e6d51c07874081de3bd6d9db19a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright 2018 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("//build/config/compiler/compiler.gni")
import("nasm_sources.gni")

configs_to_delete = [
  # Don't enable sanitizers for build tools. They slow down the overall build.
  "//build/config/sanitizers:default_sanitizer_flags",
]

configs_to_add = []
if (is_debug) {
  configs_to_delete += [
    # Build with full optimizations even on debug configurations, because some
    # yasm build steps (highbd_sad4d_sse2.asm) can take ~33 seconds or more in
    # debug component builds on Windows. Enabling compiler optimizations saves
    #  ~5 seconds.
    "//build/config/compiler:default_optimization",

    # Don't define _DEBUG. Modest savings, but good for consistency.
    "//build/config:debug",
  ]

  configs_to_add += [
    "//build/config:release",
    "//build/config/compiler:optimize_max",
  ]
  if (is_win) {
    # This switches to using the release CRT. For yasm debug component builds
    # of highbd_sad4d_sse2.asm on Windows this saved about 15 s.
    configs_to_delete += [ "//build/config/win:default_crt" ]
    configs_to_add += [ "//build/config/win:release_crt" ]
  }
}

config("nasm_config") {
  include_dirs = [
    ".",
    "asm",
    "disasm",
    "include",
    "output",
    "x86",
  ]

  defines = [ "HAVE_CONFIG_H" ]

  if (is_clang) {
    cflags = [
      # The inline functions in NASM's headers flag this.
      "-Wno-unused-function",

      # NASM writes nasm_assert(!"some string literal").
      "-Wno-string-conversion",

      # NASM sometimes redefines macros from its config.h.
      "-Wno-macro-redefined",

      # NASM sometimes compares enums to unsigned integers.
      "-Wno-sign-compare",
    ]
  } else if (is_win) {
    # Please note that's a slightly different set of warnings.
    cflags = [
      # NASM sometimes redefines macros from its config.h.
      "/wd4005",  # macro redefinition

      # NASM sometimes compares enums to unsigned integers.
      "/wd4018",  # sign compare

      # char VS const char mismatch.
      "/wd4028",  # formal parameter 1 different from declaration.

      # NASM comment: Uninitialized -> all zero by C spec
      # Or sometimes one const struct is forward declared for no reason.
      "/wd4132",  # const object should be initialized

      # NASM uses "(-x) & 0xFF" pattern to negate byte.
      "/wd4146",  # unary minus operator applied to unsigned type
    ]
  }
}

if (current_toolchain == host_toolchain) {
  executable("nasm") {
    sources = nasmlib_sources + nasm_sources
    sources += [
      "config/config.h",
      "config/config-mac.h",
      "config/config-linux.h",
      "config/config-win.h",
    ]

    configs -= configs_to_delete
    configs += configs_to_add
    configs += [ ":nasm_config" ]

    deps = [
      # Default manifest on Windows (a no-op elsewhere).
      "//build/win:default_exe_manifest",
    ]
  }
}