I have a "C"/C++ CMake project which works fine. However, I'm sometimes (re)building on a remote cluster where the time is slightly different. This machine runs Linux and I'm building using make
. I'm wondering if there is some make/CMake way to change how the changes to the files are detected, e.g. to MD5 or diff rather than using timestamps. Otherwise I guess I'd either have to endure the constant make clean
/ make -j
cycle or have to change my local time every time I'm working with that particular server.
I was poking CMake documentation to see if there is a flag which would change these settings but found none. How would this work on platforms which have no RTC (e.g. Raspberry)?
Right, so knowing that CMake /
make
does not do what I want and I don't want the hassle of synchronizing the time of my machine to the target, I came up with the following:This keeps a list of source file hashes in
src_hash.md5
and at each time it runs it compares the current files to those hashes (and updates the list accordingly).At the end, it calls
make
, passing any arguments you give to the script (such as-j
). It makes use of the--what-if=
switch which tellsmake
to act like the given file changed - that way the dependences of build targets on sources / headers are handled elegantly.You might want to also pass the path to source / include files as arguments so that those wouldn't be hardcoded inside.
Or one more iteration on the said script, using
touch
to change and restore the file timestamps for situations whenmake
is extra stubborn about not rebuilding anything:Or even run hashing in parallel in case you are building a large project: