xref: /aosp_15_r20/external/skia/modules/skcms/BUILD.gn (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1# Copyright 2022 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import("skcms.gni")
7
8# Use for CPU-specific skcms transform code that needs particular compiler flags.
9# (This is patterned after `opts` in Skia's BUILD.gn.)
10template("arch") {
11  if (invoker.enabled) {
12    source_set(target_name) {
13      visibility = [ ":*" ]
14      check_includes = false
15      forward_variables_from(invoker, "*")
16    }
17  } else {
18    # If not enabled, a phony empty target that swallows all otherwise unused variables.
19    source_set(target_name) {
20      visibility = [ ":*" ]
21      check_includes = false
22      forward_variables_from(invoker,
23                             "*",
24                             [
25                               "sources",
26                               "cflags",
27                               "defines",
28                             ])
29    }
30  }
31}
32
33arch("skcms_TransformHsw") {
34  enabled = current_cpu == "x64" && target_os != "android"
35  sources = skcms_TransformHsw
36  if (is_win) {
37    if (is_clang) {
38      cflags = [
39        "/clang:-mavx2",
40        "/clang:-mf16c",
41        "/clang:-ffp-contract=off",
42      ]
43    } else {
44      cflags = [ "/arch:AVX2" ]
45    }
46  } else {
47    cflags = [
48      "-mavx2",
49      "-mf16c",
50      "-std=c11",
51    ]
52  }
53}
54
55arch("skcms_TransformSkx") {
56  enabled = current_cpu == "x64" && target_os != "android"
57  sources = skcms_TransformSkx
58  if (is_win) {
59    if (is_clang) {
60      cflags = [
61        "/clang:-mavx512f",
62        "/clang:-mavx512dq",
63        "/clang:-mavx512cd",
64        "/clang:-mavx512bw",
65        "/clang:-mavx512vl",
66        "/clang:-ffp-contract=off",
67      ]
68    } else {
69      cflags = [ "/arch:AVX512" ]
70    }
71  } else {
72    cflags = [
73      "-mavx512f",
74      "-mavx512dq",
75      "-mavx512cd",
76      "-mavx512bw",
77      "-mavx512vl",
78      "-std=c11",
79    ]
80  }
81}
82
83static_library("skcms") {
84  cflags = []
85  if (!is_win || is_clang) {
86    cflags += [ "-std=c11" ]
87  }
88  if (target_cpu != "x64" || target_os == "android") {
89    defines = [
90      "SKCMS_DISABLE_HSW",
91      "SKCMS_DISABLE_SKX",
92    ]
93  }
94  public = skcms_public_headers
95  sources = skcms_public + skcms_TransformBaseline
96  deps = [
97    ":skcms_TransformHsw",
98    ":skcms_TransformSkx",
99  ]
100}
101