Commit 29631916 authored by Ghislain MARY's avatar Ghislain MARY

Clean CMake build system.

parent 4604d93d
......@@ -21,8 +21,7 @@
############################################################################
cmake_minimum_required(VERSION 2.8)
project(BELLESIP C)
enable_language(CXX)
project(BELLESIP C CXX)
set(PACKAGE "belle-sip")
......@@ -40,16 +39,17 @@ option(ENABLE_STATIC "Build static library (default is shared library)." OFF)
option(ENABLE_TLS "Enable TLS support" ON)
option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)
set(WITH_ANTLR "${CMAKE_INSTALL_PREFIX}" CACHE STRING "Set prefix where libantlr3c can be found (ex:/usr or /usr/local)")
set(WITH_CUNIT "${CMAKE_INSTALL_PREFIX}" CACHE STRING "Set prefix where libcunit can be found (ex:/usr or /usr/local)")
set(WITH_POLARSSL "${CMAKE_INSTALL_PREFIX}" CACHE STRING "Set prefix where polarssl can be found (ex:/usr or /usr/local)")
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(MSVC)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_PREFIX_PATH}/include/MSVC)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_PREFIX_PATH}/share/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # TODO: remove when FindTunnel has been put in tunnel repository
check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
......@@ -75,83 +75,63 @@ return 0;
HAVE_RES_GETSERVERS)
if(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" STREQUAL "")
set(HAVE_RESINIT 1)
endif(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" STREQUAL "")
endif()
find_package(Threads)
find_package(Antlr3)
find_package(Antlr3 REQUIRED)
if(${ENABLE_TLS})
find_package(PolarSSL)
find_package(PolarSSL REQUIRED)
if(POLARSSL_FOUND)
set(HAVE_POLARSSL 1)
endif(POLARSSL_FOUND)
endif(${ENABLE_TLS})
endif()
endif()
if(${ENABLE_TESTS})
find_package(CUnit)
if(CUNIT_FOUND)
check_library_exists(${CUNIT_LIBRARIES} "CU_add_suite" "" HAVE_CU_ADD_SUITE)
check_library_exists(${CUNIT_LIBRARIES} "CU_get_suite" "" HAVE_CU_GET_SUITE)
check_library_exists(${CUNIT_LIBRARIES} "CU_curses_run_tests" "" HAVE_CU_CURSES)
else(CUNIT_FOUND)
else()
message(WARNING "Could not find cunit framework, tests will not be compiled.")
set(ENABLE_TESTS OFF CACHE BOOL "Enable compilation of tests" FORCE)
endif(CUNIT_FOUND)
endif(${ENABLE_TESTS})
endif()
endif()
find_package(Tunnel)
if(TUNNEL_FOUND)
set(HAVE_TUNNEL 1)
endif(TUNNEL_FOUND)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
get_filename_component(antlr3c_library_path "${ANTLR3C_LIBRARIES}" PATH)
set(LIBS_PRIVATE "-L${antlr3c_library_path} -lantlr3c")
if(CUNIT_FOUND)
set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} cunit")
endif(CUNIT_FOUND)
if(HAVE_POLARSSL)
get_filename_component(polarssl_library_path "${POLARSSL_LIBRARIES}" PATH)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${polarssl_library_path} -lpolarssl")
endif(HAVE_POLARSSL)
if(HAVE_LIBDL)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -ldl")
endif()
if(HAVE_LIBRT)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -lrt")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/belle-sip.pc.in ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc DESTINATION lib/pkgconfig)
include_directories(
include
src
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src
)
if(MSVC)
include_directories(${CMAKE_PREFIX_PATH}/include/MSVC)
endif()
add_definitions(-DHAVE_CONFIG_H)
if(NOT MSVC)
add_definitions(-Wall -Wno-error=unknown-pragmas)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
add_definitions(-Werror -Wno-error=unknown-warning-option)
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
add_definitions(-Werror -Wno-error=pragmas)
endif()
endif(NOT MSVC)
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(LINK_FLAGS "${LINK_FLAGS} -framework CoreFoundation -framework CFNetwork")
endif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
endif()
if(WIN32)
add_definitions(-DBELLESIP_EXPORTS)
endif(WIN32)
endif()
add_subdirectory(include)
add_subdirectory(src)
......@@ -159,4 +139,4 @@ add_subdirectory(src)
if(${ENABLE_TESTS})
enable_testing()
add_subdirectory(tester)
endif(${ENABLE_TESTS})
endif()
############################################################################
# FindAntlr3.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.
#
############################################################################
#
# - Find the antlr3c include file and library and antlr.jar
#
# ANTLR3C_FOUND - system has antlr3c
# ANTLR3C_INCLUDE_DIR - the antlr3c include directory
# ANTLR3C_LIBRARIES - The libraries needed to use antlr3c
# ANTLR3_COMMAND - The command to run the antlr jar
find_package(Java)
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
include(CMakePushCheckState)
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
include(CheckIncludeFile)
include(CheckSymbolExists)
set(_ANTLR3C_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
)
if(WIN32)
set(_ANTLR3_JAR_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
)
else(WIN32)
set(_ANTLR3_JAR_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
/usr/local
/usr
/opt/local
)
endif(WIN32)
find_path(ANTLR3C_INCLUDE_DIR
NAMES antlr3.h
HINTS _ANTLR3C_ROOT_PATHS
PATH_SUFFIXES include
)
if(NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "")
set(HAVE_ANTLR3_H 1)
find_library(ANTLR3C_LIBRARIES
NAMES antlr3c
HINTS _ANTLR3C_ROOT_PATHS
PATH_SUFFIXES bin lib
)
if(NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
set(ANTLR3C_FOUND TRUE)
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
cmake_push_check_state(RESET)
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(SAVE_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(CMAKE_REQUIRED_INCLUDES ${ANTLR3C_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${ANTLR3C_LIBRARIES})
check_symbol_exists("antlr3StringStreamNew" "antlr3.h" HAVE_ANTLR_STRING_STREAM_NEW)
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
cmake_pop_check_state()
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(CMAKE_REQUIRED_INCLUDES ${SAVE_CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
endif(NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
endif(NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "")
mark_as_advanced(ANTLR3C_INCLUDE_DIR ANTLR3C_LIBRARIES)
find_file(ANTLR3_COMMAND
NAMES antlr3
HINTS ${_ANTLR3_JAR_ROOT_PATHS}
PATH_SUFFIXES bin
)
if(NOT ANTLR3_COMMAND)
# antlr3 command not found, search for the jar file
find_file(ANTLR3_JAR_PATH
NAMES antlr3.jar antlr.jar
HINTS _ANTLR3_JAR_ROOT_PATHS
PATH_SUFFIXES share/java
)
if(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
set(ANTLR3_COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR3_JAR_PATH})
endif(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
endif(NOT ANTLR3_COMMAND)
mark_as_advanced(ANTLR3_COMMAND)
############################################################################
# FindCUnit.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.
#
############################################################################
#
# - 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)
if(UNIX)
find_package(PkgConfig)
pkg_check_modules(_CUNIT QUIET cunit)
endif(UNIX)
set(_CUNIT_ROOT_PATHS
${WITH_CUNIT}
${CMAKE_INSTALL_PREFIX}
)
find_path(CUNIT_INCLUDE_DIR
NAMES CUnit/CUnit.h
HINTS _CUNIT_ROOT_PATHS
PATH_SUFFIXES include
)
if(NOT "${CUNIT_INCLUDE_DIR}" STREQUAL "")
set(HAVE_CUNIT_CUNIT_H 1)
find_library(CUNIT_LIBRARIES
NAMES cunit
HINTS ${_CUNIT_ROOT_PATHS}
PATH_SUFFIXES bin lib
)
if(NOT "${CUNIT_LIBRARIES}" STREQUAL "")
set(CUNIT_FOUND TRUE)
endif(NOT "${CUNIT_LIBRARIES}" STREQUAL "")
endif(NOT "${CUNIT_INCLUDE_DIR}" STREQUAL "")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUnit
REQUIRED_VARS
CUNIT_LIBRARIES
CUNIT_INCLUDE_DIR
FAIL_MESSAGE
"Could NOT find CUnit"
)
mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARIES)
############################################################################
# FindPolarSSL.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.
#
############################################################################
#
# - Find the polarssl include file and library
#
# POLARSSL_FOUND - system has polarssl
# POLARSSL_INCLUDE_DIR - the polarssl include directory
# POLARSSL_LIBRARIES - The libraries needed to use polarssl
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
include(CMakePushCheckState)
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
include(CheckIncludeFile)
include(CheckCSourceCompiles)
set(_POLARSSL_ROOT_PATHS
${WITH_POLARSSL}
${CMAKE_INSTALL_PREFIX}
)
find_path(POLARSSL_INCLUDE_DIR
NAMES polarssl/ssl.h
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES include
)
if(NOT "${POLARSSL_INCLUDE_DIR}" STREQUAL "")
set(HAVE_POLARSSL_SSL_H 1)
find_library(POLARSSL_LIBRARIES
NAMES polarssl
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES bin lib
)
if(NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
set(POLARSSL_FOUND TRUE)
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
cmake_push_check_state(RESET)
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(SAVE_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(CMAKE_REQUIRED_INCLUDES ${POLARSSL_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${POLARSSL_LIBRARIES})
check_c_source_compiles("#include <polarssl/version.h>
#include <polarssl/x509.h>
#if POLARSSL_VERSION_NUMBER >= 0x01030000
#include <polarssl/compat-1.2.h>
#endif
int main(int argc, char *argv[]) {
x509parse_crtpath(0,0);
return 0;
}"
X509PARSE_CRTPATH_OK)
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
cmake_pop_check_state()
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
set(CMAKE_REQUIRED_INCLUDES ${SAVE_CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.5")
endif(NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
endif(NOT "${POLARSSL_INCLUDE_DIR}" STREQUAL "")
mark_as_advanced(POLARSSL_INCLUDE_DIR POLARSSL_LIBRARIES)
......@@ -26,20 +26,20 @@ set(LIBS ${ANTLR3C_LIBRARIES})
if(${Threads_FOUND})
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX")
list(APPEND LIBS pthread)
endif(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX")
endif(${Threads_FOUND})
endif()
endif()
if(${HAVE_LIBDL})
list(APPEND LIBS dl)
endif(${HAVE_LIBDL})
endif()
if(${HAVE_LIBRT})
list(APPEND LIBS rt)
endif()
if(${HAVE_RESINIT})
list(APPEND LIBS resolv)
endif(${HAVE_RESINIT})
endif()
if(WIN32)
list(APPEND LIBS ws2_32)
endif(WIN32)
endif()
set(SDP_GENERATED_SOURCE_FILES
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpLexer.c
......@@ -74,7 +74,7 @@ if(${ENABLE_TLS})
)
list(APPEND INCLUDES ${POLARSSL_INCLUDE_DIR})
list(APPEND LIBS ${POLARSSL_LIBRARIES})
endif(${ENABLE_TLS})
endif()
if(${ENABLE_TUNNEL})
set(TUNNEL_SOURCE_FILES
......@@ -84,7 +84,7 @@ if(${ENABLE_TUNNEL})
)
set_source_files_properties(transports/tunnel_wrapper.cc PROPERTIES LANGUAGE CXX)
list(APPEND LIBS ${TUNNEL_LIBRARIES})
endif(${ENABLE_TUNNEL})
endif()
set(SOURCE_FILES
auth_event.c
......@@ -141,7 +141,7 @@ set(SOURCE_FILES
if(${ENABLE_STATIC})
add_library(bellesip STATIC ${SOURCE_FILES})
else(${ENABLE_STATIC})
else()
add_library(bellesip SHARED ${SOURCE_FILES})
set_target_properties(bellesip PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION 0)
if(MSVC)
......@@ -151,14 +151,14 @@ else(${ENABLE_STATIC})
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif(MSVC)
endif(${ENABLE_STATIC})
endif()
endif()
set_target_properties(bellesip PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LINK_FLAGS}")
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
target_include_directories(bellesip PUBLIC ${INCLUDES})
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
else()
include_directories(${INCLUDES})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
endif()
target_link_libraries(bellesip ${LIBS})
install(TARGETS bellesip
......
......@@ -43,9 +43,9 @@ add_executable(belle_sip_tester ${TESTER_SOURCES})
set_target_properties(belle_sip_tester PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
target_include_directories(belle_sip_tester PUBLIC ${CUNIT_INCLUDE_DIR})
else("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
else()
include_directories(${CUNIT_INCLUDE_DIR})
endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
endif()
target_link_libraries(belle_sip_tester ${CUNIT_LIBRARIES} bellesip)
add_test(NAME belle_sip_tester COMMAND belle_sip_tester --verbose)
......@@ -62,4 +62,3 @@ set(PARSE_SOURCES parse.c)
add_executable(belle_sip_parse ${PARSE_SOURCES})
set_target_properties(belle_sip_parse PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
target_link_libraries(belle_sip_parse bellesip)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment