From 7b5d3d735a62a8ff6e43f56b30efa4e51795cbce Mon Sep 17 00:00:00 2001 From: rolflussi Date: Fri, 11 Oct 2024 15:42:53 +0200 Subject: [PATCH] Generate cnats-config-version.cmake (#813) * provide cnats-config-version.cmake to be able to define required version in find_package * change from requiring same major version to same minor version --------- Co-authored-by: Rolf Lussi --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 409f21054..413e0523e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.13) project(cnats) include(CTest) include(FindPackageHandleStandardArgs) +include(CMakePackageConfigHelpers) # Uncomment to have the build process verbose # set(CMAKE_VERBOSE_MAKEFILE TRUE) @@ -258,6 +259,11 @@ set(NATS_VERSION_SUFFIX "-beta") set(NATS_VERSION_REQUIRED_NUMBER 0x030900) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/cnats-config-version.cmake" + COMPATIBILITY SameMinorVersion + VERSION ${NATS_VERSION_MAJOR}.${NATS_VERSION_MINOR}.${NATS_VERSION_PATCH}${NATS_VERSION_SUFFIX}) + if(NATS_UPDATE_VERSION OR NATS_UPDATE_DOC) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b18f72406..971ddf09f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,8 @@ if(NATS_BUILD_LIB_SHARED) NAMESPACE cnats:: FILE cnats-config.cmake DESTINATION ${NATS_LIBDIR}/cmake/cnats) + install(FILES "${PROJECT_BINARY_DIR}/cnats-config-version.cmake" + DESTINATION ${NATS_LIBDIR}/cmake/cnats) endif(NATS_BUILD_LIB_SHARED) if(NATS_BUILD_LIB_STATIC) @@ -79,6 +81,8 @@ if(NATS_BUILD_LIB_STATIC) NAMESPACE cnats:: FILE cnats-config.cmake DESTINATION ${NATS_LIBDIR}/cmake/cnats) + install(FILES "${PROJECT_BINARY_DIR}/cnats-config-version.cmake" + DESTINATION ${NATS_LIBDIR}/cmake/cnats) endif(NATS_BUILD_LIB_STATIC) install(FILES deprnats.h DESTINATION ${NATS_INCLUDE_DIR} RENAME nats.h)