From: Boyuan Yang <byang@debian.org>
Date: Wed, 19 Jun 2024 22:17:32 -0400
Subject: CMakeLists.txt: Add install target

---
 CMakeLists.txt | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ca6fd8..97f7c52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.23.1)
 option(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test")
 
+include(GNUInstallDirs)
+
 # Creates the file compile_commands.json in the build directory.
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 set(CMAKE_CXX_STANDARD 17)
@@ -16,6 +18,7 @@ find_package(SQLite3 REQUIRED)
 
 set(TEST_SOURCE_DIR             ${CMAKE_CURRENT_SOURCE_DIR}/tests)
 file(GLOB TEST_SOURCES          ${TEST_SOURCE_DIR}/*.cc)
+file(GLOB_RECURSE HEADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hdr/ *.h)
 
 IF(NOT ENABLE_SQLCIPHER_TESTS)
     list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc)
@@ -24,7 +27,19 @@ ENDIF(NOT ENABLE_SQLCIPHER_TESTS)
 enable_testing()
 
 add_library (sqlite_modern_cpp INTERFACE)
-target_include_directories(sqlite_modern_cpp INTERFACE hdr/)
+target_include_directories(sqlite_modern_cpp INTERFACE
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hdr/>
+)
+
+target_sources(sqlite_modern_cpp INTERFACE
+        FILE_SET HEADERS
+        BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/hdr/
+        FILES ${HEADER_SOURCES}
+)
+
+install(TARGETS sqlite_modern_cpp
+        FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
 
 add_executable(tests_runner ${TEST_SOURCES})
 target_include_directories(tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS})
