write cmake code that stores the current time in a variable named "a", prints a message,…
Jump to turn (8)
- 1write cmake code that stores the current time in a variable named "a", prints a
- 2can you get the timestamp in Windows, since it does not have the date command?
- 3can you get the timestamp without executing a process?
- 4instead of cmake\host\system\information, use the "string" function where the fi
- 5what is the format string to get the timestamp in milliseconds?
- 6instead of %3N, use %f, because that will get the microseconds
- 7make a note to install cmake 3.23 so I may use the %f format specifier
- 8that's incorrect, the %f specifier was introduced in cmake version 3.23
- User
write cmake code that stores the current time in a variable named "a", prints a message, stores the current time in a variable named "b", and subtracts the difference between the two times.
- Assistant
Here's an example CMake code that does what you've asked for:
bashcmake_minimum_required(VERSION 3.10) project(MyProject) # Get current time execute_process( COMMAND date "+%s" OUTPUT_VARIABLE a OUTPUT_STRIP_TRAILING_WHITESPACE ) # Print message message("Hello, World!") # Get current time again execute_process( COMMAND date "+%s" OUTPUT_VARIABLE b OUTPUT_STRIP_TRAILING_WHITESPACE ) # Calculate difference between times math(EXPR diff "${b} - ${a}") message("Time difference is ${diff} seconds")