From 1d33b6acfbfd73265d8d3c5cf3262a76350dfc61 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 21 Oct 2023 18:39:30 +0200 Subject: [PATCH 1/3] Added getNativeWindow --- nui/include/nui/window.hpp | 7 +++++++ nui/src/nui/backend/window.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nui/include/nui/window.hpp b/nui/include/nui/window.hpp index 319ccb0..5e5a6fb 100644 --- a/nui/include/nui/window.hpp +++ b/nui/include/nui/window.hpp @@ -224,6 +224,13 @@ namespace Nui */ void* getNativeWebView(); + /** + * @brief Get the Native Window object + * + * @return void* + */ + void* getNativeWindow(); + /** * @brief [LINUX ONLY] Enable/Disable console output from view in the console. */ diff --git a/nui/src/nui/backend/window.cpp b/nui/src/nui/backend/window.cpp index 76c18f4..53d8ec5 100644 --- a/nui/src/nui/backend/window.cpp +++ b/nui/src/nui/backend/window.cpp @@ -428,7 +428,7 @@ namespace Nui name: name, id: id, args: [...args] - }})) + }})) }}; }})(); )", @@ -518,6 +518,11 @@ namespace Nui return static_cast(impl_->view).webview(); } //--------------------------------------------------------------------------------------------------------------------- + void* Window::getNativeWindow() + { + return impl_->view.window(); + } + //--------------------------------------------------------------------------------------------------------------------- void Window::openDevTools() { std::scoped_lock lock{impl_->viewGuard}; From b19e2a741265dcef0e0f2c8cea53e41e3e6d314e Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 21 Oct 2023 18:39:58 +0200 Subject: [PATCH 2/3] Fixed inlining. --- cmake/backend/emscripten.cmake | 1 + cmake/frontend/emscripten.cmake | 4 +- cmake/inline_extractor.cmake | 53 ++++++++++++------- .../backend/source/backend/CMakeLists.txt | 6 +-- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index c2e2e7b..a9b5031 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -111,6 +111,7 @@ function(nui_add_emscripten_target) ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS} -DNUI_INLINE_EXTRACTOR_TARGET_FILE=$ -DNUI_INLINE_INJECTOR_TARGET_FILE=$ + -DNUI_MODULE_BUILD_DIR=${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} "${SOURCE_DIR}" # copy over package.json and fill parcel options that do not exist on it ${BUILD_COMMAND} diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index 2a30f78..1d6d317 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -20,7 +20,7 @@ function(nui_prepare_emscripten_target) set(INLINER_COMMAND "") if (NOT NO_INLINE) - nui_enable_inline(TARGET ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}) + nui_enable_inline(TARGET ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} RELATIVE_TO ${CMAKE_CURRENT_SOURCE_DIR}) if (NOT NO_INLINE_INJECT) set(INLINER_COMMAND COMMAND ${NUI_INLINE_INJECTOR_TARGET_FILE} "${CMAKE_BINARY_DIR}/static/index.html" "${CMAKE_BINARY_DIR}/nui-inline/inline_imports.js" "${CMAKE_BINARY_DIR}/nui-inline/inline_imports.css") endif() @@ -34,7 +34,7 @@ function(nui_prepare_emscripten_target) add_custom_target( ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel - COMMAND ${CMAKE_COMMAND} -E copy_directory "${NUI_SOURCE_DIRECTORY}/nui/js" "${CMAKE_BINARY_DIR}/nui-js" + COMMAND ${CMAKE_COMMAND} -E copy_directory "${NUI_SOURCE_DIRECTORY}/nui/js" "${NUI_MODULE_BUILD_DIR}/nui-js" COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} "${CMAKE_BINARY_DIR}/static" ${INLINER_COMMAND} COMMAND "${CMAKE_BINARY_DIR}/node_modules/.bin/parcel" build --dist-dir "${CMAKE_BINARY_DIR}/bin" ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS} diff --git a/cmake/inline_extractor.cmake b/cmake/inline_extractor.cmake index cb7a5f0..62d13f9 100644 --- a/cmake/inline_extractor.cmake +++ b/cmake/inline_extractor.cmake @@ -3,55 +3,70 @@ function(nui_preprocess_inline_js) set(multi_value_args EXTRA_CXX_FLAGS) cmake_parse_arguments(CPP "" "${one_value_args}" "${multi_value_args}" ${ARGN}) - string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) - string(REPLACE " " ";" c_flags "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}") + set(CURRENT_BUILD_TYPE "Release") + if (CMAKE_BUILD_TYPE) + set(CURRENT_BUILD_TYPE "${CMAKE_BUILD_TYPE}") + endif() + + string(TOUPPER ${CURRENT_BUILD_TYPE} PREPROCESS_BUILD_TYPE) + string(REPLACE " " ";" PREPROCESS_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${PREPROCESS_BUILD_TYPE}}") + set(INCLUDE_DIRS "$") + set(COMPILE_DEFINITIONS "$") add_custom_command( OUTPUT ${CPP_OUTPUT} COMMAND ${CMAKE_COMMAND} -E make_directory ${CPP_DIRECTORY} COMMAND ${CMAKE_CXX_COMPILER} - #"-D$,;-D>" - "-I$,;-I>" - ${c_flags} + "$<$:-D$>" + "$<$:-I$>" + ${PREPROCESS_CXX_FLAGS} $ ${CPP_EXTRA_CXX_FLAGS} -E ${CPP_SOURCE} -o ${CPP_OUTPUT} - # COMMAND "${NUI_INLINE_EXTRACTOR_TARGET_FILE}" ${CPP_INLINE_CACHE} ${CPP_OUTPUT} ${CPP_IS_FIRST} COMMAND_EXPAND_LISTS VERBATIM IMPLICIT_DEPENDS C ${CPP_SOURCE} DEPENDS ${CPP_SOURCE} ${CPP_DEPENDS}) endfunction() function(nui_enable_inline) - set(one_value_args TARGET UNPACKED_MODE) + set(one_value_args TARGET UNPACKED_MODE RELATIVE_TO) set(multi_value_args) cmake_parse_arguments(nui_enable_inline_ARGS "" "${one_value_args}" "${multi_value_args}" ${ARGN}) - get_target_property(INLINE_JS_SOURCES ${nui_enable_inline_ARGS_TARGET} SOURCES) + get_target_property(INLINE_SOURCES ${nui_enable_inline_ARGS_TARGET} SOURCES) + message(STATUS "Inline sources for ${nui_enable_inline_ARGS_TARGET}") set(INLINE_DIRECTORY_SUBDIR "nui-inline") - set(INLINE_DIRECTORY "${CMAKE_BINARY_DIR}/${INLINE_DIRECTORY_SUBDIR}") + set(INLINE_DIRECTORY "${NUI_MODULE_BUILD_DIR}/${INLINE_DIRECTORY_SUBDIR}") set(INLINE_CACHE "${INLINE_DIRECTORY}/inline.cache") set(INLINE_IMPORTS_SCRIPTS "${INLINE_DIRECTORY}/inline_imports.js") set(INLINE_IMPORTS_STYLES "${INLINE_DIRECTORY}/inline_imports.css") # for each source file preprocess it: set(IS_FIRST TRUE) - foreach(source_file ${INLINE_JS_SOURCES}) - get_filename_component(source_file_name "${source_file}" NAME) - set(preprocessed_source_file "${INLINE_DIRECTORY}/${source_file_name}.i") + foreach(SOURCE_FILE ${INLINE_SOURCES}) + # Get relative path to source file + file(RELATIVE_PATH SOURCE_FILE_NAME_RELATIVE "${nui_enable_inline_ARGS_RELATIVE_TO}" "${SOURCE_FILE}") + get_filename_component(SOURCE_FILE_NAME "${SOURCE_FILE_NAME_RELATIVE}" NAME_WE) + # Get just the directory part of the source file + get_filename_component(SOURCE_FILE_DIR "${SOURCE_FILE_NAME_RELATIVE}" DIRECTORY) + if (NOT "${SOURCE_FILE_DIR}" STREQUAL "") + set(PREPROCESSED_SOURCE_FILE "${INLINE_DIRECTORY}/${SOURCE_FILE_DIR}/${SOURCE_FILE_NAME}.i") + else() + set(PREPROCESSED_SOURCE_FILE "${INLINE_DIRECTORY}/${SOURCE_FILE_NAME}.i") + endif() nui_preprocess_inline_js( TARGET ${nui_enable_inline_ARGS_TARGET} - DIRECTORY "${INLINE_DIRECTORY}" + DIRECTORY "${INLINE_DIRECTORY}/${SOURCE_FILE_DIR}" INLINE_CACHE "${INLINE_CACHE}" - SOURCE "${source_file}" - OUTPUT "${preprocessed_source_file}" + SOURCE "${SOURCE_FILE}" + OUTPUT "${PREPROCESSED_SOURCE_FILE}" EXTRA_CXX_FLAGS -P -CC -DNUI_INLINE -DNUI_MODULE_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DNUI_MODULE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" IS_FIRST ${IS_FIRST} ) set(IS_FIRST FALSE) - message(STATUS "Preprocessing ${source_file} to ${preprocessed_source_file}") - list(APPEND preprocessed_sources "${preprocessed_source_file}") + message(STATUS "Preprocessing ${SOURCE_FILE} to ${PREPROCESSED_SOURCE_FILE}") + list(APPEND PREPROCESSED_SOURCES "${PREPROCESSED_SOURCE_FILE}") endforeach() add_custom_command( @@ -59,9 +74,9 @@ function(nui_enable_inline) ${INLINE_IMPORTS_SCRIPTS} ${INLINE_IMPORTS_STYLES} COMMAND ${CMAKE_COMMAND} -E make_directory ${INLINE_DIRECTORY} - COMMAND "${NUI_INLINE_EXTRACTOR_TARGET_FILE}" ${INLINE_CACHE} ${CMAKE_BINARY_DIR} ${INLINE_DIRECTORY_SUBDIR} ${preprocessed_sources} + COMMAND "${NUI_INLINE_EXTRACTOR_TARGET_FILE}" ${INLINE_CACHE} ${CMAKE_BINARY_DIR} ${INLINE_DIRECTORY_SUBDIR} ${PREPROCESSED_SOURCES} COMMAND_EXPAND_LISTS VERBATIM - DEPENDS ${preprocessed_sources} + DEPENDS ${PREPROCESSED_SOURCES} ) add_custom_target( diff --git a/examples/basic/backend/source/backend/CMakeLists.txt b/examples/basic/backend/source/backend/CMakeLists.txt index 11a5ba7..160e503 100644 --- a/examples/basic/backend/source/backend/CMakeLists.txt +++ b/examples/basic/backend/source/backend/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(basic-example PRIVATE main.cpp) +target_sources(basic-example PRIVATE main.cpp) target_include_directories(basic-example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include) @@ -11,10 +11,10 @@ set_target_properties(basic-example ) # Creates a target that is compiled through emscripten. This target becomes the frontend part. -nui_add_emscripten_target(basic-example +nui_add_emscripten_target( TARGET basic-example - PREJS + PREJS ${PREJS_FILE} SOURCE_DIR ${CMAKE_SOURCE_DIR} From e9bfa9ea63a325ce406fa0f13018840b87e01e74 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 21 Oct 2023 20:23:42 +0200 Subject: [PATCH 3/3] Added cosmetic tabs to inline injector --- tools/inline_injector/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/inline_injector/main.cpp b/tools/inline_injector/main.cpp index 641d1c4..cf15f7a 100644 --- a/tools/inline_injector/main.cpp +++ b/tools/inline_injector/main.cpp @@ -49,11 +49,11 @@ int main(int argc, char** argv) std::filesystem::relative(index.parent_path() / ".." / "bin" / "index.js", index.parent_path()); const std::string importScriptsHtml = "\t\n"; + relativeImportScriptsFile.generic_string() + "\";\n\t\n"; const std::string importStylesHtml = - "\t\n"; + "\t\n"; const std::string importBinIndexHtml = - "\t\n"; + "\t\n"; // find end of header from behind in indexHtml: const auto headEnd = indexHtml.rfind("");