From 9b4730cb9f77a1f5dc66ed9e6cf2acbc6efe14f2 Mon Sep 17 00:00:00 2001 From: Atul R Date: Sat, 15 Feb 2020 23:52:44 +0100 Subject: [PATCH] Adds working qt run looper --- .gitignore | 3 +- .npmignore | 3 +- CMakeLists.txt | 3 + config/common.cmake | 2 + config/qt.cmake | 92 ++++--------------- package-lock.json | 34 +++++++ package.json | 2 + scripts/preinstall.js | 13 +++ .../nodegui/core/Integration/integration.h | 11 +-- .../nodegui/core/Integration/qode-api.h | 11 +++ src/cpp/lib/core/Integration/integration.cpp | 18 ++-- 11 files changed, 102 insertions(+), 90 deletions(-) create mode 100644 scripts/preinstall.js create mode 100644 src/cpp/include/nodegui/core/Integration/qode-api.h diff --git a/.gitignore b/.gitignore index 38e6b32d5..79df30ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ dist coverage .DS_Store /.idea/ -/prebuilds \ No newline at end of file +/prebuilds +miniqt \ No newline at end of file diff --git a/.npmignore b/.npmignore index 7721cc522..ffcb68596 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,5 @@ extras/* !extras/legal src/* !src/cpp -prebuilds/* \ No newline at end of file +prebuilds/* +miniqt/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 721b43fc0..d0524e0c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,9 @@ target_include_directories(${CORE_WIDGETS_ADDON} PRIVATE target_link_libraries(${CORE_WIDGETS_ADDON} PRIVATE "${CMAKE_JS_LIB}" + Qt5::Widgets + Qt5::Core + Qt5::Gui ) diff --git a/config/common.cmake b/config/common.cmake index f362225cd..5d68d9155 100644 --- a/config/common.cmake +++ b/config/common.cmake @@ -1,3 +1,5 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) + find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") diff --git a/config/qt.cmake b/config/qt.cmake index 83ecf92b9..a661f68a0 100644 --- a/config/qt.cmake +++ b/config/qt.cmake @@ -1,79 +1,27 @@ # Adds Qt support # make sure you include this at the top of whichever Cmakelist file you are going to use. -# Need for automatic moc. Moc executable path is set in qt.cmake +# Need for automatic moc. + set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(QT_VERSION_MAJOR 5) -set(QT_VERSION_MINOR 13) -add_executable(Qt5::moc IMPORTED) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) -function(AddQtSupport addonName) - execute_process(COMMAND node -p "require('@nodegui/qode').qtHome" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE QT_HOME_DIR - ) - if(DEFINED ENV{QT_INSTALL_DIR}) - # Allows to use custom Qt installation via QT_INSTALL_DIR env variable - message(STATUS "Using Custom QT installation for ${addonName} QT_INSTALL_DIR:$ENV{QT_INSTALL_DIR}") - set(QT_HOME_DIR "$ENV{QT_INSTALL_DIR}") - endif() +macro(AddQtSupport addonName) + # execute_process(COMMAND node -p "require('@nodegui/qode').qtHome" + # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + # OUTPUT_VARIABLE QT_HOME_DIR + # ) - string(REPLACE "\n" "" QT_HOME_DIR "${QT_HOME_DIR}") - string(REPLACE "\"" "" QT_HOME_DIR "${QT_HOME_DIR}") + # if(DEFINED ENV{QT_INSTALL_DIR}) + # # Allows to use custom Qt installation via QT_INSTALL_DIR env variable + # message(STATUS "Using Custom QT installation for ${addonName} QT_INSTALL_DIR:$ENV{QT_INSTALL_DIR}") + # set(QT_HOME_DIR "$ENV{QT_INSTALL_DIR}") + # endif() - if(APPLE) - set(CUSTOM_QT_MOC_PATH "${QT_HOME_DIR}/bin/moc") - - target_include_directories(${addonName} PRIVATE - "${QT_HOME_DIR}/include" - "${QT_HOME_DIR}/lib/QtCore.framework/Versions/5/Headers" - "${QT_HOME_DIR}/lib/QtGui.framework/Versions/5/Headers" - "${QT_HOME_DIR}/lib/QtWidgets.framework/Versions/5/Headers" - ) - target_link_libraries(${addonName} PRIVATE - "${QT_HOME_DIR}/lib/QtCore.framework/Versions/5/QtCore" - "${QT_HOME_DIR}/lib/QtGui.framework/Versions/5/QtGui" - "${QT_HOME_DIR}/lib/QtWidgets.framework/Versions/5/QtWidgets" - ) - endif() - - if (WIN32) - set(CUSTOM_QT_MOC_PATH "${QT_HOME_DIR}\\bin\\moc.exe") - - target_include_directories(${addonName} PRIVATE - "${QT_HOME_DIR}\\include" - "${QT_HOME_DIR}\\include\\QtCore" - "${QT_HOME_DIR}\\include\\QtGui" - "${QT_HOME_DIR}\\include\\QtWidgets" - ) - target_link_libraries(${addonName} PRIVATE - "${QT_HOME_DIR}\\lib\\Qt5Core.lib" - "${QT_HOME_DIR}\\lib\\Qt5Gui.lib" - "${QT_HOME_DIR}\\lib\\Qt5Widgets.lib" - ) - endif() - - if(UNIX AND NOT APPLE) - set(LINUX TRUE) - endif() - - if(LINUX) - set(CUSTOM_QT_MOC_PATH "${QT_HOME_DIR}/bin/moc") - target_include_directories(${addonName} PRIVATE - "${QT_HOME_DIR}/include" - "${QT_HOME_DIR}/include/QtCore" - "${QT_HOME_DIR}/include/QtGui" - "${QT_HOME_DIR}/include/QtWidgets" - ) - target_link_libraries(${addonName} PRIVATE - "${QT_HOME_DIR}/lib/libQt5Core.so" - "${QT_HOME_DIR}/lib/libQt5Gui.so" - "${QT_HOME_DIR}/lib/libQt5Widgets.so" - ) - endif() - - # set custom moc executable location - set_target_properties(Qt5::moc PROPERTIES IMPORTED_LOCATION "${CUSTOM_QT_MOC_PATH}") - -endfunction(AddQtSupport addonName) + # string(REPLACE "\n" "" QT_HOME_DIR "${QT_HOME_DIR}") + # string(REPLACE "\"" "" QT_HOME_DIR "${QT_HOME_DIR}") + set(Qt5_DIR "/Users/atulr/Project/nodegui/nodegui/miniqt/5.15.0/clang_64/lib/cmake/Qt5") + find_package(Qt5 COMPONENTS Widgets Gui Core REQUIRED) + +endmacro(AddQtSupport addonName) diff --git a/package-lock.json b/package-lock.json index bda816854..934f6e988 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,21 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "7zip-bin": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.0.3.tgz", + "integrity": "sha512-GLyWIFBbGvpKPGo55JyRZAo4lVbnBiD52cKlw/0Vt+wnmKvWJkpZvsjVoaIolyBXDeAQKSicRtqFNPem9w0WYA==", + "dev": true + }, + "7zip-min": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/7zip-min/-/7zip-min-1.1.1.tgz", + "integrity": "sha512-GPTk3xycxB0NjRM1SKAUL7TWXjgFAyzwXkamkk5YgSLd6OneeWBw+fxULctrVr4XqPBBh+LyqpHlyj9ryfpqoQ==", + "dev": true, + "requires": { + "7zip-bin": "^5.0.3" + } + }, "@babel/code-frame": { "version": "7.5.5", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", @@ -1119,6 +1134,19 @@ "progress": "^2.0.3" } }, + "@nodegui/qt-installer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@nodegui/qt-installer/-/qt-installer-1.0.0.tgz", + "integrity": "sha512-Sy8CVkOTgzPfzQ3O3Dsc0ZETYpUCJ5Rq/Sd89x094x34Oivqgppl/JUky03aGgg56I64BRfuzK2R4LjTYk3Zmw==", + "dev": true, + "requires": { + "7zip-min": "^1.1.1", + "env-paths": "^2.2.0", + "make-dir": "^3.0.0", + "node-fetch": "^2.6.0", + "progress": "^2.0.3" + } + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -7295,6 +7323,12 @@ "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz", "integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA==" }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", + "dev": true + }, "node-gyp": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-6.1.0.tgz", diff --git a/package.json b/package.json index 6da9fe6e5..0992a5c6b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "dev": "npm run build && qode dist/demo.js", "build": "tsc && npm run build:addon", + "preinstall": "node ./scripts/preinstall.js", "postinstall": "cross-env node ./scripts/skip.js || npm run prebuild:install || npm run build:addon", "build:addon": "cross-env CMAKE_BUILD_PARALLEL_LEVEL=8 cmake-js compile", "prebuild:install": "prebuild-install --backend=cmake-js --runtime=napi --verbose", @@ -28,6 +29,7 @@ "prebuild-install": "^5.3.3" }, "devDependencies": { + "@nodegui/qt-installer": "^1.0.0", "@types/bindings": "^1.3.0", "@types/jest": "^25.1.1", "@types/node": "^13.1.2", diff --git a/scripts/preinstall.js b/scripts/preinstall.js new file mode 100644 index 000000000..126d441f7 --- /dev/null +++ b/scripts/preinstall.js @@ -0,0 +1,13 @@ +const { setupQt } = require('@nodegui/qt-installer'); +const path = require('path'); + +const qtDir = path.resolve(__dirname, '..', 'miniqt'); + +setupQt({ + qtDir, + downloadLink: + 'https://download.qt.io/online/qtsdkrepository/mac_x64/desktop/qt5_5150/qt.qt5.5150.clang_64/5.15.0-0-202002122005qtbase-MacOS-MacOS_10_13-Clang-MacOS-MacOS_10_13-X86_64.7z', + osType: 'darwin', +}).catch(err => { + throw err; +}); diff --git a/src/cpp/include/nodegui/core/Integration/integration.h b/src/cpp/include/nodegui/core/Integration/integration.h index 405de9ff6..dfd1a6df0 100644 --- a/src/cpp/include/nodegui/core/Integration/integration.h +++ b/src/cpp/include/nodegui/core/Integration/integration.h @@ -1,14 +1,5 @@ #pragma once - -// From Qode headers -namespace qode { -typedef bool (*QodeInjectedRunLoopFunc)(); -extern QodeInjectedRunLoopFunc qode_run_loop; -extern int qode_argc; -extern char **qode_argv; -extern void InjectQodeRunLoop(QodeInjectedRunLoopFunc runLoop); -} // namespace qode - +#include "qode-api.h" namespace qodeIntegration { void integrate(); } \ No newline at end of file diff --git a/src/cpp/include/nodegui/core/Integration/qode-api.h b/src/cpp/include/nodegui/core/Integration/qode-api.h new file mode 100644 index 000000000..29e13091c --- /dev/null +++ b/src/cpp/include/nodegui/core/Integration/qode-api.h @@ -0,0 +1,11 @@ +#pragma once +// From Qode headers +namespace qode { + extern int qode_argc; + extern char **qode_argv; + typedef bool (*QodeInjectedRunLoopFunc)(); + extern QodeInjectedRunLoopFunc qode_run_uv_loop_once; + extern QodeInjectedRunLoopFunc qode_run_gui_loop; + extern void InjectQodeRunLoop(QodeInjectedRunLoopFunc runLoop); + extern void InjectQodeRunUvLoopOnce(QodeInjectedRunLoopFunc runUvLoopOnce); +} // namespace qode \ No newline at end of file diff --git a/src/cpp/lib/core/Integration/integration.cpp b/src/cpp/lib/core/Integration/integration.cpp index 3549ed1d8..88330f5c8 100644 --- a/src/cpp/lib/core/Integration/integration.cpp +++ b/src/cpp/lib/core/Integration/integration.cpp @@ -7,8 +7,14 @@ namespace qodeIntegration { static NApplication* app; bool QtRunLoopWrapper() { + if(qode::qode_run_uv_loop_once){ + // Run uv loop once to start all the node integration things + qode::qode_run_uv_loop_once(); + } int exitCode = app->exec(); - exit(exitCode); + if(exitCode != 0){ + exit(exitCode); + } return false; } @@ -17,10 +23,10 @@ void integrate() { app = new NApplication(qode::qode_argc, qode::qode_argv); qode::InjectQodeRunLoop(&QtRunLoopWrapper); // Other init settings - QFont f = QApplication::font(); - if (f.defaultFamily().isEmpty()) { - f.setFamily("Sans-Serif"); - QApplication::setFont(f); - } + // QFont f = QApplication::font(); + // if (f.defaultFamily().isEmpty()) { + // f.setFamily("Sans-Serif"); + // QApplication::setFont(f); + // } } } // namespace qodeIntegration \ No newline at end of file