chromium/third_party/minigbm/BUILD.gn

# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/cast.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/linux/pkg_config.gni")

assert(is_linux || is_chromeos)

declare_args() {
  # Controls whether the build should use the version of minigbm library shipped
  # with the system. In release builds of desktop Linux and Chrome OS we use the
  # system version.
  use_system_minigbm = (is_linux && !is_castos) || is_chromeos_lacros

  use_amdgpu_minigbm = false
  use_exynos_minigbm = false
  use_intel_minigbm = false
  use_marvell_minigbm = false
  use_mediatek_minigbm = false
  use_meson_minigbm = false
  use_msm_minigbm = false
  use_radeon_minigbm = false
  use_rockchip_minigbm = false
  use_synaptics_minigbm = false
  use_tegra_minigbm = false
  use_vc4_minigbm = false
}

if (!use_system_minigbm) {
  config("minigbm_config") {
    include_dirs = [ "src" ]
    defines = []
    if (use_amdgpu_minigbm) {
      defines += [ "DRV_AMDGPU" ]
    }
    if (use_exynos_minigbm) {
      defines += [ "DRV_EXYNOS" ]
    }
    if (use_intel_minigbm) {
      defines += [ "DRV_I915" ]
    }
    if (use_meson_minigbm) {
      defines += [ "DRV_MESON" ]
    }
    if (use_msm_minigbm) {
      defines += [ "DRV_MSM" ]
    }
    if (use_radeon_minigbm) {
      defines += [ "DRV_RADEON" ]
    }
    if (use_rockchip_minigbm) {
      defines += [ "DRV_ROCKCHIP" ]
    }
    if (use_vc4_minigbm) {
      defines += [ "DRV_VC4" ]
    }
  }

  shared_library("minigbm") {
    sources = [
      "src/amdgpu.c",
      "src/dri.c",
      "src/drv.c",
      "src/drv_array_helpers.c",
      "src/drv_helpers.c",
      "src/dumb_driver.c",
      "src/gbm.c",
      "src/gbm_helpers.c",
      "src/i915.c",
      "src/mediatek.c",
      "src/msm.c",
      "src/rockchip.c",
      "src/vc4.c",
      "src/virtgpu.c",
      "src/virtgpu_cross_domain.c",
      "src/virtgpu_virgl.c",
    ]

    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]

    deps = [ "//build/config/linux/libdrm" ]
    public_configs = [ ":minigbm_config" ]

    if (use_exynos_minigbm) {
      configs += [ "//build/config/linux/libdrm:libdrm_exynos_include_config" ]
    }

    # Clients need this to pick up the shared library correctly.
    all_dependent_configs =
        [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
  }

  # This target is used for Chromecast build, which expects the resulting lib
  # to have a name <GN target name> + .so
  group("libminigbm") {
    deps = [ ":minigbm" ]
  }
}

if (use_system_minigbm) {
  pkg_config("libgbm") {
    packages = [ "gbm" ]
  }

  group("minigbm") {
    public_configs = [ ":libgbm" ]
  }
}