From c18b56240914c20bfc06780acf71beca7dc971a5 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Thu, 25 Feb 2021 20:36:34 +0900 Subject: [PATCH] add sndio support (CMake) --- CMakeLists.txt | 12 ++++++++++ cmake/modules/Findsndio.cmake | 42 +++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 8 ++++++- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 cmake/modules/Findsndio.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b67faf..e03fbd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,10 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") configure_file("${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}.desktop.in" "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" @ONLY) +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") + set(OPENBSD TRUE) + set(HAVE_SNDIO TRUE) + elseif(APPLE) if("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") message(STATUS "Build for macOS target: local version") @@ -301,6 +305,12 @@ if(LINUX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AVAHI_CLIENT") endif() +elseif (HAVE_SNDIO) + find_package(sndio REQUIRED) + if(SNDIO_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SNDIO") + endif() + elseif (NOT WIN32 AND NOT CYGWIN) find_package(Portaudio REQUIRED) if(PORTAUDIO_FOUND) @@ -314,6 +324,8 @@ else() set(UDEV_LIBRARIES "") set(PORTAUDIO_INCLUDE_DIRS "") set(PORTAUDIO_LIBRARIES "") + set(SNDIO_INCLUDE_DIRS "") + set(SNDIO_LIBRARIES "") endif() # manage and fetch new data diff --git a/cmake/modules/Findsndio.cmake b/cmake/modules/Findsndio.cmake new file mode 100644 index 0000000..e7292d5 --- /dev/null +++ b/cmake/modules/Findsndio.cmake @@ -0,0 +1,42 @@ +# - Try to find sndio +# +# SNDIO_FOUND - system has sndio +# SNDIO_LIBRARIES - location of the library for sndio +# SNDIO_INCLUDE_DIRS - location of the include files for sndio + +set(SNDIO_ROOT_DIR + "${SNDIO_ROOT_DIR}" + CACHE + PATH + "Directory to search for sndio") + +# no need to check pkg-config + +find_path(SNDIO_INCLUDE_DIRS + NAMES + sndio.h + PATHS + /usr/local/include + /usr/include + /opt/local/include + HINTS + ${SNDIO_ROOT_DIR} + ) + +find_library(SNDIO_LIBRARIES + NAMES + sndio + PATHS + /usr/local/lib + /usr/lib + /usr/lib64 + /opt/local/lib + HINTS + ${SNDIIO_ROOT_DIR} + ) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SNDIO DEFAULT_MSG SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES) + +mark_as_advanced(SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fba03b..9fe8306 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories( ${ALSA_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS} ${PORTAUDIO_INCLUDE_DIRS} + ${SNDIO_INCLUDE_DIRS} ${CUSTOM_GEOTRANZ_DIR} ${CUSTOM_HIDAPI_DIR} ) @@ -116,7 +117,11 @@ if(LINUX) list(REMOVE_ITEM direwolf_SOURCES dwgpsd.c ) - else() # macOS freebsd openbsd + elseif(HAVE_SNDIO) + list(APPEND direwolf_SOURCES + audio.c + ) + else() # macOS freebsd list(APPEND direwolf_SOURCES audio_portaudio.c ) @@ -143,6 +148,7 @@ target_link_libraries(direwolf ${ALSA_LIBRARIES} ${UDEV_LIBRARIES} ${PORTAUDIO_LIBRARIES} + ${SNDIO_LIBRARIES} ${AVAHI_LIBRARIES} )