Skip to content

Commit

Permalink
Detect and enable C++ couroutine support on CMake build with GCC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
filbranden authored and facebook-github-bot committed Sep 14, 2021
1 parent fb5c25d commit 4d5b7ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4d5b7ad

Please sign in to comment.