1# BAREOS® - Backup Archiving REcovery Open Sourced 2# 3# Copyright (C) 2019-2019 Bareos GmbH & Co. KG 4# 5# This program is Free Software; you can redistribute it and/or modify it under 6# the terms of version three of the GNU Affero General Public License as 7# published by the Free Software Foundation and included in the file LICENSE. 8# 9# This program is distributed in the hope that it will be useful, but WITHOUT 10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 12# details. 13# 14# You should have received a copy of the GNU Affero General Public License along 15# with this program; if not, write to the Free Software Foundation, Inc., 51 16# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 18function( 19 timestamp_at 20 at 21 result 22 format 23) 24 if(CMAKE_VERSION VERSION_GREATER 3.10.0) 25 set(old_epoch "$ENV{SOURCE_DATE_EPOCH}") 26 set(ENV{SOURCE_DATE_EPOCH} "${at}") 27 string(TIMESTAMP out "${format}" UTC) 28 set(ENV{SOURCE_DATE_EPOCH} "${old_epoch}") 29 else() 30 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") 31 set(DATECMD gdate) 32 else() 33 set(DATECMD date) 34 endif() 35 set(old_lang "$ENV{LC_ALL}") 36 set(ENV{LC_ALL} "C") 37 execute_process( 38 COMMAND 39 ${DATECMD} 40 --utc 41 "--date=@${at}" 42 "+${format}" 43 OUTPUT_VARIABLE out 44 OUTPUT_STRIP_TRAILING_WHITESPACE 45 ) 46 set(ENV{LC_ALL} "${old_lang}") 47 if(out STREQUAL "") 48 message( 49 FATAL_ERROR 50 "Cannot use SOURCE_DATE_EPOCH (cmake < 3.10) and your 'date' command is not compatible with Bareos' timestamp_at()." 51 ) 52 endif() 53 endif() 54 set("${result}" "${out}" PARENT_SCOPE) 55endfunction() 56