#
# Copyright 2024 Toyota Connected North America
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_guard()

if (NOT EXISTS ${CEF_ROOT})
    message(FATAL_ERROR "CEF_ROOT: \"${CEF_ROOT}\" does not exist")
endif ()

message(STATUS "  CEF_ROOT: ${CEF_ROOT}")

if (NOT CEF_BUILD_TYPE)
    set(CEF_BUILD_TYPE "Release")
endif ()

message("CEF_BUILD_TYPE: ${CEF_BUILD_TYPE}")

add_library(plugin_webview_flutter_view STATIC
        webview_flutter_view_plugin_c_api.cc
        webview_flutter_view_plugin.cc
        messages.g.cc
)

add_compile_definitions(CEF_ROOT=\"${CEF_ROOT}\")

set(WEBVIEW_SUBPROCESS_PROJECT_NAME "webview_flutter_subprocess")

add_subdirectory(${CEF_ROOT})

target_compile_definitions(plugin_webview_flutter_view PUBLIC
        MESA_EGL_NO_X11_HEADERS
        WL_EGL_PLATFORM
        EGL_NO_X11
)

target_include_directories(plugin_webview_flutter_view PRIVATE
        include
)

target_compile_options(plugin_webview_flutter_view PRIVATE
        -isystem${CEF_ROOT}
        -isystem${CEF_ROOT}/include
)

target_link_directories(plugin_webview_flutter_view PUBLIC
        ${CEF_ROOT}/${CEF_BUILD_TYPE}
)

add_dependencies(plugin_webview_flutter_view libcef_dll_wrapper)

target_link_libraries(plugin_webview_flutter_view PRIVATE
        flutter
        platform_homescreen
        libcef_dll_wrapper
        GLESv2
        EGL
)
