From 592a4aaba20818bcff9a1448c34b09aff9e0d2e9 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 a8fd3bf37b3..9f5b242683d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -303,6 +303,9 @@ if(UNIX)
   if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
     set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} rt)
   endif()
+  if(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv32")
+    set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} atomic)
+  endif()
 endif()
 
 # configure ccache if requested
-- 
2.36.0

