build: Check package version in find_package (#643)

Modify the `ftxui-config.cmake.in` file so that it includes
`ftxui-targets.cmake`. This causes cmake to check the version is
compatible with what the user requested.

This patch also includes additional minor changes.

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Henrik Gaßmann 2023-05-19 17:50:23 +02:00 committed by GitHub
parent 5e1af6bb69
commit b1c53bcd15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 32 deletions

View File

@ -12,6 +12,9 @@ current (development)
- Feature: `input` is now supporting multiple lines.
- Feature: `input` style is now customizeable.
### Build
- Check version compatibility when using cmake find_package()
4.1.0
-----

View File

@ -2,3 +2,5 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)
include("${CMAKE_CURRENT_LIST_DIR}/ftxui-targets.cmake")

View File

@ -3,41 +3,60 @@ if(NOT FTXUI_ENABLE_INSTALL)
endif()
include(GNUInstallDirs)
install(TARGETS screen dom component
EXPORT ftxui-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/ftxui DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# CMake package configuration for easy use of library in CMake
include(CMakePackageConfigHelpers)
configure_package_config_file(ftxui-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/cmake
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
write_basic_package_version_file(
ftxui-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
)
install(EXPORT ftxui-export
FILE ftxui-config-version.cmake
# ------------------------------------------------------------------------------
# Install the library and its public headers into the standard subdirectories
# ------------------------------------------------------------------------------
install(
TARGETS screen dom component
EXPORT ftxui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
DIRECTORY include/ftxui
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# ------------------------------------------------------------------------------
# Install the exported cmake targets for use in other CMake projects.
# ------------------------------------------------------------------------------
install(
EXPORT ftxui-targets
NAMESPACE ftxui::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
)
)
# pkg-config file for easy use of library in build systems other than CMake
configure_file(ftxui.pc.in
${CMAKE_CURRENT_BINARY_DIR}/ftxui.pc
@ONLY)
# ------------------------------------------------------------------------------
# Create and install the ftuxi-config.cmake and ftuxi-config-version.cmake files
# needed to support users of find_package()
# ------------------------------------------------------------------------------
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/ftxui-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/ftxui-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/cmake
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/ftxui-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/ftxui-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/ftxui-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftxui.pc
DESTINATION lib/pkgconfig
)
# ------------------------------------------------------------------------------
# Create and install pkg-config file for easy use of library in build systems
# other than CMake:
# ------------------------------------------------------------------------------
configure_file(ftxui.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ftxui.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/ftxui.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)