message(">>>>>>start updating build time")
if (NOT DEFINED BUILD_TIME_HEADER)
    message(FATAL_ERROR "Need to pass `-DBUILD_TIME_HEADER:PATH=" /path/to/header"` to this script")
endif ()
unset(DATE CACHE)
string(TIMESTAMP DATE "%b %d %Y %a %H:%M:%S")
set(DATE "${DATE}")
message("compile date: ${DATE}")
if (EXISTS ${BUILD_TIME_HEADER})
    file(REMOVE ${BUILD_TIME_HEADER})
endif ()
file(WRITE ${BUILD_TIME_HEADER}
        "//this file is automatically generated by UpdateBuildTimeScript.cmake\n"
        "#ifndef BUILD_TIME_HEADER\n"
        "#define BUILD_TIME_HEADER\n"
        "\n"
        "#define BUILD_TIME \"${DATE}\"\n"
        "\n"
        "#endif //BUILD_TIME_HEADER\n"
        )
message("Write build date to file ${BUILD_TIME_HEADER}")
message("<<<<<<finish updating build time")