I have a toolchain file which needs to set -rtlib=compiler-rt as a “required” linker flag (i. e. without it, the toolchain will either not work or silently generate broken code). As far as I can tell, I have a couple options:
- Set
CMAKE_*_LINKER_FLAGS_INIT. However, it is overridable from the cmdline and there is no guarantee that the user won’t forget about compiler-rt. - Do
set(CMAKE_C_COMPILER clang -rtlib=compiler-rt -Qunused-arguments)which is not amazing since-rtlib=compiler-rtis now passed during compilation as well. - Do some weird dance with setting something like
MY_PROJECT_REQUIRED_LINKER_FLAGSin toolchain and then prepending toCMAKE_*_LINKER_FLAGSat the top of project’s CMakeLists.txt guarded by top-level check. - Use
CMAKE_USER_MAKE_RULES_OVERRIDE_{C,CXX}and try to guess whatCMAKE_CXX_CREATE_SHARED_LIBRARY& co. are being set to in the version of CMake that happens to be installed on the user machine.
and neither of them is particularly nice. So, what is the current best practice?