From 4d5b7ad4e8ef223eef61fbb6c0393f284ae6be5d Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Tue, 14 Sep 2021 16:22:12 -0700 Subject: [PATCH] Detect and enable C++ couroutine support on CMake build with GCC Summary: This change updates the CMake config to detect whether GCC's `-fcoroutines` flag is supported and enable it for the build. This is required to enable support for Folly coroutines. Followed the instructions in GCC page about C++ coroutines to get them enabled. https://gcc.gnu.org/wiki/cxx-coroutines NOTE: This Wiki page used to indicate that exceptions had to be disabled to enable subroutines, but this only applied to experimental support for coroutines and it's no longer the case. This was uncovered by the fbthrift build, which needs Folly coroutines to implement streaming. A new fbthrift test using a stream type uncovered this missing feature in our build on Fedora. Reviewed By: yfeldblum Differential Revision: D30026779 fbshipit-source-id: 3324c2fc52fe5db793bdaba9c81f41bfe6ef2242 --- CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4d6b7d83eb..0884be8b720 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,6 +234,23 @@ if (NOT ${LIBAIO_FOUND} AND NOT ${LIBURING_FOUND}) ) endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + check_cxx_compiler_flag(-fcoroutines COMPILER_HAS_F_COROUTINES) + if (COMPILER_HAS_F_COROUTINES) + message( + STATUS + "GCC has support for C++ coroutines, setting flag for Folly build." + ) + add_compile_options(-fcoroutines) + else() + message( + STATUS + "GCC does not have support for C++ coroutines, " + "disabling Folly coroutine support." + ) + endif() +endif() + if (${LIBSODIUM_FOUND}) string(FIND "${CMAKE_LIBRARY_ARCHITECTURE}" "x86_64" IS_X86_64_ARCH) if (${IS_X86_64_ARCH} STREQUAL "-1")