Allow to build and run on native linux host 35/15235/1
authorLoïc Collignon <loic.collignon@iot.bzh>
Mon, 2 Jul 2018 13:38:32 +0000 (15:38 +0200)
committerLoïc Collignon <loic.collignon@iot.bzh>
Tue, 10 Jul 2018 17:21:41 +0000 (19:21 +0200)
Make libhomescreen and libmanager dependencies optional so that you can
build, run and debug on a native linux host, to allow faster
development.

Change-Id: Ice0b7e196e9a88dc7f0f8e9894eb9091c6ba566e
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
CMakeLists.txt
app/CMakeLists.txt
app/main.cpp

index 806ae35..37683ee 100644 (file)
@@ -21,6 +21,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
 set(AFB_HELPERS_QTWSCLIENT ON CACHE BOOL "enable Qt's WebSocket client" FORCE)
 
 add_definitions(-DUSE_API_DYN)
-#add_definitions(-DAFB_BINDING_WANT_DYNAPI)
 
 include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
index 8f8bd1e..25da122 100644 (file)
@@ -25,6 +25,12 @@ qt5_add_resources(RESOURCES Mixer.qrc)
 
 PROJECT_TARGET_ADD(mixer)
 
+option(NATIVE_BUILD "Build for native environment, without homescreen and window manager" OFF)
+if(NATIVE_BUILD)
+    message(STATUS "Native build is ON")
+    add_definitions(-DNATIVE_BUILD)
+endif()
+
 add_executable(mixer
        main.cpp
        mixer.cpp
@@ -49,9 +55,9 @@ target_link_libraries(mixer
        afb-helpers
 )
 
-#add_custom_command(TARGET ${TARGET_NAME}
-#PRE_BUILD
-#COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/../package/htdocs
-#COMMAND cp -rv ${CMAKE_CURRENT_SOURCE_DIR}/../htdocs ${CMAKE_CURRENT_BINARY_DIR}/../package/
-#COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/../package/etc
-#COMMAND cp -rv ${CMAKE_CURRENT_SOURCE_DIR}/../etc ${CMAKE_CURRENT_BINARY_DIR}/../package/)
+if(NOT NATIVE_BUILD)
+    target_link_libraries(mixer
+        homescreen
+       qtWindowmanagerWrapper
+    )
+endif()
index 9c6339f..60b2951 100644 (file)
 #include <QtQuick/qquickitem.h>
 #include <QtQuick/qquickview.h>
 #include <QQuickWindow>
+#ifndef NATIVE_BUILD
 #include <libhomescreen.hpp>
 #include <qlibwindowmanager.h>
+#else
+#include <QScreen>
+#endif
 #include "mixer.h"
 
 int main(int argc, char *argv[])
@@ -50,7 +54,7 @@ int main(int argc, char *argv[])
        parser.process(app);
        QStringList positionalArguments = parser.positionalArguments();
 
-    qmlRegisterType<Mixer>("Mixer", 1, 0, "Mixer");
+        qmlRegisterType<Mixer>("Mixer", 1, 0, "Mixer");
 
        QQmlApplicationEngine engine;
        if (positionalArguments.length() == 2) {
@@ -68,6 +72,7 @@ int main(int argc, char *argv[])
                context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
 
                std::string token = secret.toStdString();
+#ifndef NATIVE_BUILD
                LibHomeScreen* hs = new LibHomeScreen();
                QLibWindowmanager* qwm = new QLibWindowmanager();
 
@@ -100,14 +105,30 @@ int main(int argc, char *argv[])
                                }
                        }
                });
-
+#endif
                engine.load(QUrl(QStringLiteral("qrc:/Mixer.qml")));
 
                // Find the instantiated model QObject and connect the signals/slots
-               QList<QObject *> mobjs = engine.rootObjects();
+               QList<QObject*> mobjs = engine.rootObjects();
+                if (mobjs.empty())
+                {
+                    qDebug() << "[ERROR] Failed to load QML!";
+                    return -1;
+                }
 
-               QQuickWindow *window = qobject_cast<QQuickWindow *>(mobjs.first());
-               QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
+                QQuickWindow *window = qobject_cast<QQuickWindow *>(mobjs.first());
+#ifdef NATIVE_BUILD
+                window->setFlags(window->flags() & ~Qt::FramelessWindowHint); // Remove the borderless flag
+                window->setHeight(QGuiApplication::primaryScreen()->geometry().height());
+#else
+                QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
+#endif
        }
+        else
+        {
+            qDebug() << "[ERROR] No port and token specified!";
+            return -1;
+        }
+
        return app.exec();
 }