]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix overwriting of unity files in reconfiguration. 5638/head
authorDavid Wells <wellsd2@rpi.edu>
Sun, 17 Dec 2017 22:13:59 +0000 (17:13 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Mon, 18 Dec 2017 13:55:52 +0000 (08:55 -0500)
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

index 9293065d1fb9dd5a3d6af92755c0b8fa403e2a27..230bb0aab6f4a3e3bc02268b5ca34cdd136f0609 100644 (file)
@@ -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()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.