# Copyright 2010-2021, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
    "@build_bazel_rules_apple//apple:apple.bzl",
    "apple_dynamic_framework_import",
)

package(
    default_visibility = ["//visibility:public"],
)

# Qt header files (e.g. qchar.h) are in lib/QtCore.framework/Headers/,
# and included as "qchar.h" and <QtCore/qchar.h>.
# The combination of includes, include_prefix and strip_include_prefix below
# addresses this requirement.
cc_library(
    name = "qt_mac_core",
    hdrs = glob(["lib/QtCore.framework/Headers/*"]),
    include_prefix = "QtCore",
    includes = [
        "lib/QtCore.framework/Headers",
        "lib/QtCore.framework/Headers/QtCore",
    ],
    strip_include_prefix = "lib/QtCore.framework/Headers",
)

cc_library(
    name = "qt_mac_gui",
    hdrs = glob(["lib/QtGui.framework/Headers/*"]),
    include_prefix = "QtGui",
    includes = [
        "lib/QtGui.framework/Headers",
        "lib/QtGui.framework/Headers/QtGui",
    ],
    strip_include_prefix = "lib/QtGui.framework/Headers",
)

cc_library(
    name = "qt_mac_widgets",
    hdrs = glob(["lib/QtWidgets.framework/Headers/*"]),
    include_prefix = "QtWidgets",
    includes = [
        "lib/QtWidgets.framework/Headers",
        "lib/QtWidgets.framework/Headers/QtWidgets",
    ],
    strip_include_prefix = "lib/QtWidgets.framework/Headers",
)

cc_library(
    name = "qt_mac",
    deps = [
        ":qt_mac_core",
        ":qt_mac_gui",
        ":qt_mac_widgets",
    ],
)

# Versions/A/QtCore and QtCore are same and redudant, it should be merged.
# Versions/A/QtCore is actually used by the binary (see: otool -l).
# QtCore is necessary for build. (see: imported_dynamic_framework_processor.py).

apple_dynamic_framework_import(
    name = "QtCore_mac",
    framework_imports = glob(
        include = ["lib/QtCore.framework/**"],
        exclude = [
            "lib/QtCore.framework/Headers/**",
            "lib/QtCore.framework/Versions/A/Headers/**",
        ],
    ),
)

apple_dynamic_framework_import(
    name = "QtGui_mac",
    framework_imports = glob(
        include = ["lib/QtGui.framework/**"],
        exclude = [
            "lib/QtGui.framework/Headers/**",
            "lib/QtGui.framework/Versions/A/Headers/**",
        ],
    ),
)

apple_dynamic_framework_import(
    name = "QtPrintSupport_mac",
    framework_imports = glob(
        include = ["lib/QtPrintSupport.framework/**"],
        exclude = [
            "lib/QtPrintSupport.framework/Headers/**",
            "lib/QtPrintSupport.framework/Versions/A/Headers/**",
        ],
    ),
)

apple_dynamic_framework_import(
    name = "QtWidgets_mac",
    framework_imports = glob(
        include = ["lib/QtWidgets.framework/**"],
        exclude = [
            "lib/QtWidgets.framework/Headers/**",
            "lib/QtWidgets.framework/Versions/A/Headers/**",
        ],
    ),
)

filegroup(
    name = "libqcocoa",
    srcs = ["plugins/platforms/libqcocoa.dylib"],
)

exports_files(glob(["libexec/*"]))
