From 8ace78e2f8ccb77670ba3066576948e9bff7bfd6 Mon Sep 17 00:00:00 2001
From: Ghislain MARY <ghislain.mary@belledonne-communications.com>
Date: Wed, 26 Nov 2014 16:38:39 +0100
Subject: [PATCH] Handle compilation of unit tests with CMake.

---
 CMakeLists.txt         | 14 +++++++++++++
 config.h.cmake         |  3 +++
 coreapi/CMakeLists.txt |  4 +++-
 gtk/CMakeLists.txt     |  2 +-
 tester/CMakeLists.txt  | 45 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 tester/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65446420a7..2570a4cad8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,6 +55,7 @@ cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENAB
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_PREFIX_PATH}/share/cmake/Modules)
 
 include(CheckIncludeFile)
+include(CheckLibraryExists)
 
 if(MSVC)
 	list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_PREFIX_PATH}/include/MSVC)
@@ -63,6 +64,16 @@ endif()
 find_package(BelleSIP REQUIRED)
 find_package(MS2 REQUIRED)
 find_package(XML2 REQUIRED)
+if(ENABLE_UNIT_TESTS)
+	find_package(CUnit)
+	if(CUNIT_FOUND)
+		check_library_exists("cunit" "CU_get_suite" "" HAVE_CU_GET_SUITE)
+		check_library_exists("cunit" "CU_curses_run_tests" "" HAVE_CU_CURSES)
+	else()
+		message(WARNING "Could not find the cunit library!")
+		set(ENABLE_UNIT_TESTS OFF CACHE BOOL "Enable compilation of unit tests." FORCE)
+	endif()
+endif()
 if(ENABLE_TUNNEL)
 	find_package(Tunnel)
 	if(NOT TUNNEL_FOUND)
@@ -114,6 +125,9 @@ endif()
 if(ENABLE_TOOLS)
 	add_subdirectory(tools)
 endif()
+if(ENABLE_UNIT_TESTS)
+	add_subdirectory(tester)
+endif()
 
 
 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/FindLinphone.cmake
diff --git a/config.h.cmake b/config.h.cmake
index 9756ebbd74..a7020d97af 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -35,3 +35,6 @@
 #define PACKAGE_LOCALE_DIR "${PACKAGE_LOCALE_DIR}"
 #define PACKAGE_DATA_DIR "${PACKAGE_DATA_DIR}"
 #define PACKAGE_SOUND_DIR "${PACKAGE_SOUND_DIR}"
+
+#cmakedefine HAVE_CU_GET_SUITE 1
+#cmakedefine HAVE_CU_CURSES 1
\ No newline at end of file
diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt
index 6efc80e602..b2501e2fbc 100644
--- a/coreapi/CMakeLists.txt
+++ b/coreapi/CMakeLists.txt
@@ -65,6 +65,7 @@ set(SOURCE_FILES
 	linphonefriend.h
 	linphone_tunnel_config.c
 	linphone_tunnel.h
+	localplayer.c
 	lpconfig.c
 	lpconfig.h
 	lsd.c
@@ -84,7 +85,8 @@ set(SOURCE_FILES
 	sipsetup.h
 	xml2lpc.c
 	xml2lpc.h
-	xml.c)
+	xml.c
+)
 if(ENABLE_TUNNEL)
 	list(APPEND SOURCE_FILES
 		linphone_tunnel.cc
diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt
index 0092be84a9..ae395500d3 100644
--- a/gtk/CMakeLists.txt
+++ b/gtk/CMakeLists.txt
@@ -20,7 +20,7 @@
 #
 ############################################################################
 
-find_package(GTK2 2.10 REQUIRED gtk)
+find_package(GTK2 2.18 REQUIRED gtk)
 
 set(UI_FILES
 	about.ui
diff --git a/tester/CMakeLists.txt b/tester/CMakeLists.txt
new file mode 100644
index 0000000000..3131a10545
--- /dev/null
+++ b/tester/CMakeLists.txt
@@ -0,0 +1,45 @@
+############################################################################
+# CMakeLists.txt
+# Copyright (C) 2014  Belledonne Communications, Grenoble France
+#
+############################################################################
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+############################################################################
+
+set(SOURCE_FILES
+	call_tester.c
+	dtmf_tester.c
+	eventapi_tester.c
+	flexisip_tester.c
+	liblinphone_tester.c
+	log_collection_tester.c
+	message_tester.c
+	player_tester.c
+	presence_tester.c
+	quality_reporting_tester.c
+	register_tester.c
+	remote_provisioning_tester.c
+	setup_tester.c
+	stun_tester.c
+	tester.c
+	transport_tester.c
+	upnp_tester.c
+)
+
+add_executable(liblinphone_tester ${SOURCE_FILES})
+target_include_directories(liblinphone_tester PUBLIC ${CUNIT_INCLUDE_DIRS})
+target_link_libraries(liblinphone_tester linphone ${CUNIT_LIBRARIES})
-- 
GitLab