From: Michal MalĂ˝ Date: Sun, 2 Aug 2015 15:58:00 +0000 (+0200) Subject: Add support for building on Windows X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=fd84ed7ab5462a89514aabbfbc1da59f4650d57e;p=FFBChecker.git Add support for building on Windows --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6207d79..8e0d549 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() + diff --git a/conditioneffectsettings.cpp b/conditioneffectsettings.cpp index 448cabb..0676784 100644 --- a/conditioneffectsettings.cpp +++ b/conditioneffectsettings.cpp @@ -1,6 +1,5 @@ #include "conditioneffectsettings.h" #include "ui_conditioneffectsettings.h" -#include 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 diff --git a/envelopesettings.cpp b/envelopesettings.cpp index c70fae8..14cd0e2 100644 --- a/envelopesettings.cpp +++ b/envelopesettings.cpp @@ -1,6 +1,5 @@ #include "envelopesettings.h" #include "ui_envelopesettings.h" -#include EnvelopeSettings::EnvelopeSettings(QWidget *parent) : QWidget(parent), diff --git a/main.cpp b/main.cpp index 7f72805..5f0c0eb 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,10 @@ #include "mainwindow.h" #include -#include +#ifdef FFBC_PLATFORM_WIN32 +#include +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); diff --git a/mainwindow.cpp b/mainwindow.cpp index 351d7b6..a5d01f4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,9 +2,10 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include -#include +#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::type>(DeviceProber::DeviceInterfaces::LINUX)); +#endif #ifdef FFBC_HAVE_SDL2 if (SDL2DeviceProber::initializeSDL()) ui->cbox_interfaces->addItem("SDL2", static_cast::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(); break; +#endif #ifdef FFBC_HAVE_SDL2 case DeviceProber::DeviceInterfaces::SDL2: prober = std::make_shared(); @@ -193,9 +198,7 @@ void MainWindow::onEffectSlotSelected(const int cboxIdx) return; } FFBEffectTypes etype = m_activeDevice->effectTypeByEffectIdx(effectIdx); - qDebug() << static_cast(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& para break; } default: - qDebug() << "Unhandled type of effect"; return false; } diff --git a/mainwindow.h b/mainwindow.h index 2776b74..86a5c8f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -13,7 +13,7 @@ #include "rampeffectsettings.h" #include "rumbleeffectsettings.h" #include -#include +#include namespace Ui { class MainWindow; diff --git a/sdl2ffbconditioneffect.cpp b/sdl2ffbconditioneffect.cpp index c683b0a..77bc224 100644 --- a/sdl2ffbconditioneffect.cpp +++ b/sdl2ffbconditioneffect.cpp @@ -53,7 +53,7 @@ SDL_HapticEffect* SDL2FFBConditionEffect::createFFstruct() return effect; } -bool SDL2FFBConditionEffect::setParameters(std::shared_ptr params) +bool SDL2FFBConditionEffect::setParameters(const std::shared_ptr params) { try { const std::shared_ptr iParams = std::dynamic_pointer_cast(params); @@ -63,7 +63,7 @@ bool SDL2FFBConditionEffect::setParameters(std::shared_ptr } } -bool SDL2FFBConditionEffect::setParameters(std::shared_ptr params) +bool SDL2FFBConditionEffect::setParameters(const std::shared_ptr params) { if (!GlobalSettings::GS()->doSanityChecks) return true; diff --git a/sdl2ffbconditioneffect.h b/sdl2ffbconditioneffect.h index 7492434..67c43b3 100644 --- a/sdl2ffbconditioneffect.h +++ b/sdl2ffbconditioneffect.h @@ -10,12 +10,12 @@ public: SDL2FFBConditionEffect(); virtual SDL_HapticEffect* createFFstruct(); inline const std::shared_ptr parameters() const { return m_params; } - bool setParameters(std::shared_ptr params); + bool setParameters(const std::shared_ptr params); bool operator==(const FFBEffect& other) const; private: - bool setParameters(std::shared_ptr params); + bool setParameters(const std::shared_ptr params); std::shared_ptr m_params; }; diff --git a/sdl2ffbdevice.cpp b/sdl2ffbdevice.cpp index 45fed88..bc0d485 100644 --- a/sdl2ffbdevice.cpp +++ b/sdl2ffbdevice.cpp @@ -1,7 +1,6 @@ #include "sdl2ffbdevice.h" #include "sdl2ffbeffectfactory.h" #include -#include #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(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) {