Commit a0f806a4 authored by Ghislain MARY's avatar Ghislain MARY

Improve headers and libraries search for cross-compilation using CMake.

parent 67205f9b
......@@ -39,6 +39,7 @@ 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)")
......@@ -76,6 +77,8 @@ if(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" STREQ
set(HAVE_RESINIT 1)
endif(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" STREQUAL "")
find_package(Threads)
find_package(Java)
find_package(Antlr3)
......@@ -85,8 +88,9 @@ if(${ENABLE_TLS})
endif(${ENABLE_TLS})
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)
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})
message(WARNING "Could not find cunit framework, tests will not be compiled.")
set(ENABLE_TESTS OFF CACHE "Enable compilation of tests" FORCE)
......
......@@ -32,20 +32,16 @@ include(CMakePushCheckState)
include(CheckIncludeFile)
include(CheckFunctionExists)
set(_ANTLR3C_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
)
if(WIN32)
set(_ANTLR3C_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
)
set(_ANTLR3_JAR_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
)
else(WIN32)
set(_ANTLR3C_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_SYSTEM_INCLUDE_PATH}
)
set(_ANTLR3_JAR_ROOT_PATHS
${WITH_ANTLR}
${CMAKE_INSTALL_PREFIX}
......@@ -55,29 +51,31 @@ else(WIN32)
)
endif(WIN32)
check_include_file("antlr3.h" HAVE_ANTLR3_H)
if(${HAVE_ANTLR3_H})
find_path(ANTLR3C_INCLUDE_DIR
NAMES antlr3.h
HINTS _ANTLR3C_ROOT_PATHS
PATH_SUFFIXES include
)
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
)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "antlr3.h")
set(CMAKE_REQUIRED_LIBRARIES "antlr3c")
check_function_exists("antlr3StringStreamNew" HAVE_ANTLR_STRING_STREAM_NEW)
cmake_pop_check_state()
endif(${HAVE_ANTLR3_H})
if(NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
set(ANTLR3C_FOUND TRUE)
if(${HAVE_ANTLR3_H} AND NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "" AND NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
set(ANTLR3C_FOUND TRUE)
endif(${HAVE_ANTLR3_H} AND NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "" AND NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${ANTLR3C_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${ANTLR3C_LIBRARIES})
check_function_exists("antlr3StringStreamNew" HAVE_ANTLR_STRING_STREAM_NEW)
cmake_pop_check_state()
endif(NOT "${ANTLR3C_LIBRARIES}" STREQUAL "")
endif(NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "")
mark_as_advanced(ANTLR3C_INCLUDE_DIR ANTLR3C_LIBRARIES)
......
......@@ -26,14 +26,18 @@
# 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)
if(WIN32)
set(_CUNIT_ROOT_PATHS "${CMAKE_INSTALL_PREFIX}")
endif(WIN32)
set(_CUNIT_ROOT_PATHS
${WITH_CUNIT}
${CMAKE_INSTALL_PREFIX}
)
find_path(CUNIT_INCLUDE_DIR
NAMES CUnit/CUnit.h
......@@ -41,26 +45,19 @@ find_path(CUNIT_INCLUDE_DIR
PATH_SUFFIXES include
)
if(WIN32)
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
)
else(WIN32)
find_library(CUNIT_LIBRARIES
NAMES cunit
HINTS ${_CUNIT_LIBDIR}
PATH_SUFFIXES lib
)
endif(WIN32)
if(CUNIT_INCLUDE_DIR AND CUNIT_LIBRARIES)
include(CheckIncludeFile)
include(CheckLibraryExists)
check_include_file("CUnit/CUnit.h" HAVE_CUNIT_CUNIT_H)
check_library_exists("cunit" "CU_add_suite" "" HAVE_CU_ADD_SUITE)
endif(CUNIT_INCLUDE_DIR AND CUNIT_LIBRARIES)
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
......
......@@ -30,29 +30,32 @@ include(CMakePushCheckState)
include(CheckIncludeFile)
include(CheckCSourceCompiles)
if(WIN32)
set(_POLARSSL_ROOT_PATHS ${CMAKE_INSTALL_PREFIX})
else(WIN32)
set(_POLARSSL_ROOT_PATHS ${CMAKE_SYSTEM_INCLUDE_PATH})
endif(WIN32)
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)
check_include_file("polarssl/ssl.h" HAVE_POLARSSL_SSL_H)
if(${HAVE_POLARSSL_SSL_H})
find_path(POLARSSL_INCLUDE_DIR
NAMES polarssl/ssl.h
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES include
)
find_library(POLARSSL_LIBRARIES
NAMES polarssl
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES bin lib
)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${POLARSSL_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES polarssl)
check_c_source_compiles("#include <polarssl/version.h>
if(NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
set(POLARSSL_FOUND TRUE)
cmake_push_check_state(RESET)
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>
......@@ -61,12 +64,9 @@ int main(int argc, char *argv[]) {
x509parse_crtpath(0,0);
return 0;
}"
X509PARSE_CRTPATH_OK)
cmake_pop_check_state()
endif(${HAVE_POLARSSL_SSL_H})
if(${HAVE_POLARSSL_SSL_H} AND ${X509PARSE_CRTPATH_OK} AND NOT "${POLARSSL_INCLUDE_DIR}" STREQUAL "" AND NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
set(POLARSSL_FOUND TRUE)
endif(${HAVE_POLARSSL_SSL_H} AND ${X509PARSE_CRTPATH_OK} AND NOT "${POLARSSL_INCLUDE_DIR}" STREQUAL "" AND NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
X509PARSE_CRTPATH_OK)
cmake_pop_check_state()
endif(NOT "${POLARSSL_LIBRARIES}" STREQUAL "")
endif(NOT "${POLARSSL_INCLUDE_DIR}" STREQUAL "")
mark_as_advanced(POLARSSL_INCLUDE_DIR POLARSSL_LIBRARIES)
......@@ -20,10 +20,12 @@
#
############################################################################
set(INCLUDES ${ANTLR3C_INCLUDE_DIR})
set(LIBS ${ANTLR3C_LIBRARIES})
if(NOT WIN32)
if(${CMAKE_USE_PTHREADS_INIT} AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "QNX")
list(APPEND LIBS pthread)
endif(NOT WIN32)
endif(${CMAKE_USE_PTHREADS_INIT} AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "QNX")
if(${HAVE_LIBDL})
list(APPEND LIBS dl)
endif(${HAVE_LIBDL})
......@@ -59,6 +61,7 @@ if(${ENABLE_TLS})
transports/tls_listeningpoint_polarssl.c
transports/tls_channel_polarssl.c
)
list(APPEND INCLUDES ${POLARSSL_INCLUDE_DIR})
list(APPEND LIBS ${POLARSSL_LIBRARIES})
endif(${ENABLE_TLS})
......@@ -125,11 +128,9 @@ set(SOURCE_FILES
if(${ENABLE_STATIC})
add_library(bellesip STATIC ${SOURCE_FILES})
target_link_libraries(bellesip ${LIBS})
else(${ENABLE_STATIC})
add_library(bellesip SHARED ${SOURCE_FILES})
set_target_properties(bellesip PROPERTIES VERSION 0.0.0 SOVERSION 0)
target_link_libraries(bellesip ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/bellesip.pdb
......@@ -139,6 +140,9 @@ else(${ENABLE_STATIC})
endif()
endif(MSVC)
endif(${ENABLE_STATIC})
target_include_directories(bellesip PUBLIC ${INCLUDES})
target_link_libraries(bellesip ${LIBS})
install(TARGETS bellesip
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
......
......@@ -40,6 +40,7 @@ set(TESTER_SOURCES
)
add_executable(belle_sip_tester ${TESTER_SOURCES})
target_include_directories(belle_sip_tester PUBLIC ${CUNIT_INCLUDE_DIR})
target_link_libraries(belle_sip_tester ${CUNIT_LIBRARIES} bellesip)
add_test(NAME belle_sip_tester COMMAND belle_sip_tester --verbose)
......
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