Time string manipulation in CMakeLists.txt

26 views Asked by At

I want to automatically set an expiration date for two months from now in CMakeLists.txt. Is there an easy way to find that date (in whatever format) in CMakeLists.txt? I found the TIMESTAMP method but it doesn't return something easy to manipulate (like an epoch time integer or a date-time object).

1

There are 1 answers

0
Asker On

Well, I did this, and it works, but it's ugly. Wish there was a way to properly manipulate time in CMake

string(TIMESTAMP YEAR "%Y")
string(TIMESTAMP CUR_MONTH "%m")
math(EXPR FUTURE_MONTH "2+${CUR_MONTH}")
if (12 LESS ${FUTURE_MONTH})
  math(EXPR FUTURE_MONTH "${FUTURE_MONTH} % 12")
  math(EXPR YEAR "${YEAR} + 1")
endif()

set(EXPIRE_DATE "${YEAR}-${FUTURE_MONTH}-01")