Commit 7e3261e9 authored by Nicolas Michon's avatar Nicolas Michon

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

parent b88e76e9
...@@ -20,11 +20,10 @@ ...@@ -20,11 +20,10 @@
# #
############################################################################ ############################################################################
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.1)
project(bzrtp VERSION 1.0.6 LANGUAGES C CXX) project(bzrtp VERSION 1.0.6 LANGUAGES C CXX)
option(ENABLE_SHARED "Build shared library." YES) option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES) option(ENABLE_STATIC "Build static library." YES)
option(ENABLE_ZIDCACHE "Turn on compilation of ZID cache, request sqlite" YES) option(ENABLE_ZIDCACHE "Turn on compilation of ZID cache, request sqlite" YES)
...@@ -49,12 +48,7 @@ include(GNUInstallDirs) ...@@ -49,12 +48,7 @@ include(GNUInstallDirs)
include(CheckLibraryExists) include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT) check_library_exists("m" "sqrt" "" HAVE_SQRT)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) find_package(bctoolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester CONFIG)
set(BcToolbox_FIND_COMPONENTS tester)
include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
endif()
if(ENABLE_ZIDCACHE) if(ENABLE_ZIDCACHE)
find_package(Sqlite3 REQUIRED) find_package(Sqlite3 REQUIRED)
...@@ -110,45 +104,42 @@ if (ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY) ...@@ -110,45 +104,42 @@ if (ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY)
add_definitions("-DSUPPORT_EXPORTEDKEY_V010000") add_definitions("-DSUPPORT_EXPORTEDKEY_V010000")
endif() endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) set(EXPORT_TARGETS_NAME "bzrtp")
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "BZRTP")
endif()
add_subdirectory(include) add_subdirectory(include)
add_subdirectory(src) add_subdirectory(src)
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND) if(ENABLE_TESTS)
enable_testing() enable_testing()
add_subdirectory(test) add_subdirectory(test)
endif() endif()
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
write_basic_package_version_file( write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion COMPATIBILITY AnyNewerVersion
) )
export(EXPORT ${EXPORT_TARGETS_NAME}Targets export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/BZRTPTargets.cmake" FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Targets.cmake"
) )
configure_file(cmake/BZRTPConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake" configure_package_config_file(cmake/BZRTPConfig.cmake.in
@ONLY "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
NO_SET_AND_CHECK_MACRO
) )
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BZRTPTargets.cmake FILE ${EXPORT_TARGETS_NAME}Targets.cmake
DESTINATION ${CONFIG_PACKAGE_LOCATION} DESTINATION ${CONFIG_PACKAGE_LOCATION}
) )
install(FILES install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
DESTINATION ${CONFIG_PACKAGE_LOCATION} DESTINATION ${CONFIG_PACKAGE_LOCATION}
) )
add_subdirectory(build) add_subdirectory(build)
...@@ -28,34 +28,25 @@ ...@@ -28,34 +28,25 @@
# BZRTP_LIBRARIES - The libraries needed to use bzrtp # BZRTP_LIBRARIES - The libraries needed to use bzrtp
# BZRTP_CPPFLAGS - The compilation flags needed to use bzrtp # BZRTP_CPPFLAGS - The compilation flags needed to use bzrtp
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) @PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/BZRTPTargets.cmake")
endif() set(BZRTP_TARGETNAME bzrtp)
include("${CMAKE_CURRENT_LIST_DIR}/${BZRTP_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@) if(@ENABLE_SHARED@)
set(BZRTP_TARGETNAME bzrtp)
set(BZRTP_LIBRARIES ${BZRTP_TARGETNAME}) set(BZRTP_LIBRARIES ${BZRTP_TARGETNAME})
else() else()
set(BZRTP_TARGETNAME bzrtp-static)
if(TARGET ${BZRTP_TARGETNAME}) if(TARGET ${BZRTP_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) get_target_property(BZRTP_LIBRARIES ${BZRTP_TARGETNAME} LOCATION)
set(BZRTP_LIBRARIES ${BZRTP_TARGETNAME})
else()
get_target_property(BZRTP_LIBRARIES ${BZRTP_TARGETNAME} LOCATION)
endif()
get_target_property(BZRTP_LINK_LIBRARIES ${BZRTP_TARGETNAME} INTERFACE_LINK_LIBRARIES) get_target_property(BZRTP_LINK_LIBRARIES ${BZRTP_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(BZRTP_LINK_LIBRARIES) if(BZRTP_LINK_LIBRARIES)
list(APPEND BZRTP_LIBRARIES ${BZRTP_LINK_LIBRARIES}) list(APPEND BZRTP_LIBRARIES ${BZRTP_LINK_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()
get_target_property(BZRTP_INCLUDE_DIRS ${BZRTP_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES) get_target_property(BZRTP_INCLUDE_DIRS ${BZRTP_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT BZRTP_INCLUDE_DIRS 0 "${EP_bzrtp_INCLUDE_DIR}")
else()
list(INSERT BZRTP_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES BZRTP_INCLUDE_DIRS)
set(BZRTP_CPPFLAGS @BZRTP_CPPFLAGS@) set(BZRTP_CPPFLAGS @BZRTP_CPPFLAGS@)
set(BZRTP_FOUND 1) set(BZRTP_FOUND 1)
...@@ -41,23 +41,27 @@ endif() ...@@ -41,23 +41,27 @@ endif()
bc_apply_compile_flags(SOURCE_FILES STRICT_OPTIONS_CPP) bc_apply_compile_flags(SOURCE_FILES STRICT_OPTIONS_CPP)
set(INCLUDE_DIRS ${BCTOOLBOX_CORE_INCLUDE_DIRS}) set(INCLUDE_DIRS )
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES}) set(LIBS )
if(SQLITE3_FOUND) if(SQLITE3_FOUND)
list(APPEND INCLUDE_DIRS ${SQLITE3_INCLUDE_DIRS}) list(APPEND INCLUDE_DIRS ${SQLITE3_INCLUDE_DIRS})
list(APPEND LIBS ${SQLITE3_LIBRARIES}) list(APPEND LIBS $<BUILD_INTERFACE:${SQLITE3_LIBRARIES}> $<INSTALL_INTERFACE:${SQLITE3_LIBRARIES}>)
endif() endif()
if(XML2_FOUND) if(XML2_FOUND)
list(APPEND INCLUDE_DIRS ${XML2_INCLUDE_DIRS}) list(APPEND INCLUDE_DIRS ${XML2_INCLUDE_DIRS})
list(APPEND LIBS ${XML2_LIBRARIES}) list(APPEND LIBS $<BUILD_INTERFACE:${XML2_LIBRARIES}> $<INSTALL_INTERFACE:${XML2_LIBRARIES}>)
endif() endif()
if(ENABLE_STATIC) if(ENABLE_STATIC)
add_library(bzrtp-static STATIC ${SOURCE_FILES}) add_library(bzrtp STATIC ${SOURCE_FILES})
set_target_properties(bzrtp-static PROPERTIES OUTPUT_NAME bzrtp) set_target_properties(bzrtp PROPERTIES OUTPUT_NAME bzrtp)
target_include_directories(bzrtp-static PUBLIC ${INCLUDE_DIRS}) target_include_directories(bzrtp INTERFACE
target_link_libraries(bzrtp-static INTERFACE ${LIBS}) $<INSTALL_INTERFACE:include>
install(TARGETS bzrtp-static EXPORT ${EXPORT_TARGETS_NAME}Targets PRIVATE ${INCLUDE_DIRS})
target_link_libraries(bzrtp PUBLIC bctoolbox ${LIBS})
install(TARGETS bzrtp EXPORT ${EXPORT_TARGETS_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
) )
...@@ -66,8 +70,12 @@ if(ENABLE_SHARED) ...@@ -66,8 +70,12 @@ if(ENABLE_SHARED)
add_library(bzrtp SHARED ${SOURCE_FILES}) add_library(bzrtp SHARED ${SOURCE_FILES})
target_compile_definitions(bzrtp PRIVATE "-DBZRTP_EXPORTS") target_compile_definitions(bzrtp PRIVATE "-DBZRTP_EXPORTS")
set_target_properties(bzrtp PROPERTIES VERSION 0) set_target_properties(bzrtp PROPERTIES VERSION 0)
target_include_directories(bzrtp PUBLIC ${INCLUDE_DIRS}) target_include_directories(bzrtp INTERFACE
target_link_libraries(bzrtp PRIVATE ${LIBS}) $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PRIVATE ${INCLUDE_DIRS}
)
target_link_libraries(bzrtp PUBLIC bctoolbox ${LIBS})
if(MSVC) if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bzrtp.pdb install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bzrtp.pdb
......
...@@ -38,22 +38,25 @@ bc_apply_compile_flags(TEST_SOURCES STRICT_OPTIONS_CPP) ...@@ -38,22 +38,25 @@ bc_apply_compile_flags(TEST_SOURCES STRICT_OPTIONS_CPP)
add_executable(bzrtpTest ${TEST_SOURCES}) add_executable(bzrtpTest ${TEST_SOURCES})
set_target_properties(bzrtpTest PROPERTIES LINK_FLAGS "${LINK_FLAGS}") set_target_properties(bzrtpTest PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
set_target_properties(bzrtpTest PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(bzrtpTest PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(bzrtpTest PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIR})
target_link_libraries(bzrtpTest PRIVATE bctoolbox bctoolbox-tester)
if(ENABLE_STATIC) if(ENABLE_STATIC)
target_link_libraries(bzrtpTest bzrtp-static) target_link_libraries(bzrtpTest PRIVATE bzrtp)
else() else()
target_link_libraries(bzrtpTest bzrtp) target_link_libraries(bzrtpTest PRIVATE bzrtp)
endif() endif()
target_link_libraries(bzrtpTest ${BCTOOLBOX_LIBRARIES})
if(SQLITE3_FOUND) if(SQLITE3_FOUND)
target_include_directories(bzrtpTest PUBLIC ${SQLITE3_INCLUDE_DIRS}) target_include_directories(bzrtpTest PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_link_libraries(bzrtpTest ${SQLITE3_LIBRARIES}) target_link_libraries(bzrtpTest PRIVATE ${SQLITE3_LIBRARIES})
if(XML2_FOUND)
target_link_libraries(bzrtpTest ${XML2_LIBRARIES})
endif() endif()
if(XML2_FOUND)
target_include_directories(bzrtpTest PRIVATE ${XML2_INCLUDE_DIRS})
target_link_libraries(bzrtpTest PRIVATE ${XML2_LIBRARIES})
endif() endif()
if(HAVE_SQRT) if(HAVE_SQRT)
target_link_libraries(bzrtpTest m) target_link_libraries(bzrtpTest PRIVATE m)
endif() endif()
unset(PATTERN_FILES_IN_TEST_DIR CACHE) unset(PATTERN_FILES_IN_TEST_DIR CACHE)
......
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