Add required dependencies to the generated package Config.cmake file

This commit is contained in:
Eugene Shalygin 2018-04-26 16:13:05 +02:00 committed by Arvid Norberg
parent 63229dbda6
commit 4afa4932df
3 changed files with 28 additions and 5 deletions

View File

@ -469,6 +469,7 @@ if(UNIX)
endif()
find_package(Threads REQUIRED)
set(_package_dependencies "Threads") # Dependencies to be used below for generating Config.cmake file
include_directories(${includes})
@ -589,6 +590,7 @@ target_link_libraries(torrent-rasterbar
if (libiconv)
find_package(Iconv REQUIRED)
list(APPEND _package_dependencies "Iconv")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_ICONV)
target_include_directories(torrent-rasterbar PUBLIC ${ICONV_INCLUDE_DIR})
target_link_libraries(torrent-rasterbar PRIVATE ${ICONV_LIBRARIES})
@ -616,6 +618,7 @@ endif()
# Boost
find_package(Boost REQUIRED COMPONENTS system)
target_link_libraries(torrent-rasterbar PUBLIC Boost::system)
list(APPEND _package_dependencies "Boost COMPONENTS system")
if (WIN32)
target_link_libraries(torrent-rasterbar
@ -697,6 +700,10 @@ install(DIRECTORY include/libtorrent DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FIL
# === generate a CMake Config File ===
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/libtorrent-rasterbar)
string(REGEX REPLACE "([^;]+)" "find_dependency(\\1)" _find_dependency_calls "${_package_dependencies}")
string(REPLACE ";" "\n" _find_dependency_calls "${_find_dependency_calls}")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfigVersion.cmake"
VERSION ${libtorrent_VERSION}
@ -708,12 +715,13 @@ export(EXPORT torrent-rasterbarTargets
NAMESPACE Libtorrent::
)
configure_file(libtorrent-rasterbarConfig.cmake
configure_package_config_file(libtorrent-rasterbarConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfig.cmake"
COPYONLY
INSTALL_DESTINATION "${ConfigPackageLocation}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/libtorrent-rasterbar)
install(EXPORT torrent-rasterbarTargets
FILE
libtorrent-rasterbarTargets.cmake
@ -724,7 +732,7 @@ install(EXPORT torrent-rasterbarTargets
)
install(
FILES
libtorrent-rasterbarConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}

View File

@ -1 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/libtorrent-rasterbarTargets.cmake")

View File

@ -0,0 +1,16 @@
# - Config file for the @PROJECT_NAME@ package
# It defines the following variables
# @PROJECT_NAME@_INCLUDE_DIRS - include directories for @PROJECT_NAME@
# @PROJECT_NAME@_LIBRARIES - libraries to link against
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
@_find_dependency_calls@
include("${CMAKE_CURRENT_LIST_DIR}/libtorrent-rasterbarTargets.cmake")
get_target_property(@PROJECT_NAME@_INCLUDE_DIRS Libtorrent::torrent-rasterbar INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(_lt_iface_link_libraries Libtorrent::torrent-rasterbar INTERFACE_LINK_LIBRARIES)
get_target_property(_lt_imported_location Libtorrent::torrent-rasterbar IMPORTED_LOCATION)
set(@PROJECT_NAME@_LIBRARIES "${_lt_imported_location};${_lt_iface_link_libraries}")