From c25ffb3c894a2f9f5994960dd9b1c4c3aa5ea411 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Wed, 14 Jan 2026 23:29:11 +0900
Subject: Add macro to process and install header files

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 modules/TDEMacros.cmake | 100 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake
index 55a0c95..a768814 100644
--- a/modules/TDEMacros.cmake
+++ b/modules/TDEMacros.cmake
@@ -3255,6 +3255,106 @@ macro( tde_setup_polkit )
 endmacro( )
 
 
+#################################################
+#####
+##### tde_process_includes
+#####
+##### The macro performs the following actions:
+##### 1. create symlinks to the files into ${CMAKE_BINARY_DIR}/include
+#####    or one of its subfolders.
+##### 2. optionally install the header files
+#####
+##### Syntax:
+#####   tde_process_includes(
+#####     [FILES] include_name [include_name]
+#####     [DESTINATION subdir]
+#####     [ONLY_SYMLINK]
+#####   )
+#####
+##### If DESTINATION is not specified, it defaults to ${INCLUDE_INSTALL_DIR}
+##### If DESTINATION is not an absolute path, it is interpreted as a
+##### subfolder of ${INCLUDE_INSTALL_DIR}.
+##### It will also be added as subfolder to ${CMAKE_BINARY_DIR}/include
+##### for the location of the symlinks.
+
+macro( tde_process_includes )
+
+  unset( _files )
+  unset( _install_dest )
+  unset( _only_symlink )
+  set( _var _files )
+  foreach( _arg ${ARGN} )
+
+    # found directive "FILES"
+    if( "+${_arg}" STREQUAL "+FILES" )
+      unset( _files )
+      set( _var _files )
+      set( _directive 1 )
+    endif( )
+
+    # found directive "DESTINATION"
+    if( "+${_arg}" STREQUAL "+DESTINATION" )
+      unset( _install_dest )
+      set( _var _install_dest )
+      set( _directive 1 )
+    endif( )
+
+    # found directive "ONLY_SYMLINK"
+    if( "+${_arg}" STREQUAL "+ONLY_SYMLINK" )
+      unset( _var )
+      set( _only_symlink 1 )
+      set( _directive 1 )
+    endif( )
+
+    # collect data
+    if( _directive )
+      unset( _directive )
+    elseif( _var )
+      list( APPEND ${_var} ${_arg} )
+    endif( )
+
+  endforeach( )
+
+  # determine installation and build folders
+  if( NOT IS_ABSOLUTE "${_install_dest}" )
+    set( _install_dest "${INCLUDE_INSTALL_DIR}/${_install_dest}" )
+  endif()
+  file( RELATIVE_PATH _dest_sub "${INCLUDE_INSTALL_DIR}" "${_install_dest}" )
+  set( _build_dest "${CMAKE_BINARY_DIR}/include/${_dest_sub}" )
+  file( MAKE_DIRECTORY "${_build_dest}" )
+
+  # process files
+  foreach( _file IN LISTS _files )
+    if( NOT TARGET tde-includes )
+      add_custom_target( tde-includes
+        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
+        COMMENT "Prepare includes..." )
+    endif()
+
+    get_filename_component( _source_name "${_file}" NAME )
+    get_filename_component( _source_file "${_file}" ABSOLUTE )
+    file( RELATIVE_PATH _link_source "${_build_dest}" ${_source_file} )
+    file( RELATIVE_PATH _target_name "${CMAKE_SOURCE_DIR}" "${_source_file}" )
+    string( REPLACE "/" "+" _target_name "${_target_name}" )
+    if( NOT TARGET ${_target_name} )
+      add_custom_target( ${_target_name}
+        COMMAND
+          ${CMAKE_COMMAND} -E create_symlink
+          ${_link_source} ${_build_dest}/${_source_name}
+        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
+        COMMENT "Include file ${_source_name}"
+      )
+      add_dependencies( tde-includes ${_target_name} )
+    endif()
+
+    if( NOT "${_only_symlink}" )
+      install( FILES ${_file} DESTINATION ${_install_dest} )
+    endif()
+  endforeach( _file )
+
+endmacro( tde_process_includes )
+
+
 #################################################
 #####
 ##### restore CMake policies
-- 
cgit v1.2.3

