INCLUDE(WebKitEfl)

LIST(APPEND WebKit_LINK_FLAGS
    ${ECORE_X_LDFLAGS}
    ${EDJE_LDFLAGS}
    ${EFLDEPS_LDFLAGS}
    ${EVAS_LDFLAGS}
)

LIST(APPEND WebKit_INCLUDE_DIRECTORIES
    "${WEBKIT_DIR}/efl/ewk"
    "${WEBKIT_DIR}/efl/WebCoreSupport"
    "${WEBCORE_DIR}/platform/efl"
    "${WEBCORE_DIR}/platform/graphics/cairo"
    ${Cairo_INCLUDE_DIRS}
    ${ECORE_X_INCLUDE_DIRS}
    ${EDJE_INCLUDE_DIRS}
    ${EFLDEPS_INCLUDE_DIRS}
    ${EVAS_INCLUDE_DIRS}
    ${LIBXML2_INCLUDE_DIR}
    ${LIBXSLT_INCLUDE_DIRS}
    ${SQLITE_INCLUDE_DIRS}
)

IF (ENABLE_VIDEO)
LIST(APPEND WebKit_INCLUDE_DIRECTORIES
    "${WEBCORE_DIR}/platform/graphics/gstreamer"
    ${GStreamer-App_INCLUDE_DIRS}
    ${GStreamer-Interfaces_INCLUDE_DIRS}
    ${GStreamer-Pbutils_INCLUDE_DIRS}
    ${GStreamer-Video_INCLUDE_DIRS}
)
ENDIF()

IF (WTF_USE_FREETYPE)
  LIST(APPEND WebKit_INCLUDE_DIRECTORIES
    "${WEBCORE_DIR}/platform/graphics/freetype"
  )
ENDIF ()

IF (WTF_USE_PANGO)
  LIST(APPEND WebKit_INCLUDE_DIRECTORIES
    "${WEBCORE_DIR}/platform/graphics/pango"
    ${Pango_INCLUDE_DIRS}
  )
  LIST(APPEND WebKit_LIBRARIES
    ${Pango_LIBRARIES}
  )
ENDIF ()

LIST(APPEND WebKit_SOURCES
    efl/WebCoreSupport/ChromeClientEfl.cpp
    efl/WebCoreSupport/DeviceOrientationClientEfl.cpp
    efl/WebCoreSupport/DeviceMotionClientEfl.cpp
    efl/WebCoreSupport/DragClientEfl.cpp
    efl/WebCoreSupport/EditorClientEfl.cpp
    efl/WebCoreSupport/FrameLoaderClientEfl.cpp
    efl/WebCoreSupport/FullscreenVideoControllerEfl.cpp
    efl/WebCoreSupport/InspectorClientEfl.cpp

    efl/ewk/ewk_contextmenu.cpp
    efl/ewk/ewk_cookies.cpp
    efl/ewk/ewk_frame.cpp
    efl/ewk/ewk_history.cpp
    efl/ewk/ewk_main.cpp
    efl/ewk/ewk_network.cpp
    efl/ewk/ewk_settings.cpp
    efl/ewk/ewk_tiled_backing_store.c
    efl/ewk/ewk_tiled_matrix.c
    efl/ewk/ewk_tiled_model.c
    efl/ewk/ewk_util.cpp
    efl/ewk/ewk_view.cpp
    efl/ewk/ewk_view_single.c
    efl/ewk/ewk_view_tiled.c
    efl/ewk/ewk_window_features.cpp
)

LIST(APPEND WebKit_LIBRARIES
    ${Cairo_LIBRARIES}
    ${ECORE_X_LIBRARIES}
    ${EFLDEPS_LIBRARIES}
    ${Freetype_LIBRARIES}
    ${LIBXML2_LIBRARIES}
    ${SQLITE_LIBRARIES}
    ${FONTCONFIG_LIBRARIES}
    ${PNG_LIBRARY}
    ${JPEG_LIBRARY}
    ${CMAKE_DL_LIBS}
)

IF (ENABLE_GLIB_SUPPORT)
  LIST(APPEND WebKit_INCLUDE_DIRECTORIES
    ${Gdk_INCLUDE_DIRS}
    ${Glib_INCLUDE_DIRS}
    ${JAVASCRIPTCORE_DIR}/wtf/gobject
  )
  LIST(APPEND WebKit_LIBRARIES
    ${Glib_LIBRARIES}
    ${Gdk_LIBRARIES}
  )
ENDIF ()

IF (WTF_USE_SOUP)
  LIST(APPEND WebKit_INCLUDE_DIRECTORIES ${LIBSOUP24_INCLUDE_DIRS})
  LIST(APPEND WebKit_LIBRARIES ${LIBSOUP24_LIBRARIES})
  LIST(APPEND WebKit_SOURCES
    efl/ewk/ewk_auth.cpp
    efl/ewk/ewk_auth_soup.cpp
  )
ENDIF ()

IF (WTF_USE_CURL)
  LIST(APPEND WebKit_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
  LIST(APPEND WebKit_LIBRARIES ${CURL_LIBRARIES} ${ZLIB_LIBRARIES})
ENDIF ()

SET(BUILD_DATA_DIR ${CMAKE_BINARY_DIR}/WebKit/efl/DefaultTheme)
SET(BUILD_DATA_DIR ${BUILD_DATA_DIR} PARENT_SCOPE)
FILE(MAKE_DIRECTORY ${BUILD_DATA_DIR})

SET(WebKit_THEME_DEFINITION "")
IF (ENABLE_PROGRESS_TAG)
  LIST(APPEND WebKit_THEME_DEFINITION "-DENABLE_PROGRESS_TAG")
ENDIF ()

SET(WebKit_THEME ${BUILD_DATA_DIR}/default.edj)
ADD_CUSTOM_COMMAND(
  OUTPUT ${WebKit_THEME}
  COMMAND ${EDJE_CC_EXECUTABLE} -v -id ${WEBKIT_DIR}/efl/DefaultTheme ${WebKit_THEME_DEFINITION} ${WEBKIT_DIR}/efl/DefaultTheme/default.edc ${WebKit_THEME}
  DEPENDS
    ${WEBKIT_DIR}/efl/DefaultTheme/default.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_knob_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_knob_press_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_knob_press_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_knob_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_fill_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_fill_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/slider/slider_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_focus_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_press.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/icon.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_normal.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_normal_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_hover_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/combo/combo_press_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/decoration/search_decoration.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/decoration/decoration_normal_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/field/field_hovered.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/field/search_field.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/field/field_normal.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/field/field_focused.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/cancel/cancel_normal_button.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/cancel/cancel_normal_button2.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/search/cancel/search_cancel.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_off_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/check.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_on_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_on_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_off_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_off.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/check/img_check_on.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_on.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_off_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_off_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_on_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/radio.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_off.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/radio/img_radio_on_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/button/img_button_normal.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/button/img_button_press.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/button/img_button_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/button/img_button_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/button/button.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/entry/entry.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/entry/img_normal.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/entry/img_focused.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/entry/img_hovered.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/scrollbar/scrollbar_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/scrollbar/scrollbar_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/scrollbar/scrollbar_knob_v.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/scrollbar/scrollbar_knob_h.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/scrollbar/scrollbar.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/file/file_normal.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/file/file_press.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/file/file_hover.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/file/file_focus.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/file/file.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/progressbar/progressbar.edc
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/progressbar/shelf_inset.png
    ${WEBKIT_DIR}/efl/DefaultTheme/widget/progressbar/bt_base.png
  VERBATIM
)

LIST(APPEND WebKit_SOURCES
     ${WebKit_THEME}
)

IF (SHARED_CORE)
    SET(LIBS_PRIVATE "-l${WTF_LIBRARY_NAME} -l${JavaScriptCore_LIBRARY_NAME} -l${WebCore_LIBRARY_NAME}")
ELSE ()
    SET(LIBS_PRIVATE "")
ENDIF ()

CONFIGURE_FILE(
    efl/ewebkit.pc.in
    ${CMAKE_BINARY_DIR}/WebKit/efl/ewebkit.pc
    @ONLY)
INSTALL(FILES ${CMAKE_BINARY_DIR}/WebKit/efl/ewebkit.pc
    DESTINATION lib/pkgconfig)

UNSET(LIBS_PRIVATE)

FILE(GLOB EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/*.h")
LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_private.h")
LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_tiled_private.h")
LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_tiled_backing_store.h")
LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_tiled_matrix.h")
LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_tiled_model.h")

IF (NOT WTF_USE_SOUP)
    LIST(REMOVE_ITEM EWebKit_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/efl/ewk/ewk_auth_soup.h")
ENDIF ()

INSTALL(FILES ${EWebKit_HEADERS}
        DESTINATION include/${WebKit_LIBRARY_NAME}-${PROJECT_VERSION_MAJOR})

INSTALL(FILES ${WebKit_THEME}
        DESTINATION share/${WebKit_LIBRARY_NAME}-${PROJECT_VERSION_MAJOR}/themes)
