Link in libsigrok and libsigrokdecode
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Fri, 11 May 2012 08:48:50 +0000 (09:48 +0100)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Mon, 3 Sep 2012 12:49:38 +0000 (13:49 +0100)
main.cpp
sigrok-qt2.pro

index 80b9ec93d5a37967b310a70bbbf4907c0d54ebb6..bb95f9ba4ef8e0e0ad9467ba6e8b0829b847e901 100644 (file)
--- a/main.cpp
+++ b/main.cpp
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+extern "C" {
+#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include <stdint.h>
+#include <libsigrok/libsigrok.h>
+}
+
 #include <QtGui/QApplication>
+#include <QDebug>
 #include "mainwindow.h"
 
 int main(int argc, char *argv[])
 {
        QApplication a(argc, argv);
-       MainWindow w;
-       w.show();
 
        /* Set some application metadata. */
        QApplication::setApplicationVersion(APP_VERSION);
        QApplication::setApplicationName("sigrok-qt");
        QApplication::setOrganizationDomain("http://www.sigrok.org");
 
-       return a.exec();
+       /* Initialise libsigrok */
+       if (sr_init() != SR_OK) {
+               qDebug() << "ERROR: libsigrok init failed.";
+               return 1;
+       }
+
+       /* Initialise libsigrokdecode */
+       if (srd_init(NULL) != SRD_OK) {
+               qDebug() << "ERROR: libsigrokdecode init failed.";
+               return 1;
+       }
+
+       /* Load the protocol decoders */
+       srd_decoder_load_all();
+
+       /* Initialise the main window */
+       MainWindow w;
+       w.show();
+
+       /* Run the application */
+       const int ret = a.exec();
+
+       /* Destroy libsigrokdecode and libsigrok */
+       srd_exit();
+       sr_exit();
+
+       return ret;
 }
index a93b9bc3940dd5ab7f911e72b54125229d0e90f7..dde53996a74f5d1d977ba6258691f13c432313f5 100644 (file)
@@ -19,3 +19,19 @@ SOURCES += main.cpp\
 HEADERS  += mainwindow.h
 
 FORMS    += mainwindow.ui
+
+# libsigrok and libsigrokdecode
+# TODO: Check for the minimum versions of libsigrok/libsigrokdecode we need.
+win32 {
+       # On Windows/MinGW we need to use '--libs --static'.
+       # We also need to strip some stray '\n' characters here.
+       QMAKE_CXXFLAGS += $$system(pkg-config --cflags libsigrokdecode \
+                         libsigrok | sed s/\n//g)
+       LIBS           += $$system(pkg-config --libs --static libsigrokdecode \
+                         libsigrok | sed s/\n//g)
+} else {
+       QMAKE_CXXFLAGS += $$system(pkg-config --cflags libsigrokdecode)
+       QMAKE_CXXFLAGS += $$system(pkg-config --cflags libsigrok)
+       LIBS           += $$system(pkg-config --libs libsigrokdecode)
+       LIBS           += $$system(pkg-config --libs libsigrok)
+}