Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3bda6ab

Browse files
bhardwajschwarr
andauthored
[c++] Add CMake support for pre-installed gRPC
Some systems have a pre-installed gRPC library that they would like to use, but Bond always builds gRPC from its submodule. Add the CMake variable `BOND_FIND_GRPC` so that an external gRPC installation can be used. Co-authored-by: Christopher Warrington <chwarr@microsoft.com>
1 parent 28d6068 commit 3bda6ab

9 files changed

Lines changed: 56 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ different versioning scheme, following the Haskell community's
2020

2121
### C++/Python ###
2222

23+
* Added CMake variable `BOND_FIND_GRPC` to allow for external gRPC
24+
installations. The search for external GRPC installations is only done
25+
when `BOND_ENABLE_GRPC` is `TRUE`.
2326
* Removed use of deprecated `std::ptr_fun` in the Python library. ([Issue
2427
\#1080](https://github.com/microsoft/bond/issues/1080))
2528

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ set (CMAKE_MODULE_PATH
1616
set (BOND_ENABLE_GRPC
1717
"TRUE"
1818
CACHE BOOL "If FALSE, then do not build gRPC integration")
19+
set (BOND_FIND_GRPC
20+
"FALSE"
21+
CACHE BOOL "If TRUE, search for an installed gRPC library; if FALSE, then build and use gRPC from the /thirdparty subdirectory")
1922
set (BOND_FIND_RAPIDJSON
2023
"FALSE"
21-
CACHE BOOL "If FALSE, then use and install rapidjson from thirdparty subdirectory")
24+
CACHE BOOL "If FALSE, then use and install rapidjson from the /thirdparty subdirectory")
2225
# We need to include third-party CMake modules before we configure our own
2326
# settings so that we don't apply our settings to third-party code.
2427
add_subdirectory (thirdparty)

examples/cpp/grpc/async-server/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ add_bond_test (grpc-async-server async-server.bond async-server.cpp GRPC)
22

33
cxx_target_compile_definitions (MSVC grpc-async-server PRIVATE -D_WIN32_WINNT=0x0600)
44

5-
target_link_libraries(grpc-async-server PRIVATE grpc++)
5+
if (BOND_FIND_GRPC)
6+
find_package(grpc CONFIG REQUIRED)
7+
target_link_libraries(grpc-async-server PRIVATE gRPC::grpc++)
8+
else ()
9+
target_link_libraries(grpc-async-server PRIVATE grpc++)
10+
endif ()

examples/cpp/grpc/grpc_dll/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ target_compile_definitions (grpc_dll_example_lib PRIVATE -DBUILDING_DLLEXAMPLE_D
1414
1515
add_target_to_folder (grpc_dll_example_lib)
1616
17+
if (BOND_FIND_GRPC)
18+
find_package(grpc CONFIG REQUIRED)
19+
target_link_libraries(grpc_dll_example_lib PUBLIC
20+
gRPC::grpc++)
21+
else ()
22+
target_link_libraries(grpc_dll_example_lib PUBLIC
23+
grpc++)
24+
endif ()
25+
1726
target_link_libraries (grpc_dll_example_lib PUBLIC
18-
grpc++
1927
bond)
2028
2129
cxx_target_compile_definitions (MSVC grpc_dll_example_lib PRIVATE

examples/cpp/grpc/grpc_static_library/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ add_library (grpc_static_library_lib EXCLUDE_FROM_ALL
1010

1111
add_target_to_folder (grpc_static_library_lib)
1212

13+
if (BOND_FIND_GRPC)
14+
find_package(grpc CONFIG REQUIRED)
15+
target_link_libraries (grpc_static_library_lib PUBLIC
16+
gRPC::grpc++)
17+
else ()
18+
target_link_libraries (grpc_static_library_lib PUBLIC
19+
grpc++)
20+
endif ()
21+
1322
target_link_libraries (grpc_static_library_lib PUBLIC
14-
grpc++
1523
bond)
1624

1725
add_bond_test (grpc_static_library_server

examples/cpp/grpc/helloworld/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ add_bond_test (grpc-helloworld helloworld.bond helloworld.cpp GRPC)
22

33
cxx_target_compile_definitions (MSVC grpc-helloworld PRIVATE -D_WIN32_WINNT=0x0600)
44

5-
target_link_libraries(grpc-helloworld PRIVATE grpc++)
5+
if (BOND_FIND_GRPC)
6+
find_package(grpc CONFIG REQUIRED)
7+
target_link_libraries(grpc-helloworld PRIVATE gRPC::grpc++)
8+
else ()
9+
target_link_libraries(grpc-helloworld PRIVATE grpc++)
10+
endif ()

examples/cpp/grpc/pingpong/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ add_bond_test (grpc-pingpong pingpong.bond pingpong.cpp GRPC)
22

33
cxx_target_compile_definitions (MSVC grpc-pingpong PRIVATE -D_WIN32_WINNT=0x0600)
44

5-
target_link_libraries(grpc-pingpong PRIVATE grpc++)
5+
if (BOND_FIND_GRPC)
6+
find_package(grpc CONFIG REQUIRED)
7+
target_link_libraries(grpc-pingpong PRIVATE gRPC::grpc++)
8+
else ()
9+
target_link_libraries(grpc-pingpong PRIVATE grpc++)
10+
endif ()

examples/cpp/grpc/scalar/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ add_bond_test (grpc-scalar scalar.bond scalar.cpp GRPC)
22

33
cxx_target_compile_definitions (MSVC grpc-scalar PRIVATE -D_WIN32_WINNT=0x0600)
44

5-
target_link_libraries(grpc-scalar PRIVATE grpc++)
5+
if (BOND_FIND_GRPC)
6+
find_package(grpc CONFIG REQUIRED)
7+
target_link_libraries(grpc-scalar PRIVATE gRPC::grpc++)
8+
else ()
9+
target_link_libraries(grpc-scalar PRIVATE grpc++)
10+
endif ()

thirdparty/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
include (Compiler)
22

33
if (BOND_ENABLE_GRPC)
4-
cxx_add_compile_options (Clang -Wno-unused-value)
5-
add_subdirectory(grpc)
6-
endif()
4+
if (BOND_FIND_GRPC)
5+
find_package(grpc CONFIG REQUIRED)
6+
else ()
7+
cxx_add_compile_options(Clang -Wno-unused-value)
8+
add_subdirectory(grpc)
9+
endif ()
10+
endif ()

0 commit comments

Comments
 (0)