Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake build #1103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add CMake build #1103

wants to merge 1 commit into from

Conversation

pedro-vicente
Copy link

This is a simple prototype to add a CMake build
It builds the 'bind' example using hardcoded paths for Microsoft WebView2.

WebView2 was downloaded using the build script 'build.bat', but Windows includes WebView2 by default,
so downloading the library should not be necessary

The next step is to use the already installed WebView2 in the CMake script

@pedro-vicente
Copy link
Author

This is a bit off topic, but my goal here is to add a React JS front end (not done yet) for a large C++ backend (already done) .

This library seems just perfect for that, one single C++ file, that we can embed the Javascript in

Does anyone could provide a simple "hello world" sample in React?

More specifically, I am interested in responding to events

https://legacy.reactjs.org/docs/handling-events.html

@dark-steveneq
Copy link

I hope this gets merged

@Macintron
Copy link

There is an absolute (private) path in your CMakeLists.txt.
There are multiple examples how to get the WebView2 SDK from Microsoft within cmake.

One example is: (not tested)
You can provide the WEBVIEW2_PACKAGE_DIR when configuring cmake. If it can't be found, it will be downloaded into your build directory.

if(WIN32)
  # WebView2 SDK
  set(WEBVIEW2_VERSION "1.0.2210.55")
  set(WEBVIEW2_URL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/${WEBVIEW2_VERSION}")
  set(WEBVIEW2_SHA256 "c0945ddfe38272f10f24673a1cb07b54b018f614eec85d3e830628369039ad3d")
  set(WEBVIEW2_DEFAULT_PACKAGE_DIR "${CMAKE_CURRENT_BINARY_DIR}/packages/Microsoft.Web.WebView2.${WEBVIEW2_VERSION}")

  if(NOT EXISTS ${WEBVIEW2_PACKAGE_DIR})
    unset(WEBVIEW2_PACKAGE_DIR CACHE)
  endif()
  find_path(WEBVIEW2_PACKAGE_DIR
    NAMES
      "build/native/include/WebView2.h"
    NO_DEFAULT_PATH
    NO_CMAKE_FIND_ROOT_PATH  # dont prepend CMAKE_PREFIX
  )
  if(NOT WEBVIEW2_PACKAGE_DIR)
    message(WARNING "WebView2 SDK not found locally, downloading ${WEBVIEW2_VERSION} ...")
    set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_DEFAULT_PACKAGE_DIR} CACHE PATH "WebView2 SDK PATH" FORCE)
    file(
      DOWNLOAD
        ${WEBVIEW2_URL}
        ${CMAKE_CURRENT_BINARY_DIR}/webview2.nuget
      EXPECTED_HASH
        SHA256=${WEBVIEW2_SHA256}
    )
    file(MAKE_DIRECTORY ${WEBVIEW2_PACKAGE_DIR})
    execute_process(
      COMMAND
        "${CMAKE_COMMAND}" -E tar x "${CMAKE_CURRENT_BINARY_DIR}/webview2.nuget"
      WORKING_DIRECTORY
        "${WEBVIEW2_PACKAGE_DIR}"
    )
  endif()
  set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_PACKAGE_DIR} CACHE INTERNAL "" FORCE)

  target_include_directories(bind
    PRIVATE
      "${WEBVIEW2_PACKAGE_DIR}/build/native/include"
  )
  target_link_libraries(bind
    PRIVATE
      shlwapi
      version
      "${WEBVIEW2_PACKAGE_DIR}/build/native/x64/WebView2LoaderStatic.lib"
  )
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants