string(TIMESTAMP) misbehaves when called multiple times
We found a very weird problem in our build, which seems to unearth a bug in string(TIMESTAMP)
.
Take the following example:
cmake_minimum_required( VERSION 3.0 )
project( TimeStampTests )
string( TIMESTAMP currentSeconds "%s" )
message( STATUS "currentSeconds = ${currentSeconds}" )
string( TIMESTAMP currentTime "%Y-%m-%dT%H%M" )
message( STATUS "currentTime = ${currentTime}" )
It sets the currentTime
variable according to UTC. But if I comment the first TIMESTAMP
call, then it switched to the expected local time.
-- The C compiler identification is AppleClang 10.0.0.10001145
-- The CXX compiler identification is AppleClang 10.0.0.10001145
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- currentSeconds = 1539009211
-- currentTime = 2018-10-08T1433
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/krasznaa/Development/cmake/build_ts
vs.
-- The C compiler identification is AppleClang 10.0.0.10001145
-- The CXX compiler identification is AppleClang 10.0.0.10001145
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- currentTime = 2018-10-08T1634
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/krasznaa/Development/cmake/build_ts
I.e. it's half past four in local time when I ran this...
Unfortunately I don't even know how to avoid this. Since the UTC
argument for string(...)
can only be used to force UTC time. It's not possible to force the function to return the local time...