[llvm] [CMake] Limit -gsplit-dwarf option to the C and C++ compiler (PR #67247)

George Lyon via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 23 14:40:01 PDT 2023


https://github.com/GeorgeLyon created https://github.com/llvm/llvm-project/pull/67247

Currently, If the C or C++ compiler supports the `-gsplit-dwarf` option, it is added to _all_ compilers. If a project decides to use another language, such as Swift, this option will be sent to that compiler as well, regardless whether that compiler supports it or not (Swift does not). This patch uses [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html) to limit the `-gsplit-dwarf` option to only those compilers that can support it (C and C++). 

>From 7081c258e8a9e597f69f82ded40e96a5baea63d2 Mon Sep 17 00:00:00 2001
From: George <GeorgeLyon at users.noreply.github.com>
Date: Sat, 23 Sep 2023 14:34:21 -0700
Subject: [PATCH] Limit -gsplit-dwarf option to the C and C++ compiler

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index f72c41aaffb5061..095453d699b31ea 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1004,7 +1004,7 @@ if (LLVM_USE_SPLIT_DWARF AND
   # 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)
+    add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-gsplit-dwarf>)
     include(LLVMCheckLinkerFlag)
     llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
     append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index"



More information about the llvm-commits mailing list