[cmake] Fix LLVM_USE_SPLIT_DWARF
authorMichael Liao <michael.hliao@gmail.com>
Fri, 28 Feb 2020 05:01:08 +0000 (00:01 -0500)
committerMichael Liao <michael.hliao@gmail.com>
Sat, 29 Feb 2020 04:05:55 +0000 (23:05 -0500)
Summary:
- Add `-gsplit-dwarf` as an option instead of a definition.
- Only add that option on compilers supporting dwarf splitting, such as clang
  and gcc.

Reviewers: echristo, pcc

Subscribers: mgorny, aprantl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75328

llvm/cmake/modules/HandleLLVMOptions.cmake

index b91523736a3e72be21645d2c1b7eca6ef684f934..b19846c0852c2b2953bf524651beae2e46639e9b 100644 (file)
@@ -746,9 +746,15 @@ if(LLVM_USE_SANITIZER)
   endif()
 endif()
 
-# Turn on -gsplit-dwarf if requested
-if(LLVM_USE_SPLIT_DWARF)
-  add_definitions("-gsplit-dwarf")
+# Turn on -gsplit-dwarf if requested in debug builds.
+if (LLVM_USE_SPLIT_DWARF AND
+    ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
+     (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
+  # Limit to clang and gcc so far. Add compilers supporting this option.
+  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
+      CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    add_compile_options(-gsplit-dwarf)
+  endif()
 endif()
 
 add_definitions( -D__STDC_CONSTANT_MACROS )