From efe95ded36965ca96c1e8cb6308c607da6e78b6e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 2 Jul 2015 03:48:27 -0700 Subject: [PATCH] closer to building on windows --- .gitignore | 1 + CMakeLists.txt | 70 +++++++++++++++++++++++++++++-------------------- README.md | 32 ++++++++++++++++++++++ src/config.h.in | 1 + src/soundio.cpp | 8 +++++- 5 files changed, 83 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 567609b..04029d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +build-win/ diff --git a/CMakeLists.txt b/CMakeLists.txt index b5ed2d9..abe2a42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,15 +16,56 @@ set(LIBSOUNDIO_VERSION_PATCH 0) set(LIBSOUNDIO_VERSION "${LIBSOUNDIO_VERSION_MAJOR}.${LIBSOUNDIO_VERSION_MINOR}.${LIBSOUNDIO_VERSION_PATCH}") message("Configuring libsoundio version ${LIBSOUNDIO_VERSION}") +find_package(Threads) +if(Threads_FOUND) + set(STATUS_THREADS "OK") +else(Threads_FOUND) + set(STATUS_THREADS "not found") +endif(Threads_FOUND) + + +if(WIN32) + set(SOUNDIO_HAVE_PULSEAUDIO false) + set(STATUS_PULSEAUDIO "disabled") +else() + find_package(PulseAudio) + if(PULSEAUDIO_FOUND) + set(STATUS_PULSEAUDIO "OK") + set(SOUNDIO_HAVE_PULSEAUDIO true) + else() + set(STATUS_PULSEAUDIO "not found") + set(SOUNDIO_HAVE_PULSEAUDIO false) + endif() +endif() + +if(APPLE OR WIN32) + set(SOUNDIO_HAVE_ALSA false) + set(STATUS_ALSA "disabled") +else() + find_package(ALSA) + if(ALSA_FOUND) + set(STATUS_ALSA "OK") + set(SOUNDIO_HAVE_ALSA true) + else() + set(STATUS_ALSA "not found") + set(SOUNDIO_HAVE_ALSA false) + endif() +endif() + set(LIBSOUNDIO_SOURCES "${CMAKE_SOURCE_DIR}/src/soundio.cpp" "${CMAKE_SOURCE_DIR}/src/util.cpp" "${CMAKE_SOURCE_DIR}/src/os.cpp" "${CMAKE_SOURCE_DIR}/src/dummy.cpp" - "${CMAKE_SOURCE_DIR}/src/pulseaudio.cpp" "${CMAKE_SOURCE_DIR}/src/dummy_ring_buffer.cpp" "${CMAKE_SOURCE_DIR}/src/channel_layout.cpp" ) +if(SOUNDIO_HAVE_PULSEAUDIO) + set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} + "${CMAKE_SOURCE_DIR}/src/pulseaudio.cpp" + ) +endif() + set(CONFIGURE_OUT_FILE "${CMAKE_BINARY_DIR}/config.h") set(LIBSOUNDIO_HEADERS "${CMAKE_SOURCE_DIR}/src/soundio.h" @@ -35,33 +76,6 @@ set(TEST_SOURCES "${CMAKE_SOURCE_DIR}/test/unit_tests.cpp" ) -find_package(Threads) -if(Threads_FOUND) - set(STATUS_THREADS "OK") -else(Threads_FOUND) - set(STATUS_THREADS "not found") -endif(Threads_FOUND) - - -find_package(PulseAudio) -if(PULSEAUDIO_FOUND) - set(STATUS_PULSEAUDIO "OK") -else() - set(STATUS_PULSEAUDIO "not found") -endif() - -if(APPLE) - set(SOUNDIO_HAVE_ALSA false) - set(STATUS_ALSA "OK") -else() - set(SOUNDIO_HAVE_ALSA true) - find_package(ALSA) - if(ALSA_FOUND) - set(STATUS_ALSA "OK") - else() - set(STATUS_ALSA "not found") - endif() -endif() # GTFO, -lstdc++ !! set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") diff --git a/README.md b/README.md index a4b72c4..40d928a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,38 @@ libsoundio is programmed in a tiny subset of C++: * No references. * No linking against libstdc++. +### Building + +``` +$ mkdir build +$ cd build +$ cmake .. +$ make +$ sudo make install +``` + +### Building With MXE + +You can build libsoundio with [mxe](http://mxe.cc/). Follow the +[requirements](http://mxe.cc/#requirements) section to install the +packages necessary on your system. Then somewhere on your file system: + +``` +$ git clone https://github.com/mxe/mxe +$ cd mxe +$ make gcc +``` + +Then in the libsoundio source directory (replace "/path/to/mxe" with the +appropriate path): + +``` +$ mkdir build-win +$ cd build-win +$ cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake +$ make +``` + ## Roadmap 0. ALSA (Linux) diff --git a/src/config.h.in b/src/config.h.in index cb37e96..04c5439 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -7,5 +7,6 @@ #define SOUNDIO_VERSION_STRING "@LIBSOUNDIO_VERSION@" #cmakedefine SOUNDIO_HAVE_ALSA +#cmakedefine SOUNDIO_HAVE_PULSEAUDIO #endif diff --git a/src/soundio.cpp b/src/soundio.cpp index 411054f..a11dab5 100644 --- a/src/soundio.cpp +++ b/src/soundio.cpp @@ -8,8 +8,12 @@ #include "soundio.hpp" #include "util.hpp" #include "dummy.hpp" -#include "pulseaudio.hpp" #include "os.hpp" +#include "config.h" + +#ifdef SOUNDIO_HAVE_PULSEAUDIO +#include "pulseaudio.hpp" +#endif #include #include @@ -84,12 +88,14 @@ struct SoundIo * soundio_create(void) { int soundio_connect(struct SoundIo *soundio) { int err; +#ifdef SOUNDIO_HAVE_PULSEAUDIO soundio->current_backend = SoundIoBackendPulseAudio; err = soundio_pulseaudio_init(soundio); if (err != SoundIoErrorInitAudioBackend) { soundio_disconnect(soundio); return err; } +#endif soundio->current_backend = SoundIoBackendDummy; err = soundio_dummy_init(soundio);