From 1934fcfe2e5d9babca3116668ca98a6612707d3f Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 17 Dec 2017 17:13:59 -0500 Subject: [PATCH] Fix overwriting of unity files in reconfiguration. One flaw in the unity build system is that it always generates the unity inclusion files when the build system is (re)configured. This results in a lot of extra compilation. This patch fixes the issue by first writing to a temporary file and then moving it only if it is not equal to the current unity file. --- cmake/macros/macro_setup_unity_target.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmake/macros/macro_setup_unity_target.cmake b/cmake/macros/macro_setup_unity_target.cmake index 9293065d1f..230bb0aab6 100644 --- a/cmake/macros/macro_setup_unity_target.cmake +++ b/cmake/macros/macro_setup_unity_target.cmake @@ -46,6 +46,8 @@ MACRO(SETUP_UNITY_TARGET _unity_include_src _n_includes_per_unity_file _output_s FOREACH(_unity_prefix ${_unity_prefixes}) SET(_unity_file_name "${CMAKE_CURRENT_BINARY_DIR}/${_unity_prefix}.cc") + SET(_tmp_unity_file_name "${CMAKE_CURRENT_BINARY_DIR}/${_unity_prefix}_tmp.cc") + # # Note the CMake weirdness: _output_src is actually a string containing the # variable name since we are in a macro... @@ -54,13 +56,21 @@ MACRO(SETUP_UNITY_TARGET _unity_include_src _n_includes_per_unity_file _output_s ${${_output_src}} ${_unity_file_name} ) - FILE(WRITE "${_unity_file_name}" + FILE(WRITE "${_tmp_unity_file_name}" "// This file was automatically generated by the deal.II CMake configuration as // part of the unity build subsystem. Please do not edit this file directly; // instead, make appropriate changes to the relevant CMakeLists.txt file.\n\n" ) FOREACH(_unity_file ${${_unity_prefix}}) - FILE(APPEND "${_unity_file_name}" "#include \"${_unity_file}\"\n") + FILE(APPEND "${_tmp_unity_file_name}" "#include \"${_unity_file}\"\n") ENDFOREACH() + + # + # CMake regenerates all unity files as part of the configuration process, + # even though they usually have not changed. Avoid some recompilation by + # using the CONFIGURE_FILE command, which won't update the time stamp unless + # the content has changed. + # + CONFIGURE_FILE(${_tmp_unity_file_name} ${_unity_file_name} COPYONLY) ENDFOREACH() ENDMACRO() -- 2.39.5