| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | # TODO
 | 
					
						
							|  |  |  | # - backend selection via command line, rather than simply detecting headers.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | project(cubeb C CXX)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | option(LAZY_LOAD_LIBS "Lazily load shared libraries" ON)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(NOT CMAKE_BUILD_TYPE)
 | 
					
						
							|  |  |  |   set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING | 
					
						
							|  |  |  |       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | endif()
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | set(CMAKE_C_STANDARD 99)
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | set(CMAKE_CXX_STANDARD 17)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | set(CMAKE_CXX_STANDARD_REQUIRED ON)
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | set(CMAKE_CXX_WARNING_LEVEL 4)
 | 
					
						
							|  |  |  | if(NOT MSVC)
 | 
					
						
							|  |  |  |   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter")
 | 
					
						
							| 
									
										
										
										
											2020-12-07 04:28:41 +00:00
										 |  |  |   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -fno-exceptions -fno-rtti")
 | 
					
						
							|  |  |  | else()
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  |   string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable RTTI
 | 
					
						
							|  |  |  |   string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable Exceptions
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | add_library(cubeb | 
					
						
							|  |  |  |   src/cubeb.c
 | 
					
						
							|  |  |  |   src/cubeb_mixer.cpp
 | 
					
						
							|  |  |  |   src/cubeb_resampler.cpp
 | 
					
						
							|  |  |  |   src/cubeb_log.cpp
 | 
					
						
							|  |  |  |   src/cubeb_strings.c
 | 
					
						
							|  |  |  |   src/cubeb_utils.cpp
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | target_include_directories(cubeb | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |   PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-10 08:14:59 +00:00
										 |  |  | add_library(speex OBJECT subprojects/speex/resample.c)
 | 
					
						
							|  |  |  | set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
 | 
					
						
							|  |  |  | target_include_directories(speex INTERFACE subprojects)
 | 
					
						
							|  |  |  | target_compile_definitions(speex PUBLIC | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  |   OUTSIDE_SPEEX
 | 
					
						
							|  |  |  |   FLOATING_POINT
 | 
					
						
							|  |  |  |   EXPORT=
 | 
					
						
							|  |  |  |   RANDOM_PREFIX=speex
 | 
					
						
							| 
									
										
										
										
											2022-08-10 08:14:59 +00:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # $<BUILD_INTERFACE:> required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415
 | 
					
						
							|  |  |  | target_link_libraries(cubeb PRIVATE $<BUILD_INTERFACE:speex>)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | include(CheckIncludeFiles)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | # Threads needed by cubeb_log, _pulse, _alsa, _jack, _sndio, _oss and _sun
 | 
					
						
							|  |  |  | set(THREADS_PREFER_PTHREAD_FLAG ON)
 | 
					
						
							|  |  |  | find_package(Threads)
 | 
					
						
							|  |  |  | target_link_libraries(cubeb PRIVATE Threads::Threads)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(LAZY_LOAD_LIBS)
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  |   if(NOT APPLE AND NOT WIN32)
 | 
					
						
							|  |  |  |     # Skip checks on MacOS because it takes ages in XCode.
 | 
					
						
							|  |  |  |     check_include_files(pulse/pulseaudio.h USE_PULSE)
 | 
					
						
							|  |  |  |     check_include_files(alsa/asoundlib.h   USE_ALSA)
 | 
					
						
							|  |  |  |     check_include_files(jack/jack.h        USE_JACK)
 | 
					
						
							|  |  |  |     check_include_files(sndio.h            USE_SNDIO)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(USE_PULSE OR USE_ALSA OR USE_JACK OR USE_SNDIO)
 | 
					
						
							|  |  |  |       target_link_libraries(cubeb PRIVATE ${CMAKE_DL_LIBS})
 | 
					
						
							|  |  |  |     endif()
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | elseif(NOT APPLE AND NOT WIN32)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   find_package(PkgConfig REQUIRED)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
 | 
					
						
							|  |  |  |   if(libpulse_FOUND)
 | 
					
						
							|  |  |  |     set(USE_PULSE ON)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE DISABLE_LIBPULSE_DLOPEN)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE PkgConfig::libpulse)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   pkg_check_modules(alsa IMPORTED_TARGET alsa)
 | 
					
						
							|  |  |  |   if(alsa_FOUND)
 | 
					
						
							|  |  |  |     set(USE_ALSA ON)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE DISABLE_LIBASOUND_DLOPEN)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE PkgConfig::alsa)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   pkg_check_modules(jack IMPORTED_TARGET jack)
 | 
					
						
							|  |  |  |   if(jack_FOUND)
 | 
					
						
							|  |  |  |     set(USE_JACK ON)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE DISABLE_LIBJACK_DLOPEN)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE PkgConfig::jack)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   check_include_files(sndio.h USE_SNDIO)
 | 
					
						
							|  |  |  |   if(USE_SNDIO)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE DISABLE_LIBSNDIO_DLOPEN)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE sndio)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(USE_PULSE)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |   target_sources(cubeb PRIVATE src/cubeb_pulse.c)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  |   target_compile_definitions(cubeb PRIVATE USE_PULSE)
 | 
					
						
							|  |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(USE_ALSA)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |   target_sources(cubeb PRIVATE src/cubeb_alsa.c)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  |   target_compile_definitions(cubeb PRIVATE USE_ALSA)
 | 
					
						
							|  |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(USE_JACK)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |   target_sources(cubeb PRIVATE src/cubeb_jack.cpp)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  |   target_compile_definitions(cubeb PRIVATE USE_JACK)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(USE_SNDIO)
 | 
					
						
							|  |  |  |   target_sources(cubeb PRIVATE src/cubeb_sndio.c)
 | 
					
						
							|  |  |  |   target_compile_definitions(cubeb PRIVATE USE_SNDIO)
 | 
					
						
							|  |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | if(APPLE)
 | 
					
						
							|  |  |  |   check_include_files(AudioUnit/AudioUnit.h USE_AUDIOUNIT)
 | 
					
						
							|  |  |  |   if(USE_AUDIOUNIT)
 | 
					
						
							|  |  |  |     target_sources(cubeb PRIVATE | 
					
						
							|  |  |  |       src/cubeb_audiounit.cpp
 | 
					
						
							|  |  |  |       src/cubeb_osx_run_loop.cpp)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE USE_AUDIOUNIT)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE "-framework AudioUnit" "-framework CoreAudio" "-framework CoreServices")
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | if(WIN32)
 | 
					
						
							|  |  |  |   check_include_files(audioclient.h USE_WASAPI)
 | 
					
						
							|  |  |  |   if(USE_WASAPI)
 | 
					
						
							|  |  |  |     target_sources(cubeb PRIVATE | 
					
						
							|  |  |  |       src/cubeb_wasapi.cpp)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE USE_WASAPI)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE avrt ole32 ksuser)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  |   check_include_files("windows.h;mmsystem.h" USE_WINMM)
 | 
					
						
							|  |  |  |   if(USE_WINMM)
 | 
					
						
							|  |  |  |     target_sources(cubeb PRIVATE | 
					
						
							|  |  |  |       src/cubeb_winmm.c)
 | 
					
						
							|  |  |  |     target_compile_definitions(cubeb PRIVATE USE_WINMM)
 | 
					
						
							|  |  |  |     target_link_libraries(cubeb PRIVATE winmm)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 11:14:39 +00:00
										 |  |  | if(NOT WIN32 AND NOT APPLE)
 | 
					
						
							|  |  |  |   check_include_files(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
 | 
					
						
							|  |  |  |   if(HAVE_SYS_SOUNDCARD_H)
 | 
					
						
							|  |  |  |     try_compile(USE_OSS "${PROJECT_BINARY_DIR}/compile_tests" | 
					
						
							|  |  |  |       ${PROJECT_SOURCE_DIR}/cmake/compile_tests/oss_is_v4.c)
 | 
					
						
							|  |  |  |     if(USE_OSS)
 | 
					
						
							|  |  |  |       # strlcpy is not available on BSD systems that use glibc,
 | 
					
						
							|  |  |  |       # like Debian kfreebsd, so try using libbsd if available
 | 
					
						
							|  |  |  |       include(CheckSymbolExists)
 | 
					
						
							|  |  |  |       check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
 | 
					
						
							|  |  |  |       if(NOT HAVE_STRLCPY)
 | 
					
						
							|  |  |  |         pkg_check_modules(libbsd-overlay IMPORTED_TARGET libbsd-overlay)
 | 
					
						
							|  |  |  |         if(libbsd-overlay_FOUND)
 | 
					
						
							|  |  |  |           target_link_libraries(cubeb PRIVATE PkgConfig::libbsd-overlay)
 | 
					
						
							|  |  |  |           set(HAVE_STRLCPY true)
 | 
					
						
							|  |  |  |         endif()
 | 
					
						
							|  |  |  |       endif()
 | 
					
						
							|  |  |  |       if (HAVE_STRLCPY)
 | 
					
						
							|  |  |  |         target_sources(cubeb PRIVATE | 
					
						
							|  |  |  |           src/cubeb_oss.c)
 | 
					
						
							|  |  |  |         target_compile_definitions(cubeb PRIVATE USE_OSS)
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  |       endif()
 | 
					
						
							|  |  |  |     endif()
 | 
					
						
							| 
									
										
										
										
											2020-10-24 11:05:37 +00:00
										 |  |  |   endif()
 | 
					
						
							|  |  |  | endif()
 |