LoginSignup
0
0

More than 5 years have passed since last update.

CMakeでタイムスタンプを変数で取得

Posted at

実験でログを取るときのファイル名に利用するために調べました.

方法

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
$
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0