# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

PRODUCT_NAME = "cefsimple"
PKG_NAME = "//tests/{}".format(PRODUCT_NAME)

# Allow access from subpackages only.
package(default_visibility = [
    ":__subpackages__",
])

load("//bazel:library_helpers.bzl", "declare_cc_library", "declare_objc_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

#
# Source file lists.
#

srcs_browser = [
    "simple_app.cc",
    "simple_app.h",
    "simple_handler.cc",
    "simple_handler.h"
]

srcs_browser_linux = [
    "cefsimple_linux.cc",
    "simple_handler_linux.cc"
]

srcs_browser_mac = [
    "cefsimple_mac.mm",
    "simple_handler_mac.mm"
]

srcs_browser_win = [
    "cefsimple_win.cc",
    "resource.h",
    "simple_handler_win.cc"
]

srcs_renderer_mac = [
    "process_helper_mac.cc"
]

#
# MacOS targets.
#

declare_objc_library(
    name = "BrowserLibMac",
    srcs = srcs_browser + srcs_browser_mac,
    target_compatible_with = [
        "@platforms//os:macos",
    ],
    deps = [
        "//:cef_wrapper",
    ],
)

declare_cc_library(
    name = "RendererLibMac",
    srcs = srcs_renderer_mac,
    target_compatible_with = [
        "@platforms//os:macos",
    ],
    deps = [
        "//:cef_wrapper",
    ],
)

#
# Windows targets.
#

# Allow access to resource.h from the declare_exe target.
cc_library(
    name = "ResourceH",
    hdrs = [
        "resource.h"
    ]
)

# Include files directly in the declare_exe target. This simplifies the build
# configuration and avoids issues with Windows discarding symbols (like WinMain)
# when linking libraries.
filegroup(
    name = "SrcsWin",
    srcs = srcs_browser + srcs_browser_win,
    target_compatible_with = [
        "@platforms//os:windows",
    ],
)

#
# Linux targets.
#

# Include files directly in the declare_exe target. This simplifies the build
# configuration.
filegroup(
    name = "SrcsLinux",
    srcs = srcs_browser + srcs_browser_linux,
    target_compatible_with = [
        "@platforms//os:linux",
    ],
)

#
# Alias to platform-specific build targets.
#

alias(
    name = PRODUCT_NAME,
    actual = select({
        "@platforms//os:linux": "{}/linux:{}".format(PKG_NAME, PRODUCT_NAME),
        "@platforms//os:macos": "{}/mac:{}".format(PKG_NAME, PRODUCT_NAME),
        "@platforms//os:windows": "{}/win:{}".format(PKG_NAME, PRODUCT_NAME),
    }),
)
