From 01a29c294c898cf6e13fb500b8514e9982982e1f Mon Sep 17 00:00:00 2001
From: Rui Costa <rui.ms.costa@ctw.bmwgroup.com>
Date: Mon, 7 Jul 2025 18:16:35 +0300
Subject: [PATCH] Add package configuration files

Upstream-Status: Pending

Signed-off-by: Rui Costa <rui.ms.costa@ctw.bmwgroup.com>
Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
---
 lang/c++/CMakeLists.txt            | 46 ++++++++++++++++++++++++------
 lang/c++/cmake/AvroCppConfig.cmake |  5 ++++
 2 files changed, 43 insertions(+), 8 deletions(-)
 create mode 100644 lang/c++/cmake/AvroCppConfig.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f5f98c83..73596a6cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -167,18 +167,48 @@ set (CPACK_PACKAGE_FILE_NAME "avrocpp-${AVRO_VERSION_MAJOR}")

 include (CPack)

-install (TARGETS avrocpp avrocpp_s
-    LIBRARY DESTINATION lib
-    ARCHIVE DESTINATION lib
-    RUNTIME DESTINATION lib)
-
-install (TARGETS avrogencpp RUNTIME DESTINATION bin)
-
-install (DIRECTORY include/avro DESTINATION include
+install(TARGETS avrocpp
+    EXPORT AvroCppTargets
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+install(TARGETS avrogencpp
+    EXPORT AvroCppTargets
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+install(DIRECTORY include/avro DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
     FILES_MATCHING PATTERN *.hh)

+
 if (NOT CMAKE_BUILD_TYPE)
     set (CMAKE_BUILD_TYPE Release CACHE STRING
       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
       FORCE)
 endif (NOT CMAKE_BUILD_TYPE)
+
+# Create cmake config files
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+    "${CMAKE_CURRENT_BINARY_DIR}/AvroCppConfigVersion.cmake"
+    VERSION ${AVRO_VERSION_MAJOR}.${AVRO_VERSION_MINOR}.${AVRO_VERSION_PATCH}
+    COMPATIBILITY AnyNewerVersion
+)
+
+configure_file(cmake/AvroCppConfig.cmake
+    "${CMAKE_CURRENT_BINARY_DIR}/AvroCppConfig.cmake"
+    COPYONLY
+)
+
+set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/avrocpp)
+install(EXPORT AvroCppTargets
+    FILE AvroCppTargets.cmake
+    NAMESPACE AvroCpp::
+    DESTINATION ${ConfigPackageLocation}
+)
+install(FILES
+    "cmake/AvroCppConfig.cmake"
+    "${CMAKE_CURRENT_BINARY_DIR}/AvroCppConfigVersion.cmake"
+    DESTINATION ${ConfigPackageLocation}
+    COMPONENT Devel)
diff --git a/lang/c++/cmake/AvroCppConfig.cmake b/lang/c++/cmake/AvroCppConfig.cmake
new file mode 100644
index 000000000..deb8aaa31
--- /dev/null
+++ b/cmake/AvroCppConfig.cmake
@@ -0,0 +1,5 @@
+include(CMakeFindDependencyMacro)
+find_dependency(Boost 1.38 REQUIRED
+    COMPONENTS filesystem iostreams program_options regex system)
+
+include("${CMAKE_CURRENT_LIST_DIR}/AvroCppTargets.cmake")
--
2.43.0

