Allow passing linker arguments to check_ipo_supported()
Hi, on my system I have GCC/Clang and bfd/gold/lld installed. lld is default one, i.e. ld points to ld.lld-10. It seems that lld can't do LTO with gcc's object files. I can fix this by using -fuse-ld=bfd
if CMAKE_CXX_COMPILER_ID
is GNU
. But check_ipo_supported()
always uses default linker and it returns false so this doesn't work:
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_options(my_proj PRIVATE -fuse-ld=bfd)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT isIpoSupported)
message(STATUS "IPO supported: ${isIpoSupported}")
if(isIpoSupported)
set_target_properties(my_proj PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
endif()
However, if we do set_target_properties(my_proj PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
without any checks LTO will work. Surprisingly, bfd/gold can do LTO with Clang's object files but lld can't do LTO with GCC's ones, if I add -ffat-lto-object it can link them but LTO is not applied.
Maybe it would be useful to have something like check_ipo_supported(RESULT isIpoSupported LINK_OPTIONS "-fuse-ld=bfd")
or some another mechanism to allow check_ipo_supported()
to use specific linker?