Blob Blame Raw
From eaa6776ea95df00bf9fa3a6dbcd91e7503bed24d Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Fri, 3 Aug 2012 13:18:37 +0400
Subject: [PATCH 14/18] Allow build against external iLBC

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
 CMakeLists.txt                   | 11 ++++++++---
 cmake/FindIlbc.cmake             | 17 +++++++++++++++++
 core/plug-in/ilbc/CMakeLists.txt |  8 ++++++--
 3 files changed, 31 insertions(+), 5 deletions(-)
 create mode 100644 cmake/FindIlbc.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 34f27e5..9e4d81e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,7 +31,7 @@ OPTION(SEMS_USE_SPANDSP       "Build with spandsp" OFF)
 OPTION(SEMS_USE_LIBSAMPLERATE "Build with libsamplerate" OFF)
 OPTION(SEMS_USE_ZRTP          "Build with ZRTP" OFF)
 OPTION(SEMS_USE_MP3           "Build with Lame MP3" OFF)
-OPTION(SEMS_USE_ILBC          "Build with bundled iLBC library" ON)
+OPTION(SEMS_USE_ILBC          "Build with iLBC library (fallback to bundled)" ON)
 OPTION(SEMS_USE_TTS           "Build with Text-to-speech support (requires Flite)" OFF)
 OPTION(SEMS_USE_OPENSSL       "Build with OpenSSL" OFF)
 OPTION(SEMS_USE_MONITORING    "Build with monitoring support" OFF)
@@ -115,9 +115,14 @@ ELSE(SEMS_USE_MP3)
 ENDIF(SEMS_USE_MP3)
 
 IF(SEMS_USE_ILBC)
-	MESSAGE(STATUS "Using bundled iLBC library: YES (default)")
+	FIND_PACKAGE(Ilbc)
+	IF(ILBC_FOUND)
+		MESSAGE(STATUS "Using iLBC library: YES (external)")
+	ELSE(ILBC_FOUND)
+		MESSAGE(STATUS "Using iLBC library: YES (bundled, default)")
+	ENDIF(ILBC_FOUND)
 ELSE(SEMS_USE_ILBC)
-	MESSAGE(STATUS "Using bundled iLBC library: NO")
+	MESSAGE(STATUS "Uusing iLBC library: NO")
 ENDIF(SEMS_USE_ILBC)
 
 # build in support for monitoring?
diff --git a/cmake/FindIlbc.cmake b/cmake/FindIlbc.cmake
new file mode 100644
index 0000000..c5fa5c1
--- /dev/null
+++ b/cmake/FindIlbc.cmake
@@ -0,0 +1,17 @@
+FIND_PATH(ILBC_INCLUDE_DIR ilbc.h)
+FIND_LIBRARY(ILBC_LIBRARIES NAMES ilbc)
+
+IF(ILBC_INCLUDE_DIR AND ILBC_LIBRARIES)
+	SET(ILBC_FOUND TRUE)
+ENDIF(ILBC_INCLUDE_DIR AND ILBC_LIBRARIES)
+
+IF(ILBC_FOUND)
+	IF (NOT Ilbc_FIND_QUIETLY)
+		MESSAGE(STATUS "Found ilbc includes:	${ILBC_INCLUDE_DIR}/ilbc.h")
+		MESSAGE(STATUS "Found ilbc library: ${ILBC_LIBRARIES}")
+	ENDIF (NOT Ilbc_FIND_QUIETLY)
+ELSE(ILBC_FOUND)
+	IF (Ilbc_FIND_REQUIRED)
+		MESSAGE(FATAL_ERROR "Could NOT find ilbc development files")
+	ENDIF (Ilbc_FIND_REQUIRED)
+ENDIF(ILBC_FOUND)
diff --git a/core/plug-in/ilbc/CMakeLists.txt b/core/plug-in/ilbc/CMakeLists.txt
index 1f4dcfb..bf77875 100644
--- a/core/plug-in/ilbc/CMakeLists.txt
+++ b/core/plug-in/ilbc/CMakeLists.txt
@@ -2,10 +2,14 @@ set (ilbc_SRCS
  ilbc.c
 )
 
+SET(sems_module_name ilbc)
+IF(ILBC_FOUND)
+SET(sems_module_libs ilbc)
+ELSE(ILBC_FOUND)
 ADD_SUBDIRECTORY (iLBC_rfc3951)
 INCLUDE_DIRECTORIES (iLBC_rfc3951)
-
-SET(sems_module_name ilbc)
 SET(sems_module_libs libilbc)
+ENDIF(ILBC_FOUND)
+
 INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt)
 
-- 
1.8.0