string(TIMESTAMP: inconsistent handling of local vs UTC time zones
0 reputation · 22 Jan 2023, 03:20 UTC
string(TIMESTAMP: inconsistent handling of local vs UTC time zones
The string(TIMESTAMP) command formats the current date and time. Without the UTC flag it relies on the build machine’s local time zone, which is derived from the TZ environment variable or the system clock. When UTC is specified the output is deterministic, but CMake offers no way to target an arbitrary region or to apply daylight‑saving rules beyond the host’s current setting.
Because the underlying strftime implementation varies between POSIX systems and Windows, the same format string can yield different results (e.g., %Z may be empty on Windows). Moreover, changing TZ after CMake has already configured a project has no effect on timestamps that were already computed.
These differences raise the following unresolved questions:
- Is it possible to request a specific time zone offset or named zone directly from
string(TIMESTAMP)without external tooling? - How does CMake’s local‑time calculation handle daylight‑saving transitions, and can the behavior be made reproducible across systems with different
tzdataversions? - What impact does the
TZenvironment variable have on Windows builds, and does it provide the same level of control as on POSIX platforms?