* [Windows][MinGW] Update some WIN32 macro checks in source code to be MSVC-specific (not needed for GCC-based builds).
* [build] CMakeLists updates:
Adjust for Windows MinGW builds: now fully compatible with Qt5.5+ and MinGW-w64 toolchain (included in Qt installs);
Add option to specify path to required libraries/includes (instead of hard-coding `c:\programs`);
Add package check for Python and use found executable name;
Remove custom FindSdl package handler in favor of stock (and improved) CMake one (still works with Windows);
Do not force SIMU_AUDIO and LUA_COMPILER in SIMU builds (leave it up to user);
Add SIMU_LUA_COMPILER option specifically for SIMU builds (default = ON);
* [build][Windows] Rewrite/Fix Windows Companion `install` target, with two options:
a) just copy supporting Qt and c++ DLLs to build folder so programs can be quickly be run from there (this is default and similar to the old behavior);
b) full installation to CMAKE_INSTALL_PREFIX path, including all binaries, supporting DLLs, language files, and OTx utilities.
Option b) can be selected with new WIN_DO_FULL_INSTALL parameter;
Also cleans up the Linux install a bit and consolidates the OS X parts;
* [simulator][Windows] Add option to build Windows simulator with system console/terminal enabled (both standalone and when launched from Companion). Mostly useful for debug as it gives output messages much sooner in the startup process than the current debug console. Also helpful because you don't have to open it manually on every launch, and it remembers last window position and size. Possible candidate for a user-selectable runtime option in the future.
* [Windows] Fix MSVC build issues.
* [build] More build fixes:
Use a customized FindSDL.cmake script again due to bugs and deficiencies in the official version (based on script from CMake v3.7);
Fixes missing SDL DLL error in NSIS installer);
Use string for Timers option (checkbox in GUI is confusing);
Remove an unused variable.
* [simu][Windows] Fix f_getcwd() cutting off too many characters (fixes SD browser interactions).
120 lines
3.2 KiB
C++
120 lines
3.2 KiB
C++
/*
|
|
* Copyright (C) OpenTX
|
|
*
|
|
* Based on code named
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "simulatorinterface.h"
|
|
#include <QDebug>
|
|
#include <QDir>
|
|
#include <QLibrary>
|
|
#include <QLibraryInfo>
|
|
#include <QMap>
|
|
#include <QMessageBox>
|
|
#include "version.h"
|
|
#if defined _MSC_VER || !defined __GNUC__
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
QMap<QString, SimulatorFactory *> registered_simulators;
|
|
|
|
void registerSimulatorFactory(SimulatorFactory *factory)
|
|
{
|
|
qDebug() << "registering" << factory->name() << "simulator";
|
|
registered_simulators[factory->name()] = factory;
|
|
}
|
|
|
|
void registerSimulator(const QString &filename)
|
|
{
|
|
QLibrary lib(filename);
|
|
typedef SimulatorFactory * (*RegisterSimulator)();
|
|
RegisterSimulator registerSimulator = (RegisterSimulator)lib.resolve("registerSimu");
|
|
if (registerSimulator) {
|
|
SimulatorFactory * factory = registerSimulator();
|
|
registerSimulatorFactory(factory);
|
|
}
|
|
else {
|
|
qWarning() << "Library error" << filename << lib.errorString();
|
|
}
|
|
}
|
|
|
|
void registerSimulators()
|
|
{
|
|
bool simulatorsFound = false;
|
|
QDir dir(".");
|
|
QStringList filters;
|
|
#if defined(__APPLE__)
|
|
filters << "*-simulator.dylib";
|
|
#elif defined(WIN32) || defined(__CYGWIN__)
|
|
filters << "*-simulator.dll";
|
|
#else
|
|
filters << "*-simulator.so";
|
|
#endif
|
|
|
|
foreach(QString filename, dir.entryList(filters, QDir::Files)) {
|
|
registerSimulator(filename.prepend("./"));
|
|
simulatorsFound = true;
|
|
}
|
|
|
|
if (!simulatorsFound) {
|
|
#if defined(__APPLE__)
|
|
dir = QLibraryInfo::location(QLibraryInfo::PrefixPath) + "/Resources";
|
|
#elif (!defined __GNUC__)
|
|
char name[MAX_PATH];
|
|
GetModuleFileName(NULL, name, MAX_PATH);
|
|
QString path(name);
|
|
path.truncate(path.lastIndexOf('\\'));
|
|
dir.setPath(path);
|
|
#else
|
|
dir = SIMULATOR_LIB_SEARCH_PATH;
|
|
#endif
|
|
foreach(QString filename, dir.entryList(filters, QDir::Files)) {
|
|
registerSimulator(filename.prepend(dir.path() + "/"));
|
|
simulatorsFound = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
SimulatorFactory * getSimulatorFactory(const QString & name)
|
|
{
|
|
QString simuName = name;
|
|
while(1) {
|
|
qDebug() << "searching" << simuName << "simulator";
|
|
foreach (QString name, registered_simulators.keys()) {
|
|
if (name.contains(simuName)) {
|
|
simuName = name;
|
|
qDebug() << "found" << simuName;
|
|
return registered_simulators[simuName];
|
|
}
|
|
}
|
|
int pos = simuName.lastIndexOf('-');
|
|
if (pos <= 0)
|
|
break;
|
|
simuName = simuName.mid(0, pos);
|
|
if (simuName.count('-') == 0)
|
|
break;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void unregisterSimulators()
|
|
{
|
|
foreach(SimulatorFactory *factory, registered_simulators) {
|
|
delete factory;
|
|
}
|
|
}
|