cmake: use FindALSA.cmake to find ALSA libraries

Co-authored-by: nfarid <54642193+nfarid@users.noreply.github.com>
main
Anonymous Maarten 2022-12-12 00:18:06 +01:00
parent 053ce39d67
commit 9eb4d1f020
7 changed files with 74 additions and 25 deletions

6
.gitignore vendored
View File

@ -62,6 +62,11 @@ cmake-build-*
xcuserdata xcuserdata
*.xcworkspace *.xcworkspace
# for QtCreator
CMakeLists.txt.user
build*/
*.pro.user*
# for Visual C++ # for Visual C++
.vs .vs
Debug Debug
@ -164,6 +169,7 @@ test/testyuv
test/torturethread test/torturethread
builddir/ builddir/
!build-scripts/
debian/*.debhelper.log debian/*.debhelper.log
debian/*.substvars debian/*.substvars
debian/*.tar.gz debian/*.tar.gz

View File

@ -18,6 +18,9 @@ endif()
set(EXTRA_LIBS) set(EXTRA_LIBS)
set(EXTRA_LDFLAGS) set(EXTRA_LDFLAGS)
set(CMAKE_DEPENDS)
set(PKGCONFIG_DEPENDS)
# This is a virtual "library" that just exists to collect up compiler and # This is a virtual "library" that just exists to collect up compiler and
# linker options that used to be global to this CMake project. When you # linker options that used to be global to this CMake project. When you
# specify it as part of a real library's target_link_libraries(), that # specify it as part of a real library's target_link_libraries(), that
@ -27,7 +30,6 @@ set(EXTRA_LDFLAGS)
add_library(sdl-build-options INTERFACE) add_library(sdl-build-options INTERFACE)
if(WINDOWS_STORE) if(WINDOWS_STORE)
cmake_minimum_required(VERSION 3.11.0)
target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1") target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1")
target_compile_options(sdl-build-options INTERFACE "-ZW") target_compile_options(sdl-build-options INTERFACE "-ZW")
endif() endif()
@ -3051,8 +3053,7 @@ if (SDL_ASAN)
endif() endif()
endif() endif()
if(SDL_CCACHE) if(SDL_CCACHE AND NOT CMAKE_VERSION VERSION_LESS 3.4)
cmake_minimum_required(VERSION 3.4)
find_program(CCACHE_BINARY ccache) find_program(CCACHE_BINARY ccache)
if(CCACHE_BINARY) if(CCACHE_BINARY)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY}) set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY})
@ -3062,6 +3063,8 @@ if(SDL_CCACHE)
else() else()
set(HAVE_CCACHE OFF) set(HAVE_CCACHE OFF)
endif() endif()
else()
set(HAVE_CCACHE OFF)
endif() endif()
if(SDL_TESTS) if(SDL_TESTS)
@ -3222,7 +3225,7 @@ if(SDL_SHARED)
set_target_properties(SDL3 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB") set_target_properties(SDL3 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
endif() endif()
# FIXME: if CMAKE_VERSION >= 3.13, use target_link_options for EXTRA_LDFLAGS # FIXME: if CMAKE_VERSION >= 3.13, use target_link_options for EXTRA_LDFLAGS
target_link_libraries(SDL3 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}) target_link_libraries(SDL3 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD} ${CMAKE_DEPENDS})
target_include_directories(SDL3 target_include_directories(SDL3
PRIVATE PRIVATE
"$<BUILD_INTERFACE:${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>" "$<BUILD_INTERFACE:${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>"
@ -3257,7 +3260,7 @@ if(SDL_STATIC)
target_compile_definitions(SDL3-static PRIVATE SDL_STATIC_LIB) target_compile_definitions(SDL3-static PRIVATE SDL_STATIC_LIB)
# TODO: Win32 platforms keep the same suffix .lib for import and static # TODO: Win32 platforms keep the same suffix .lib for import and static
# libraries - do we need to consider this? # libraries - do we need to consider this?
target_link_libraries(SDL3-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) target_link_libraries(SDL3-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${CMAKE_DEPENDS})
target_include_directories(SDL3-static target_include_directories(SDL3-static
PRIVATE PRIVATE
"$<BUILD_INTERFACE:${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>" "$<BUILD_INTERFACE:${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>>"
@ -3402,6 +3405,7 @@ if(NOT SDL3_DISABLE_INSTALL)
FILES FILES
${CMAKE_CURRENT_BINARY_DIR}/SDL3Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/SDL3Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake
${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake
DESTINATION "${SDL_INSTALL_CMAKEDIR}" DESTINATION "${SDL_INSTALL_CMAKEDIR}"
COMPONENT Devel COMPONENT Devel
) )

View File

@ -30,6 +30,16 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake")
set(SDL3_SDL3_test_FOUND TRUE) set(SDL3_SDL3_test_FOUND TRUE)
endif() endif()
include("${CMAKE_CURRENT_LIST_DIR}/sdlfind.cmake")
set(SDL_ALSA @SDL_ALSA@)
set(SDL_ALSA_SHARED @SDL_ALSA_SHARED@)
if(SDL_ALSA AND NOT SDL_ALSA_SHARED AND TARGET SDL2::SDL2-static)
sdlFindALSA()
endif()
unset(SDL_ALSA)
unset(SDL_ALSA_SHARED)
check_required_components(SDL3) check_required_components(SDL3)
# Create SDL3::SDL3 alias for static-only builds # Create SDL3::SDL3 alias for static-only builds

View File

@ -29,7 +29,7 @@ ENDMACRO()
# Message Output # Message Output
macro(MESSAGE_WARN _TEXT) macro(MESSAGE_WARN _TEXT)
message(STATUS "*** WARNING: ${_TEXT}") message(WARNING "${_TEXT}")
endmacro() endmacro()
macro(MESSAGE_ERROR _TEXT) macro(MESSAGE_ERROR _TEXT)
@ -78,7 +78,7 @@ macro(LISTTOSTR _LIST _OUTPUT)
endforeach() endforeach()
endmacro() endmacro()
macro(LISTTOSTRREV _LIST _OUTPUT) function(LISTTOSTRREV _LIST _OUTPUT)
if(${ARGC} EQUAL 3) if(${ARGC} EQUAL 3)
# prefix for each element # prefix for each element
set(_LPREFIX ${ARGV2}) set(_LPREFIX ${ARGV2})
@ -87,10 +87,12 @@ macro(LISTTOSTRREV _LIST _OUTPUT)
endif() endif()
# Do not use string(REPLACE ";" " ") here to avoid messing up list # Do not use string(REPLACE ";" " ") here to avoid messing up list
# entries # entries
set(res)
foreach(_ITEM ${${_LIST}}) foreach(_ITEM ${${_LIST}})
set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}") set(res "${res} ${_LPREFIX}${_ITEM}")
endforeach() endforeach()
endmacro() set($_OUTPUT} "${res}" PARENT_SCOPE)
endfunction()
if(CMAKE_VERSION VERSION_LESS 3.16.0 OR SDL3_SUBPROJECT) if(CMAKE_VERSION VERSION_LESS 3.16.0 OR SDL3_SUBPROJECT)
# - CMake versions <3.16 do not support the OBJC language # - CMake versions <3.16 do not support the OBJC language

View File

@ -1,4 +1,6 @@
include(CMakeParseArguments) include(CMakeParseArguments)
include(${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake)
macro(FindLibraryAndSONAME _LIB) macro(FindLibraryAndSONAME _LIB)
cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN}) cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN})
@ -6,6 +8,13 @@ macro(FindLibraryAndSONAME _LIB)
string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}") string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}")
find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS}) find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS})
if(${_LNAME}_LIB MATCHES ".*\\${CMAKE_SHARED_LIBRARY_SUFFIX}.*" AND NOT ${_LNAME}_LIB MATCHES ".*\\${CMAKE_STATIC_LIBRARY_SUFFIX}.*")
set(${_LNAME}_SHARED TRUE)
else()
set(${_LNAME}_SHARED FALSE)
endif()
if(${_LNAME}_LIB) if(${_LNAME}_LIB)
# reduce the library name for shared linking # reduce the library name for shared linking
@ -83,27 +92,36 @@ endmacro()
# - HAVE_SDL_LOADSO opt # - HAVE_SDL_LOADSO opt
macro(CheckALSA) macro(CheckALSA)
if(SDL_ALSA) if(SDL_ALSA)
CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H) sdlFindALSA()
if(HAVE_ASOUNDLIB_H) if(ALSA_FOUND)
CHECK_LIBRARY_EXISTS(asound snd_pcm_recover "" HAVE_LIBASOUND) file(GLOB ALSA_SOURCES "${SDL3_SOURCE_DIR}/src/audio/alsa/*.c")
endif()
if(HAVE_LIBASOUND)
set(HAVE_ALSA TRUE)
file(GLOB ALSA_SOURCES ${SDL3_SOURCE_DIR}/src/audio/alsa/*.c)
list(APPEND SOURCE_FILES ${ALSA_SOURCES}) list(APPEND SOURCE_FILES ${ALSA_SOURCES})
set(SDL_AUDIO_DRIVER_ALSA 1) set(SDL_AUDIO_DRIVER_ALSA 1)
if(SDL_ALSA_SHARED AND NOT HAVE_SDL_LOADSO) set(HAVE_ALSA TRUE)
message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading") set(HAVE_ALSA_SHARED FALSE)
endif() if(SDL_ALSA_SHARED)
if(HAVE_SDL_LOADSO)
FindLibraryAndSONAME("asound") FindLibraryAndSONAME("asound")
if(SDL_ALSA_SHARED AND ASOUND_LIB AND HAVE_SDL_LOADSO) if(ASOUND_LIB AND ASOUND_SHARED)
target_include_directories(sdl-build-options INTERFACE $<TARGET_PROPERTY:ALSA::ALSA,INTERFACE_INCLUDE_DIRECTORIES>)
set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
set(HAVE_ALSA_SHARED TRUE) set(HAVE_ALSA_SHARED TRUE)
else() else()
list(APPEND EXTRA_LIBS asound) message(WARNING "Unable to find asound shared object")
endif()
else()
message(WARNING "You must have SDL_LoadObject() support for dynamic ALSA loading")
endif()
endif()
if(NOT HAVE_ALSA_SHARED)
list(APPEND CMAKE_DEPENDS ALSA::ALSA)
list(APPEND PKGCONFIG_DEPENDS alsa)
endif() endif()
set(HAVE_SDL_AUDIO TRUE) set(HAVE_SDL_AUDIO TRUE)
endif() endif()
else()
set(HAVE_ALSA FALSE)
message(WARNING "Unable to find the alsa development library")
endif() endif()
endmacro() endmacro()

9
cmake/sdlfind.cmake Normal file
View File

@ -0,0 +1,9 @@
macro(sdlFindALSA)
find_package(ALSA MODULE)
if(ALSA_FOUND AND (NOT TARGET ALSA::ALSA) )
add_Library(ALSA::ALSA UNKNOWN IMPORTED)
set_property(TARGET ALSA::ALSA PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
set_property(TARGET ALSA::ALSA APPEND PROPERTY IMPORTED_LOCATION ${ALSA_LIBRARY})
endif()
endmacro()

View File

@ -8,7 +8,7 @@ includedir=@includedir@
Name: sdl3 Name: sdl3
Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
Version: @SDL_VERSION@ Version: @SDL_VERSION@
Requires: Requires.private: @PKGCONFIG_DEPENDS@
Conflicts: Conflicts:
Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ @PKGCONFIG_LIBS_PRIV@ @SDL_STATIC_LIBS@ Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ @PKGCONFIG_LIBS_PRIV@ @SDL_STATIC_LIBS@
Cflags: -I${includedir} @SDL_CFLAGS@ Cflags: -I${includedir} @SDL_CFLAGS@