chore: Convert simu/simulator/companion to SDL2 (#3085)

* chore(pc): convert simu/simulator/companion to use SDL2

* switch companion builds to SDL2 - OSX is not converted
the linux change is done a bit hacky, it should be done by updating the EdgeTX docker container

* update build system setup scripts

* add compatibility for old and new SDL2 cmake integration

* fix windows installer

* fix simulator audio on windows by using DirectSound vie SDL2

* fix windows audio with SDL2
enable simu for windows builds

* remove workflow changes for linux builds, this needs to be fixed in the build environment

* fix OSX build, thx @pafleraf

* fix windows audio for companion and simulator with SDL2

* select SDL2 branch of the build-docker environment

* Revert "select SDL2 branch of the build-docker environment"

This reverts commit da801609d78e1aed513ad7d9d8ab3ebded2900b9.

* fix tests with SDL2
This commit is contained in:
Malte Langermann
2023-02-22 20:32:51 +10:00
committed by GitHub
parent cbec97d76e
commit 8d91c0ae95
21 changed files with 72 additions and 67 deletions
+2 -13
View File
@@ -89,19 +89,8 @@ jobs:
./configure &&
make install
- name: Install libsdl
run: wget https://www.libsdl.org/release/SDL-1.2.15.tar.gz &&
tar xfv SDL-1.2.15.tar.gz &&
export MACOSX_DEPLOYMENT_TARGET=10.9 &&
cd SDL-1.2.15 &&
wget 'https://bugzilla-attachments.libsdl.org/attachment.cgi?id=1320' -O patch1 &&
wget 'https://bugzilla-attachments.libsdl.org/attachment.cgi?id=1324' -O patch2 &&
wget 'https://hg.libsdl.org/SDL/raw-rev/91ad7b43317a' -O patch3 &&
patch -p1 < patch1 &&
patch -p1 < patch2 &&
patch -p1 < patch3 &&
./configure --without-x &&
make install
- name: Install SDL2
run: brew install SDL2
- name: Build
working-directory: ${{github.workspace}}
+1 -1
View File
@@ -54,7 +54,7 @@ jobs:
mingw-w64-i686-openjpeg2 \
mingw-w64-i686-libimagequant \
mingw-w64-i686-libraqm \
mingw-w64-i686-SDL \
mingw-w64-i686-SDL2 \
mingw-w64-i686-clang \
mingw-w64-i686-nsis
python -m pip install clang
+1 -1
View File
@@ -68,7 +68,7 @@ jobs:
mingw-w64-x86_64-openjpeg2 \
mingw-w64-x86_64-libimagequant \
mingw-w64-x86_64-libraqm \
mingw-w64-x86_64-SDL \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-clang \
mingw-w64-x86_64-nsis
python -m pip install clang
+1 -1
View File
@@ -136,7 +136,7 @@ if(NATIVE_BUILD)
include(NativeTargets)
else()
# Prevent CMake warnings
set(IGNORE "${SDL_LIBRARY_PATH}")
set(IGNORE "${SDL2_LIBRARY_PATH}")
endif()
add_subdirectory(${RADIO_SRC_DIR})
+9 -14
View File
@@ -8,13 +8,11 @@ option(DISABLE_COMPANION "Disable building companion and simulators" OFF)
# endif()
# libfox
if(NOT WIN32)
find_package(Fox QUIET) # QUIET not working on WIN32?
if (FOX_FOUND)
message(STATUS "Foxlib found at ${FOX_LIBRARY}")
else() # if(NOT WIN32)
message("Libfox not found, simu target will not be available")
endif()
find_package(Fox QUIET) # QUIET not working on WIN32?
if (FOX_FOUND)
message(STATUS "Foxlib found at ${FOX_LIBRARY}")
else()
message("Libfox not found, simu target will not be available")
endif()
if(NOT DISABLE_COMPANION)
@@ -22,13 +20,10 @@ if(NOT DISABLE_COMPANION)
endif(NOT DISABLE_COMPANION)
if(Qt5Core_FOUND OR FOX_FOUND)
set(SDL_BUILDING_LIBRARY YES) # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
find_package("SDL")
if(SDL_FOUND)
message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}")
if (NOT ${SDL_VERSION_STRING} VERSION_LESS "2.0")
message(FATAL_ERROR "OpenTX requires SDL 1.x, not 2.x")
endif()
set(SDL2_BUILDING_LIBRARY YES) # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
find_package("SDL2")
if(SDL2_FOUND)
message(STATUS "SDL2 Lib: ${SDL2_LIBRARIES}; Headers: ${SDL2_INCLUDE_DIRS}")
else()
message(STATUS "SDL not found! Simulator audio, and joystick inputs, will not work.")
endif()
+12 -9
View File
@@ -48,9 +48,12 @@ if(WIN32)
endif()
endif()
if(SDL_FOUND)
include_directories(${SDL_INCLUDE_DIR})
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
add_definitions(-DJOYSTICKS)
if(TARGET SDL2::SDL2)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
endif()
add_definitions(${APP_COMMON_DEFINES}) # set in top-level CMakeLists
@@ -175,7 +178,7 @@ target_link_libraries(common
Qt5::Xml
Qt5::Widgets
${PTHREAD_LIBRARY}
${SDL_LIBRARY}
${SDL2_LIBRARIES}
${WIN_LINK_LIBRARIES}
)
@@ -417,12 +420,12 @@ elseif(WIN32)
# Add installer command to execute windeployqt
message(STATUS "windeployqt command: ${QT_BIN_DIR}/windeployqt.exe ${wdqtopts}")
# SDL dll
if(SDL_FOUND AND EXISTS "${SDL_LIBRARY_PATH}/SDL.dll")
set(SDL_DIR ${SDL_LIBRARY_PATH}) # this is also used by NSIS installer script
install(FILES ${SDL_DIR}/SDL.dll DESTINATION ${INSTALL_DESTINATION})
elseif(SDL_FOUND)
message(WARNING "Installer: SDL.dll not found, set SDL_LIBRARY_PATH manually.")
# SDL2 dll
if(SDL2_FOUND AND EXISTS "${SDL2_LIBRARY_PATH}/SDL2.dll")
set(SDL2_DIR ${SDL2_LIBRARY_PATH}) # this is also used by NSIS installer script
install(FILES ${SDL2_DIR}/SDL2.dll DESTINATION ${INSTALL_DESTINATION})
elseif(SDL2_FOUND)
message(WARNING "Installer: SDL2.dll not found, set SDL2_LIBRARY_PATH manually.")
endif()
if (OPENSSL_FOUND)
+3
View File
@@ -222,6 +222,9 @@ int main(int argc, char *argv[])
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
#if defined(_WIN32) || defined(_WIN64)
putenv("SDL_AUDIODRIVER=directsound");
#endif
if (SDL_Init(sdlFlags) < 0) {
fprintf(stderr, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError());
}
+1 -1
View File
@@ -93,7 +93,7 @@ set(simulation_HDRS
widgets/virtualjoystickwidget.h
)
if(SDL_FOUND)
if(SDL2_FOUND)
set(simulation_SRCS
${simulation_SRCS}
joystick.cpp
+7 -1
View File
@@ -26,7 +26,13 @@ Joystick::Joystick(QObject *parent, int joystickEventTimeout, bool doAutoRepeat,
if ( SDL_WasInit(SDL_INIT_JOYSTICK) ) {
int i;
for (i = 0; i < SDL_NumJoysticks(); i++)
joystickNames.append(SDL_JoystickName(i));
{
SDL_Joystick* joy = SDL_JoystickOpen(i);
if(joy == nullptr)
continue;
joystickNames.append(SDL_JoystickName(joy));
SDL_JoystickClose(joy);
}
connect(&joystickTimer, SIGNAL(timeout()), this, SLOT(processEvents()));
} else {
fprintf(stderr, "ERROR: couldn't initialize SDL joystick support\n");
+3
View File
@@ -270,6 +270,9 @@ int main(int argc, char *argv[])
#ifdef SIMU_AUDIO
sdlFlags |= SDL_INIT_AUDIO;
#endif
#if defined(_WIN32) || defined(_WIN64)
putenv("SDL_AUDIODRIVER=directsound");
#endif
if (SDL_Init(sdlFlags) < 0) {
showMessage(QApplication::translate("SimulatorMain", "WARNING: couldn't initialize SDL:\n%1").arg(SDL_GetError()), QMessageBox::Warning);
}
+1 -1
View File
@@ -178,7 +178,7 @@ Section "un.EdgeTX Companion @VERSION_FAMILY@"
Delete "$INSTDIR\companion.exe"
Delete "$INSTDIR\simulator.exe"
Delete "$INSTDIR\*edgetx-*-simulator.dll"
Delete "$INSTDIR\SDL.dll"
Delete "$INSTDIR\SDL2.dll"
; MSVC-specific libs
Delete "$INSTDIR\msvcp140.dll"
Delete "$INSTDIR\vcruntime140.dll"
+1 -1
View File
@@ -32,7 +32,7 @@ option(SEMIHOSTING "Enable debugger semihosting" OFF)
option(JITTER_MEASURE "Enable ADC jitter measurement" OFF)
option(WATCHDOG "Enable hardware Watchdog" ON)
option(ASTERISK "Enable asterisk icon (test only firmware)" OFF)
if(SDL_FOUND)
if(SDL2_FOUND)
option(SIMU_AUDIO "Enable simulator audio." ON)
endif()
option(LUA "Enable LUA support" ON)
+1 -1
View File
@@ -22,9 +22,9 @@
#pragma once
#include <stdlib.h>
#include "debounce.h"
#include "definitions.h"
#include "opentx_types.h"
#include "debounce.h"
#include "opentx_helpers.h"
#include "touch.h"
+9 -6
View File
@@ -19,6 +19,11 @@
* GNU General Public License for more details.
*/
#if defined(SIMU_AUDIO)
#include <SDL.h>
#undef main
#endif
#include "fx.h"
#include "FXExpression.h"
#include "FXPNGImage.h"
@@ -29,11 +34,6 @@
#include <ctype.h>
#include "targets/simu/simulcd.h"
#if defined(SIMU_AUDIO)
#include <SDL.h>
#undef main
#endif
#if LCD_W > 212
#define LCD_ZOOM 1
#else
@@ -94,11 +94,14 @@ FXDEFMAP(OpenTxSim) OpenTxSimMap[] = {
FXIMPLEMENT(OpenTxSim, FXMainWindow, OpenTxSimMap, ARRAYNUMBER(OpenTxSimMap))
OpenTxSim::OpenTxSim(FXApp* a):
FXMainWindow(a, "OpenTX Simu", nullptr, nullptr, DECOR_ALL, 20, 90, 0, 0)
FXMainWindow(a, "EdgeTX Simu", nullptr, nullptr, DECOR_ALL, 20, 90, 0, 0)
{
bmp = new FXPPMImage(getApp(), nullptr, IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2);
#if defined(SIMU_AUDIO)
#if defined(_WIN32) || defined(_WIN64)
putenv("SDL_AUDIODRIVER=directsound");
#endif
SDL_Init(SDL_INIT_AUDIO);
#endif
+7 -4
View File
@@ -19,9 +19,12 @@ set(SIMU_DRIVERS
)
if(SDL_FOUND)
include_directories(${SDL_INCLUDE_DIR})
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
add_definitions(-DJOYSTICKS)
if(TARGET SDL2::SDL2)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
endif()
if(SIMU_LUA_COMPILER)
@@ -76,7 +79,7 @@ if(Qt5Widgets_FOUND)
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${SIMU_SRC_OPTIONS})
target_compile_definitions(${SIMULATOR_TARGET} PUBLIC ${APP_COMMON_DEFINES})
target_link_libraries(${SIMULATOR_TARGET} ${SDL_LIBRARY} Qt5::Core)
target_link_libraries(${SIMULATOR_TARGET} ${SDL2_LIBRARIES} Qt5::Core)
# Remove debug symbols on release builds
if(NOT CLANG)
@@ -162,7 +165,7 @@ if(FOX_FOUND)
${RADIO_SRC_DIR}/simu.cpp)
target_include_directories(simu PUBLIC ${FOX_INCLUDE_DIR} )
target_link_libraries(simu ${FOX_LIBRARY} pthread ${SDL_LIBRARY})
target_link_libraries(simu ${FOX_LIBRARY} pthread ${SDL2_LIBRARIES})
target_compile_options(simu PRIVATE -DSIMU)
endif()
+4 -4
View File
@@ -21,6 +21,10 @@
#define SIMPGMSPC_USE_QT 0
#if defined(SIMU_AUDIO)
#include <SDL.h>
#endif
#include "opentx.h"
#include "simulcd.h"
@@ -33,10 +37,6 @@
#include <sys/time.h>
#endif
#if defined(SIMU_AUDIO)
#include <SDL.h>
#endif
int g_snapshot_idx = 0;
uint8_t simu_start_mode = 0;
+3 -3
View File
@@ -34,9 +34,9 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
target_link_libraries(gtests-radio-lib PRIVATE ${WIN_LINK_LIBRARIES})
endif(WIN32)
if(SDL_FOUND AND SIMU_AUDIO)
target_include_directories(gtests-radio-lib PUBLIC ${SDL_INCLUDE_DIR})
target_link_libraries(gtests-radio-lib PRIVATE ${SDL_LIBRARY})
if(SDL2_FOUND)
target_include_directories(gtests-radio-lib PUBLIC ${SDL2_INCLUDE_DIR})
target_link_libraries(gtests-radio-lib PRIVATE ${SDL2_LIBRARIES})
endif()
+2 -2
View File
@@ -35,9 +35,9 @@ if [ "$(uname)" = "Darwin" ]; then
COMMON_OPTIONS="${COMMON_OPTIONS} -DCMAKE_OSX_DEPLOYMENT_TARGET='10.9'"
elif [ "$(uname)" != "Linux" ]; then # Assume Windows and MSYS2
if [ "${MSYSTEM,,}" == "mingw32" ]; then # MSYS 32bit detected
COMMON_OPTIONS="${COMMON_OPTIONS} -DSDL_LIBRARY_PATH=/mingw32/bin/"
COMMON_OPTIONS="${COMMON_OPTIONS} -DSDL2_LIBRARY_PATH=/mingw32/bin/"
else # fallback to 64bit
COMMON_OPTIONS="${COMMON_OPTIONS} -DSDL_LIBRARY_PATH=/mingw64/bin/"
COMMON_OPTIONS="${COMMON_OPTIONS} -DSDL2_LIBRARY_PATH=/mingw64/bin/"
fi
fi
+2 -2
View File
@@ -185,8 +185,8 @@ if [[ $PAUSEAFTEREACHLINE == "true" ]]; then
fi
echo "=== Step $((STEP++)): Running CMake for ${RADIO_TYPE} as an example ==="
cmake -G "MSYS Makefiles" -Wno-dev -DCMAKE_PREFIX_PATH=$HOME/5.12.9/mingw73_64 -DSDL_LIBRARY_PATH=/mingw64/bin/ ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release ../
check_command $? "cmake -G MSYS Makefiles -Wno-dev -DCMAKE_PREFIX_PATH=$HOME/5.12.9/mingw73_64 -DSDL_LIBRARY_PATH=/mingw64/bin/ ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release ../"
cmake -G "MSYS Makefiles" -Wno-dev -DCMAKE_PREFIX_PATH=$HOME/5.12.9/mingw73_64 -DSDL2_LIBRARY_PATH=/mingw64/bin/ ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release ../
check_command $? "cmake -G MSYS Makefiles -Wno-dev -DCMAKE_PREFIX_PATH=$HOME/5.12.9/mingw73_64 -DSDL2_LIBRARY_PATH=/mingw64/bin/ ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release ../"
if [[ $PAUSEAFTEREACHLINE == "true" ]]; then
echo "Step finished. Please check the output above and press Enter to continue or Ctrl+C to stop."
read
+1 -1
View File
@@ -14,7 +14,7 @@ do
done
echo "=== Step $((STEP++)): Installing packages ==="
pacman -S --noconfirm mingw-w64-x86_64-cmake mingw-w64-x86_64-python-pip mingw-w64-x86_64-python-pillow mingw-w64-x86_64-python-lz4 mingw-w64-x86_64-arm-none-eabi-gcc mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-zlib mingw-w64-x86_64-libtiff mingw-w64-x86_64-freetype mingw-w64-x86_64-lcms2 mingw-w64-x86_64-libwebp mingw-w64-x86_64-openjpeg2 mingw-w64-x86_64-libimagequant mingw-w64-x86_64-libraqm mingw-w64-x86_64-SDL mingw-w64-x86_64-nsis mingw-w64-x86_64-clang mingw-w64-x86_64-openssl
pacman -S --noconfirm mingw-w64-x86_64-cmake mingw-w64-x86_64-python-pip mingw-w64-x86_64-python-pillow mingw-w64-x86_64-python-lz4 mingw-w64-x86_64-arm-none-eabi-gcc mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-zlib mingw-w64-x86_64-libtiff mingw-w64-x86_64-freetype mingw-w64-x86_64-lcms2 mingw-w64-x86_64-libwebp mingw-w64-x86_64-openjpeg2 mingw-w64-x86_64-libimagequant mingw-w64-x86_64-libraqm mingw-w64-x86_64-SDL2 mingw-w64-x86_64-nsis mingw-w64-x86_64-clang mingw-w64-x86_64-openssl
if [[ $PAUSEAFTEREACHLINE == "true" ]]; then
echo "Step finished. Please check the output above and press Enter to continue or Ctrl+C to stop."
read
+1 -1
View File
@@ -42,7 +42,7 @@ if [[ $PAUSEAFTEREACHLINE == "true" ]]; then
fi
echo "=== Step $((STEP++)): Installing packages ==="
sudo apt-get -y install build-essential cmake gcc git lib32ncurses-dev lib32z1 libfox-1.6-dev libsdl1.2-dev qt5-default qtmultimedia5-dev qttools5-dev qttools5-dev-tools qtcreator libqt5svg5-dev software-properties-common wget zip python-pip-whl python-pil libgtest-dev python3-pip python3-tk python3-setuptools clang-7 python-clang-7 libusb-1.0-0-dev stlink-tools openocd npm pv libncurses5:i386 libpython2.7:i386 libclang-6.0-dev
sudo apt-get -y install build-essential cmake gcc git lib32ncurses-dev lib32z1 libfox-1.6-dev libsdl2-dev qt5-default qtmultimedia5-dev qttools5-dev qttools5-dev-tools qtcreator libqt5svg5-dev software-properties-common wget zip python-pip-whl python-pil libgtest-dev python3-pip python3-tk python3-setuptools clang-7 python-clang-7 libusb-1.0-0-dev stlink-tools openocd npm pv libncurses5:i386 libpython2.7:i386 libclang-6.0-dev
if [[ $PAUSEAFTEREACHLINE == "true" ]]; then
echo "Step finished. Please check the output above and press Enter to continue or Ctrl+C to stop."
read