[CMake] Move -ffunction-data-sections stuff to HandleLLVMOptions.
authorNAKAMURA Takumi <geek4civic@gmail.com>
Tue, 28 Jan 2014 09:43:55 +0000 (09:43 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Tue, 28 Jan 2014 09:43:55 +0000 (09:43 +0000)
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
cmake/modules/HandleLLVMOptions.cmake

index 82a767862b2321d8056548b75f70b9ec5d22410d..5bc3c22cf893404f3ef9d56e941a4fec7454f8ca 100644 (file)
@@ -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()
index 6c99682f76698213b5477ee0c6289576d854d584..89122eee0b7dd9a1b605ed562de44e1b64fa99d9 100644 (file)
@@ -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()