Update tde_create_tarball macro

+ Use external tar for ensure files owner in tarball.
+ Add an option to specify compression program.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit d9d9396324)
v3.5.13-sru
Slávek Banko 6 years ago
parent d3232e0c86
commit f43bab5f15
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -1443,6 +1443,7 @@ macro( tde_create_tarball )
unset( _files )
unset( _destination )
set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" )
set( _compression "gzip" )
set( _var _target )
foreach( _arg ${ARGN} )
@ -1475,6 +1476,13 @@ macro( tde_create_tarball )
set( _directive 1 )
endif( )
# found directive "COMPRESSION"
if( "+${_arg}" STREQUAL "+COMPRESSION" )
unset( _compression )
set( _var _compression )
set( _directive 1 )
endif( )
# collect data
if( _directive )
unset( _directive )
@ -1497,6 +1505,39 @@ macro( tde_create_tarball )
list( APPEND _files_deps "${_sourcedir}/${_file}" )
endforeach( )
if( NOT DEFINED TAR_EXECUTABLE )
find_program( TAR_EXECUTABLE NAMES tar )
if( "${TAR_EXECUTABLE}" STREQUAL "TAR_EXECUTABLE-NOTFOUND" )
tde_message_fatal( "tar executable is required but not found on your system" )
endif( )
endif( )
if( NOT DEFINED TAR_SETOWNER )
execute_process(
COMMAND ${TAR_EXECUTABLE} --version
OUTPUT_VARIABLE TAR_VERSION
)
string( REGEX REPLACE "^([^\n]*)\n.*" "\\1" TAR_VERSION "${TAR_VERSION}" )
if( "${TAR_VERSION}" MATCHES "GNU *tar" )
set( TAR_SETOWNER "--owner=root;--group=root" )
elseif( "${TAR_VERSION}" MATCHES "bsd *tar" )
set( TAR_SETOWNER "--uname=root;--gname=root" )
else( )
set( TAR_SETOWNER "" )
endif( )
endif( )
if( "${_compression}" STREQUAL "-" )
unset( _compression )
endif( )
if( _compression )
if( "${_compression}" STREQUAL "gzip" )
set( _compression "-z" )
else( )
set( _compression "--use-compress-program=\"${_compression}\"" )
endif( )
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}" )
@ -1504,7 +1545,8 @@ macro( tde_create_tarball )
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_target}" )
add_custom_command(
COMMAND ${CMAKE_COMMAND} -E tar "cfz" "${CMAKE_CURRENT_BINARY_DIR}/${_target}" -- ${_files}
COMMAND ${TAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${_target}
${_compression} ${TAR_SETOWNER} -- ${_files}
WORKING_DIRECTORY "${_sourcedir}"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_target}"
DEPENDS ${_files_deps}

Loading…
Cancel
Save