[A] Add cmake package files to installation phase

This commit is contained in:
seleznevae 2020-02-10 23:00:47 +03:00
parent c22a518766
commit 3f64ceba68
3 changed files with 43 additions and 3 deletions

View File

@ -260,3 +260,12 @@ list(APPEND ${PROJECT_NAME}_ctests
foreach(exe ${${PROJECT_NAME}_ctests}) foreach(exe ${${PROJECT_NAME}_ctests})
add_test(NAME ${exe} COMMAND ${exe}) add_test(NAME ${exe} COMMAND ${exe})
endforeach() endforeach()
# ------------------------------------------------------------------------------
# Exported targets for outer applications.
# ------------------------------------------------------------------------------
export(
TARGETS fort
FILE libfort-exports.cmake
)

View File

@ -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)

View File

@ -32,7 +32,8 @@ endif()
include(GNUInstallDirs) include(GNUInstallDirs)
install( install(
TARGETS fort TARGETS fort
EXPORT LibFort EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
@ -48,8 +49,33 @@ install(
DESTINATION lib/pkgconfig 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( install(
EXPORT LibFort FILES
NAMESPACE LibFort:: ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} 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
)