--- CMakeLists.txt.orig	2013-09-16 04:58:51.000000000 +0200
+++ CMakeLists.txt	2013-09-16 05:15:59.000000000 +0200
@@ -351,51 +351,81 @@
 		message("OpenMP parallelization disabled")
 	endif()
 
-	include(FindALSA OPTIONAL)
-	if(ALSA_FOUND)
-		add_definitions(-DHAVE_ALSA=1)
-		message("ALSA found, enabling ALSA sound backend")
+	option(DISABLE_ALSA "Disable ALSA sound backend" OFF)
+	if(NOT DISABLE_ALSA)
+		include(FindALSA OPTIONAL)
+		if(ALSA_FOUND)
+			add_definitions(-DHAVE_ALSA=1)
+			message("ALSA found, enabling ALSA sound backend")
+		else()
+			add_definitions(-DHAVE_ALSA=0)
+			message("ALSA NOT found, disabling ALSA sound backend")
+		endif(ALSA_FOUND)
 	else()
 		add_definitions(-DHAVE_ALSA=0)
-		message("ALSA NOT found, disabling ALSA sound backend")
-	endif(ALSA_FOUND)
+		message("ALSA sound backend disabled")
+	endif()
 
-	check_lib(AO ao QUIET)
-	if(AO_FOUND)
-		add_definitions(-DHAVE_AO=1)
-		message("ao found, enabling ao sound backend")
+	option(DISABLE_AO "Disable ao sound backend" OFF)
+	if(NOT DISABLE_AO)
+		check_lib(AO ao QUIET)
+		if(AO_FOUND)
+			add_definitions(-DHAVE_AO=1)
+			message("ao found, enabling ao sound backend")
+		else()
+			add_definitions(-DHAVE_AO=0)
+			message("ao NOT found, disabling ao sound backend")
+		endif(AO_FOUND)
 	else()
 		add_definitions(-DHAVE_AO=0)
-		message("ao NOT found, disabling ao sound backend")
-	endif(AO_FOUND)
+		message("ao sound backend disabled")
+	endif()
 
-	check_lib(BLUEZ bluez QUIET)
-	if(BLUEZ_FOUND)
-		add_definitions(-DHAVE_BLUEZ=1)
-		message("bluez found, enabling bluetooth support")
+	option(DISABLE_BLUEZ "Disable bluez (bluetooth) support" OFF)
+	if(NOT DISABLE_BLUEZ)
+		check_lib(BLUEZ bluez QUIET)
+		if(BLUEZ_FOUND)
+			add_definitions(-DHAVE_BLUEZ=1)
+			message("bluez found, enabling bluetooth support")
+		else()
+			add_definitions(-DHAVE_BLUEZ=0)
+			message("bluez NOT found, disabling bluetooth support")
+		endif(BLUEZ_FOUND)
 	else()
 		add_definitions(-DHAVE_BLUEZ=0)
-		message("bluez NOT found, disabling bluetooth support")
-	endif(BLUEZ_FOUND)
+		message("bluez (bluetooth) support disabled")
+	endif()
 
-	check_lib(PULSEAUDIO libpulse-simple QUIET)
-	if(PULSEAUDIO_FOUND)
-		add_definitions(-DHAVE_PULSEAUDIO=1)
-		message("PulseAudio found, enabling PulseAudio sound backend")
+	option(DISABLE_PULSEAUDIO "Disable PulseAudio sound backend" OFF)
+	if(NOT DISABLE_PULSEAUDIO)
+		check_lib(PULSEAUDIO libpulse-simple QUIET)
+		if(PULSEAUDIO_FOUND)
+			add_definitions(-DHAVE_PULSEAUDIO=1)
+			message("PulseAudio found, enabling PulseAudio sound backend")
+		else()
+			add_definitions(-DHAVE_PULSEAUDIO=0)
+			message("PulseAudio NOT found, disabling PulseAudio sound backend")
+		endif(PULSEAUDIO_FOUND)
 	else()
 		add_definitions(-DHAVE_PULSEAUDIO=0)
-		message("PulseAudio NOT found, disabling PulseAudio sound backend")
-	endif(PULSEAUDIO_FOUND)
+		message("PulseAudio sound backend disabled")
+	endif()
 
-	include(FindOpenAL OPTIONAL)
-	if(OPENAL_FOUND)
-		add_definitions(-DHAVE_OPENAL=1)
-		include_directories(${OPENAL_INCLUDE_DIR})
-		message("OpenAL found, enabling OpenAL sound backend")
+	option(DISABLE_OPENAL "Disable OpenAL sound backend" OFF)
+	if(NOT DISABLE_OPENAL)
+		include(FindOpenAL OPTIONAL)
+		if(OPENAL_FOUND)
+			add_definitions(-DHAVE_OPENAL=1)
+			include_directories(${OPENAL_INCLUDE_DIR})
+			message("OpenAL found, enabling OpenAL sound backend")
+		else()
+			add_definitions(-DHAVE_OPENAL=0)
+			message("OpenAL NOT found, disabling OpenAL sound backend")
+		endif(OPENAL_FOUND)
 	else()
 		add_definitions(-DHAVE_OPENAL=0)
-		message("OpenAL NOT found, disabling OpenAL sound backend")
-	endif(OPENAL_FOUND)
+		message("OpenAL sound backend disabled")
+	endif()
 
 	if(UNIX AND NOT APPLE)
 		# Note: The convention is to check USE_X11 or USE_WAYLAND where needed.
@@ -455,21 +485,32 @@
 		check_libav()
 	endif()
 
-	set(CMAKE_REQUIRED_LIBRARIES portaudio)
-	CHECK_CXX_SOURCE_RUNS(
-		"#include <portaudio.h>
-		int main(int argc, char **argv)
-		{ if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
-		PORTAUDIO)
-	if(PORTAUDIO)
-		message("PortAudio found, enabling mic support")
-		add_definitions(-DHAVE_PORTAUDIO=1)
-		set(PORTAUDIO_FOUND TRUE)
+	option(DISABLE_PORTAUDIO "Disable PortAudio (mic) support" OFF)
+	if(NOT DISABLE_PORTAUDIO)
+		include_directories(BEFORE ${CMAKE_INSTALL_PREFIX}/include/portaudio2)
+		link_directories(${CMAKE_INSTALL_PREFIX}/lib/portaudio2)
+		set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INSTALL_PREFIX}/include/portaudio2)
+		set(CMAKE_REQUIRED_FLAGS -L${CMAKE_INSTALL_PREFIX}/lib/portaudio2)
+		set(CMAKE_REQUIRED_LIBRARIES portaudio)
+		CHECK_CXX_SOURCE_RUNS(
+			"#include <portaudio.h>
+			int main(int argc, char **argv)
+			{ if(Pa_GetVersion() >= 1890) return 0; else return 1; }"
+			PORTAUDIO)
+		if(PORTAUDIO)
+			message("PortAudio found, enabling mic support")
+			add_definitions(-DHAVE_PORTAUDIO=1)
+			set(PORTAUDIO_FOUND TRUE)
+		else()
+			message("PortAudio not found, disabling mic support")
+			add_definitions(-DHAVE_PORTAUDIO=0)
+			set(PORTAUDIO_FOUND FALSE)
+		endif(PORTAUDIO)
 	else()
-		message("PortAudio not found, disabling mic support")
+		message("PortAudio (mic) support disabled")
 		add_definitions(-DHAVE_PORTAUDIO=0)
 		set(PORTAUDIO_FOUND FALSE)
-	endif(PORTAUDIO)
+	endif()
 
 	if(OPROFILING)
 		check_lib(OPROFILE opagent opagent.h)
