From ce1126b290d3141779050b8298e284b770bd73f6 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 6 Mar 2015 11:14:37 +0100 Subject: [PATCH] Use a config-file package instead of a find-module package in CMake. --- CMakeLists.txt | 36 ++++++++++----- cmake/FindCUnit.cmake | 58 ++++++++++++++++++++++++ cmake/FindIconv.cmake | 1 - cmake/FindIntl.cmake | 1 - cmake/FindLinphone.cmake.in | 83 ----------------------------------- cmake/FindNotify.cmake | 1 - cmake/FindSoup.cmake | 1 - cmake/FindSqlite3.cmake | 55 +++++++++++++++++++++++ cmake/FindXML2.cmake | 55 +++++++++++++++++++++++ cmake/LinphoneConfig.cmake.in | 44 +++++++++++++++++++ coreapi/CMakeLists.txt | 2 +- 11 files changed, 239 insertions(+), 98 deletions(-) create mode 100644 cmake/FindCUnit.cmake delete mode 100644 cmake/FindLinphone.cmake.in create mode 100644 cmake/FindSqlite3.cmake create mode 100644 cmake/FindXML2.cmake create mode 100644 cmake/LinphoneConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 308bfb12d..5bfb4af67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,6 @@ cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENAB list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/share/cmake/Modules") include(CheckIncludeFile) include(CheckSymbolExists) @@ -88,10 +87,7 @@ if(ENABLE_TUNNEL) endif() endif() if(ENABLE_MSG_STORAGE) - find_package(Sqlite3) - if(NOT SQLITE3_FOUND) - message(FATAL_ERROR "Could not find the sqlite3 library!") - endif() + find_package(Sqlite3 REQUIRED) endif() if(ENABLE_NOTIFY) find_package(Notify) @@ -200,9 +196,29 @@ if(ENABLE_UNIT_TESTS) endif() -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLinphone.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindLinphone.cmake) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FindLinphone.cmake - DESTINATION share/cmake/Modules - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake" + VERSION ${LINPHONE_VERSION} + COMPATIBILITY AnyNewerVersion +) +export(EXPORT LinphoneTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/LinphoneTargets.cmake" + NAMESPACE BelledonneCommunications:: +) +configure_file(cmake/LinphoneConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake" + @ONLY +) + +set(ConfigPackageLocation lib/cmake/Linphone) +install(EXPORT LinphoneTargets + FILE LinphoneTargets.cmake + NAMESPACE BelledonneCommunications:: + DESTINATION ${ConfigPackageLocation} +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake" + DESTINATION ${ConfigPackageLocation} ) diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake new file mode 100644 index 000000000..10c1a10b6 --- /dev/null +++ b/cmake/FindCUnit.cmake @@ -0,0 +1,58 @@ +############################################################################ +# FindCUnit.txt +# Copyright (C) 2015 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. +# +############################################################################ +# +# - Find the CUnit include file and library +# +# CUNIT_FOUND - system has CUnit +# CUNIT_INCLUDE_DIRS - the CUnit include directory +# CUNIT_LIBRARIES - The libraries needed to use CUnit + +include(CheckIncludeFile) +include(CheckLibraryExists) + +set(_CUNIT_ROOT_PATHS + ${CMAKE_INSTALL_PREFIX} +) + +find_path(CUNIT_INCLUDE_DIRS + NAMES CUnit/CUnit.h + HINTS _CUNIT_ROOT_PATHS + PATH_SUFFIXES include +) + +if(CUNIT_INCLUDE_DIRS) + set(HAVE_CUNIT_CUNIT_H 1) +endif() + +find_library(CUNIT_LIBRARIES + NAMES cunit + HINTS ${_CUNIT_ROOT_PATHS} + PATH_SUFFIXES bin lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CUnit + DEFAULT_MSG + CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES +) + +mark_as_advanced(CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES) diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index a1f6a8ad8..c65317a56 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -27,7 +27,6 @@ # ICONV_LIBRARIES - The libraries needed to use libiconv set(_ICONV_ROOT_PATHS - ${WITH_ICONV} ${CMAKE_INSTALL_PREFIX} ) diff --git a/cmake/FindIntl.cmake b/cmake/FindIntl.cmake index a974801fa..35ec969cd 100644 --- a/cmake/FindIntl.cmake +++ b/cmake/FindIntl.cmake @@ -27,7 +27,6 @@ # INTL_LIBRARIES - The libraries needed to use libintl set(_INTL_ROOT_PATHS - ${WITH_INTL} ${CMAKE_INSTALL_PREFIX} ) diff --git a/cmake/FindLinphone.cmake.in b/cmake/FindLinphone.cmake.in deleted file mode 100644 index 5f8b03b19..000000000 --- a/cmake/FindLinphone.cmake.in +++ /dev/null @@ -1,83 +0,0 @@ -############################################################################ -# FindLinphone.cmake -# 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. -# -############################################################################ -# -# - Find the linphone include file and library -# -# LINPHONE_FOUND - system has linphone -# LINPHONE_INCLUDE_DIRS - the linphone include directory -# LINPHONE_LIBRARIES - The libraries needed to use linphone -# LINPHONE_CPPFLAGS - The compilation flags needed to use linphone -# LINPHONE_LDFLAGS - The linking flags needed to use linphone - -find_package(ORTP REQUIRED) -find_package(MS2 REQUIRED) -find_package(XML2 REQUIRED) -find_package(BelleSIP REQUIRED) -if(@ENABLE_MSG_STORAGE@) - find_package(Sqlite3) -endif() - -set(_LINPHONE_ROOT_PATHS - ${WITH_LINPHONE} - ${CMAKE_INSTALL_PREFIX} -) - -find_path(LINPHONE_INCLUDE_DIRS - NAMES linphone/linphonecore.h - HINTS _LINPHONE_ROOT_PATHS - PATH_SUFFIXES include -) - -if(LINPHONE_INCLUDE_DIRS) - set(HAVE_LINPHONE_LINPHONECORE_H 1) -endif() - -find_library(LINPHONE_LIBRARIES - NAMES linphone - HINTS ${_LINPHONE_ROOT_PATHS} - PATH_SUFFIXES bin lib -) - -list(APPEND LINPHONE_INCLUDE_DIRS ${ORTP_INCLUDE_DIRS} ${MS2_INCLUDE_DIRS} ${XML2_INCLUDE_DIRS} ${BELLESIP_INCLUDE_DIRS}) -list(APPEND LINPHONE_LIBRARIES ${ORTP_LIBRARIES} ${MS2_LIBRARIES} ${XML2_LIBRARIES} ${BELLESIP_LIBRARIES}) - -if(SQLITE3_FOUND) - list(APPEND LINPHONE_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIRS}) - list(APPEND LINPHONE_LIBRARIES ${SQLITE3_LIBRARIES}) -endif() - -if(WIN32) - list(APPEND LINPHONE_LIBRARIES shlwapi) -endif(WIN32) - -list(REMOVE_DUPLICATES LINPHONE_INCLUDE_DIRS) -list(REMOVE_DUPLICATES LINPHONE_LIBRARIES) -set(LINPHONE_CPPFLAGS "${MS2_CPPFLAGS}") -set(LINPHONE_LDFLAGS "${MS2_LDFLAGS} ${BELLESIP_LDFLAGS}") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Linphone - DEFAULT_MSG - LINPHONE_INCLUDE_DIRS LINPHONE_LIBRARIES -) - -mark_as_advanced(LINPHONE_INCLUDE_DIRS LINPHONE_LIBRARIES LINPHONE_CPPFLAGS LINPHONE_LDFLAGS) diff --git a/cmake/FindNotify.cmake b/cmake/FindNotify.cmake index f77e0885f..a9fb4d978 100644 --- a/cmake/FindNotify.cmake +++ b/cmake/FindNotify.cmake @@ -27,7 +27,6 @@ # NOTIFY_LIBRARIES - The libraries needed to use libnotify set(_NOTIFY_ROOT_PATHS - ${WITH_NOTIFY} ${CMAKE_INSTALL_PREFIX} ) diff --git a/cmake/FindSoup.cmake b/cmake/FindSoup.cmake index 6e4c0a194..3aeffaefa 100644 --- a/cmake/FindSoup.cmake +++ b/cmake/FindSoup.cmake @@ -32,7 +32,6 @@ endif() find_package(GTK2 2.18 REQUIRED gtk) set(_SOUP_ROOT_PATHS - ${WITH_SOUP} ${CMAKE_INSTALL_PREFIX} ) diff --git a/cmake/FindSqlite3.cmake b/cmake/FindSqlite3.cmake new file mode 100644 index 000000000..7cab06bd1 --- /dev/null +++ b/cmake/FindSqlite3.cmake @@ -0,0 +1,55 @@ +############################################################################ +# FindSqlite3.cmake +# 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. +# +############################################################################ +# +# - Find the sqlite3 include file and library +# +# SQLITE3_FOUND - system has sqlite3 +# SQLITE3_INCLUDE_DIRS - the sqlite3 include directory +# SQLITE3_LIBRARIES - The libraries needed to use sqlite3 + +set(_SQLITE3_ROOT_PATHS + ${CMAKE_INSTALL_PREFIX} +) + +find_path(SQLITE3_INCLUDE_DIRS + NAMES sqlite3.h + HINTS _SQLITE3_ROOT_PATHS + PATH_SUFFIXES include +) + +if(SQLITE3_INCLUDE_DIRS) + set(HAVE_SQLITE3_H 1) +endif() + +find_library(SQLITE3_LIBRARIES + NAMES sqlite3 + HINTS ${_SQLITE3_ROOT_PATHS} + PATH_SUFFIXES bin lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Sqlite3 + DEFAULT_MSG + SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES HAVE_SQLITE3_H +) + +mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES HAVE_SQLITE3_H) diff --git a/cmake/FindXML2.cmake b/cmake/FindXML2.cmake new file mode 100644 index 000000000..9d0eebe14 --- /dev/null +++ b/cmake/FindXML2.cmake @@ -0,0 +1,55 @@ +############################################################################ +# FindXML2.txt +# Copyright (C) 2015 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. +# +############################################################################ +# +# - Find the libxml2 include file and library +# +# XML2_FOUND - system has libxml2 +# XML2_INCLUDE_DIRS - the libxml2 include directory +# XML2_LIBRARIES - The libraries needed to use libxml2 + +set(_XML2_ROOT_PATHS + ${CMAKE_INSTALL_PREFIX} +) + +find_path(XML2_INCLUDE_DIRS + NAMES libxml/xmlreader.h + HINTS _XML2_ROOT_PATHS + PATH_SUFFIXES include/libxml2 +) + +if(XML2_INCLUDE_DIRS) + set(HAVE_LIBXML_XMLREADER_H 1) +endif() + +find_library(XML2_LIBRARIES + NAMES xml2 + HINTS ${_XML2_ROOT_PATHS} + PATH_SUFFIXES bin lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(XML2 + DEFAULT_MSG + XML2_INCLUDE_DIRS XML2_LIBRARIES +) + +mark_as_advanced(XML2_INCLUDE_DIRS XML2_LIBRARIES) diff --git a/cmake/LinphoneConfig.cmake.in b/cmake/LinphoneConfig.cmake.in new file mode 100644 index 000000000..94920e242 --- /dev/null +++ b/cmake/LinphoneConfig.cmake.in @@ -0,0 +1,44 @@ +############################################################################ +# LinphoneConfig.cmake +# Copyright (C) 2015 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. +# +############################################################################ +# +# Config file for the belle-sip package. +# It defines the following variables: +# +# LINPHONE_FOUND - system has linphone +# LINPHONE_INCLUDE_DIRS - the linphone include directory +# LINPHONE_LIBRARIES - The libraries needed to use linphone +# LINPHONE_LDFLAGS - The linking flags needed to use linphone + +include("${CMAKE_CURRENT_LIST_DIR}/LinphoneTargets.cmake") +if(@ENABLE_TUNNEL@) + find_package(Tunnel) +endif() + +get_filename_component(LINPHONE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(LINPHONE_INCLUDE_DIRS "${LINPHONE_CMAKE_DIR}/../../../include") +set(LINPHONE_LIBRARIES BelledonneCommunications::linphone) +set(LINPHONE_LDFLAGS @LINK_FLAGS@) +if(TUNNEL_FOUND) + list(APPEND LINPHONE_INCLUDE_DIRS ${TUNNEL_INCLUDE_DIRS}) + list(APPEND LINPHONE_LIBRARIES ${TUNNEL_LIBRARIES}) +endif() +set(LINPHONE_FOUND 1) diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index b21afc87d..fc59af95e 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -159,7 +159,7 @@ if(ICONV_FOUND) target_include_directories(linphone PUBLIC ${ICONV_INCLUDE_DIRS}) endif() -install(TARGETS linphone +install(TARGETS linphone EXPORT LinphoneTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib