From bcf3f6bf29ea9bde2c423f117239c32f4db93d4f Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 14 Sep 2021 17:43:45 -0400 Subject: [PATCH] feat: example QT app --- .gitignore | 1 + Makefile | 2 +- test/qtapp/CMakeLists.txt | 111 +++++++++++ test/qtapp/CMakeLists.txt.user | 328 +++++++++++++++++++++++++++++++++ test/qtapp/README.md | 8 + test/qtapp/build/.gitignore | 2 + test/qtapp/main.cpp | 45 +++++ test/qtapp/main.qml | 9 + test/qtapp/qml.qrc | 5 + 9 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 test/qtapp/CMakeLists.txt create mode 100644 test/qtapp/CMakeLists.txt.user create mode 100644 test/qtapp/README.md create mode 100644 test/qtapp/build/.gitignore create mode 100644 test/qtapp/main.cpp create mode 100644 test/qtapp/main.qml create mode 100644 test/qtapp/qml.qrc diff --git a/.gitignore b/.gitignore index 035fbe1..311e874 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ nimcache vendor/.nimble /bottles/ /test_nim/build +tmp diff --git a/Makefile b/Makefile index 5755327..eff2cd5 100644 --- a/Makefile +++ b/Makefile @@ -122,7 +122,7 @@ libstatuslib: | $(STATUSGO) echo -e $(BUILD_MSG) "$@" && \ $(ENV_SCRIPT) nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" -o:build/$@.$(LIBSTATUS_EXT).0 -d:ssl --app:lib --noMain --header --nimcache:nimcache/libstatuslib statuslib.nim && \ rm -f build/$@.$(LIBSTATUS_EXT) && \ - ln -s $@.$(LIBSTATUS_EXT).0 build/$@.so && \ + ln -s $@.$(LIBSTATUS_EXT).0 build/$@.$(LIBSTATUS_EXT) && \ cp nimcache/libstatuslib/*.h build/. && \ [[ $$? = 0 ]] diff --git a/test/qtapp/CMakeLists.txt b/test/qtapp/CMakeLists.txt new file mode 100644 index 0000000..7907601 --- /dev/null +++ b/test/qtapp/CMakeLists.txt @@ -0,0 +1,111 @@ +cmake_minimum_required(VERSION 3.14) + +project(test-qtapp LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include(ExternalProject) + +# QtCreator supports the following variables for Android, which are identical to qmake Android variables. +# Check https://doc.qt.io/qt/deployment-android.html for more information. +# They need to be set before the find_package(...) calls below. + +#if(ANDROID) +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") +# if (ANDROID_ABI STREQUAL "armeabi-v7a") +# set(ANDROID_EXTRA_LIBS +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) +# endif() +#endif() + +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED) + +set(PROJECT_SOURCES + main.cpp + qml.qrc +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(test-qtapp + ${PROJECT_SOURCES} + ) +else() + if(ANDROID) + add_library(test-qtapp SHARED + ${PROJECT_SOURCES} + ) + else() + add_executable(test-qtapp + ${PROJECT_SOURCES} + ) + endif() +endif() + + + +# Begin: status-go +set(STATUSGO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/status-go) +set(STATUSGO_LIB_DIR ${STATUSGO_ROOT}/build/bin) +ExternalProject_Add(status-go + PREFIX ${STATUSGO_ROOT} + SOURCE_DIR ${STATUSGO_ROOT} + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND "" + INSTALL_COMMAND "" + BUILD_IN_SOURCE 1 + BUILD_COMMAND make statusgo-shared-library V=1 + BUILD_BYPRODUCTS ${STATUSGO_LIB_DIR}/libstatus.so +) +ExternalProject_Get_Property(status-go SOURCE_DIR) +add_library(status SHARED IMPORTED) +set_property(TARGET status PROPERTY IMPORTED_LOCATION ${STATUSGO_LIB_DIR}/libstatus.so) +add_dependencies(status status-go) +include_directories(${STATUSGO_LIB_DIR}) + + + +# Include nim headers +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/nimbus-build-system/vendor/Nim/lib) + + + +# Begin: status-lib +set(STATUSLIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) +set(STATUSLIB_LIB_DIR ${STATUSLIB_ROOT}/build) +ExternalProject_Add(libstatuslib + PREFIX ${STATUSLIB_ROOT} + SOURCE_DIR ${STATUSLIB_ROOT} + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND "" + INSTALL_COMMAND "" + BUILD_IN_SOURCE 1 + BUILD_COMMAND make V=1 + BUILD_BYPRODUCTS ${STATUSLIB_LIB_DIR}/libstatuslib.so +) +ExternalProject_Get_Property(libstatuslib SOURCE_DIR) +add_library(statuslib SHARED IMPORTED) +set_property(TARGET statuslib PROPERTY IMPORTED_LOCATION ${STATUSLIB_LIB_DIR}/libstatuslib.so) +add_dependencies(statuslib libstatuslib) +include_directories(${STATUSLIB_LIB_DIR}) +message(STATUS "foo include dir: ${STATUSLIB_LIB_DIR}") + + +target_compile_definitions(test-qtapp + PRIVATE $<$,$>:QT_QML_DEBUG>) +target_link_libraries(test-qtapp + PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Quick + statuslib + status) diff --git a/test/qtapp/CMakeLists.txt.user b/test/qtapp/CMakeLists.txt.user new file mode 100644 index 0000000..26dd369 --- /dev/null +++ b/test/qtapp/CMakeLists.txt.user @@ -0,0 +1,328 @@ + + + + + + EnvironmentId + {4f03a750-4418-477d-a144-f714841eb5c7} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 5.14.2 GCC 64bit + Desktop Qt 5.14.2 GCC 64bit + qt.qt5.5142.gcc_64_kit + 0 + 0 + 0 + + -GNinja +-DCMAKE_BUILD_TYPE:String=Debug +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/richard/status/status-lib/test/qtapp/test-qtapp/../build-test-qtapp-Desktop_Qt_5_14_2_GCC_64bit-Debug + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + -GNinja +-DCMAKE_BUILD_TYPE:String=Release +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/richard/status/status-lib/test/qtapp/test-qtapp/../build-test-qtapp-Desktop_Qt_5_14_2_GCC_64bit-Release + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + -GNinja +-DCMAKE_BUILD_TYPE:String=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/richard/status/status-lib/test/qtapp/test-qtapp/../build-test-qtapp-Desktop_Qt_5_14_2_GCC_64bit-RelWithDebInfo + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + -GNinja +-DCMAKE_BUILD_TYPE:String=MinSizeRel +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + /home/richard/status/status-lib/test/qtapp/test-qtapp/../build-test-qtapp-Desktop_Qt_5_14_2_GCC_64bit-MinSizeRel + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/test/qtapp/README.md b/test/qtapp/README.md new file mode 100644 index 0000000..9ec05b8 --- /dev/null +++ b/test/qtapp/README.md @@ -0,0 +1,8 @@ +# Example QT app + +``` +cd build +cmake .. +make +./test-qtapp +``` \ No newline at end of file diff --git a/test/qtapp/build/.gitignore b/test/qtapp/build/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/test/qtapp/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/test/qtapp/main.cpp b/test/qtapp/main.cpp new file mode 100644 index 0000000..6a39601 --- /dev/null +++ b/test/qtapp/main.cpp @@ -0,0 +1,45 @@ +#include +#include + +extern "C" +{ +#include "statuslib.h" // TODO: is it possible to export directly to C++? +} + +int main(int argc, char *argv[]) +{ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif + + NimMain(); + helloWorld(); + + std::string someDirName{"./test"}; + char *cstr = &someDirName[0]; + + ensureDirectories(cstr, cstr, cstr); + + std::string fleetStr{"{\"fleets\":{\"eth.prod\":{\"boot\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"enode://6e6554fb3034b211398fcd0f0082cbb6bd13619e1a7e76ba66e1809aaa0c5f1ac53c9ae79cf2fd4a7bacb10d12010899b370c75fed19b991d9c0cdd02891abad@47.75.99.169:443\"},\"mail\":{\"mail-01.ac-cn-hongkong-c.eth.prod\":\"enode://606ae04a71e5db868a722c77a21c8244ae38f1bd6e81687cc6cfe88a3063fa1c245692232f64f45bd5408fed5133eab8ed78049332b04f9c110eac7f71c1b429@47.75.247.214:443\"},\"rendezvous\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"/ip4/47.75.99.169/tcp/30703/ethv4/16Uiu2HAmV8Hq9e3zm9TMVP4zrVHo3BjqW5D6bDVV6VQntQd687e4\"},\"whisper\":{\"node-01.ac-cn-hongkong-c.eth.prod\":\"enode://b957e51f41e4abab8382e1ea7229e88c6e18f34672694c6eae389eac22dab8655622bbd4a08192c321416b9becffaab11c8e2b7a5d0813b922aa128b82990dab@47.75.222.178:443\"}}},\"meta\":{\"hostname\":\"node-01.do-ams3.proxy.misc\",\"timestamp\":\"2021-09-09T00:00:14.760436\"}}"}; + char *cfleetStr = &fleetStr[0]; + + // TODO: figure out how to unmangle this type + tyObject_StatuscolonObjectType___PzMt9bO9aFlTtVlqs6Od8kZA *statusObj = newStatusInstance(cfleetStr); + initNode(statusObj, cstr, cstr); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect( + &engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) + { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, + Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/test/qtapp/main.qml b/test/qtapp/main.qml new file mode 100644 index 0000000..f98fc7f --- /dev/null +++ b/test/qtapp/main.qml @@ -0,0 +1,9 @@ +import QtQuick 2.14 +import QtQuick.Window 2.14 + +Window { + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") +} diff --git a/test/qtapp/qml.qrc b/test/qtapp/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/test/qtapp/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + +