util, refactor: Add UNIQUE_NAME helper macro
Summary:
This change replaces repetitive code with a helper macro.
This is a backport of core#24355
Test Plan:
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ninja all check-all`
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D14890