From a0ef0e7d0ce602590c18277ec3483c340366a8a6 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 2 Nov 2014 12:14:22 +0000 Subject: [PATCH] [cmake] Pass -O3 when linking. Gold and bfd ld enable misc optimizations. lld ignores the option for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221097 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/AddLLVM.cmake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 6646a4b8255..198393dc507 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -142,7 +142,14 @@ function(add_llvm_symbol_exports target_name export_file) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) endfunction(add_llvm_symbol_exports) -function(add_dead_strip target_name) +function(add_link_opts target_name) + # Pass -O3 to the linker. This enabled different optimizations on different + # linkers. + if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32)) + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-O3") + endif() + if(NOT LLVM_NO_DEAD_STRIP) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # ld64's implementation of -dead_strip breaks tools that use plugins. @@ -157,7 +164,7 @@ function(add_dead_strip target_name) LINK_FLAGS " -Wl,--gc-sections") endif() endif() -endfunction(add_dead_strip) +endfunction(add_link_opts) # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, @@ -287,7 +294,7 @@ function(llvm_add_library name) endif() set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) if(ARG_OUTPUT_NAME) set_target_properties(${name} PROPERTIES @@ -445,7 +452,7 @@ macro(add_llvm_executable name) add_executable(${name} ${ALL_FILES}) endif() llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) # Do not add -Dname_EXPORTS to the command-line when building files in this # target. Doing so is actively harmful for the modules build because it -- 2.11.0