Commit 26f1c8e0 authored by Nicolas Michon's avatar Nicolas Michon

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

parent 2c9d933a
......@@ -23,7 +23,6 @@
cmake_minimum_required(VERSION 3.2) #since cmake 3.2 is available as a patch for yocto Fido
set(CMAKE_MACOSX_RPATH ON) # Before cmake 3.0.0, MACOSX_RPATH was not set to ON by default - however this is no good reason to not enable it by default
project(bctoolbox)
set(BCTOOLBOX_VERSION_MAJOR 0)
......@@ -74,8 +73,9 @@ if(ENABLE_MBEDTLS)
set(HAVE_MBEDTLS 1)
endif()
endif()
if(ENABLE_DECAF)
find_package(Decaf)
find_package(Decaf CONFIG)
if(DECAF_FOUND)
message(STATUS "Using Decaf")
set(HAVE_DECAF 1)
......@@ -111,8 +111,8 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_TESTS_COMPONENT)
find_package(BcUnit REQUIRED)
cmake_push_check_state(RESET)
find_package(BcUnit CONFIG REQUIRED)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${BCUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${BCUNIT_LIBRARIES})
check_symbol_exists("CU_get_suite" "BCUnit/BCUnit.h" HAVE_CU_GET_SUITE)
......@@ -149,11 +149,7 @@ if(CMAKE_VERSION VERSION_LESS 3.1 AND NOT APPLE AND NOT MSVC)
list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "BcToolbox")
endif()
set(EXPORT_TARGETS_NAME "bctoolbox")
check_library_exists("rt" "clock_gettime" "" HAVE_LIBRT)
check_library_exists("dl" "dladdr" "" HAVE_LIBDL)
......@@ -172,28 +168,32 @@ endif()
add_subdirectory(build)
include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_file(cmake/BcToolboxConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
@ONLY
configure_package_config_file(cmake/BcToolboxConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
NO_SET_AND_CHECK_MACRO
)
configure_file(cmake/BcToolboxCMakeUtils.cmake "${CMAKE_CURRENT_BINARY_DIR}/BcToolboxCMakeUtils.cmake" COPYONLY)
configure_file(cmake/BcToolboxCMakeUtils.cmake "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}CMakeUtils.cmake" COPYONLY)
configure_file(cmake/BcGitVersion.cmake "${CMAKE_CURRENT_BINARY_DIR}/BcGitVersion.cmake" COPYONLY)
configure_file(cmake/gitversion.h.in "${CMAKE_CURRENT_BINARY_DIR}/gitversion.h.in" COPYONLY)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BcToolboxTargets.cmake
FILE "${EXPORT_TARGETS_NAME}Targets.cmake"
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxCMakeUtils.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}CMakeUtils.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BcGitVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/gitversion.h.in"
DESTINATION ${CONFIG_PACKAGE_LOCATION}
......
......@@ -93,11 +93,7 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/libbctoolbox.so
%endif
%{_libdir}/pkgconfig/bctoolbox.pc
%{_datadir}/bctoolbox/cmake/BcGitVersion.cmake
%{_datadir}/bctoolbox/cmake/BcToolboxCMakeUtils.cmake
%{_datadir}/bctoolbox/cmake/BcToolboxConfig*.cmake
%{_datadir}/bctoolbox/cmake/BcToolboxTargets*.cmake
%{_datadir}/bctoolbox/cmake/gitversion.h.in
%{_datadir}/bctoolbox/cmake/*
%if @ENABLE_TESTS_COMPONENT@
%if @ENABLE_STATIC@
%{_libdir}/libbctoolbox-tester.a
......
......@@ -34,18 +34,23 @@
# BCTOOLBOX_${comp}_INCLUDE_DIRS - the bctoolbox "comp" component include directory
# BCTOOLBOX_${comp}_LIBRARIES - The libraries needed to use bctoolbox "comp" component
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/BcToolboxTargets.cmake")
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/bctoolboxTargets.cmake")
list(APPEND bctoolbox_FIND_COMPONENTS core)
if (ENABLE_TESTS_COMPONENT)
list(APPEND bctoolbox_FIND_COMPONENTS tester)
endif()
list(APPEND BcToolbox_FIND_COMPONENTS core)
list(REMOVE_DUPLICATES BcToolbox_FIND_COMPONENTS)
set(BcToolbox_FIND_REQUIRED_core TRUE)
list(REMOVE_DUPLICATES bctoolbox_FIND_COMPONENTS)
set(bctoolbox_FIND_REQUIRED_core TRUE)
set(BCTOOLBOX_CPPFLAGS @BCTOOLBOX_CPPFLAGS@)
set(BCTOOLBOX_LDFLAGS "@LINK_FLAGS_STR@")
set(BCTOOLBOX_LIBRARIES )
foreach(comp ${BcToolbox_FIND_COMPONENTS})
foreach(comp ${bctoolbox_FIND_COMPONENTS})
string(TOUPPER ${comp} uppercomp)
if(comp STREQUAL "core")
set(targetname bctoolbox)
......@@ -76,25 +81,16 @@ foreach(comp ${BcToolbox_FIND_COMPONENTS})
if(NOT BCTOOLBOX_${uppercomp}_INCLUDE_DIRS)
set(BCTOOLBOX_${uppercomp}_INCLUDE_DIRS)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT BCTOOLBOX_${uppercomp}_INCLUDE_DIRS 0 "${EP_bctoolbox_INCLUDE_DIR}")
else()
list(INSERT BCTOOLBOX_${uppercomp}_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES BCTOOLBOX_${uppercomp}_INCLUDE_DIRS)
list(APPEND BCTOOLBOX_LIBRARIES ${BCTOOLBOX_${uppercomp}_LIBRARIES})
list(APPEND BCTOOLBOX_INCLUDE_DIRS ${BCTOOLBOX_${uppercomp}_INCLUDE_DIRS})
set(BCTOOLBOX_${uppercomp}_FOUND 1)
if(comp STREQUAL "core")
set(BCTOOLBOX_FOUND 1)
endif()
elseif(BcToolbox_FIND_REQUIRED_${comp})
elseif(bctoolbox_FIND_REQUIRED_${comp})
message(FATAL_ERROR "Required bctoolbox component \"${comp}\" cannot be found")
endif()
endforeach()
if(BCTOOLBOX_INCLUDE_DIRS)
list(REMOVE_DUPLICATES BCTOOLBOX_INCLUDE_DIRS)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/BcToolboxCMakeUtils.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/bctoolboxCMakeUtils.cmake")
......@@ -129,7 +129,7 @@ if(ENABLE_SHARED)
endif()
set_target_properties(bctoolbox PROPERTIES LINKER_LANGUAGE "CXX")
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
set_target_properties(bctoolbox PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
set_target_properties(bctoolbox PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
endif()
if(NOT ANDROID)
# Do not version shared library on Android
......@@ -152,7 +152,7 @@ if(ENABLE_SHARED)
if(ENABLE_TESTS_COMPONENT)
add_library(bctoolbox-tester SHARED ${BCTOOLBOX_TESTER_SOURCE_FILES})
set_target_properties(bctoolbox-tester PROPERTIES LINKER_LANGUAGE "CXX")
target_link_libraries(bctoolbox-tester PRIVATE bctoolbox)
target_link_libraries(bctoolbox-tester PUBLIC bctoolbox PRIVATE ${BCUNIT_TARGETNAME})
if(WIN32)
target_compile_definitions(bctoolbox-tester PRIVATE "-DBCTBX_EXPORTS")
endif()
......@@ -171,46 +171,56 @@ if(ENABLE_SHARED)
endif()
endif()
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(MBEDTLS_FOUND)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static SYSTEM PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_include_directories(bctoolbox-static SYSTEM PRIVATE ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static INTERFACE ${MBEDTLS_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox SYSTEM PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_include_directories(bctoolbox SYSTEM PRIVATE ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${MBEDTLS_LIBRARIES})
endif()
endif()
if(POLARSSL_FOUND)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static SYSTEM PUBLIC ${POLARSSL_INCLUDE_DIRS})
target_include_directories(bctoolbox-static SYSTEM PRIVATE ${POLARSSL_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static INTERFACE ${POLARSSL_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox SYSTEM PUBLIC ${POLARSSL_INCLUDE_DIRS})
target_include_directories(bctoolbox PRIVATE ${POLARSSL_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${POLARSSL_LIBRARIES})
endif()
endif()
if(DECAF_FOUND)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static SYSTEM PUBLIC ${DECAF_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static INTERFACE ${DECAF_LIBRARY})
target_include_directories(bctoolbox-static PRIVATE ${DECAF_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static PUBLIC decaf-static)
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox SYSTEM PUBLIC ${DECAF_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${DECAF_LIBRARY})
target_include_directories(bctoolbox PRIVATE ${DECAF_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${DECAF_TARGETNAME})
endif()
endif()
if(ENABLE_TESTS_COMPONENT)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-tester-static SYSTEM PUBLIC ${BCUNIT_INCLUDE_DIRS})
target_link_libraries(bctoolbox-tester-static INTERFACE bctoolbox-static ${BCUNIT_LIBRARIES})
target_link_libraries(bctoolbox-tester-static PUBLIC bctoolbox-static ${BCUNIT_TARGETNAME})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox-tester SYSTEM PUBLIC ${BCUNIT_INCLUDE_DIRS})
target_link_libraries(bctoolbox-tester PRIVATE bctoolbox ${BCUNIT_LIBRARIES})
if(APPLE)
set_target_properties(bctoolbox-tester PROPERTIES
FRAMEWORK TRUE
......
......@@ -48,12 +48,13 @@ if(ENABLE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
target_link_libraries(bctoolbox_tester_exe PRIVATE ${PROJECT_LIBS})
if(MBEDTLS_FOUND)
target_link_libraries(bctoolbox_tester_exe PRIVATE ${MBEDTLS_LIBRARIES})
target_include_directories(bctoolbox_tester_exe PRIVATE ${MBEDTLS_INCLUDE_DIRS})
endif()
if(POLARSSL_FOUND)
target_link_libraries(bctoolbox_tester_exe PRIVATE ${POLARSSL_LIBRARIES})
endif()
if(DECAF_FOUND)
target_link_libraries(bctoolbox_tester_exe PRIVATE ${DECAF_LIBRARY})
target_link_libraries(bctoolbox_tester_exe PRIVATE ${DECAF_LIBRARIES})
endif()
set_target_properties(bctoolbox_tester_exe PROPERTIES XCODE_ATTRIBUTE_WARNING_CFLAGS "")
add_test(NAME bctoolbox_tester COMMAND bctoolbox_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