Commit 06dccc9d authored by Nicolas Michon's avatar Nicolas Michon

Cmake changes for cross-compilation and better use of imported targets

parent 99dda3d1
......@@ -20,7 +20,7 @@
#
############################################################################
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.1)
project(belle-sip VERSION 1.6.3 LANGUAGES C CXX)
......@@ -85,12 +85,7 @@ if(ENABLE_RTP_MAP_ALWAYS_IN_SDP)
set(BELLE_SDP_FORCE_RTP_MAP 1)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(BcToolbox_FIND_COMPONENTS tester)
include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
find_package(BcToolbox 0.5.0 REQUIRED OPTIONAL_COMPONENTS tester)
endif()
find_package(bctoolbox 0.5.0 REQUIRED OPTIONAL_COMPONENTS tester)
if(ENABLE_TUNNEL)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
......@@ -124,27 +119,15 @@ set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
get_filename_component(bctoolbox_library_path "${BCTOOLBOX_CORE_LIBRARIES}" PATH)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${bctoolbox_library_path} -lbctoolbox")
if(ZLIB_FOUND)
set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} z")
endif()
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 "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
include_directories(
include
src
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src
${BCTOOLBOX_CORE_INCLUDE_DIRS}
)
if(TUNNEL_FOUND)
include_directories(${TUNNEL_INCLUDE_DIRS})
......@@ -233,13 +216,15 @@ add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(tester)
endif()
include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/BelleSIP/cmake")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
......@@ -248,12 +233,12 @@ write_basic_package_version_file(
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/BelleSIPTargets.cmake"
)
configure_file(cmake/BelleSIPConfig.cmake.in
configure_package_config_file(cmake/BelleSIPConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
@ONLY
INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
NO_SET_AND_CHECK_MACRO
)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/BelleSIP/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BelleSIPTargets.cmake
DESTINATION ${CONFIG_PACKAGE_LOCATION}
......
......@@ -29,6 +29,8 @@
# BELLESIP_CPPFLAGS - The compilation flags needed to use belle-sip
# BELLESIP_LDFLAGS - The linking flags needed to use belle-sip
@PACKAGE_INIT@
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/BelleSIPTargets.cmake")
endif()
......@@ -50,13 +52,8 @@ else()
endif()
endif()
endif()
get_target_property(BELLESIP_INCLUDE_DIRS ${BELLESIP_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT BELLESIP_INCLUDE_DIRS 0 "${EP_bellesip_INCLUDE_DIR}")
else()
list(INSERT BELLESIP_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES BELLESIP_INCLUDE_DIRS)
set(BELLESIP_CPPFLAGS @BELLESIP_CPPFLAGS@)
set(BELLESIP_LDFLAGS "@LINK_FLAGS_STR@")
......
......@@ -36,15 +36,15 @@ function(require_c99 target)
endfunction()
set(PUBLIC_INCLUDE_DIRS
${BCTOOLBOX_CORE_INCLUDE_DIR}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/belle-sip>
)
set(PRIVATE_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/antlr3c/include
${CMAKE_CURRENT_BINARY_DIR}/antlr3c
)
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES})
set(LIBS bctoolbox)
if(Threads_FOUND)
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX" AND NOT ANDROID)
......@@ -196,8 +196,8 @@ if(ENABLE_STATIC)
add_library(bellesip-static STATIC ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC} ${ANTLR3C_SOURCE_FILES})
set_target_properties(bellesip-static PROPERTIES OUTPUT_NAME bellesip)
set_target_properties(bellesip-static PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
target_include_directories(bellesip-static PUBLIC ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
target_link_libraries(bellesip-static INTERFACE ${LIBS})
target_include_directories(bellesip-static INTERFACE ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
target_link_libraries(bellesip-static PRIVATE ${LIBS})
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(bellesip-static PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
......@@ -212,7 +212,7 @@ if(ENABLE_SHARED)
set_target_properties(bellesip PROPERTIES SOVERSION 0)
set_target_properties(bellesip PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(bellesip PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
target_include_directories(bellesip PUBLIC ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
target_include_directories(bellesip INTERFACE ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
target_link_libraries(bellesip PRIVATE ${LIBS})
if(APPLE)
if(IOS)
......
......@@ -66,8 +66,8 @@ bc_apply_compile_flags(SOURCE_FILES_OBJC STRICT_OPTIONS_CPP STRICT_OPTIONS_OBJC)
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
add_library(belle_sip_tester_static STATIC ${SOURCE_FILES_C})
target_include_directories(belle_sip_tester_static PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(belle_sip_tester_static ${BCTOOLBOX_LIBRARIES} ${PROJECT_LIBS})
# target_include_directories(belle_sip_tester_static PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(belle_sip_tester_static bctoolbox bctoolbox-tester ${PROJECT_LIBS})
set(RUNTIME_COMPONENT_SOURCES
belle_sip_tester_windows.cpp
......@@ -112,8 +112,7 @@ else()
if(WIN32)
target_link_libraries(belle_sip_tester "Ws2_32")
endif()
target_include_directories(belle_sip_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(belle_sip_tester ${BCTOOLBOX_LIBRARIES} ${PROJECT_LIBS})
target_link_libraries(belle_sip_tester bctoolbox bctoolbox-tester ${PROJECT_LIBS})
add_test(NAME belle_sip_tester COMMAND belle_sip_tester --verbose)
if(NOT IOS)
install(TARGETS belle_sip_tester
......@@ -132,7 +131,7 @@ else()
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_object_describe PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_object_describe ${BCTOOLBOX_CORE_LIBRARIES} ${PROJECT_LIBS})
target_link_libraries(belle_sip_object_describe bctoolbox ${PROJECT_LIBS})
set(OBJECT_RESOLVE_SOURCES resolve.c)
bc_apply_compile_flags(OBJECT_DESCRIBE_SOURCES STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
......@@ -141,8 +140,7 @@ else()
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_resolve PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_resolve ${BCTOOLBOX_CORE_LIBRARIES} ${PROJECT_LIBS})
target_link_libraries(belle_sip_resolve bctoolbox ${PROJECT_LIBS})
set(PARSE_SOURCES parse.c)
......@@ -152,8 +150,8 @@ else()
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_parse PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_parse ${BCTOOLBOX_CORE_LIBRARIES} ${PROJECT_LIBS})
target_link_libraries(belle_sip_parse bctoolbox ${PROJECT_LIBS})
set(GET_SOURCES get.c)
bc_apply_compile_flags(GET_SOURCES STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
......@@ -162,7 +160,7 @@ else()
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_http_get PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_http_get ${BCTOOLBOX_CORE_LIBRARIES} ${PROJECT_LIBS})
target_link_libraries(belle_sip_http_get bctoolbox ${PROJECT_LIBS})
endif()
......
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