From 3f64ceba682f62d1e1814ce90125cb0b5125c1f7 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Mon, 10 Feb 2020 23:00:47 +0300 Subject: [PATCH] [A] Add cmake package files to installation phase --- CMakeLists.txt | 9 +++++++++ cmake/libfort-config.cmake.in | 5 +++++ lib/CMakeLists.txt | 32 +++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 cmake/libfort-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4103408..3492cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,3 +260,12 @@ list(APPEND ${PROJECT_NAME}_ctests foreach(exe ${${PROJECT_NAME}_ctests}) add_test(NAME ${exe} COMMAND ${exe}) endforeach() + +# ------------------------------------------------------------------------------ +# Exported targets for outer applications. +# ------------------------------------------------------------------------------ +export( + TARGETS fort + FILE libfort-exports.cmake +) + diff --git a/cmake/libfort-config.cmake.in b/cmake/libfort-config.cmake.in new file mode 100644 index 0000000..5e76e5d --- /dev/null +++ b/cmake/libfort-config.cmake.in @@ -0,0 +1,5 @@ +if(NOT TARGET @PROJECT_NAME@::fort) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") +endif() + +set(@PROJECT_NAME@_LIBRARIES @PROJECT_NAME@::fort) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 837ed5f..f8d1931 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -32,7 +32,8 @@ endif() include(GNUInstallDirs) install( TARGETS fort - EXPORT LibFort + EXPORT ${PROJECT_NAME}-targets + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -48,8 +49,33 @@ install( DESTINATION lib/pkgconfig ) +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/${PROJECT_NAME}-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake + COMPATIBILITY SameMajorVersion +) install( - EXPORT LibFort - NAMESPACE LibFort:: + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) + +install( + EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +export( + TARGETS fort + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}-exports.cmake +) +