Skip to content

Commit

Permalink
Generalize CMake flag handling to support GCC
Browse files Browse the repository at this point in the history
While clang uses the -fcoroutines-ts flag to add support for the
Coroutines TS, GCC uses the -fcoroutines flag.

This commit refactors the cmake finder to support both.
  • Loading branch information
dutow committed Jul 19, 2020
1 parent 0b201f8 commit d99be58
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions cmake/FindCppcoroCoroutines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ include(CheckIncludeFileCXX)
include(FindPackageHandleStandardArgs)

check_cxx_compiler_flag(/await Coroutines_SUPPORTS_MS_FLAG)
check_cxx_compiler_flag(-fcoroutines-ts Coroutines_SUPPORTS_GNU_FLAG)
if(Coroutines_SUPPORTS_MS_FLAG OR Coroutines_SUPPORTS_GNU_FLAG)
check_cxx_compiler_flag(-fcoroutines-ts Coroutines_SUPPORTS_CLANG_FLAG)
check_cxx_compiler_flag(-fcoroutines Coroutines_SUPPORTS_GCC_FLAG)
if(Coroutines_SUPPORTS_MS_FLAG OR Coroutines_SUPPORTS_CLANG_FLAG OR Coroutines_SUPPORTS_GCC_FLAG)
set(Coroutines_COMPILER_SUPPORT ON)
endif()

set(Coroutines_ADDITIONAL_FLAG "")
if(Coroutines_SUPPORTS_MS_FLAG)
check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT "/await")
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT "/await")
elseif(Coroutines_SUPPORTS_GNU_FLAG)
check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT "-fcoroutines-ts")
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT "-fcoroutines-ts")
set(Coroutines_ADDITIONAL_FLAG "/await")
elseif(Coroutines_SUPPORTS_CLANG_FLAG)
set(Coroutines_ADDITIONAL_FLAG "-fcoroutines-ts")
elseif(Coroutines_SUPPORTS_GCC_FLAG)
set(Coroutines_ADDITIONAL_FLAG "-fcoroutines")
endif()

check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT ${Coroutines_ADDITIONAL_FLAG})
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT ${Coroutines_ADDITIONAL_FLAG})

if(Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT OR Coroutines_STANDARD_LIBRARY_SUPPORT)
set(Coroutines_LIBRARY_SUPPORT ON)
endif()
Expand All @@ -29,8 +34,4 @@ if(NOT CppcoroCoroutines_FOUND OR TARGET cppcoro::coroutines)
endif()

add_library(cppcoro::coroutines INTERFACE IMPORTED)
if(Coroutines_SUPPORTS_MS_FLAG)
target_compile_options(cppcoro::coroutines INTERFACE /await)
elseif(Coroutines_SUPPORTS_GNU_FLAG)
target_compile_options(cppcoro::coroutines INTERFACE -fcoroutines-ts)
endif()
target_compile_options(cppcoro::coroutines INTERFACE ${Coroutines_ADDITIONAL_FLAG})

0 comments on commit d99be58

Please sign in to comment.