実験でログを取るときのファイル名に利用するために調べました.
方法
string (TIMESTAMP <variable> <format>)
で取れます.formatを上のリンクをご参照ください.
CMakeLists.txt
CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
PROJECT(timestamp)
string(TIMESTAMP TIMESTAMP "%Y%m%d-%H%M%S") #ここ
message(STATUS "TIMESTAMP=" ${TIMESTAMP})
ADD_CUSTOM_TARGET(timestamptest ALL
COMMAND echo ${TIMESTAMP} > ${TIMESTAMP}.txt
)
結果
$ cmake ..
-- The C compiler identification is AppleClang 9.0.0.9000039
-- The CXX compiler identification is AppleClang 9.0.0.9000039
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/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: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- TIMESTAMP=20180622-192950
-- Configuring done
-- Generating done
-- Build files have been written to: /****/cmake_timestamp/build
$