Skip to content

Commit

Permalink
Fetch sdl through cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Mar 12, 2024
1 parent 506b673 commit c45c549
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 37 deletions.
50 changes: 50 additions & 0 deletions cmake/BuildSdl2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# find_package(SDL2 QUIET)
if(SDL2_FOUND)
message(STATUS "Using SDL2 via find_package")
endif()

# 2. Try using a vendored SDL library
if(NOT SDL2_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL/CMakeLists.txt")
message(STATUS "Using SDL2 via add_subdirectory")
add_subdirectory(SDL)
set(SDL2_FOUND TRUE)
endif()

# 3. Download SDL, and use that.
if(NOT SDL2_FOUND)
message(STATUS "Using SDL2 via FetchContent")
include(FetchContent)
set(SDL2_DISABLE_SDL2MAIN TRUE CACHE INTERNAL "")
set(SDL_SHARED FALSE CACHE INTERNAL "")
set(SDL_STATIC TRUE CACHE INTERNAL "")
set(SDL_TEST FALSE CACHE INTERNAL "")

set(SDL_ATOMIC TRUE CACHE INTERNAL "")
set(SDL_AUDIO FALSE CACHE INTERNAL "")
set(SDL_CPUINFO TRUE CACHE INTERNAL "")
set(SDL_EVENTS TRUE CACHE INTERNAL "")
set(SDL_FILE FALSE CACHE INTERNAL "")
set(SDL_FILESYSTEM FALSE CACHE INTERNAL "")
set(SDL_HAPTIC FALSE CACHE INTERNAL "")
set(SDL_HIDAPI TRUE CACHE INTERNAL "")
set(SDL_JOYSTICK TRUE CACHE INTERNAL "")
set(SDL_LOADSO TRUE CACHE INTERNAL "")
set(SDL_LOCALE TRUE CACHE INTERNAL "")
set(SDL_MISC FALSE CACHE INTERNAL "")
set(SDL_POWER FALSE CACHE INTERNAL "")
set(SDL_RENDER FALSE CACHE INTERNAL "")
set(SDL_SENSOR FALSE CACHE INTERNAL "")
set(SDL_THREADS TRUE CACHE INTERNAL "")
set(SDL_TIMERS FALSE CACHE INTERNAL "")
set(SDL_VIDEO FALSE CACHE INTERNAL "")

FetchContent_Declare(
SDL
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-2.30.1
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(SDL)
set(SDL2_FOUND TRUE)
endif()
1 change: 0 additions & 1 deletion libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_subdirectory(libevents)
add_subdirectory(OpenSSL)
add_subdirectory(qtandroidserialport)
add_subdirectory(sdl2)
add_subdirectory(zlib)
add_subdirectory(qmlglsink)

Expand Down
26 changes: 0 additions & 26 deletions libs/sdl2/CMakeLists.txt

This file was deleted.

22 changes: 12 additions & 10 deletions src/Joystick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ if(ANDROID)
Qt6::CorePrivate
)
else()
target_sources(Joystick
PRIVATE
JoystickSDL.cc
JoystickSDL.h
)

target_link_libraries(Joystick
PUBLIC
sdl2
)
include(BuildSdl2)
if(SDL2_FOUND)
target_sources(Joystick
PRIVATE
JoystickSDL.cc
JoystickSDL.h
)
target_link_libraries(Joystick
PUBLIC
SDL2::SDL2
)
endif()
endif()

target_link_libraries(Joystick
Expand Down
1 change: 1 addition & 0 deletions src/Joystick/JoystickSDL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in
}

bool JoystickSDL::init(void) {
// SDL_SetMainReady
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK) < 0) {
SDL_JoystickEventState(SDL_ENABLE);
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError();
Expand Down

0 comments on commit c45c549

Please sign in to comment.