diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ff1a7b135e..6c370c3ebd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,15 +220,41 @@ function(protobuf_generate_grpc_cpp) endforeach() endfunction() +# These options allow users to enable or disable the building of the various +# protoc plugins. For example, running CMake with +# -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF will disable building the C# plugin. +set(_gRPC_PLUGIN_LIST) +option(gRPC_BUILD_GRPC_CPP_PLUGIN "Build grpc_cpp_plugin" ON) +if (gRPC_BUILD_GRPC_CPP_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_cpp_plugin) +endif () +option(gRPC_BUILD_GRPC_CSHARP_PLUGIN "Build grpc_csharp_plugin" ON) +if (gRPC_BUILD_GRPC_CSHARP_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_csharp_plugin) +endif () +option(gRPC_BUILD_GRPC_NODE_PLUGIN "Build grpc_node_plugin" ON) +if (gRPC_BUILD_GRPC_NODE_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_node_plugin) +endif () +option(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN "Build grpc_objective_c_plugin" ON) +if (gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_objective_c_plugin) +endif () +option(gRPC_BUILD_GRPC_PHP_PLUGIN "Build grpc_php_plugin" ON) +if (gRPC_BUILD_GRPC_PHP_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_php_plugin) +endif () +option(gRPC_BUILD_GRPC_PYTHON_PLUGIN "Build grpc_python_plugin" ON) +if (gRPC_BUILD_GRPC_PYTHON_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_python_plugin) +endif () +option(gRPC_BUILD_GRPC_RUBY_PLUGIN "Build grpc_ruby_plugin" ON) +if (gRPC_BUILD_GRPC_RUBY_PLUGIN) + list(APPEND _gRPC_PLUGIN_LIST grpc_ruby_plugin) +endif () + add_custom_target(plugins - DEPENDS - grpc_cpp_plugin - grpc_csharp_plugin - grpc_node_plugin - grpc_objective_c_plugin - grpc_php_plugin - grpc_python_plugin - grpc_ruby_plugin + DEPENDS ${_gRPC_PLUGIN_LIST} ) add_custom_target(tools_c @@ -12906,7 +12932,7 @@ target_link_libraries(grpc_cli endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_CPP_PLUGIN) add_executable(grpc_cpp_plugin src/compiler/cpp_plugin.cc @@ -12943,7 +12969,7 @@ if(gRPC_INSTALL) endif() endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_CSHARP_PLUGIN) add_executable(grpc_csharp_plugin src/compiler/csharp_plugin.cc @@ -13053,7 +13079,7 @@ target_link_libraries(grpc_linux_system_roots_test endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_NODE_PLUGIN) add_executable(grpc_node_plugin src/compiler/node_plugin.cc @@ -13090,7 +13116,7 @@ if(gRPC_INSTALL) endif() endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN) add_executable(grpc_objective_c_plugin src/compiler/objective_c_plugin.cc @@ -13127,7 +13153,7 @@ if(gRPC_INSTALL) endif() endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_PHP_PLUGIN) add_executable(grpc_php_plugin src/compiler/php_plugin.cc @@ -13164,7 +13190,7 @@ if(gRPC_INSTALL) endif() endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_PYTHON_PLUGIN) add_executable(grpc_python_plugin src/compiler/python_plugin.cc @@ -13201,7 +13227,7 @@ if(gRPC_INSTALL) endif() endif() -if(gRPC_BUILD_CODEGEN) +if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_GRPC_RUBY_PLUGIN) add_executable(grpc_ruby_plugin src/compiler/ruby_plugin.cc diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 923cda9b34c..998234972b7 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -315,13 +315,21 @@ endforeach() endfunction() - add_custom_target(plugins - DEPENDS + # These options allow users to enable or disable the building of the various + # protoc plugins. For example, running CMake with + # -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF will disable building the C# plugin. + set(_gRPC_PLUGIN_LIST) % for tgt in targets: % if tgt.build == 'protoc': - ${tgt.name} + option(gRPC_BUILD_${tgt.name.upper()} "Build ${tgt.name}" ON) + if (gRPC_BUILD_${tgt.name.upper()}) + list(APPEND _gRPC_PLUGIN_LIST ${tgt.name}) + endif () % endif % endfor + + add_custom_target(plugins + DEPENDS <%text>${_gRPC_PLUGIN_LIST} ) add_custom_target(tools_c @@ -419,7 +427,7 @@ endif() % elif tgt.build in ["protoc"]: - if(gRPC_BUILD_CODEGEN) + if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_${tgt.name.upper()}) <%block filter='platforms_condition_block(tgt.platforms)'> ${cc_binary(tgt)} ${cc_install(tgt)}