# 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.

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

# Allow access from all //tests packages.
package(default_visibility = [
    "//tests:__subpackages__",
])

#
# Source file lists.
#

srcs_common = [
    "common/binary_value_utils.cc",
    "common/binary_value_utils.h",
    "common/client_app.cc",
    "common/client_app.h",
    "common/client_app_other.cc",
    "common/client_app_other.h",
    "common/client_switches.cc",
    "common/client_switches.h",
    "common/string_util.cc",
    "common/string_util.h"
]

srcs_browser = [
    "browser/client_app_browser.cc",
    "browser/client_app_browser.h",
    "browser/file_util.cc",
    "browser/file_util.h",
    "browser/geometry_util.cc",
    "browser/geometry_util.h",
    "browser/main_message_loop.cc",
    "browser/main_message_loop.h",
    "browser/main_message_loop_external_pump.cc",
    "browser/main_message_loop_external_pump.h",
    "browser/main_message_loop_std.cc",
    "browser/main_message_loop_std.h",
    "browser/resource_util.h"
]

srcs_browser_linux = [
    "browser/main_message_loop_external_pump_linux.cc",
    "browser/resource_util_posix.cc"
]

srcs_browser_mac = [
    "browser/main_message_loop_external_pump_mac.mm",
    "browser/resource_util_mac.mm",
    "browser/resource_util_posix.cc"
]

srcs_browser_mac_ceftests = [
    "renderer/client_app_renderer.h"
]

srcs_browser_win = [
    "browser/main_message_loop_external_pump_win.cc",
    "browser/resource_util_win.cc",
    "browser/util_win.cc",
    "browser/util_win.h"
]

srcs_renderer = [
    "renderer/client_app_renderer.cc",
    "renderer/client_app_renderer.h"
]

srcs_renderer_mac = [
    "process_helper_mac.cc"
]

srcs_renderer_mac_ceftests = [
    "browser/client_app_browser.h",
    "browser/file_util.cc",
    "browser/file_util.h",
    "browser/resource_util.h",
    "browser/resource_util_mac.mm",
    "browser/resource_util_posix.cc"
]

srcs_resources = [
    "resources/osr_test.html",
    "resources/pdf.html",
    "resources/pdf.pdf",
    "resources/window_icon.1x.png",
    "resources/window_icon.2x.png"
]

filegroup(
    name = "Resources",
    srcs = srcs_resources,
)

#
# MacOS targets.
#

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

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

# Same as above, but adding additional files for ceftests. This is a workaround
# for ceftests including browser and renderer test code in the same cc files.
# Needs to be defined here because Bazel disallows direct access to files
# outside of the package directory.

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

declare_objc_library(
    name = "RendererLibMacCefTests",
    srcs = srcs_renderer_mac_ceftests,
    target_compatible_with = [
        "@platforms//os:macos",
    ],
    deps = [
        "//:cef_wrapper",
        ":RendererLibMac",
    ],
)

#
# Windows targets.
#

# 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_common + srcs_browser + srcs_browser_win + srcs_renderer,
    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_common + srcs_browser + srcs_browser_linux + srcs_renderer,
    target_compatible_with = [
        "@platforms//os:linux",
    ],
)

