From d48c835f654acdeb61c155455bd76e7e29b54e9b Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 8 Jul 2017 14:11:22 -0700 Subject: [PATCH] add cmake package support This enables libtorrent to be used with the find_package command for easy integration with applications which use cmake. --- CMakeLists.txt | 42 +++++++++++++++++++++++++++++--- libtorrent-rasterbarConfig.cmake | 1 + 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 libtorrent-rasterbarConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a7a351cb..336e790e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -365,12 +365,46 @@ else() set (LIBDIR "lib") endif() -install(TARGETS torrent-rasterbar DESTINATION ${LIBDIR}) -install(DIRECTORY include/libtorrent - DESTINATION include - PATTERN ".svn" EXCLUDE) +install(TARGETS torrent-rasterbar EXPORT torrent-rasterbarTargets + DESTINATION ${LIBDIR} INCLUDES DESTINATION include) +install(DIRECTORY include/libtorrent DESTINATION include) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar.pc DESTINATION ${LIBDIR}/pkgconfig) +# === generate a CMake Config File === +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfigVersion.cmake" + VERSION ${VERSION} + COMPATIBILITY ExactVersion +) + +export(EXPORT torrent-rasterbarTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarTargets.cmake" + NAMESPACE Libtorrent:: +) + +configure_file(libtorrent-rasterbarConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfig.cmake" + COPYONLY +) + +set(ConfigPackageLocation lib/cmake/libtorrent-rasterbar) +install(EXPORT torrent-rasterbarTargets + FILE + libtorrent-rasterbarTargets.cmake + NAMESPACE + Libtorrent:: + DESTINATION + ${ConfigPackageLocation} +) +install( + FILES + libtorrent-rasterbarConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfigVersion.cmake" + DESTINATION + ${ConfigPackageLocation} +) + # === set up examples directory as an independent project === file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples) configure_file(examples/run_cmake.sh.in examples/run_cmake.sh) diff --git a/libtorrent-rasterbarConfig.cmake b/libtorrent-rasterbarConfig.cmake new file mode 100644 index 000000000..e4bdebff7 --- /dev/null +++ b/libtorrent-rasterbarConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/libtorrent-rasterbarTargets.cmake")