diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake index d48033c..baa51d1 100644 --- a/modules/TDEMacros.cmake +++ b/modules/TDEMacros.cmake @@ -1593,6 +1593,7 @@ macro( tde_create_tarball ) unset( _files ) unset( _destination ) set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" ) + set( _compression "gzip" ) set( _var _target ) foreach( _arg ${ARGN} ) @@ -1625,6 +1626,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 ) @@ -1647,6 +1655,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}" ) @@ -1654,7 +1695,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}