This is an automated email from the ASF dual-hosted git repository.

lausen pushed a commit to branch leezu-patch-4
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit b94d7b108a1a763ea9cc2086a2c4f33e9b7091e4
Author: Leonard Lausen <[email protected]>
AuthorDate: Fri Sep 18 10:58:31 2020 -0700

    Set -fstandalone-debug in clang debug builds
    
    "Clang supports a number of optimizations to reduce the size of debug 
information in the binary. They work based on the assumption that the debug 
type information can be spread out over multiple compilation units. For 
instance, Clang will not emit type definitions for types that are not needed by 
a module and could be replaced with a forward declaration. Further, Clang will 
only emit type info for a dynamic C++ class in the module that contains the 
vtable for the class.
    
    The -fstandalone-debug option turns off these optimizations. This is useful 
when working with 3rd-party libraries that don’t come with debug information. 
Note that Clang will never emit type information for types that are not 
referenced at all by the program."
    
    Without -fstandalone-debug, lldb usage is degraded as debug information of 
C++ standard library types such strings or containers will be unusable and the 
types cannot be printed in lldb.
---
 CMakeLists.txt | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 189afd2..f79b4ed 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -183,13 +183,14 @@ if(MSVC)
 else()
   include(CheckCXXCompilerFlag)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-sign-compare")
-  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL 
"RelWithDebInfo")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fstandalone-debug")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
-  elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
-  else()
+    if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstandalone-debug")
+    endif()
+  endif()
+  if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL 
"RelWithDebInfo")
     add_definitions(-DNDEBUG=1)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
   endif()

Reply via email to