diff --git a/rapid/plugin/group_replication/rpcgen.cmake b/rapid/plugin/group_replication/rpcgen.cmake
index b9c5895..f4569cd 100644
--- a/rapid/plugin/group_replication/rpcgen.cmake
+++ b/rapid/plugin/group_replication/rpcgen.cmake
@@ -87,6 +87,12 @@ FOREACH(X xcom_vp)
         ${XCOM_BASEDIR}/xcom_proto_enum.h
         ${XCOM_BASEDIR}/xcom_limits.h)
   ELSE()
+    FIND_PROGRAM(RPCGEN_EXECUTABLE rpcgen DOC "path to the rpcgen executable")
+    MARK_AS_ADVANCED(RPCGEN_EXECUTABLE)
+    IF(NOT RPCGEN_EXECUTABLE)
+      MESSAGE(FATAL_ERROR "Could not find rpcgen")
+    ENDIF()
+
     # on unix systems try to generate them if needed
     ADD_CUSTOM_COMMAND(OUTPUT ${x_gen_h} ${x_gen_c} ${x_tmp_plat_h}
       COMMAND ${CMAKE_COMMAND} -E copy_if_different
@@ -103,10 +109,10 @@ FOREACH(X xcom_vp)
 
        # generate the sources
        COMMAND ${CMAKE_COMMAND} -E remove -f ${x_gen_h}
-       COMMAND rpcgen  -C -h -o
+       COMMAND ${RPCGEN_EXECUTABLE}  -C -h -o
                     ${x_gen_h} ${x_tmp_x_canonical_name}
        COMMAND ${CMAKE_COMMAND} -E remove -f ${x_gen_c}
-                COMMAND rpcgen  -C -c -o
+                COMMAND ${RPCGEN_EXECUTABLE}  -C -c -o
                 ${x_gen_c} ${x_tmp_x_canonical_name}
        WORKING_DIRECTORY ${gen_xdr_dir}
        DEPENDS

diff --git a/rapid/plugin/group_replication/CMakeLists.txt b/rapid/plugin/group_replication/CMakeLists.txt
index 5bcaa8b..bce9de4 100644
--- a/rapid/plugin/group_replication/CMakeLists.txt
+++ b/rapid/plugin/group_replication/CMakeLists.txt
@@ -218,6 +218,7 @@ MYSQL_ADD_PLUGIN(group_replication
                  LINK_LIBRARIES
                  ${LZ4_LIBRARY}
                  ${SSL_LIBRARIES}
+                 ${TIRPC_LIBRARY}
                  MODULE_ONLY MODULE_OUTPUT_NAME "group_replication")
 
 ### INSTALLATION ###
diff --git a/rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_transport.c b/rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_transport.c
index 245dda0..210e124 100644
--- a/rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_transport.c
+++ b/rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_transport.c
@@ -417,7 +417,11 @@ x_putbytes (XDR *xdrs, const char *bp MY_ATTRIBUTE((unused)), u_int len)
 
 
 static u_int
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(HAVE_TIRPC)
+x_getpostn(XDR *xdrs)
+#else
 x_getpostn (const XDR *xdrs)
+#endif
 {
 #ifdef OLD_XDR
   return (u_int)(xdrs->x_handy);
diff --git a/rapid/plugin/group_replication/rpcgen.cmake b/rapid/plugin/group_replication/rpcgen.cmake
index f4569cd..cccb1c3 100644
--- a/rapid/plugin/group_replication/rpcgen.cmake
+++ b/rapid/plugin/group_replication/rpcgen.cmake
@@ -93,6 +93,24 @@ FOREACH(X xcom_vp)
       MESSAGE(FATAL_ERROR "Could not find rpcgen")
     ENDIF()
 
+    # First look for tirpc, then the old Sun RPC
+    FIND_PATH(RPC_INCLUDE_DIR
+      NAMES rpc/rpc.h
+      HINTS /usr/include/tirpc
+      NO_DEFAULT_PATH
+      )
+    FIND_PATH(RPC_INCLUDE_DIR NAMES rpc/rpc.h)
+    IF(NOT RPC_INCLUDE_DIR)
+      MESSAGE(FATAL_ERROR
+        "Could not find rpc/rpc.h in /usr/include or /usr/include/tirpc")
+    ENDIF()
+    MESSAGE(STATUS "RPC_INCLUDE_DIR ${RPC_INCLUDE_DIR}")
+    IF(RPC_INCLUDE_DIR STREQUAL "/usr/include/tirpc")
+      INCLUDE_DIRECTORIES(SYSTEM /usr/include/tirpc)
+      ADD_DEFINITIONS(-DHAVE_TIRPC)
+      SET(TIRPC_LIBRARY tirpc)
+    ENDIF()
+
     # on unix systems try to generate them if needed
     ADD_CUSTOM_COMMAND(OUTPUT ${x_gen_h} ${x_gen_c} ${x_tmp_plat_h}
       COMMAND ${CMAKE_COMMAND} -E copy_if_different
