File: QtWebViewProviderConfig.cmake

package info (click to toggle)
martchus-qtutilities 6.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 780 kB
  • sloc: cpp: 5,908; xml: 37; sh: 25; ansic: 12; makefile: 12
file content (65 lines) | stat: -rw-r--r-- 2,877 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)

# determines the web view provider (either Qt WebKit or Qt WebEngine)

if (TARGET_CONFIG_DONE)
    message(FATAL_ERROR "Can not include QtWebViewProviderConfig module when targets are already configured.")
endif ()

# include required modules
include(QtLinkage)

# check whether Qt WebEngine is present
find_package("${QT_PACKAGE_PREFIX}WebEngineWidgets" "${META_QT_VERSION}")
set(WEBVIEW_PROVIDER_DEFAULT "none")
if ("${${QT_PACKAGE_PREFIX}WebEngineWidgets_FOUND}")
    set(WEBVIEW_PROVIDER_DEFAULT "webengine")
endif ()

# configure the specified web view provider
set(WEBVIEW_PROVIDER
    "${WEBVIEW_PROVIDER_DEFAULT}"
    CACHE STRING "specifies the web view provider: webengine (default), webkit or none")
if (WEBVIEW_PROVIDER STREQUAL "webkit")
    set(WEBVIEW_PROVIDER WebKitWidgets)
    set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT")
    message(STATUS "Using Qt WebKit as web view provider.")
elseif (WEBVIEW_PROVIDER STREQUAL "webengine")
    set(WEBVIEW_PROVIDER WebEngineWidgets)
    set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE")
    list(APPEND ADDITIONAL_QT_REPOS "webengine")
    message(STATUS "Using Qt WebEngine as web view provider.")
elseif (WEBVIEW_PROVIDER STREQUAL "none")
    set(WEBVIEW_PROVIDER "")
    set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_WEBVIEW")
    message(STATUS "Built-in web view has been disabled.")
else ()
    message(FATAL_ERROR "The specified web view provider '${WEBVIEW_PROVIDER}' is unknown.")
endif ()

# add header files with some defines/includes to conveniently use the selected provider
if (WEBVIEW_PROVIDER)
    list(APPEND ADDITIONAL_QT_MODULES "${WEBVIEW_PROVIDER}")

    if (META_WEBVIEW_SRC_DIR)
        set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${META_WEBVIEW_SRC_DIR}")
    else ()
        set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gui")
    endif ()

    include(TemplateFinder)
    find_template_file("webviewdefs.h" QT_UTILITIES WEBVIEWDEFS_H_TEMPLATE_FILE)
    configure_file(
        "${WEBVIEWDEFS_H_TEMPLATE_FILE}" "${WEBVIEW_HEADER_DIR}/webviewdefs.h" # simply add this to source to ease inclusion
        NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
    )
    find_template_file("webviewincludes.h" QT_UTILITIES WEBVIEWINCLUDES_H_TEMPLATE_FILE)
    configure_file(
        "${WEBVIEWINCLUDES_H_TEMPLATE_FILE}" "${WEBVIEW_HEADER_DIR}/webviewincludes.h" # simply add this to source to ease
                                                                                       # inclusion
        NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
    )
    list(APPEND WIDGETS_FILES "${WEBVIEW_HEADER_DIR}/webviewdefs.h" "${WEBVIEW_HEADER_DIR}/webviewincludes.h")
endif ()

list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${WEBVIEW_DEFINITION})