@@ -1747,6 +1747,31 @@ function(add_llvm_implicit_projects)
17471747 llvm_add_implicit_projects(LLVM)
17481748endfunction (add_llvm_implicit_projects)
17491749
1750+ function (set_unittest_link_flags target_name)
1751+ # The runtime benefits of LTO don't outweight the compile time costs for
1752+ # tests.
1753+ if (LLVM_ENABLE_LTO)
1754+ if ((UNIX OR MINGW) AND LINKER_IS_LLD)
1755+ if (LLVM_ENABLE_FATLTO AND NOT APPLE )
1756+ # When using FatLTO, just use relocatable linking.
1757+ set_property (TARGET ${target_name} APPEND_STRING PROPERTY
1758+ LINK_FLAGS " -Wl,--no-fat-lto-objects" )
1759+ else ()
1760+ set_property (TARGET ${target_name} APPEND_STRING PROPERTY
1761+ LINK_FLAGS " -Wl,--lto-O0" )
1762+ endif ()
1763+ elseif (LINKER_IS_LLD_LINK)
1764+ set_property (TARGET ${target_name} APPEND_STRING PROPERTY
1765+ LINK_FLAGS " /opt:lldlto=0" )
1766+ elseif (APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN" )
1767+ set_property (TARGET ${target_name} APPEND_STRING PROPERTY
1768+ LINK_FLAGS " -Wl,-mllvm,-O0" )
1769+ endif ()
1770+ endif ()
1771+
1772+ target_link_options (${target_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS} " )
1773+ endfunction (set_unittest_link_flags)
1774+
17501775# Generic support for adding a unittest.
17511776function (add_unittest test_suite test_name)
17521777 if ( NOT LLVM_BUILD_TESTS )
@@ -1770,27 +1795,7 @@ function(add_unittest test_suite test_name)
17701795 get_subproject_title(subproject_title)
17711796 set_target_properties (${test_name} PROPERTIES FOLDER "${subproject_title} /Tests/Unit" )
17721797
1773- # The runtime benefits of LTO don't outweight the compile time costs for tests.
1774- if (LLVM_ENABLE_LTO)
1775- if ((UNIX OR MINGW) AND LINKER_IS_LLD)
1776- if (LLVM_ENABLE_FATLTO AND NOT APPLE )
1777- # When using FatLTO, just use relocatable linking.
1778- set_property (TARGET ${test_name} APPEND_STRING PROPERTY
1779- LINK_FLAGS " -Wl,--no-fat-lto-objects" )
1780- else ()
1781- set_property (TARGET ${test_name} APPEND_STRING PROPERTY
1782- LINK_FLAGS " -Wl,--lto-O0" )
1783- endif ()
1784- elseif (LINKER_IS_LLD_LINK)
1785- set_property (TARGET ${test_name} APPEND_STRING PROPERTY
1786- LINK_FLAGS " /opt:lldlto=0" )
1787- elseif (APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN" )
1788- set_property (TARGET ${target_name} APPEND_STRING PROPERTY
1789- LINK_FLAGS " -Wl,-mllvm,-O0" )
1790- endif ()
1791- endif ()
1792-
1793- target_link_options (${test_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS} " )
1798+ set_unittest_link_flags(${test_name} )
17941799
17951800 set (outdir ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_CFG_INTDIR} )
17961801 set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir} )
0 commit comments