Commit 4920b20c authored by Nicolas Michon's avatar Nicolas Michon
Browse files

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

parent 2cc14d04
......@@ -25,7 +25,7 @@ include(CheckLibraryExists)
include(CMakePushCheckState)
include(CMakePackageConfigHelpers)
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.1)
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
......@@ -58,12 +58,7 @@ if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
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.1 REQUIRED OPTIONAL_COMPONENTS tester)
endif()
find_package(bctoolbox 0.5.1 REQUIRED OPTIONAL_COMPONENTS tester)
find_package(Soci REQUIRED)
......@@ -76,10 +71,6 @@ if(MSVC)
include_directories(${MSVC_INCLUDE_DIR})
endif()
set(LIME_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/include
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
......@@ -131,11 +122,7 @@ if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "lime")
endif()
set(EXPORT_TARGETS_NAME "lime")
if (ENABLE_CURVE25519)
add_definitions("-DEC25519_ENABLED")
......@@ -166,25 +153,29 @@ endif()
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
if(ENABLE_UNIT_TESTS)
enable_testing()
add_subdirectory(tester)
endif()
set(ConfigPackageLocation "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/LimeTargets.cmake"
FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Targets.cmake"
)
configure_file(cmake/LimeConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/LimeConfig.cmake"
@ONLY
configure_package_config_file(cmake/LimeConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation}
NO_SET_AND_CHECK_MACRO
)
set(ConfigPackageLocation "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE LimeTargets.cmake
FILE ${EXPORT_TARGETS_NAME}Targets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/LimeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
DESTINATION ${ConfigPackageLocation}
)
......
......@@ -28,21 +28,18 @@
# LIME_LIBRARIES - The libraries needed to use lime
# LIME_CPPFLAGS - The compilation flags needed to use lime
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/LimeTargets.cmake")
endif()
@PACKAGE_INIT@
set(LIME_TARGETNAME lime)
include("${CMAKE_CURRENT_LIST_DIR}/${LIME_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@)
set(LIME_TARGETNAME lime)
set(LIME_LIBRARIES ${LIME_TARGETNAME})
else()
set(LIME_TARGETNAME lime-static)
if(TARGET ${LIME_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(LIME_LIBRARIES ${LIME_TARGETNAME})
else()
get_target_property(LIME_LIBRARIES ${LIME_TARGETNAME} LOCATION)
endif()
get_target_property(LIME_LIBRARIES ${LIME_TARGETNAME} LOCATION)
get_target_property(LIME_LINK_LIBRARIES ${LIME_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(LIME_LINK_LIBRARIES)
list(APPEND LIME_LIBRARIES ${LIME_LINK_LIBRARIES})
......@@ -50,12 +47,10 @@ else()
endif()
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT LIME_INCLUDE_DIRS 0 "${EP_lime_INCLUDE_DIR}")
else()
list(INSERT LIME_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
get_target_property(LIME_INCLUDE_DIRS ${LIME_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(NOT LIME_INCLUDE_DIRS)
set(LIME_INCLUDE_DIRS )
endif()
list(REMOVE_DUPLICATES LIME_INCLUDE_DIRS)
set(LIME_CPPFLAGS @LIME_CPPFLAGS@)
set(LIME_FOUND 1)
......@@ -58,8 +58,8 @@ bc_apply_compile_flags(LIME_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_C
if(ENABLE_STATIC)
add_library(lime-static STATIC ${LIME_PRIVATE_HEADER_FILES} ${LIME_SOURCE_FILES_CXX})
set_target_properties(lime-static PROPERTIES OUTPUT_NAME lime)
target_include_directories(lime-static PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS})
target_link_libraries(lime-static INTERFACE ${BCTOOLBOX_CORE_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
target_include_directories(lime-static PUBLIC ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS})
target_link_libraries(lime-static INTERFACE bctoolbox ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
if(ENABLE_PROFILING)
set_target_properties(lime-static PROPERTIES LINK_FLAGS "-pg")
endif()
......@@ -67,8 +67,11 @@ endif()
if(ENABLE_SHARED)
add_library(lime SHARED ${LIME_PRIVATE_HEADER_FILES} ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_CXX})
set_target_properties(lime PROPERTIES VERSION ${LIME_SO_VERSION})
target_include_directories(lime PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS})
target_link_libraries(lime PRIVATE ${BCTOOLBOX_CORE_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
target_include_directories(lime PRIVATE ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS} INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
target_link_libraries(lime PRIVATE bctoolbox ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
if(APPLE)
if(IOS)
set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
......
......@@ -22,11 +22,9 @@
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
else()
find_package(BelleSIP REQUIRED)
endif()
find_package(BelleSIP REQUIRED CONFIG)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if(ENABLE_SHARED)
set(LIME_LIBRARIES_FOR_TESTER lime)
......@@ -56,10 +54,9 @@ find_package (Threads REQUIRED)
if(ANDROID OR IOS)
add_library(limetester SHARED ${HEADER_FILES_CXX} ${SOURCE_FILES_CXX} ${SOURCE_FILES_C} )
target_include_directories(limetester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS} ${BELLESIP_INCLUDE_DIRS})
target_link_libraries(limetester ${LIME_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES} ${BCTOOLBOX_TESTER_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(limetester PRIVATE bctoolbox bctoolbox-tester ${BELLESIP_TARGETNAME} ${LIME_LIBRARIES_FOR_TESTER} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
if(IOS)
target_link_libraries(limetester sqlite3)
target_link_libraries(limetester PRIVATE sqlite3)
set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
set_target_properties(limetester PROPERTIES
FRAMEWORK TRUE
......@@ -82,8 +79,7 @@ if(ANDROID OR IOS)
else()
add_executable(lime_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX} ${SOURCE_FILES_C} )
set_target_properties(lime_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(lime_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS} ${BELLESIP_INCLUDE_DIRS})
target_link_libraries(lime_tester ${LIME_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES} ${BCTOOLBOX_TESTER_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(lime_tester PRIVATE bctoolbox bctoolbox-tester ${BELLESIP_TARGETNAME} ${LIME_LIBRARIES_FOR_TESTER} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${CMAKE_THREAD_LIBS_INIT})
# Some tests suite need a local X3DH server running in default config, so run them suite by suite to at least be able to pass some if no server can be found
add_test(NAME crypto COMMAND lime_tester --verbose --resource-dir ${CMAKE_CURRENT_SOURCE_DIR} --suite "Crypto")
......
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