From e2aff66b988ed4d5681233a895c04bbb7ea0f96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Ga=C3=9Fmann?= Date: Fri, 19 May 2023 17:50:23 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 8 +- .../ftxui-config.cmake.in | 2 + cmake/ftxui_install.cmake | 83 ++++++++++++------- 3 files changed, 60 insertions(+), 33 deletions(-) rename ftxui-config.cmake.in => cmake/ftxui-config.cmake.in (56%) diff --git a/CHANGELOG.md b/CHANGELOG.md index da703b1..3801051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ Changelog ========= -4.1.0 +4.1.1 +----- + +### Build +- Check version compatibility when using cmake find_package() + +4.1.0 (abandonned) ----- ### Component diff --git a/ftxui-config.cmake.in b/cmake/ftxui-config.cmake.in similarity index 56% rename from ftxui-config.cmake.in rename to cmake/ftxui-config.cmake.in index 5045a69..b04ba33 100644 --- a/ftxui-config.cmake.in +++ b/cmake/ftxui-config.cmake.in @@ -2,3 +2,5 @@ include(CMakeFindDependencyMacro) find_dependency(Threads) + +include("${CMAKE_CURRENT_LIST_DIR}/ftxui-targets.cmake") diff --git a/cmake/ftxui_install.cmake b/cmake/ftxui_install.cmake index 605841d..d6de491 100644 --- a/cmake/ftxui_install.cmake +++ b/cmake/ftxui_install.cmake @@ -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} + )