diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2026-01-14 23:29:11 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2026-01-14 23:47:29 +0900 |
| commit | e1909bf2a08a8ebe70d13582abc7b7015e2335dc (patch) | |
| tree | 7432fc750e6af4e2ddf4695095196223491eac28 /modules | |
| parent | 121212fa9f1618044b2544757efb2df35ef4c33b (diff) | |
| download | tde-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>
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/TDEMacros.cmake | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake index 55a0c95..e345e28 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 a subfolder of +##### ${CMAKE_BINARY_DIR}/include, based on the relative +##### location of the the calling `CMakeLists.txt` file +##### in the source tree +##### 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} + +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_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" ) + 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 ) |
