From 54e8dca9b39b8c8a6532576a0286e548f97607fa Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Tue, 19 Apr 2022 16:07:19 -0700
Subject: [PATCH] cmake: Link with libatomic on rv32/rv64

Fixes
riscv64-yoe-linux-musl/12.0.1/ld: libgrpc.so.23.0.0: undefined reference to `__atomic_exchange_1'
| collect2: error: ld returned 1 exit status

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 06e6453b5c..476d7f1576 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -306,6 +306,9 @@ if(UNIX AND NOT HAIKU)
       set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} rt)
     endif()
   endif()
+  if(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv32")
+    set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} atomic)
+  endif()
 endif()
 
 include(CheckCXXSourceCompiles)
