The task is to build a library and next to it generate a file that will record the date the library was created in the format CREATED DD / MM / YY, etc. I try different options, but so far unsuccessfully. .cpp. In the file CMakeLists.txt wrote the following rules:

add_executable(hello Hello.cpp ) add_custom_target(time_step ALL COMMAND echo "CREATED ${date}" > output.txt VERBATIM) 

I tried many different options in the section after COMMAMD. The best thing that happened was when I used COMMAND 2 times and wrote the CREATED line to the file in one command, added the date to the same file in the other with the help of the bash >> command. But this is writing. And I need to be written at once and in one line. Tell me how this can be done. I heard that you can do this with the help of the configure_file command, but I also don’t really understand it.

    1 answer 1

    Your example can be done like this. CMakeLists.txt:

     cmake_minimum_required(VERSION 3.5) string(TIMESTAMP TS) configure_file(output.txt.in output.txt) 

    output.txt.in:

     CREATED @TS@ 
    • Yes indeed. It worked. Thanks for the help! - Sergey