Skip to content

Commit ef632ac

Browse files
enhance gRPC library checks for better compatibility
1 parent f115214 commit ef632ac

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tutorial/grpc/CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
find_package(gRPC CONFIG 1.51)
22

33
if(gRPC_FOUND AND NOT HPP_PROTO_ENABLE_SANITIZERS)
4-
message("Found gRPC ${gRPC_VERSION} at ${gRPC_DIR}")
5-
## when sanitizer is enable, we can't use gRPC unless the gRPC library is built with sanitizer.
4+
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
5+
include(CheckCXXSymbolExists)
6+
7+
# Check for libc++
8+
check_cxx_symbol_exists(_LIBCPP_VERSION "<version>" LIBCPP_FOUND)
9+
if(LIBCPP_FOUND)
10+
get_target_property(LIBGRPC_PATH gRPC::grpc++ LOCATION)
11+
execute_process(
12+
COMMAND ldd "${LIBGRPC_PATH}"
13+
OUTPUT_VARIABLE LDD_OUTPUT
14+
RESULT_VARIABLE LDD_RESULT
15+
OUTPUT_STRIP_TRAILING_WHITESPACE
16+
)
17+
if(LDD_RESULT EQUAL 0)
18+
string(FIND LDD_OUTPUT "libc++" LIBCXX_FOUND)
19+
if(LIBCXX_FOUND EQUAL -1)
20+
message(WARNING "gRPC library is not built with libc++. Skipping grpc example.")
21+
endif()
22+
else()
23+
message(FATAL_ERROR "Failed to run ldd on gRPC library: ${LDD_OUTPUT}")
24+
endif()
25+
endif()
26+
endif()
27+
28+
# # when sanitizer is enable, we can't use gRPC unless the gRPC library is built with sanitizer.
629
add_library(helloworld INTERFACE)
730

831
protobuf_generate_hpp(TARGET helloworld
@@ -25,10 +48,11 @@ if(gRPC_FOUND AND NOT HPP_PROTO_ENABLE_SANITIZERS)
2548
helloworld)
2649

2750
find_program(BASH_PATH bash)
51+
2852
if(BASH_PATH)
2953
add_test(NAME greeter_test
3054
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/greeter_test.sh
3155
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
32-
set_tests_properties(greeter_test PROPERTIES TIMEOUT 30)
56+
set_tests_properties(greeter_test PROPERTIES TIMEOUT 30)
3357
endif()
3458
endif()

0 commit comments

Comments
 (0)