Skip to content

Commit c9c3c8f

Browse files
author
Sylvain Garcia
committed
fix finding libc++ coroutine header on ubuntu
1 parent 645c6d1 commit c9c3c8f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cmake/FindCppcoroCoroutines.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ if(Coroutines_SUPPORTS_MS_FLAG)
1515
elseif(Coroutines_ts_SUPPORTS_GNU_FLAG)
1616
check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT "-fcoroutines-ts")
1717
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT "-fcoroutines-ts")
18+
# workaround:
19+
# clang not find stdlibc++ headers when on ubuntu 20.04
20+
# So, we retry with libc++ enforcement
21+
if(NOT Coroutines_STANDARD_LIBRARY_SUPPORT
22+
AND NOT Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT
23+
AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
24+
set(CMAKE_REQUIRED_FLAGS "-stdlib=libc++")
25+
check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT_LIBCPP "-fcoroutines-ts")
26+
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT_LIBCPP "-fcoroutines-ts")
27+
if(Coroutines_STANDARD_LIBRARY_SUPPORT_LIBCPP OR Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT_LIBCPP)
28+
list(APPEND Coroutines_EXTRA_FLAGS "-stdlib=libc++")
29+
set(Coroutines_STANDARD_LIBRARY_SUPPORT ${Coroutines_STANDARD_LIBRARY_SUPPORT_LIBCPP})
30+
set(Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT ${Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT_LIBCPP})
31+
endif()
32+
endif()
1833
elseif(Coroutines_SUPPORTS_GNU_FLAG)
1934
check_include_file_cxx("coroutine" Coroutines_STANDARD_LIBRARY_SUPPORT "-fcoroutines")
2035
check_include_file_cxx("experimental/coroutine" Coroutines_EXPERIMENTAL_LIBRARY_SUPPORT "-fcoroutines")
@@ -40,3 +55,5 @@ elseif(Coroutines_ts_SUPPORTS_GNU_FLAG)
4055
elseif(Coroutines_SUPPORTS_GNU_FLAG)
4156
target_compile_options(cppcoro::coroutines INTERFACE -fcoroutines)
4257
endif()
58+
59+
target_compile_options(cppcoro::coroutines INTERFACE ${Coroutines_EXTRA_FLAGS})

0 commit comments

Comments
 (0)