From ffda10ca01b08e386cc1331e68a19576b907b9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Fri, 11 Jan 2019 03:00:07 +0100 Subject: [PATCH] Add tde_create_tarball macro. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit 6f9d42cd992ded747ffdc1cf407460e5136491fc) --- modules/TDEMacros.cmake | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake index ef1ed07..bb6b831 100644 --- a/modules/TDEMacros.cmake +++ b/modules/TDEMacros.cmake @@ -1580,6 +1580,89 @@ macro( tde_create_handbook ) endmacro( ) +################################################# +##### +##### tde_create_tarball +##### +##### Macro is used to create tarball. +##### + +macro( tde_create_tarball ) + + unset( _target ) + unset( _files ) + unset( _destination ) + set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" ) + set( _var _target ) + + foreach( _arg ${ARGN} ) + + # found directive "TARGET" + if( "+${_arg}" STREQUAL "+TARGET" ) + unset( _target ) + set( _var _target ) + set( _directive 1 ) + endif( ) + + # found directive "SOURCEDIR" + if( "+${_arg}" STREQUAL "+SOURCEDIR" ) + unset( _sourcedir ) + set( _var _sourcedir ) + set( _directive 1 ) + endif( ) + + # found directive "FILES" + if( "+${_arg}" STREQUAL "+FILES" ) + unset( _files ) + set( _var _files ) + set( _directive 1 ) + endif( ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + unset( _dest ) + set( _var _dest ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif( ) + + endforeach( ) + + if( NOT _target ) + tde_message_fatal( "Target tarball name not specified." ) + endif( ) + + if( NOT _files ) + file( GLOB_RECURSE _files RELATIVE ${_sourcedir} "${_sourcedir}/*" ) + endif( ) + + get_filename_component( _target_path "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ABSOLUTE ) + file( RELATIVE_PATH _target_path "${CMAKE_BINARY_DIR}" "${_target_path}" ) + string( REPLACE "/" "+" _target_name "${_target_path}" ) + add_custom_target( "${_target_name}-tarball" ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ) + + add_custom_command( + COMMAND ${CMAKE_COMMAND} -E tar "cfz" "${CMAKE_CURRENT_BINARY_DIR}/${_target}" -- ${_files} + WORKING_DIRECTORY "${_sourcedir}" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_target}" + DEPENDS ${_files} + COMMENT "Create tarball ${_target_path}" + ) + + if( _destination ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_target} DESTINATION ${_destination} ) + endif( ) + +endmacro() + + ################################################# ##### ##### tde_include_tqt