1function(check_lto) 2 if (DEFINED LTO_WORKS) 3 return() 4 endif() 5 6 set(LTO_WORKS FALSE CACHE INTERNAL "LTO works") 7 8 CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) 9 10 if (NOT HAS_LTO_FLAG) 11 return() 12 endif() 13 14 find_program(LTO_AR NAMES "${CMAKE_C_COMPILER}-ar" gcc-ar) 15 find_program(LTO_RANLIB NAMES "${CMAKE_C_COMPILER}-ranlib" gcc-ranlib) 16 17 if (NOT LTO_AR OR NOT LTO_RANLIB) 18 return() 19 endif() 20 21 EXECUTE_PROCESS(COMMAND "${LTO_AR}" --version RESULT_VARIABLE ret OUTPUT_QUIET ERROR_QUIET) 22 if (ret) 23 return() 24 endif() 25 26 EXECUTE_PROCESS(COMMAND "${LTO_RANLIB}" --version RESULT_VARIABLE ret OUTPUT_QUIET ERROR_QUIET) 27 if (ret) 28 return() 29 endif() 30 31 set(LTO_WORKS TRUE CACHE INTERNAL "LTO works") 32endfunction() 33