Skip to content

Commit

Permalink
Merge pull request #94 from NuiCpp/devel
Browse files Browse the repository at this point in the history
Custom Scheme Handler Support
  • Loading branch information
5cript authored Nov 4, 2023
2 parents 99e2b9d + 9a4297d commit d0c0c51
Show file tree
Hide file tree
Showing 66 changed files with 9,416 additions and 337 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos_13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: MacOS 13

on:
push:
branches: ["main", "devel", "macos"]
branches: ["main", "devel"]
pull_request:
branches: ["main"]
branches: ["main", "devel"]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu_20.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Ubnutu 20
name: Ubuntu 20

on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main"]
branches: ["main", "devel"]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ubuntu_22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main"]
branches: ["main", "devel"]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down Expand Up @@ -34,8 +34,11 @@ jobs:
# OPTIONAL: Specify a platform version
platform_version: 22.04

- name: Symlink xlocale
run: sudo ln -s /usr/include/locale.h /usr/include/xlocale.h

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DNUI_ENABLE_TESTS=on -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=on -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_LINKER=lld -DCMAKE_CXX_STANDARD=20
run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DNUI_ENABLE_TESTS=on -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=on -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_LINKER=lld -DCMAKE_CXX_STANDARD=20
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main"]
branches: ["main", "devel"]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ else()
if (${NUI_ENABLE_TESTS})
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/libcpppre.cmake)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/binaryen.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/emscripten.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/nlohmann_json.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/portable_file_dialog.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/webview.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/roar.cmake)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/bin2hpp)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_acorn)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/parcel_adapter)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_emscripten_config)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/inline_parser)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/inline_injector)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/webview_uuid)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/binaryen.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/emscripten.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/nlohmann_json.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/portable_file_dialog.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/webview.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/roar.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/backend/common.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/backend/emscripten.cmake)
endif()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A template to get going can be found here: [Template](https://github.com/NuiCpp/
## Platforms & Compilers
Tested on:
- Ubuntu 20 (using clang15 and libstdc++10) ![example workflow](https://github.com/NuiCpp/Nui/actions/workflows/ubuntu_20.yml/badge.svg)
- Ubuntu 22 (using clang14 and libstdc++12) ![example workflow](https://github.com/NuiCpp/Nui/actions/workflows/ubuntu_22.yml/badge.svg)
- Ubuntu 22 (using clang14 and libc++) ![example workflow](https://github.com/NuiCpp/Nui/actions/workflows/ubuntu_22.yml/badge.svg)
- Windows (using clang16 and current msys libstdc++) ![example workflow](https://github.com/NuiCpp/Nui/actions/workflows/windows.yml/badge.svg)
- MacOS 13: (using clang16) ![example workflow](https://github.com/NuiCpp/Nui/actions/workflows/macos_13.yml/badge.svg)

Expand Down
16 changes: 13 additions & 3 deletions cmake/backend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function(nui_add_emscripten_target)
endif()

if (ENABLE_BIN2HPP AND ${ENABLE_BIN2HPP})
set(BIN2HPP_COMMAND COMMAND $<TARGET_FILE:bin2hpp> "on" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/include/index.hpp" index)
set(BIN2HPP_COMMAND COMMAND $<TARGET_FILE:bin2hpp> "on" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/include/index.hpp" index)
else()
set(BIN2HPP_COMMAND COMMAND cmake -E true)
endif()
Expand Down Expand Up @@ -155,8 +155,18 @@ function(nui_add_emscripten_target)
)

if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} INTERFACE "${CMAKE_BINARY_DIR}/include")
target_include_directories(
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
INTERFACE
"${CMAKE_BINARY_DIR}/include"
"${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/include"
)
else()
target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} PRIVATE "${CMAKE_BINARY_DIR}/include")
target_include_directories(
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
PRIVATE
"${CMAKE_BINARY_DIR}/include"
"${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/include"
)
endif()
endfunction()
22 changes: 8 additions & 14 deletions cmake/dependencies/webview.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ if (APPLE)
elseif (UNIX)
find_package(PkgConfig REQUIRED)
pkg_search_module(
webkit2 REQUIRED webkit2gtk-4.0 webkit2gtk-4.1 webkit2gtk
webkit2 REQUIRED webkit2gtk-4.1 webkit2gtk-4.0 webkit2gtk
IMPORTED_TARGET
)
endif()

option(NUI_FETCH_WEBVIEW "Fetch webview" ON)
set(NUI_WEBVIEW_REPOSITORY "https://github.com/5cript/webview.git" CACHE STRING "Webview repository")
set(NUI_WEBVIEW_TAG "749f9dfbe140f5fd0be1cd53abcec7f05496cbc3" CACHE STRING "Webview tag")
set(NUI_WEBVIEW_TAG "c962bbe343c82d58ecfdfb2942d49cc2c1410705" CACHE STRING "Webview tag")

if (NUI_FETCH_WEBVIEW)
include(FetchContent)
Expand Down Expand Up @@ -98,22 +98,16 @@ if (NUI_FETCH_WEBVIEW)
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}/WebView2Loader.dll.lib" "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
)
# add_custom_command(
# OUTPUT "${CMAKE_BINARY_DIR}/include/WebView2.h"
# COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
# COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include/WebView2.h" "${CMAKE_BINARY_DIR}/include"
# )
# add_custom_command(
# OUTPUT "${CMAKE_BINARY_DIR}/include/WebView2EnvironmentOptions.h"
# COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
# COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include/WebView2EnvironmentOptions.h" "${CMAKE_BINARY_DIR}/include"
# )
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
COMMAND $<TARGET_FILE:webview-uuid> "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include/WebView2.h" "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
)
add_custom_target(
webview2-win
DEPENDS "${CMAKE_BINARY_DIR}/bin/WebView2Loader.dll"
DEPENDS "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
# DEPENDS "${CMAKE_BINARY_DIR}/include/WebView2.h"
# DEPENDS "${CMAKE_BINARY_DIR}/include/WebView2EnvironmentOptions.h"
DEPENDS "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
)
endif()
endif()
Expand Down
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(basic)
add_subdirectory(basic)
add_subdirectory(custom_schemes)
4 changes: 2 additions & 2 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.21)

project(nui-template VERSION 0.1.0)
project(basic-example VERSION 0.1.0)

include (${CMAKE_CURRENT_LIST_DIR}/_cmake/common_options.cmake)

Expand All @@ -10,7 +10,7 @@ set_common_options(basic-example)

set(PREJS_FILE ${CMAKE_CURRENT_LIST_DIR}/frontend/source/frontend/js/module.js)

if (EMSCRIPTEN)
if (EMSCRIPTEN)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/frontend/source/frontend)
else()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/backend/source/backend)
Expand Down
12 changes: 6 additions & 6 deletions examples/basic/backend/source/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
target_sources(basic-example PRIVATE main.cpp)
target_sources(${PROJECT_NAME} PRIVATE main.cpp)

target_include_directories(basic-example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include)

# Link backend of nui outside of emscripten
target_link_libraries(basic-example PRIVATE nui-backend)
target_link_libraries(${PROJECT_NAME} PRIVATE nui-backend)

set_target_properties(basic-example
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/examples/basic-example"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/examples/${PROJECT_NAME}"
)

# Creates a target that is compiled through emscripten. This target becomes the frontend part.
nui_add_emscripten_target(
TARGET
basic-example
${PROJECT_NAME}
PREJS
${PREJS_FILE}
SOURCE_DIR
Expand Down
10 changes: 5 additions & 5 deletions examples/basic/frontend/source/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
target_sources(basic-example PRIVATE main.cpp main_page.cpp)
target_sources(${PROJECT_NAME} PRIVATE main.cpp main_page.cpp)

target_include_directories(basic-example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include)

# Link frontend of nui inside of emscripten
target_link_libraries(basic-example PRIVATE nui-frontend)
target_link_libraries(${PROJECT_NAME} PRIVATE nui-frontend)

nui_prepare_emscripten_target(
TARGET
basic-example
${PROJECT_NAME}
PARCEL_ARGS
PREJS
${PREJS_FILE}
EMSCRIPTEN_LINK_OPTIONS
-sEXPORTED_FUNCTIONS=_frontendMain
-O2
-sALLOW_MEMORY_GROWTH=1
-sALLOW_MEMORY_GROWTH=1
EMSCRIPTEN_COMPILE_OPTIONS
-O3
)
8 changes: 8 additions & 0 deletions examples/custom_schemes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build
_build
.vscode
.vs
.idea
out
CMakeSettings.json
node_modules
7 changes: 7 additions & 0 deletions examples/custom_schemes/.parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@parcel/config-default",
"reporters": [
"...",
"parcel-reporter-static-files-copy"
]
}
17 changes: 17 additions & 0 deletions examples/custom_schemes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.21)

project(custom-schemes VERSION 0.1.0)

include (${CMAKE_CURRENT_LIST_DIR}/_cmake/common_options.cmake)

# Add executable (sources are added later, depending on frontend/backend)
add_executable(custom-schemes)
set_common_options(custom-schemes)

set(PREJS_FILE ${CMAKE_CURRENT_LIST_DIR}/frontend/source/frontend/js/module.js)

if (EMSCRIPTEN)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/frontend/source/frontend)
else()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/backend/source/backend)
endif()
23 changes: 23 additions & 0 deletions examples/custom_schemes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions examples/custom_schemes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# nui-template
static/source/index.js contains a fetch onto custom schemes and a fetch to a mapped folder.

And main.cpp defines some custom schemes and a mapped folder.
12 changes: 12 additions & 0 deletions examples/custom_schemes/_cmake/common_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function(set_common_options TARGET)
if (${MSVC})
set(WARNINGS -Wmost)
else()
set(WARNINGS -Wall -Wextra -Wpedantic)
endif()
set(COMMON_OPTIONS ${WARNINGS} -fexceptions -pedantic)
set(DEBUG_OPTIONS -g ${COMMON_OPTIONS})
set(RELEASE_OPTIONS -O3 ${COMMON_OPTIONS})
target_compile_options(${TARGET} PUBLIC "$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>")
target_compile_options(${TARGET} PUBLIC "$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
endfunction()
25 changes: 25 additions & 0 deletions examples/custom_schemes/backend/source/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
target_sources(${PROJECT_NAME} PRIVATE main.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include)

# Link backend of nui outside of emscripten
target_link_libraries(${PROJECT_NAME} PRIVATE nui-backend)

set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/examples/${PROJECT_NAME}"
)

# Creates a target that is compiled through emscripten. This target becomes the frontend part.
nui_add_emscripten_target(
TARGET
${PROJECT_NAME}
PREJS
${PREJS_FILE}
SOURCE_DIR
${CMAKE_SOURCE_DIR}
CMAKE_OPTIONS
"-DNUI_BUILD_EXAMPLES=on"
# I recommend to work with a release build by default because debug builds get big fast.
"-DCMAKE_BUILD_TYPE=Release"
)
Loading

0 comments on commit d0c0c51

Please sign in to comment.