summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2026-01-14 23:29:11 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2026-01-15 16:15:59 +0900
commit84c2c873bf1ecb53a6581bb6cd50535ed9a79895 (patch)
tree9c09756a14af1b3bba7c016bf1f1a80889f60559
parent121212fa9f1618044b2544757efb2df35ef4c33b (diff)
downloadtde-cmake-add/tde-process-includes.tar.gz
tde-cmake-add/tde-process-includes.zip
Add macro to process and install header filesadd/tde-process-includes
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--modules/TDEMacros.cmake102
1 files changed, 102 insertions, 0 deletions
diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake
index 55a0c95..c6bbca1 100644
--- a/modules/TDEMacros.cmake
+++ b/modules/TDEMacros.cmake
@@ -3257,6 +3257,108 @@ 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
+##### "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}
+#####
+##### If DESTINATION is not an absolute path, it is interpreted as a
+##### subfolder of ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}.
+##### 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 "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${_install_dest}" )
+ endif()
+ file( RELATIVE_PATH _dest_sub "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}" "${_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
cmake_policy( POP )