Skip to content

Commit

Permalink
cmake: make sure SDL2_sound::SDL2_sound always exists
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr authored and icculus committed Oct 26, 2023
1 parent 1507be9 commit c8e96be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,9 @@ message_bool_option("Build static library" SDLSOUND_BUILD_STATIC)
message_bool_option("Build shared library" SDLSOUND_BUILD_SHARED)
message_bool_option("Build stdio test program" SDLSOUND_BUILD_TEST)

# Make sure SDL2_sound::SDL2_sound always exists
if(TARGET SDL2_sound::SDL2_sound-static AND NOT TARGET SDL2_sound::SDL2_sound)
add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound-static)
endif()

# end of CMakeLists.txt
11 changes: 11 additions & 0 deletions cmake/SDL2_soundConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_sound-static-targets.cmake")
endif()

check_required_components(SDL2_sound)

# Create SDL2_sound::SDL2_sound alias for static-only builds
if(TARGET SDL2_sound::SDL2_sound-static AND NOT TARGET SDL2_sound::SDL2_sound)
if(CMAKE_VERSION VERSION_LESS "3.18")
# FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
add_library(SDL2_sound::SDL2_sound INTERFACE IMPORTED)
set_target_properties(SDL2_sound::SDL2_sound PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2_sound::SDL2_sound-static")
else()
add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound::SDL2_sound-static)
endif()
endif()

0 comments on commit c8e96be

Please sign in to comment.