Commit 55f5c1fc authored by Nicolas Michon's avatar Nicolas Michon

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

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