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

Improved CMake Files #52

Merged
merged 7 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions cmake/backend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else()
"${CMAKE_BINARY_DIR}/_deps/emscripten-src/java/bin/java.exe"
# not setting node, because global installed node might be preferred
# "${CMAKE_BINARY_DIR}/_deps/emscripten-src/node/bin/node.exe"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/emscripten-src
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/emscripten-src"
)
endif()
add_custom_target(
Expand Down Expand Up @@ -92,13 +92,13 @@ function(nui_add_emscripten_target)
-DCMAKE_CXX_STANDARD=23
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS}
${SOURCE_DIR}
"${SOURCE_DIR}"
# copy over package.json and fill parcel options that do not exist on it
BUILD_COMMAND $<TARGET_FILE:parcel-adapter> ${SOURCE_DIR}/package.json ${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}"
BUILD_COMMAND $<TARGET_FILE:parcel-adapter> "${SOURCE_DIR}/package.json" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json" "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}"
# emscripten make
COMMAND cmake --build "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" --target ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel
# convert result to header file containing the page
COMMAND $<TARGET_FILE:bin2hpp> ${ENABLE_BIN2HPP} ${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html ${CMAKE_BINARY_DIR}/include/index.hpp index
COMMAND $<TARGET_FILE:bin2hpp> ${ENABLE_BIN2HPP} "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/include/index.hpp" index
BINARY_DIR "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}"
BUILD_ALWAYS 1
BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html"
Expand All @@ -110,20 +110,24 @@ function(nui_add_emscripten_target)
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-prejs ALL
DEPENDS ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_PREJS}
)
add_custom_target(
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel-dep
DEPENDS ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten
)
add_dependencies(
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-prejs
emscripten-setup
)
add_dependencies(
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel-dep
emscripten-setup
)
set_property(TARGET ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} PROPERTY OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html")

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")
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")
endif()
endfunction()
2 changes: 0 additions & 2 deletions cmake/dependencies/boostpp.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(boost_preprocessor-git NONE)

include(FetchContent)
FetchContent_Declare(
boost_preprocessor
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/describe.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(boost_describe-git NONE)

include(FetchContent)
FetchContent_Declare(
boost_describe
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/fmt.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(fmt-git NONE)

include(FetchContent)
FetchContent_Declare(
fmt
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(fmt-git NONE)

include(FetchContent)
FetchContent_Declare(
gtest
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/interval_tree.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(interval-tree-git NONE)

include(FetchContent)
FetchContent_Declare(
interval-tree
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/libcpppre.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(libcpppre-git NONE)

include(FetchContent)
FetchContent_Declare(
libcpppre
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/mp11.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(boost_mp11-git NONE)

include(FetchContent)
FetchContent_Declare(
boost_mp11
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/mplex.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(mplex-git NONE)

include(FetchContent)
FetchContent_Declare(
mplex
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/nlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(nlohmann_json-git NONE)

include(FetchContent)
FetchContent_Declare(
nlohmann_json
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/portable_file_dialog.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(portable_file_dialogs-git NONE)

# TODO: fork not necessary i think
include(FetchContent)
FetchContent_Declare(
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/roar.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(roar-git NONE)

include(FetchContent)
FetchContent_Declare(
roar
Expand Down
2 changes: 0 additions & 2 deletions cmake/dependencies/webview.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
project(webview-git NONE)

if (UNIX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(
Expand Down
15 changes: 8 additions & 7 deletions cmake/frontend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function(nui_prepare_emscripten_target)

if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC)
get_target_property(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} SOURCE_DIR)
set(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR}/static)
set(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC "${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR}/static")
endif()

nui_set_target_output_directories(${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET})
Expand All @@ -22,11 +22,12 @@ function(nui_prepare_emscripten_target)

add_custom_target(
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} ${CMAKE_BINARY_DIR}/static
COMMAND ${CMAKE_BINARY_DIR}/node_modules/.bin/parcel build --dist-dir ${CMAKE_BINARY_DIR}/bin ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/index.html
DEPENDS ${CMAKE_BINARY_DIR}/bin/index.js
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../nui/js" "${CMAKE_BINARY_DIR}/nui-js"
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} "${CMAKE_BINARY_DIR}/static"
COMMAND "${CMAKE_BINARY_DIR}/node_modules/.bin/parcel" build --dist-dir "${CMAKE_BINARY_DIR}/bin" ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
BYPRODUCTS "${CMAKE_BINARY_DIR}/bin/index.html"
DEPENDS "${CMAKE_BINARY_DIR}/bin/index.js"
)

if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_UNPACKED_MODE)
Expand All @@ -37,7 +38,7 @@ function(nui_prepare_emscripten_target)
set(SINGLE_FILE_STRING "")
add_custom_target(
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-copy-wasm
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/index.wasm ${CMAKE_BINARY_DIR}/../bin/index.wasm
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/bin/index.wasm" "${CMAKE_BINARY_DIR}/../bin/index.wasm"
)
add_dependencies(${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-copy-wasm)
else()
Expand Down
9 changes: 9 additions & 0 deletions nui/include/nui/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ namespace Nui
*/
void navigate(const std::string& url);

#ifdef NUI_BACKEND
/**
* @brief Navigate to file.
*
* @param file path to an html file.
*/
void navigate(const std::filesystem::path& file);
#endif

/**
* @brief Close the window and exit run.
*/
Expand Down
46 changes: 46 additions & 0 deletions nui/js/make_resizeable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// TODO: improve:

const makeResizable = (element, borderSize, edge) => {
edge = edge || "right";

let pos;
const resize = (e) => {
const w = parseInt(getComputedStyle(element, '').width);
const h = parseInt(getComputedStyle(element, '').height);

if (edge === "right") {
const dx = -(pos - e.x);
pos = e.x;
element.style.width = (w + dx) + "px";
}
if (edge === "bottom") {
const dy = -(pos - e.y);
pos = e.y;
element.style.height = (h + dy) + "px";
}
}

element.addEventListener("mousedown", (e) => {
const w = parseInt(getComputedStyle(e.target, '').width);
const h = parseInt(getComputedStyle(e.target, '').height);

if (edge == "right") {
if (w - e.x < borderSize + 1 /*rounding tolerance*/) {
pos = e.x;
document.addEventListener("mousemove", resize, false);
}
}
if (edge == "bottom") {
if (h - e.y < borderSize + 1 /*rounding tolerance*/) {
pos = e.y;
document.addEventListener("mousemove", resize, false);
}
}
}, false);

document.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", resize, false);
}, false);
}

export default makeResizable;
7 changes: 7 additions & 0 deletions nui/src/nui/backend/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ namespace Nui
impl_->view.navigate(url);
}
//---------------------------------------------------------------------------------------------------------------------
void Window::navigate(const std::filesystem::path& file)
{
using namespace std::string_literals;
std::scoped_lock lock{impl_->viewGuard};
impl_->view.navigate("file://"s + file.string());
}
//---------------------------------------------------------------------------------------------------------------------
void Window::run()
{
#ifdef _WIN32
Expand Down
7 changes: 7 additions & 0 deletions tools/parcel_adapter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ void disablePolyfillIfNotSet(nlohmann::json& alias, std::string_view aliasName)
alias[aliasName] = false;
}

void addNuiAlias(nlohmann::json& alias)
{
alias["nui"] = "./nui-js";
}

void createPackageJsonIfMissing(std::filesystem::path const& where, std::string const& targetName)
{
using nlohmann::json;
Expand Down Expand Up @@ -88,6 +93,8 @@ int main(int argc, char** argv)
if (!package.contains("alias"))
package["alias"] = json::object();

addNuiAlias(package["alias"]);

disablePolyfillIfNotSet(package["alias"], "assert");
disablePolyfillIfNotSet(package["alias"], "fs");
disablePolyfillIfNotSet(package["alias"], "buffer");
Expand Down