Commit 5afc8a8b authored by Nicolas Michon's avatar Nicolas Michon

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

parent b7e53a74
......@@ -20,7 +20,7 @@
#
############################################################################
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.1)
project(oRTP VERSION 1.0.2)
......@@ -61,11 +61,7 @@ endif()
find_package(Threads)
find_library(LIBM NAMES m)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
find_package(BcToolbox 0.2.0 REQUIRED)
endif()
find_package(bctoolbox 0.2.0 REQUIRED)
check_include_file(sys/uio.h HAVE_SYS_UIO_H)
check_include_file(sys/audio.h HAVE_SYS_AUDIO_H)
......@@ -157,13 +153,7 @@ if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "ORTP")
endif()
set(EXPORT_TARGET_NAME ortp)
add_subdirectory(include)
add_subdirectory(src)
......@@ -202,38 +192,39 @@ set(ORTPDEPS_LIBS )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ortp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
add_subdirectory(build)
include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${EXPORT_TARGET_NAME}/cmake")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}ConfigVersion.cmake"
VERSION ${ORTP_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/ORTPTargets.cmake"
export(EXPORT "${EXPORT_TARGET_NAME}Targets"
FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}Targets.cmake"
)
configure_file(ORTPConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfig.cmake"
@ONLY
configure_package_config_file(ORTPConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_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 ORTPTargets.cmake
install(EXPORT ${EXPORT_TARGET_NAME}Targets
FILE "${EXPORT_TARGET_NAME}Targets.cmake"
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}ConfigVersion.cmake"
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
"${CMAKE_CURRENT_SOURCE_DIR}/ChangeLog"
"${CMAKE_CURRENT_SOURCE_DIR}/COPYING"
"${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS"
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}")
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}"
)
......@@ -28,34 +28,30 @@
# ORTP_LIBRARIES - The libraries needed to use oRTP
# ORTP_CPPFLAGS - The cflags needed to use oRTP
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/ORTPTargets.cmake")
endif()
@PACKAGE_INIT@
set(ORTP_TARGETNAME ortp)
include("${CMAKE_CURRENT_LIST_DIR}/${ORTP_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@)
set(ORTP_TARGETNAME ortp)
set(ORTP_LIBRARIES ${ORTP_TARGETNAME})
else()
set(ORTP_TARGETNAME ortp-static)
if(TARGET ${ORTP_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(ORTP_LIBRARIES ${ORTP_TARGETNAME})
else()
get_target_property(ORTP_LIBRARIES ${ORTP_TARGETNAME} LOCATION)
endif()
get_target_property(ORTP_LINK_LIBRARIES ${ORTP_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(ORTP_LINK_LIBRARIES)
list(APPEND ORTP_LIBRARIES ${ORTP_LINK_LIBRARIES})
list(APPEND ORTP_LIBRARIES ${ORTP_LINK_LIBRARIES})
endif()
endif()
endif()
get_target_property(ORTP_INCLUDE_DIRS ${ORTP_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT ORTP_INCLUDE_DIRS 0 "${EP_ortp_INCLUDE_DIR}")
else()
list(INSERT ORTP_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES ORTP_INCLUDE_DIRS)
set(ORTP_CPPFLAGS @ORTP_CPPFLAGS@)
set(ORTP_FOUND 1)
......@@ -118,8 +118,8 @@ rm -rf $RPM_BUILD_ROOT
%endif
%{_libdir}/pkgconfig/*.pc
%{_includedir}/*
%{_datadir}/oRTP/cmake/ORTPConfig*.cmake
%{_datadir}/oRTP/cmake/ORTPTargets*.cmake
%{_datadir}/ortp/cmake/*
%changelog
......
......@@ -20,7 +20,7 @@
#
############################################################################
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES})
set(LIBS )
if(NOT ANDROID)
list(APPEND LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
......@@ -94,9 +94,8 @@ if(ENABLE_STATIC)
add_library(ortp-static STATIC ${ORTP_HEADER_FILES} ${ORTP_SOURCE_FILES_C} ${ORTP_SOURCE_FILES_CXX})
set_target_properties(ortp-static PROPERTIES OUTPUT_NAME ortp)
target_compile_definitions(ortp-static PRIVATE "ORTP_EXPORTS")
target_include_directories(ortp-static PUBLIC ${BCTOOLBOX_CORE_INCLUDE_DIRS})
target_link_libraries(ortp-static INTERFACE ${LIBS})
install(TARGETS ortp-static EXPORT ${EXPORT_TARGETS_NAME}Targets
install(TARGETS ortp-static EXPORT ${EXPORT_TARGET_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
......@@ -126,8 +125,10 @@ if(ENABLE_SHARED)
target_compile_options(ortp PRIVATE "/DELAYLOAD:Qwave.dll")
endif()
target_compile_definitions(ortp PRIVATE "ORTP_EXPORTS")
target_include_directories(ortp PUBLIC ${BCTOOLBOX_CORE_INCLUDE_DIRS})
target_link_libraries(ortp PRIVATE ${LIBS})
target_include_directories(ortp
INTERFACE $<INSTALL_INTERFACE:include>
)
target_link_libraries(ortp PUBLIC bctoolbox PRIVATE ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/ortp.pdb
......@@ -136,7 +137,7 @@ if(ENABLE_SHARED)
)
endif()
endif()
install(TARGETS ortp EXPORT ${EXPORT_TARGETS_NAME}Targets
install(TARGETS ortp EXPORT ${EXPORT_TARGET_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
......
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