aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-01-17 19:00:17 +0000
committerSimon Tatham <anakin@pobox.com>2023-01-17 19:04:22 +0000
commit80f64cfcdafd3d0c4578ad7d559f38018d583c15 (patch)
treee7723004af4509406fb76fdee1fe2e8decb95a1c
parent1dc1ed786fda790f60f2fe9f8e7c404c73ae64da (diff)
downloadpuzzles-80f64cfcdafd3d0c4578ad7d559f38018d583c15.zip
puzzles-80f64cfcdafd3d0c4578ad7d559f38018d583c15.tar.gz
puzzles-80f64cfcdafd3d0c4578ad7d559f38018d583c15.tar.bz2
puzzles-80f64cfcdafd3d0c4578ad7d559f38018d583c15.tar.xz
Avoid unnecessary timestamp bumps on generated-games.h.
If I re-run cmake in a Unix build directory, it unconditionally rewrites generated-games.h, which causes fuzzpuzz to be rebuilt. This is a waste of effort in the extremely common case where the rewritten generated-games.h is identical to the old one. Now we write the data to a temporary file first, and use cmake's 'configure_file' command to copy that to generated-games.h, because it so happens that configure_file checks if the two files are identical and avoids updating the timestamp on the destination file if so. (This will presumably also be a beneficial change on any other platform that uses generated_games.h in the build, such as OS X. I just hadn't noticed until it hit the build I most often re-run in an existing build directory.) cmake 3.21 has a more intuitively spelled command I could have used, called 'file(COPY_FILE src dst ONLY_IF_DIFFERENT)'. But we currently permit cmake all the way back to 3.5, so I can't use that.
-rw-r--r--cmake/setup.cmake7
1 files changed, 5 insertions, 2 deletions
diff --git a/cmake/setup.cmake b/cmake/setup.cmake
index 344d028..8f879e4 100644
--- a/cmake/setup.cmake
+++ b/cmake/setup.cmake
@@ -145,13 +145,16 @@ endfunction()
function(write_generated_games_header)
set(generated_include_dir ${CMAKE_CURRENT_BINARY_DIR}/include)
set(generated_include_dir ${generated_include_dir} PARENT_SCOPE)
+ set(header_pre ${generated_include_dir}/generated-games.h.pre)
+ set(header ${generated_include_dir}/generated-games.h)
file(MAKE_DIRECTORY ${generated_include_dir})
- file(WRITE ${generated_include_dir}/generated-games.h "")
+ file(WRITE ${header_pre} "")
list(SORT puzzle_names)
foreach(name ${puzzle_names})
- file(APPEND ${generated_include_dir}/generated-games.h "GAME(${name})\n")
+ file(APPEND ${header_pre} "GAME(${name})\n")
endforeach()
+ configure_file(${header_pre} ${header} COPYONLY)
endfunction()
# This has to be run from the unfinished subdirectory, so that the