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)
r14.0.x
Slávek Banko 6 years ago
parent 30d86a1f29
commit 4bce22ab48
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -1593,6 +1593,7 @@ macro( tde_create_tarball )
unset( _files ) unset( _files )
unset( _destination ) unset( _destination )
set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" ) set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" )
set( _compression "gzip" )
set( _var _target ) set( _var _target )
foreach( _arg ${ARGN} ) foreach( _arg ${ARGN} )
@ -1625,6 +1626,13 @@ macro( tde_create_tarball )
set( _directive 1 ) set( _directive 1 )
endif( ) endif( )
# found directive "COMPRESSION"
if( "+${_arg}" STREQUAL "+COMPRESSION" )
unset( _compression )
set( _var _compression )
set( _directive 1 )
endif( )
# collect data # collect data
if( _directive ) if( _directive )
unset( _directive ) unset( _directive )
@ -1647,6 +1655,39 @@ macro( tde_create_tarball )
list( APPEND _files_deps "${_sourcedir}/${_file}" ) list( APPEND _files_deps "${_sourcedir}/${_file}" )
endforeach( ) 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 ) get_filename_component( _target_path "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ABSOLUTE )
file( RELATIVE_PATH _target_path "${CMAKE_BINARY_DIR}" "${_target_path}" ) file( RELATIVE_PATH _target_path "${CMAKE_BINARY_DIR}" "${_target_path}" )
string( REPLACE "/" "+" _target_name "${_target_path}" ) string( REPLACE "/" "+" _target_name "${_target_path}" )
@ -1654,7 +1695,8 @@ macro( tde_create_tarball )
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ) DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_target}" )
add_custom_command( 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}" WORKING_DIRECTORY "${_sourcedir}"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_target}" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_target}"
DEPENDS ${_files_deps} DEPENDS ${_files_deps}

Loading…
Cancel
Save