My project uses CMake to build both static and dynamic libraries from the same C++ code. The dynamic library file (.so) stays the same on rebuild, but the static library file (.a) changes on every rebuild. I have come to understand that it's because of the behaviour of ar
tool and I need to pass D argument to create deterministic output.
I've found a cmake variable CMAKE_AR
, which points to /usr/bin/ar
on my machine. The compile output shows that the command executed is: /usr/bin/ar qc libfoo.a file1.o file2.o ...
.
From ar
documentation, I should be changing the above invocation to /usr/bin/ar qcD ...
for deterministic output.
How do I accomplish this with CMake?
I'm on Linux and need a solution compatible with CMake >= v3.11