From 4bd1e3dcbdb24c87661218cdb9e17c74fa50c9d8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 30 Dec 2017 19:58:57 +0000 Subject: [PATCH] cmake: avoid timestamp change of version_string.inc file --- cmake/OpenCVUtils.cmake | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 1bb539e957..7fd9ac7e8d 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -519,16 +519,29 @@ endmacro() if(NOT DEFINED CMAKE_ARGC) # Guard CMake standalone invocations -set(OPENCV_BUILD_INFO_FILE "${CMAKE_BINARY_DIR}/version_string.tmp") -file(REMOVE "${OPENCV_BUILD_INFO_FILE}") +set(OPENCV_BUILD_INFO_STR "" CACHE INTERNAL "") function(ocv_output_status msg) message(STATUS "${msg}") string(REPLACE "\\" "\\\\" msg "${msg}") string(REPLACE "\"" "\\\"" msg "${msg}") - file(APPEND "${OPENCV_BUILD_INFO_FILE}" "\"${msg}\\n\"\n") + set(OPENCV_BUILD_INFO_STR "${OPENCV_BUILD_INFO_STR}\"${msg}\\n\"\n" CACHE INTERNAL "") endfunction() macro(ocv_finalize_status) + set(OPENCV_BUILD_INFO_FILE "${CMAKE_BINARY_DIR}/version_string.tmp") + if(EXISTS "${OPENCV_BUILD_INFO_FILE}") + file(READ "${OPENCV_BUILD_INFO_FILE}" __content) + else() + set(__content "") + endif() + if("${__content}" STREQUAL "${OPENCV_BUILD_INFO_STR}") + #message(STATUS "${OPENCV_BUILD_INFO_FILE} contains the same content") + else() + file(WRITE "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_BUILD_INFO_STR}") + endif() + unset(__content) + unset(OPENCV_BUILD_INFO_STR CACHE) + if(NOT OPENCV_SKIP_STATUS_FINALIZATION) if(DEFINED OPENCV_MODULE_opencv_core_BINARY_DIR) execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc" OUTPUT_QUIET)