Skip to content

Commit

Permalink
Use the provided SDL2_mixer target
Browse files Browse the repository at this point in the history
Instead of relying on variables defined in the FindSDL2_mixer module,
create an IMPORTED target. This allows any overriding system
SDL2_mixerConfig to add additional properties needed for the build
to succeed.

This might help with bugs with vcpkg/macOS.
  • Loading branch information
lmoureaux committed Dec 25, 2023
1 parent 26febb5 commit 9edcf4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ endif()

if (AUDIO_SDL)
target_sources(freeciv21-client PRIVATE audio/audio_sdl.cpp)
# SDL comes with the -s option on emscripten
if (NOT EMSCRIPTEN)
# SDL comes with the -s option on emscripten
# See https://github.com/microsoft/vcpkg/blob/2023.12.12/ports/sdl2/usage
target_link_libraries(freeciv21-client
PRIVATE $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>)
target_link_libraries(freeciv21-client PRIVATE ${SDL2_MIXER_LIBRARIES})
target_include_directories(freeciv21-client PRIVATE ${SDL2_MIXER_INCLUDE_DIR})
target_link_libraries(freeciv21-client PRIVATE SDL2_mixer::SDL2_mixer)
endif()
endif()

Expand Down
7 changes: 7 additions & 0 deletions cmake/FindSDL2_mixer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer
REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS
VERSION_VAR SDL2_MIXER_VERSION_STRING)

if (SDL2_MIXER_FOUND)
add_library(SDL2_mixer::SDL2_mixer UNKNOWN IMPORTED)
set_target_properties(SDL2_mixer::SDL2_mixer PROPERTIES
IMPORTED_LOCATION "${SDL2_MIXER_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}")
endif()

# for backward compatiblity
set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES})
set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS})
Expand Down
6 changes: 2 additions & 4 deletions cmake/FreecivDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ endif()
# SDL2 for audio
find_package(SDL2)
find_package(SDL2_mixer)
if (SDL2_MIXER_LIBRARIES AND SDL2_FOUND)
if (SDL2_MIXER_FOUND AND SDL2_FOUND)
set(AUDIO_SDL TRUE)
endif()
if (NOT SDL2_FOUND)
message(STATUS "SDL2 not found - audio support disabled")
endif()
if (NOT SDL2_MIXER_LIBRARIES)
if (NOT SDL2_MIXER_FOUND)
message(STATUS "SDL2_mixer not found - audio support disabled")
set(SDL2_MIXER_LIBRARIES "")
set(SDL2_MIXER_INCLUDE_DIR "")
endif()

# Lua
Expand Down

0 comments on commit 9edcf4f

Please sign in to comment.