check_linker_flag does not use add_link_options
I have a project where I set LLD as the linker via add_link_options
:
add_link_options("$<$<BOOL:${STABLEHLO_ENABLE_LLD}>:-fuse-ld=lld>")
Further down in the CMakeList.txt file I check for the availability of a flag using check_linker_flag
:
check_linker_flag(CXX "-Wl,--gdb-index" STABLEHLO_SUPPORTS_GDB_INDEX)
The linker used is not lld
but the default on the system still.
I resolved it with an OR generator expression:
add_link_options("$<$<OR:$<BOOL:${STABLEHLO_SUPPORTS_GDB_INDEX}>,$<BOOL:${STABLEHLO_ENABLE_LLD}>>:-Wl,--gdb-index>")
But it's definitely a footgun since there's very little diagnostic information beyond the logs that the option was not added. (Would be good to even have some STATUS messages produced with whether the check was successful)