chore: cleanup SDL2 definitions (#6467)

This commit is contained in:
Raphael Coeffic
2025-07-27 17:01:15 +10:00
committed by GitHub
parent 89f5d006c9
commit 2a1538417b
18 changed files with 98 additions and 130 deletions
+35 -18
View File
@@ -44,12 +44,9 @@ if(WIN32)
endif()
endif()
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
add_definitions(-DJOYSTICKS -DSIMU_AUDIO)
if(TARGET SDL2::SDL2)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
if(TARGET SDL2::SDL2)
add_definitions(-DUSE_SDL)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
add_definitions(${APP_COMMON_DEFINES}) # set in top-level CMakeLists
@@ -267,10 +264,21 @@ if(WIN32)
set(icon_RC images/winicons/icon.rc)
endif()
add_executable(${COMPANION_NAME}
MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${companion_SRCS} ${companion_HDRS} ${icon_RC})
target_link_libraries(${COMPANION_NAME}
PRIVATE ${CPN_COMMON_LIB} generaledit modeledit qcustomplot miniz updates)
add_executable(${COMPANION_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE}
${companion_SRCS}
${companion_HDRS}
${icon_RC}
)
target_link_libraries(${COMPANION_NAME} PRIVATE
${CPN_COMMON_LIB}
${SDL2_LIBRARIES}
generaledit
modeledit
qcustomplot
miniz
updates
)
PrintTargetReport("${COMPANION_NAME}")
@@ -278,10 +286,15 @@ PrintTargetReport("${COMPANION_NAME}")
set(simu_SRCS simulator.cpp )
add_executable(${SIMULATOR_NAME}
MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${simu_SRCS} ${icon_RC})
target_link_libraries(${SIMULATOR_NAME}
PRIVATE ${CPN_COMMON_LIB})
add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE}
${simu_SRCS}
${icon_RC}
)
target_link_libraries(${SIMULATOR_NAME} PRIVATE
${CPN_COMMON_LIB}
${SDL2_LIBRARIES}
)
add_subdirectory(tests)
@@ -450,10 +463,14 @@ elseif(WIN32)
endif()
endif(OPENSSL_FOUND)
if(SDL2_FOUND AND DEFINED SDL2_LIB_PATH)
install(FILES "${SDL2_LIB_PATH}"
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
if(TARGET SDL2::SDL2)
# Get the SDL2 DLL location
get_target_property(SDL2_DLL_PATH SDL2::SDL2 IMPORTED_LOCATION)
if(SDL2_DLL_PATH)
install(FILES "${SDL2_DLL_PATH}"
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
endif()
endif()
elseif(APPLE)
+4 -4
View File
@@ -24,7 +24,7 @@
#include "mainwindow.h"
#include "helpers.h"
#include "storage.h"
#if defined(JOYSTICKS)
#if defined(USE_SDL)
#include "joystick.h"
#include "joystickdialog.h"
#endif
@@ -57,7 +57,7 @@ AppPreferencesDialog::AppPreferencesDialog(QWidget * parent, UpdateFactories * f
connect(ui->opt_appDebugLog, &QCheckBox::toggled, this, &AppPreferencesDialog::toggleAppLogSettings);
connect(ui->opt_fwTraceLog, &QCheckBox::toggled, this, &AppPreferencesDialog::toggleAppLogSettings);
#if !defined(JOYSTICKS)
#if !defined(USE_SDL)
ui->joystickCB->hide();
ui->joystickCB->setDisabled(true);
ui->joystickcalButton->hide();
@@ -296,7 +296,7 @@ void AppPreferencesDialog::initSettings()
ui->chkSimuScrollButtons->setChecked(g.simuScrollButtons());
ui->joystickWarningCB->setChecked(g.disableJoystickWarning());
#if defined(JOYSTICKS)
#if defined(USE_SDL)
ui->joystickChkB->setChecked(g.jsSupport());
if (ui->joystickChkB->isChecked()) {
QStringList joystickNames;
@@ -627,7 +627,7 @@ void AppPreferencesDialog::on_btnClearPos_clicked()
g.profile[g.sessionId()].simulatorOptions(opts);
}
#if defined(JOYSTICKS)
#if defined(USE_SDL)
void AppPreferencesDialog::on_joystickChkB_clicked() {
if (ui->joystickChkB->isChecked()) {
QStringList joystickNames;
+1 -1
View File
@@ -74,7 +74,7 @@ class AppPreferencesDialog : public QDialog
void on_btn_appLogsDir_clicked();
void on_btnClearPos_clicked();
#if defined(JOYSTICKS)
#if defined(USE_SDL)
void on_joystickChkB_clicked();
void on_joystickcalButton_clicked();
#endif
+5 -11
View File
@@ -25,7 +25,8 @@
#include <QFile>
#include <QMessageBox>
#include <QSplashScreen>
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#if defined(USE_SDL)
#include <SDL.h>
#undef main
#endif
@@ -216,18 +217,11 @@ int main(int argc, char *argv[])
Translations::installTranslators();
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
uint32_t sdlFlags = 0;
#ifdef JOYSTICKS
sdlFlags |= SDL_INIT_JOYSTICK;
#endif
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
#if defined(USE_SDL)
#if defined(_WIN32) || defined(_WIN64)
putenv("SDL_AUDIODRIVER=directsound");
#endif
if (SDL_Init(sdlFlags) < 0) {
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError());
}
#endif
@@ -269,7 +263,7 @@ int main(int argc, char *argv[])
unregisterStorageFactories();
gBoardFactories->unregisterBoardFactories();
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#if defined(USE_SDL)
SDL_Quit();
#endif
+6 -3
View File
@@ -24,9 +24,8 @@ set(${PROJECT_NAME}_NAMES
simulateduiwidgetGeneric
)
if(SDL2_FOUND)
set(${PROJECT_NAME}_NAMES
${${PROJECT_NAME}_NAMES}
if(TARGET SDL2::SDL2)
list(APPEND ${PROJECT_NAME}_NAMES
joystick
joystickdialog
)
@@ -61,6 +60,10 @@ target_link_libraries(${PROJECT_NAME}
Qt::Svg
)
if(TARGET SDL2::SDL2)
target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2)
endif()
target_include_directories(${PROJECT_NAME}
PRIVATE
"${CMAKE_SOURCE_DIR}"
@@ -29,7 +29,7 @@
#include "simulatorinterface.h"
#include "telemetrysimu.h"
#include "trainersimu.h"
#ifdef JOYSTICKS
#ifdef USE_SDL
#include "joystickdialog.h"
#endif
#include "serialportsdialog.h"
@@ -128,7 +128,7 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, const QString & simula
ui->actionReloadLua->setDisabled(true);
if(!m_simulator->getCapability(SimulatorInterface::CAP_TELEM_FRSKY_SPORT))
m_telemetryDockWidget->toggleViewAction()->setDisabled(true);
#ifndef JOYSTICKS
#ifndef USE_SDL
ui->actionJoystickSettings->setDisabled(true);
#endif
@@ -482,7 +482,7 @@ void SimulatorMainWindow::toggleRadioDocked(bool dock)
void SimulatorMainWindow::openJoystickDialog(bool)
{
#ifdef JOYSTICKS
#ifdef USE_SDL
joystickDialog * jd = new joystickDialog(this);
if (jd->exec() == QDialog::Accepted && m_simulatorWidget)
m_simulatorWidget->setupJoysticks();
+5 -5
View File
@@ -33,7 +33,7 @@
#include "simulateduiwidget.h"
#include "storage.h"
#include "virtualjoystickwidget.h"
#ifdef JOYSTICKS
#ifdef USE_SDL
#include "joystick.h"
#include "joystickdialog.h"
#endif
@@ -126,7 +126,7 @@ SimulatorWidget::~SimulatorWidget()
delete radioUiWidget;
delete vJoyLeft;
delete vJoyRight;
#ifdef JOYSTICKS
#ifdef USE_SDL
delete joystick;
#endif
firmware = nullptr;
@@ -607,7 +607,7 @@ void SimulatorWidget::setupRadioWidgets()
void SimulatorWidget::setupJoysticks()
{
#ifdef JOYSTICKS
#ifdef USE_SDL
bool joysticksEnabled = false;
if (g.jsSupport()) {
@@ -806,7 +806,7 @@ void SimulatorWidget::onRadioWidgetValueChange(const RadioWidget::RadioWidgetTyp
void SimulatorWidget::onjoystickAxisValueChanged(int axis, int value)
{
#ifdef JOYSTICKS
#ifdef USE_SDL
static const int ttlSticks = 4;
const int ttlKnobs = Boards::getCapability(m_board, Board::Pots);
const int ttlFaders = Boards::getCapability(m_board, Board::Sliders);
@@ -855,7 +855,7 @@ void SimulatorWidget::onjoystickAxisValueChanged(int axis, int value)
void SimulatorWidget::onjoystickButtonValueChanged(int button, bool state)
{
#ifdef JOYSTICKS
#ifdef USE_SDL
if (!joystick || button >= MAX_JS_BUTTONS)
return;
+2 -2
View File
@@ -38,7 +38,7 @@ class Firmware;
class SimulatorInterface;
class SimulatedUIWidget;
class VirtualJoystickWidget;
#ifdef JOYSTICKS
#ifdef USE_SDL
class Joystick;
#endif
@@ -149,7 +149,7 @@ class SimulatorWidget : public QWidget
bool deleteTempRadioData = false;
bool saveTempRadioData = false;
#ifdef JOYSTICKS
#ifdef USE_SDL
Joystick * joystick = nullptr;
int switchDirection[MAX_JS_BUTTONS];
#endif
+5 -11
View File
@@ -26,7 +26,8 @@
#include <QString>
#include <QTextStream>
#include <QRegularExpression>
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#if defined(USE_SDL)
#include <SDL.h>
#undef main
#endif
@@ -278,18 +279,11 @@ int main(int argc, char *argv[])
Translations::installTranslators();
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
uint32_t sdlFlags = 0;
#ifdef JOYSTICKS
sdlFlags |= SDL_INIT_JOYSTICK;
#endif
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
#if defined(USE_SDL)
#if defined(_WIN32) || defined(_WIN64)
putenv("SDL_AUDIODRIVER=directsound");
#endif
if (SDL_Init(sdlFlags) < 0) {
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) {
showMessage(QApplication::translate("SimulatorMain", "WARNING: couldn't initialize SDL:\n%1").arg(SDL_GetError()), QMessageBox::Warning);
}
#endif
@@ -403,7 +397,7 @@ int finish(int exitCode)
unregisterStorageFactories();
gBoardFactories->unregisterBoardFactories();
#if defined(JOYSTICKS) || defined(SIMU_AUDIO)
#if defined(USE_SDL)
SDL_Quit();
#endif