From 4fc67f04914586ea18695fdf758878fc174557c1 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Tue, 28 Jan 2014 09:43:55 +0000 Subject: [PATCH] [CMake] Move -ffunction-data-sections stuff to HandleLLVMOptions. With this tweaks, also unittests are compiled with -ffunction-sections. It's hard to control contextual CMAKE_CXX_FLAGS. We should get rid of twiddling it as possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200299 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/AddLLVM.cmake | 11 +---------- cmake/modules/HandleLLVMOptions.cmake | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 82a767862b2..5bc3c22cf89 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -100,21 +100,12 @@ function(add_llvm_symbol_exports target_name export_file) endfunction(add_llvm_symbol_exports) function(add_dead_strip target_name) - # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? - # But MinSizeRel seems to add that automatically, so maybe disable these - # flags instead if LLVM_NO_DEAD_STRIP is set. - if(NOT CYGWIN AND NOT MINGW AND NOT MSVC) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - SET(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections" - PARENT_SCOPE) - endif() - endif() if(NOT LLVM_NO_DEAD_STRIP) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") elseif(NOT WIN32) + # Object files are compiled with -ffunction-data-sections. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections") endif() diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 6c99682f766..89122eee0b7 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -349,3 +349,13 @@ if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() + +# Add flags for add_dead_strip(). +# FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? +# But MinSizeRel seems to add that automatically, so maybe disable these +# flags instead if LLVM_NO_DEAD_STRIP is set. +if(NOT CYGWIN AND NOT WIN32) + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + append("-ffunction-sections -fdata-sections" CMAKE_CXX_FLAGS) + endif() +endif() -- 2.34.1