]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Add support for building on Windows
authorMichal Malý <madcatxster@devoid-pointer.net>
Sun, 2 Aug 2015 15:58:00 +0000 (17:58 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sun, 2 Aug 2015 15:58:00 +0000 (17:58 +0200)
CMakeLists.txt
conditioneffectsettings.cpp
envelopesettings.cpp
main.cpp
mainwindow.cpp
mainwindow.h
sdl2ffbconditioneffect.cpp
sdl2ffbconditioneffect.h
sdl2ffbdevice.cpp

index 6207d792ff83a8da9f61e4a0689dd68b24839aa5..8e0d5490482b14f733360e011eeb47ccc2af9423 100644 (file)
@@ -2,18 +2,35 @@ cmake_minimum_required(VERSION 2.8.13)
 
 project(FFBChecker)
 
-add_definitions("-std=c++11 -Wall -Wextra")
+find_package(Qt5Widgets)
 
-if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
-  add_definitions("-ggdb -g3")
-endif()
+if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+    # Linux-specific definitions
+    set(PLATFORM_LINUX 1)
+    add_definitions("-std=c++11 -Wall -Wextra")
+    add_definitions("-DFFBC_PLATFORM_LINUX")
 
-find_package(Qt5Widgets)
+    if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
+        add_definitions("-ggdb -g3")
+    endif()
 
-include(FindPkgConfig)
-pkg_search_module(SDL2 sdl2)
-if (SDL2_FOUND)
-    add_definitions("-DFFBC_HAVE_SDL2")
+    # Try to utilize SDL2 if it is available
+    include(FindPkgConfig)
+    pkg_search_module(SDL2 sdl2)
+    if (SDL2_FOUND)
+        add_definitions("-DFFBC_HAVE_SDL2")
+    endif()
+elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+    set(PLATFORM_WIN32 1)
+    add_definitions("-DFFBC_PLATFORM_WIN32 -DFFBC_HAVE_SDL2")
+
+    # Enforce SDL2 on Windows
+    set(SDL2_FOUND 1)
+    # Adjust these paths accordingly to your setup
+    set(QT_LIBS_PATH "C://Qt-Static//bin_noicu")
+    set(SDL2_INCLUDE_DIRS "C://Users//Sacrilegium//Hacking//SDL2-2.0.3//include")
+    set(SDL2_LIBRARIES ${SDL2_LIBRARIES} "C://Users//Sacrilegium//Hacking//SDL2-2.0.3//lib//x86//SDL2.lib")
+    # set(SDL2_LIBRARIES ${SDL2_LIBRARIES} "C://Users//Sacrilegium//Hacking//SDL2-2.0.3//lib//x86//SDL2main.lib")
 endif()
 
 set(CMAKE_AUTOMOC ON)
@@ -24,33 +41,38 @@ set(FFBChecker_SRCS
     conditioneffectsettings.cpp
     constanteffectsettings.cpp
     effectsettings.cpp
-    envelopesettings.cpp
-    linuxffbconditioneffect.cpp
-    ffbconditioneffectparameters.cpp
-    linuxffbconstanteffect.cpp
+    envelopesettings.cpp    
+    ffbconditioneffectparameters.cpp    
     ffbconstanteffectparameters.cpp
     ffbdevice.cpp
-    ffbeffect.cpp
-    linuxffbeffect.cpp
-    linuxffbeffectfactory.cpp
+    ffbeffect.cpp    
     ffbeffectparameters.cpp
     ffbenvelopeparameters.cpp
-    ffbnulleffect.cpp
-    linuxffbperiodiceffect.cpp
-    ffbperiodiceffectparameters.cpp
-    linuxffbrampeffect.cpp
+    ffbnulleffect.cpp    
+    ffbperiodiceffectparameters.cpp   
     ffbrampeffectparameters.cpp
-    linuxffbrumbleeffect.cpp
     ffbrumbleeffectparameters.cpp
     globalsettings.cpp
-    linuxdeviceprober.cpp
-    linuxffbdevice.cpp
     main.cpp
     mainwindow.cpp
     periodiceffectsettings.cpp
     rampeffectsettings.cpp
     rumbleeffectsettings.cpp)
 
+if (PLATFORM_LINUX)
+    set(FFBChecker_SRCS
+        ${FFBChecker_SRCS}
+        linuxdeviceprober.cpp
+        linuxffbdevice.cpp
+        linuxffbrumbleeffect.cpp
+        linuxffbrampeffect.cpp
+        linuxffbperiodiceffect.cpp
+        linuxffbeffect.cpp
+        linuxffbeffectfactory.cpp
+        linuxffbconstanteffect.cpp
+        linuxffbconditioneffect.cpp)
+endif()
+
 if (SDL2_FOUND)
     set(FFBChecker_SRCS
         ${FFBChecker_SRCS}
@@ -69,9 +91,29 @@ if (SDL2_FOUND)
     include_directories(${SDL2_INCLUDE_DIRS})
 endif()
 
+if (PLATFORM_WIN32)
+    include_directories("${QT_LIBS_PATH}//include")
+endif()
+
 add_executable(FFBChecker ${FFBChecker_SRCS})
-target_link_libraries(FFBChecker Qt5::Widgets)
+
+if (PLATFORM_LINUX)
+    target_link_libraries(FFBChecker Qt5::Widgets)
+elseif (PLATFORM_WIN32)
+    target_link_libraries(FFBChecker "Ws2_32.lib")
+    target_link_libraries(FFBChecker "imm32.lib")
+    target_link_libraries(FFBChecker "winmm.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//plugins//platforms//qwindows.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//qtpcre.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//qtharfbuzzng.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//qtfreetype.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//Qt5Core.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//Qt5PlatformSupport.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//Qt5Gui.lib")
+    target_link_libraries(FFBChecker "${QT_LIBS_PATH}//lib//Qt5Widgets.lib")
+endif()
 
 if (SDL2_FOUND)
     target_link_libraries(FFBChecker ${SDL2_LIBRARIES})
 endif()
+
index 448cabb8b083b8a4ee715b86e1e166967c0ce141..067678449995b77dcd6ff150194a51ea8bfeea77 100644 (file)
@@ -1,6 +1,5 @@
 #include "conditioneffectsettings.h"
 #include "ui_conditioneffectsettings.h"
-#include <QDebug>
 
 ConditionEffectSettings::ConditionEffectSettings(QWidget* parent) :
   EffectSettings(parent),
@@ -22,7 +21,6 @@ void ConditionEffectSettings::axisChanged(const int idx)
   ui->qstw_leftSat->setCurrentIndex(idx);
   ui->qstw_rightCoeff->setCurrentIndex(idx);
   ui->qstw_rightSat->setCurrentIndex(idx);
-  qDebug() << "Axis changed" << idx;
 }
 
 QString ConditionEffectSettings::conditionSubtypeToConditionName(const ConditionSubtypes subtype) const
index c70fae8bfa3238895854f8ce2ca996cf60c7aaa2..14cd0e28e112607695b4614a4432bb7b2880555b 100644 (file)
@@ -1,6 +1,5 @@
 #include "envelopesettings.h"
 #include "ui_envelopesettings.h"
-#include <QDebug>
 
 EnvelopeSettings::EnvelopeSettings(QWidget *parent) :
   QWidget(parent),
index 7f728054e1aad4f7e58a779610e6c57acd2143f3..5f0c0ebe33d3f734ac66f369d797e0728a09db3a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,7 +3,10 @@
 #include "mainwindow.h"
 #include <QtWidgets/QApplication>
 
-#include <QDebug>
+#ifdef FFBC_PLATFORM_WIN32
+#include <QtCore/QtPlugin>
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
+#endif
 
 const QString NO_CHECKS_ARG("--no-checks");
 
@@ -17,10 +20,9 @@ int main(int argc, char** argv)
   {
     bool doSanityChecks;
     QStringList cmdArgs = QCoreApplication::arguments();
-    if (cmdArgs.contains(NO_CHECKS_ARG)) {
+    if (cmdArgs.contains(NO_CHECKS_ARG))
       doSanityChecks = false;
-      qDebug() << "Disabling effect parameters sanity checks";
-    } else
+    else
       doSanityChecks = true;
 
    GlobalSettings::init(doSanityChecks);
index 351d7b65a3afbaf80480bf07083457e5f39998b2..a5d01f4ff1114f3568c329aa480a14e645bbe570 100644 (file)
@@ -2,9 +2,10 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include <QtWidgets/QMessageBox>
-#include <QDebug>
 
+#ifdef FFBC_PLATFORM_LINUX
 #include "linuxdeviceprober.h"
+#endif
 #ifdef FFBC_HAVE_SDL2
 #include "sdl2deviceprober.h"
 #endif
@@ -37,14 +38,16 @@ MainWindow::MainWindow(const QString& title, QWidget* parent) :
     ui->ql_noChecksWarning->setHidden(true);
 
   /* Fill the list of available interfaces */
+#ifdef FFBC_PLATFORM_LINUX
   ui->cbox_interfaces->addItem("Linux API", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::LINUX));
+#endif
 #ifdef FFBC_HAVE_SDL2
   if (SDL2DeviceProber::initializeSDL())
     ui->cbox_interfaces->addItem("SDL2", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::SDL2));
 #endif
 
   ui->cbox_interfaces->setCurrentIndex(0);
-  createDeviceProber(DeviceProber::DeviceInterfaces::LINUX);
+  onInterfaceSelected(0);
   fillDeviceList();
 
   connect(ui->cbox_devices, SIGNAL(activated(const int)), this, SLOT(onDeviceSelected(const int)));
@@ -72,9 +75,11 @@ bool MainWindow::createDeviceProber(const DeviceProber::DeviceInterfaces iface)
   }
 
   switch (iface) {
+#ifdef FFBC_PLATFORM_LINUX
   case DeviceProber::DeviceInterfaces::LINUX:
     prober = std::make_shared<LinuxDeviceProber>();
     break;
+#endif
 #ifdef FFBC_HAVE_SDL2
   case DeviceProber::DeviceInterfaces::SDL2:
     prober = std::make_shared<SDL2DeviceProber>();
@@ -193,9 +198,7 @@ void MainWindow::onEffectSlotSelected(const int cboxIdx)
     return;
   }
   FFBEffectTypes etype = m_activeDevice->effectTypeByEffectIdx(effectIdx);
-  qDebug() << static_cast<int>(etype);
   if (etype == FFBEffectTypes::NONE) {
-    qDebug() << "Empty effect";
     setEffectTypeIndexByType(etype);
     ui->qstw_effectSpecifics->setCurrentWidget(effectSettingsByType(FFBEffectTypes::CONSTANT));
     setEffectStatusText(FFBEffect::FFBEffectStatus::NOT_LOADED);
@@ -325,10 +328,9 @@ void MainWindow::onStartEffectClicked()
     return;
   }
 
-  if (!readEffectParameters(params, etype)) {
-    qDebug() << "Cannot read effect params.";
+  if (!readEffectParameters(params, etype))
     return;
-  }
+
   bool ret = m_activeDevice->startEffect(effectSlot, etype, params);
   if (ret)
     setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
@@ -369,10 +371,9 @@ void MainWindow::onUploadEffectClicked()
     return;
   }
 
-  if (!readEffectParameters(params, etype)) {
-    qDebug() << "Cannot read effect params.";
+  if (!readEffectParameters(params, etype))
     return;
-  }
+
   bool ret = m_activeDevice->uploadEffect(effectSlot, etype, params);
   if (ret)
     setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
@@ -552,7 +553,6 @@ bool MainWindow::readEffectParameters(std::shared_ptr<FFBEffectParameters>& para
       break;
     }
     default:
-      qDebug() << "Unhandled type of effect";
       return false;
   }
 
index 2776b749226fa48ef7b74602f6b659de8db05015..86a5c8fb7121e259f0a542fe8f34d40383bc7b2c 100644 (file)
@@ -13,7 +13,7 @@
 #include "rampeffectsettings.h"
 #include "rumbleeffectsettings.h"
 #include <memory>
-#include <QMainWindow>
+#include <QtWidgets/QMainWindow>
 
 namespace Ui {
   class MainWindow;
index c683b0a10ec9a2ea25cd43f62a7e6397e3be21c9..77bc2242505b40216210d8be9bfcbd2621591f88 100644 (file)
@@ -53,7 +53,7 @@ SDL_HapticEffect* SDL2FFBConditionEffect::createFFstruct()
   return effect;
 }
 
-bool SDL2FFBConditionEffect::setParameters(std::shared_ptr<FFBEffectParameters> params)
+bool SDL2FFBConditionEffect::setParameters(const std::shared_ptr<FFBEffectParameters> params)
 {
   try {
     const std::shared_ptr<FFBConditionEffectParameters> iParams = std::dynamic_pointer_cast<FFBConditionEffectParameters>(params);
@@ -63,7 +63,7 @@ bool SDL2FFBConditionEffect::setParameters(std::shared_ptr<FFBEffectParameters>
   }
 }
 
-bool SDL2FFBConditionEffect::setParameters(std::shared_ptr<FFBConditionEffectParameters> params)
+bool SDL2FFBConditionEffect::setParameters(const std::shared_ptr<FFBConditionEffectParameters> params)
 {
   if (!GlobalSettings::GS()->doSanityChecks)
     return true;
index 7492434cc3a1fb53923eea173d170c60faf0cd6c..67c43b34b896fcaf7f70ae2c912431ab20e60e03 100644 (file)
@@ -10,12 +10,12 @@ public:
   SDL2FFBConditionEffect();
   virtual SDL_HapticEffect* createFFstruct();
   inline const std::shared_ptr<FFBEffectParameters> parameters() const { return m_params; }
-  bool setParameters(std::shared_ptr<FFBEffectParameters> params);
+  bool setParameters(const std::shared_ptr<FFBEffectParameters> params);
 
   bool operator==(const FFBEffect& other) const;
 
 private:
-  bool setParameters(std::shared_ptr<FFBConditionEffectParameters> params);
+  bool setParameters(const std::shared_ptr<FFBConditionEffectParameters> params);
 
   std::shared_ptr<FFBConditionEffectParameters> m_params;
 };
index 45fed88d9244809f9644650ab2f84e1da3513d2c..bc0d48509521b5b37d661e8f3a8c649b426c6100 100644 (file)
@@ -1,7 +1,6 @@
 #include "sdl2ffbdevice.h"
 #include "sdl2ffbeffectfactory.h"
 #include <QtWidgets/QMessageBox>
-#include <QtCore/QDebug>
 
 #define CHECK_EFFECT_IDX(idx) if (idx < 0 || idx > c_maxEffectCount) return false
 
@@ -236,39 +235,31 @@ bool SDL2FFBDevice::uploadEffect(const int idx, const FFBEffectTypes type, std::
   else
     return false;
 
-  if (sdlEff == nullptr) {
-    qDebug() << "Unable to create effect";
+  if (sdlEff == nullptr)
     return false;
-  }
 
-  if (!sdlEff->setParameters(parameters)) {
-    qDebug() << "Unable to set effect parameters, some values are probably invalid.";
+  if (!sdlEff->setParameters(parameters))
     return false;
-  }
 
   /* There is no effect in the selected slot */
   if (m_effects[idx]->type() != FFBEffectTypes::NONE) {
     /* Effects are not of the same type, delete the previous effect and create a new one */
     if (*m_effects[idx] != *sdlEff) {
       if (!removeEffect(idx)) {
-       qDebug() << "Recreating effect";
-       return false;
+        return false;
       }
     } else {
       /* Effects are of the same type, update it */
-      qDebug() << "Updating effect";
 
       underlEff = sdlEff->createFFstruct();
-      if (underlEff == nullptr) {
-       qDebug() << "SDL2: Unable to create effect data";
-       return false;
-      }
+      if (underlEff == nullptr)
+        return false;
 
       intIdx = SDL_HapticUpdateEffect(c_haptic, std::static_pointer_cast<SDL2FFBEffect>(m_effects[idx])->internalIdx(), underlEff);
       if (intIdx < 0) {
-       QMessageBox::critical(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to update the effect:\n%1").arg(SDL_GetError()));
-       m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::UPLOADED);
-       return true;
+        QMessageBox::critical(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to update the effect:\n%1").arg(SDL_GetError()));
+        m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::UPLOADED);
+        return true;
       }
       sdlEff->setStatus(m_effects[idx]->status());
 
@@ -276,12 +267,9 @@ bool SDL2FFBDevice::uploadEffect(const int idx, const FFBEffectTypes type, std::
     }
   }
 
-  qDebug() << "Creating new effect";
   underlEff = sdlEff->createFFstruct();
-  if (underlEff == nullptr) {
-    qDebug() << "SDL2: Unable to create effect data";
+  if (underlEff == nullptr)
     return false;
-  }
 
   intIdx = SDL_HapticNewEffect(c_haptic, underlEff);
   if (intIdx < 0) {