Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set cmake project description with current datetime

I just learned how I can use

project(ProjectName VERSION 1.0)

and the configure_file to play with the version and embed it into the binary.

On project documentation I see it also accept a description string.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

project(ProjectName VERSION 1.0 description_string)

So I want to use the current datetime at the time cmake is running
as the description string.

Wondering if I can use datetime, not commit datetime but current datetime at the time cmake is running?

>Solution :

You can use string(TIMESTAMP ...) like this:

string(TIMESTAMP RUN_TIME)
project(ProjectName VERSION 1.0 DESCRIPTION "${RUN_TIME}")

Note, however, that this will be populated only when CMake is actually run on this script. So, for example, you generated your project for, say, Visual Studio and work a few days on it there. If you didn’t change the CMake file, remove CMake cache or run cmake on the script any other way your date will be stale.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading