# GRPC global cmake file, modified for control-box-rst.
# This currently builds C and C++ code.
# Notice: Patch is based on https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/contrib/cmake/patches/grpc/CMakeLists.txt
# This file is based on the CMakeLists.txt available from here:
# https://github.com/grpc/grpc/blob/3bc78cd0b5bd784a235c01612d634b1ec5f8fb97/CMakeLists.txt
# with modifications to remove dependencies on SSL, and to reuse
# previously compiled libprotobuf.
#
# Copyright 2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.8)

set(PACKAGE_NAME      "grpc")
set(PACKAGE_VERSION   "1.3.0-corbo")
set(PACKAGE_STRING    "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME   "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
project(${PACKAGE_NAME} C CXX)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if (MSVC)
  include(cmake/msvc_static_runtime.cmake)
  add_definitions(-D_WIN32_WINNT=0x0A00 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
  # needed to compile protobuf
  add_definitions(/wd4065 /wd4506)
  # TODO(jtattermusch): revisit C4267 occurrences throughout the code
  add_definitions(/wd4267)
    
else (MSVC)
  set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -std=c11")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  # Apple macOS
  set(_gRPC_ALLTARGETS_LIBRARIES dl m pthread)
elseif (UNIX)
  set(_gRPC_ALLTARGETS_LIBRARIES dl m rt pthread)
endif()

if(WIN32 AND MSVC)
  set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)
endif()


# zlib Dependency
if(NOT ZLIB_ROOT_DIR)
  set(ZLIB_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib)
endif()
# zconf.h is generated by cmake and added to build dir
set(ZLIB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib)
set(ZLIB_INCLUDE_DIRS "${ZLIB_ROOT_DIR};${ZLIB_BUILD_DIR}")
if(EXISTS "${ZLIB_ROOT_DIR}/CMakeLists.txt")
  add_subdirectory(${ZLIB_ROOT_DIR} third_party/zlib)
  if(TARGET zlibstatic)
    set(_gRPC_ZLIB_LIBRARIES zlibstatic)
  endif()
else()
endif()

# CARES Dependency
if(NOT CARES_ROOT_DIR)
    set(CARES_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/c-ares)
endif()
    string(TOLOWER ${CMAKE_SYSTEM_NAME} CARES_SYSTEM_NAME)
    set(CARES_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares")
    set(CARES_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares")
    set(CARES_PLATFORM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/config_${CARES_SYSTEM_NAME}")
if(EXISTS "${CARES_ROOT_DIR}/CMakeLists.txt")
if("${CARES_SYSTEM_NAME}" MATCHES "windows")
    add_definitions(-DCARES_STATICLIB=1)
    add_definitions(-DWIN32_LEAN_AND_MEAN=1)
else()
    add_definitions(-DHAVE_CONFIG_H=1)
    add_definitions(-D_GNU_SOURCE=1)
endif()
    add_subdirectory(src/c-ares third_party/cares)
if(TARGET cares)
    set(_gRPC_CARES_LIBRARIES cares)
endif()
else()
    message(WARNING "gRPC_CARES_PROVIDER is \"module\" but CARES_ROOT_DIR is wrong")
endif()

# Libraries

add_library(gpr
  src/core/lib/profiling/basic_timers.c
  src/core/lib/profiling/stap_timers.c
  src/core/lib/support/alloc.c
  src/core/lib/support/arena.c
  src/core/lib/support/atm.c
  src/core/lib/support/avl.c
  src/core/lib/support/backoff.c
  src/core/lib/support/cmdline.c
  src/core/lib/support/cpu_iphone.c
  src/core/lib/support/cpu_linux.c
  src/core/lib/support/cpu_posix.c
  src/core/lib/support/cpu_windows.c
  src/core/lib/support/env_linux.c
  src/core/lib/support/env_posix.c
  src/core/lib/support/env_windows.c
  src/core/lib/support/histogram.c
  src/core/lib/support/host_port.c
  src/core/lib/support/log.c
  src/core/lib/support/log_android.c
  src/core/lib/support/log_linux.c
  src/core/lib/support/log_posix.c
  src/core/lib/support/log_windows.c
  src/core/lib/support/mpscq.c
  src/core/lib/support/murmur_hash.c
  src/core/lib/support/stack_lockfree.c
  src/core/lib/support/string.c
  src/core/lib/support/string_posix.c
  src/core/lib/support/string_util_windows.c
  src/core/lib/support/string_windows.c
  src/core/lib/support/subprocess_posix.c
  src/core/lib/support/subprocess_windows.c
  src/core/lib/support/sync.c
  src/core/lib/support/sync_posix.c
  src/core/lib/support/sync_windows.c
  src/core/lib/support/thd.c
  src/core/lib/support/thd_posix.c
  src/core/lib/support/thd_windows.c
  src/core/lib/support/time.c
  src/core/lib/support/time_posix.c
  src/core/lib/support/time_precise.c
  src/core/lib/support/time_windows.c
  src/core/lib/support/tls_pthread.c
  src/core/lib/support/tmpfile_msys.c
  src/core/lib/support/tmpfile_posix.c
  src/core/lib/support/tmpfile_windows.c
  src/core/lib/support/wrap_memcpy.c
)

if(WIN32 AND MSVC)
  set_target_properties(gpr PROPERTIES COMPILE_PDB_NAME "gpr"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
  )
endif()

target_include_directories(gpr
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  PRIVATE ${PROTOBUF_INCLUDE_DIRS}
  PRIVATE ${ZLIB_INCLUDE_DIRS}
)

target_link_libraries(gpr
  ${_gRPC_ALLTARGETS_LIBRARIES}
)

add_library(grpc_unsecure
  src/core/lib/surface/init.c
  src/core/lib/surface/init_unsecure.c
  src/core/lib/channel/channel_args.c
  src/core/lib/channel/channel_stack.c
  src/core/lib/channel/channel_stack_builder.c
  src/core/lib/channel/compress_filter.c
  src/core/lib/channel/connected_channel.c
  src/core/lib/channel/deadline_filter.c
  src/core/lib/channel/handshaker.c
  src/core/lib/channel/handshaker_factory.c
  src/core/lib/channel/handshaker_registry.c
  src/core/lib/channel/http_client_filter.c
  src/core/lib/channel/http_server_filter.c
  src/core/lib/channel/message_size_filter.c
  src/core/lib/compression/compression.c
  src/core/lib/compression/message_compress.c
  src/core/lib/debug/trace.c
  src/core/lib/http/format_request.c
  src/core/lib/http/httpcli.c
  src/core/lib/http/parser.c
  src/core/lib/iomgr/closure.c
  src/core/lib/iomgr/combiner.c
  src/core/lib/iomgr/endpoint.c
  src/core/lib/iomgr/endpoint_pair_posix.c
  src/core/lib/iomgr/endpoint_pair_uv.c
  src/core/lib/iomgr/endpoint_pair_windows.c
  src/core/lib/iomgr/error.c
  src/core/lib/iomgr/ev_epoll_linux.c
  src/core/lib/iomgr/ev_poll_posix.c
  src/core/lib/iomgr/ev_posix.c
  src/core/lib/iomgr/exec_ctx.c
  src/core/lib/iomgr/executor.c
  src/core/lib/iomgr/iocp_windows.c
  src/core/lib/iomgr/iomgr.c
  src/core/lib/iomgr/iomgr_posix.c
  src/core/lib/iomgr/iomgr_uv.c
  src/core/lib/iomgr/iomgr_windows.c
  src/core/lib/iomgr/load_file.c
  src/core/lib/iomgr/network_status_tracker.c
  src/core/lib/iomgr/polling_entity.c
  src/core/lib/iomgr/pollset_set_uv.c
  src/core/lib/iomgr/pollset_set_windows.c
  src/core/lib/iomgr/pollset_uv.c
  src/core/lib/iomgr/pollset_windows.c
  src/core/lib/iomgr/resolve_address_posix.c
  src/core/lib/iomgr/resolve_address_uv.c
  src/core/lib/iomgr/resolve_address_windows.c
  src/core/lib/iomgr/resource_quota.c
  src/core/lib/iomgr/sockaddr_utils.c
  src/core/lib/iomgr/socket_factory_posix.c
  src/core/lib/iomgr/socket_mutator.c
  src/core/lib/iomgr/socket_utils_common_posix.c
  src/core/lib/iomgr/socket_utils_linux.c
  src/core/lib/iomgr/socket_utils_posix.c
  src/core/lib/iomgr/socket_utils_uv.c
  src/core/lib/iomgr/socket_utils_windows.c
  src/core/lib/iomgr/socket_windows.c
  src/core/lib/iomgr/tcp_client_posix.c
  src/core/lib/iomgr/tcp_client_uv.c
  src/core/lib/iomgr/tcp_client_windows.c
  src/core/lib/iomgr/tcp_posix.c
  src/core/lib/iomgr/tcp_server_posix.c
  src/core/lib/iomgr/tcp_server_utils_posix_common.c
  src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c
  src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c
  src/core/lib/iomgr/tcp_server_uv.c
  src/core/lib/iomgr/tcp_server_windows.c
  src/core/lib/iomgr/tcp_uv.c
  src/core/lib/iomgr/tcp_windows.c
  src/core/lib/iomgr/time_averaged_stats.c
  src/core/lib/iomgr/timer_generic.c
  src/core/lib/iomgr/timer_heap.c
  src/core/lib/iomgr/timer_uv.c
  src/core/lib/iomgr/udp_server.c
  src/core/lib/iomgr/unix_sockets_posix.c
  src/core/lib/iomgr/unix_sockets_posix_noop.c
  src/core/lib/iomgr/wakeup_fd_cv.c
  src/core/lib/iomgr/wakeup_fd_eventfd.c
  src/core/lib/iomgr/wakeup_fd_nospecial.c
  src/core/lib/iomgr/wakeup_fd_pipe.c
  src/core/lib/iomgr/wakeup_fd_posix.c
  src/core/lib/iomgr/workqueue_uv.c
  src/core/lib/iomgr/workqueue_windows.c
  src/core/lib/json/json.c
  src/core/lib/json/json_reader.c
  src/core/lib/json/json_string.c
  src/core/lib/json/json_writer.c
  src/core/lib/slice/b64.c
  src/core/lib/slice/percent_encoding.c
  src/core/lib/slice/slice.c
  src/core/lib/slice/slice_buffer.c
  src/core/lib/slice/slice_hash_table.c
  src/core/lib/slice/slice_intern.c
  src/core/lib/slice/slice_string_helpers.c
  src/core/lib/surface/alarm.c
  src/core/lib/surface/api_trace.c
  src/core/lib/surface/byte_buffer.c
  src/core/lib/surface/byte_buffer_reader.c
  src/core/lib/surface/call.c
  src/core/lib/surface/call_details.c
  src/core/lib/surface/call_log_batch.c
  src/core/lib/surface/channel.c
  src/core/lib/surface/channel_init.c
  src/core/lib/surface/channel_ping.c
  src/core/lib/surface/channel_stack_type.c
  src/core/lib/surface/completion_queue.c
  src/core/lib/surface/completion_queue_factory.c
  src/core/lib/surface/event_string.c
  src/core/lib/surface/lame_client.c
  src/core/lib/surface/metadata_array.c
  src/core/lib/surface/server.c
  src/core/lib/surface/validate_metadata.c
  src/core/lib/surface/version.c
  src/core/lib/transport/bdp_estimator.c
  src/core/lib/transport/byte_stream.c
  src/core/lib/transport/connectivity_state.c
  src/core/lib/transport/error_utils.c
  src/core/lib/transport/metadata.c
  src/core/lib/transport/metadata_batch.c
  src/core/lib/transport/pid_controller.c
  src/core/lib/transport/service_config.c
  src/core/lib/transport/static_metadata.c
  src/core/lib/transport/status_conversion.c
  src/core/lib/transport/timeout_encoding.c
  src/core/lib/transport/transport.c
  src/core/lib/transport/transport_op_string.c
  src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
  src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c
  src/core/ext/transport/chttp2/transport/bin_decoder.c
  src/core/ext/transport/chttp2/transport/bin_encoder.c
  src/core/ext/transport/chttp2/transport/chttp2_plugin.c
  src/core/ext/transport/chttp2/transport/chttp2_transport.c
  src/core/ext/transport/chttp2/transport/frame_data.c
  src/core/ext/transport/chttp2/transport/frame_goaway.c
  src/core/ext/transport/chttp2/transport/frame_ping.c
  src/core/ext/transport/chttp2/transport/frame_rst_stream.c
  src/core/ext/transport/chttp2/transport/frame_settings.c
  src/core/ext/transport/chttp2/transport/frame_window_update.c
  src/core/ext/transport/chttp2/transport/hpack_encoder.c
  src/core/ext/transport/chttp2/transport/hpack_parser.c
  src/core/ext/transport/chttp2/transport/hpack_table.c
  src/core/ext/transport/chttp2/transport/huffsyms.c
  src/core/ext/transport/chttp2/transport/incoming_metadata.c
  src/core/ext/transport/chttp2/transport/parsing.c
  src/core/ext/transport/chttp2/transport/stream_lists.c
  src/core/ext/transport/chttp2/transport/stream_map.c
  src/core/ext/transport/chttp2/transport/varint.c
  src/core/ext/transport/chttp2/transport/writing.c
  src/core/ext/transport/chttp2/alpn/alpn.c
  src/core/ext/transport/chttp2/server/chttp2_server.c
  src/core/ext/transport/chttp2/client/insecure/channel_create.c
  src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c
  src/core/ext/transport/chttp2/client/chttp2_connector.c
  src/core/ext/filters/client_channel/channel_connectivity.c
  src/core/ext/filters/client_channel/client_channel.c
  src/core/ext/filters/client_channel/client_channel_factory.c
  src/core/ext/filters/client_channel/client_channel_plugin.c
  src/core/ext/filters/client_channel/connector.c
  src/core/ext/filters/client_channel/http_connect_handshaker.c
  src/core/ext/filters/client_channel/http_proxy.c
  src/core/ext/filters/client_channel/lb_policy.c
  src/core/ext/filters/client_channel/lb_policy_factory.c
  src/core/ext/filters/client_channel/lb_policy_registry.c
  src/core/ext/filters/client_channel/parse_address.c
  src/core/ext/filters/client_channel/proxy_mapper.c
  src/core/ext/filters/client_channel/proxy_mapper_registry.c
  src/core/ext/filters/client_channel/resolver.c
  src/core/ext/filters/client_channel/resolver_factory.c
  src/core/ext/filters/client_channel/resolver_registry.c
  src/core/ext/filters/client_channel/retry_throttle.c
  src/core/ext/filters/client_channel/subchannel.c
  src/core/ext/filters/client_channel/subchannel_index.c
  src/core/ext/filters/client_channel/uri_parser.c
  src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c
  src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c
  src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c
  src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c
  src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c
  src/core/ext/filters/load_reporting/load_reporting.c
  src/core/ext/filters/load_reporting/load_reporting_filter.c
  src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c
  src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.c
  src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c
  src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c
  third_party/nanopb/pb_common.c
  third_party/nanopb/pb_decode.c
  third_party/nanopb/pb_encode.c
  src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c
  src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c
  src/core/ext/census/base_resources.c
  src/core/ext/census/context.c
  src/core/ext/census/gen/census.pb.c
  src/core/ext/census/gen/trace_context.pb.c
  src/core/ext/census/grpc_context.c
  src/core/ext/census/grpc_filter.c
  src/core/ext/census/grpc_plugin.c
  src/core/ext/census/initialize.c
  src/core/ext/census/mlog.c
  src/core/ext/census/operation.c
  src/core/ext/census/placeholders.c
  src/core/ext/census/resource.c
  src/core/ext/census/trace_context.c
  #src/core/ext/census/tracing.c
  src/core/ext/filters/max_age/max_age_filter.c
  src/core/plugin_registry/grpc_unsecure_plugin_registry.c
)

if(WIN32 AND MSVC)
  set_target_properties(grpc_unsecure PROPERTIES COMPILE_PDB_NAME "grpc_unsecure"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
  )
endif()

target_include_directories(grpc_unsecure
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  PRIVATE ${PROTOBUF_INCLUDE_DIRS}  
#PRIVATE ${PROTOBUF_ROOT_DIR}/src
  PRIVATE ${ZLIB_INCLUDE_DIRS}
  PRIVATE ${CARES_BUILD_INCLUDE_DIR}
  PRIVATE ${CARES_INCLUDE_DIR}
  PRIVATE ${CARES_PLATFORM_INCLUDE_DIR}
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include
)

target_link_libraries(grpc_unsecure PUBLIC_LINK
  ${_gRPC_BASELIB_LIBRARIES}
  ${_gRPC_ALLTARGETS_LIBRARIES}
  gpr
  ${_gRPC_ZLIB_LIBRARIES}
)

add_library(grpc++_unsecure
  src/cpp/client/insecure_credentials.cc
  src/cpp/common/insecure_create_auth_context.cc
  src/cpp/server/insecure_server_credentials.cc
  src/cpp/client/channel_cc.cc
  src/cpp/client/client_context.cc
  src/cpp/client/create_channel.cc
  src/cpp/client/create_channel_internal.cc
  src/cpp/client/create_channel_posix.cc
  src/cpp/client/credentials_cc.cc
  src/cpp/client/generic_stub.cc
  src/cpp/common/channel_arguments.cc
  src/cpp/common/channel_filter.cc
  src/cpp/common/completion_queue_cc.cc
  src/cpp/common/core_codegen.cc
  src/cpp/common/resource_quota_cc.cc
  src/cpp/common/rpc_method.cc
  src/cpp/common/version_cc.cc
  src/cpp/server/async_generic_service.cc
  src/cpp/server/channel_argument_option.cc
  src/cpp/server/create_default_thread_pool.cc
  src/cpp/server/dynamic_thread_pool.cc
  src/cpp/server/health/default_health_check_service.cc
  src/cpp/server/health/health.pb.c
  src/cpp/server/health/health_check_service.cc
  src/cpp/server/health/health_check_service_server_builder_option.cc
  src/cpp/server/server_builder.cc
  src/cpp/server/server_cc.cc
  src/cpp/server/server_context.cc
  src/cpp/server/server_credentials.cc
  src/cpp/server/server_posix.cc
  src/cpp/thread_manager/thread_manager.cc
  src/cpp/util/byte_buffer_cc.cc
  src/cpp/util/slice_cc.cc
  src/cpp/util/status.cc
  src/cpp/util/string_ref.cc
  src/cpp/util/time_cc.cc
  src/core/lib/channel/channel_args.c
  src/core/lib/channel/channel_stack.c
  src/core/lib/channel/channel_stack_builder.c
  src/core/lib/channel/compress_filter.c
  src/core/lib/channel/connected_channel.c
  src/core/lib/channel/deadline_filter.c
  src/core/lib/channel/handshaker.c
  src/core/lib/channel/handshaker_factory.c
  src/core/lib/channel/handshaker_registry.c
  src/core/lib/channel/http_client_filter.c
  src/core/lib/channel/http_server_filter.c
  src/core/lib/channel/message_size_filter.c
  src/core/lib/compression/compression.c
  src/core/lib/compression/message_compress.c
  src/core/lib/debug/trace.c
  src/core/lib/http/format_request.c
  src/core/lib/http/httpcli.c
  src/core/lib/http/parser.c
  src/core/lib/iomgr/closure.c
  src/core/lib/iomgr/combiner.c
  src/core/lib/iomgr/endpoint.c
  src/core/lib/iomgr/endpoint_pair_posix.c
  src/core/lib/iomgr/endpoint_pair_uv.c
  src/core/lib/iomgr/endpoint_pair_windows.c
  src/core/lib/iomgr/error.c
  src/core/lib/iomgr/ev_epoll_linux.c
  src/core/lib/iomgr/ev_poll_posix.c
  src/core/lib/iomgr/ev_posix.c
  src/core/lib/iomgr/exec_ctx.c
  src/core/lib/iomgr/executor.c
  src/core/lib/iomgr/iocp_windows.c
  src/core/lib/iomgr/iomgr.c
  src/core/lib/iomgr/iomgr_posix.c
  src/core/lib/iomgr/iomgr_uv.c
  src/core/lib/iomgr/iomgr_windows.c
  src/core/lib/iomgr/load_file.c
  src/core/lib/iomgr/network_status_tracker.c
  src/core/lib/iomgr/polling_entity.c
  src/core/lib/iomgr/pollset_set_uv.c
  src/core/lib/iomgr/pollset_set_windows.c
  src/core/lib/iomgr/pollset_uv.c
  src/core/lib/iomgr/pollset_windows.c
  src/core/lib/iomgr/resolve_address_posix.c
  src/core/lib/iomgr/resolve_address_uv.c
  src/core/lib/iomgr/resolve_address_windows.c
  src/core/lib/iomgr/resource_quota.c
  src/core/lib/iomgr/sockaddr_utils.c
  src/core/lib/iomgr/socket_factory_posix.c
  src/core/lib/iomgr/socket_mutator.c
  src/core/lib/iomgr/socket_utils_common_posix.c
  src/core/lib/iomgr/socket_utils_linux.c
  src/core/lib/iomgr/socket_utils_posix.c
  src/core/lib/iomgr/socket_utils_uv.c
  src/core/lib/iomgr/socket_utils_windows.c
  src/core/lib/iomgr/socket_windows.c
  src/core/lib/iomgr/tcp_client_posix.c
  src/core/lib/iomgr/tcp_client_uv.c
  src/core/lib/iomgr/tcp_client_windows.c
  src/core/lib/iomgr/tcp_posix.c
  src/core/lib/iomgr/tcp_server_posix.c
  src/core/lib/iomgr/tcp_server_utils_posix_common.c
  src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c
  src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c
  src/core/lib/iomgr/tcp_server_uv.c
  src/core/lib/iomgr/tcp_server_windows.c
  src/core/lib/iomgr/tcp_uv.c
  src/core/lib/iomgr/tcp_windows.c
  src/core/lib/iomgr/time_averaged_stats.c
  src/core/lib/iomgr/timer_generic.c
  src/core/lib/iomgr/timer_heap.c
  src/core/lib/iomgr/timer_uv.c
  src/core/lib/iomgr/udp_server.c
  src/core/lib/iomgr/unix_sockets_posix.c
  src/core/lib/iomgr/unix_sockets_posix_noop.c
  src/core/lib/iomgr/wakeup_fd_cv.c
  src/core/lib/iomgr/wakeup_fd_eventfd.c
  src/core/lib/iomgr/wakeup_fd_nospecial.c
  src/core/lib/iomgr/wakeup_fd_pipe.c
  src/core/lib/iomgr/wakeup_fd_posix.c
  src/core/lib/iomgr/workqueue_uv.c
  src/core/lib/iomgr/workqueue_windows.c
  src/core/lib/json/json.c
  src/core/lib/json/json_reader.c
  src/core/lib/json/json_string.c
  src/core/lib/json/json_writer.c
  src/core/lib/slice/b64.c
  src/core/lib/slice/percent_encoding.c
  src/core/lib/slice/slice.c
  src/core/lib/slice/slice_buffer.c
  src/core/lib/slice/slice_hash_table.c
  src/core/lib/slice/slice_intern.c
  src/core/lib/slice/slice_string_helpers.c
  src/core/lib/surface/alarm.c
  src/core/lib/surface/api_trace.c
  src/core/lib/surface/byte_buffer.c
  src/core/lib/surface/byte_buffer_reader.c
  src/core/lib/surface/call.c
  src/core/lib/surface/call_details.c
  src/core/lib/surface/call_log_batch.c
  src/core/lib/surface/channel.c
  src/core/lib/surface/channel_init.c
  src/core/lib/surface/channel_ping.c
  src/core/lib/surface/channel_stack_type.c
  src/core/lib/surface/completion_queue.c
  src/core/lib/surface/completion_queue_factory.c
  src/core/lib/surface/event_string.c
  src/core/lib/surface/lame_client.c
  src/core/lib/surface/metadata_array.c
  src/core/lib/surface/server.c
  src/core/lib/surface/validate_metadata.c
  src/core/lib/surface/version.c
  src/core/lib/transport/bdp_estimator.c
  src/core/lib/transport/byte_stream.c
  src/core/lib/transport/connectivity_state.c
  src/core/lib/transport/error_utils.c
  src/core/lib/transport/metadata.c
  src/core/lib/transport/metadata_batch.c
  src/core/lib/transport/pid_controller.c
  src/core/lib/transport/service_config.c
  src/core/lib/transport/static_metadata.c
  src/core/lib/transport/status_conversion.c
  src/core/lib/transport/timeout_encoding.c
  src/core/lib/transport/transport.c
  src/core/lib/transport/transport_op_string.c
  third_party/nanopb/pb_common.c
  third_party/nanopb/pb_decode.c
  third_party/nanopb/pb_encode.c
  src/cpp/codegen/codegen_init.cc
)

if(WIN32 AND MSVC)
  set_target_properties(grpc++_unsecure PROPERTIES COMPILE_PDB_NAME "grpc++_unsecure"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
  )
endif()

target_include_directories(grpc++_unsecure
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  PRIVATE ${PROTOBUF_INCLUDE_DIRS}
  PRIVATE ${ZLIB_INCLUDE_DIRS}
)

target_link_libraries(grpc++_unsecure PUBLIC_LINK
  ${_gRPC_BASELIB_LIBRARIES}
  ${PROTOBUF_LIBRARIES}
  ${_gRPC_ALLTARGETS_LIBRARIES}
  gpr
  grpc_unsecure
)



## Plugin Executable

add_library(grpc_plugin_support
  src/compiler/cpp_generator.cc
  src/compiler/csharp_generator.cc
  src/compiler/node_generator.cc
  src/compiler/objective_c_generator.cc
  src/compiler/php_generator.cc
  src/compiler/python_generator.cc
  src/compiler/ruby_generator.cc
)

if(WIN32 AND MSVC)
  set_target_properties(grpc_plugin_support PROPERTIES COMPILE_PDB_NAME "grpc_plugin_support"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
  )
endif()


target_include_directories(grpc_plugin_support
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  PRIVATE ${BORINGSSL_ROOT_DIR}/include
  #PRIVATE ${PROTOBUF_ROOT_DIR}/src
  PRIVATE ${PROTOBUF_INCLUDE_DIRS}
  PRIVATE ${ZLIB_INCLUDE_DIR}
  PRIVATE ${BENCHMARK}/include
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib
  PRIVATE ${CARES_BUILD_INCLUDE_DIR}
  PRIVATE ${CARES_INCLUDE_DIR}
  PRIVATE ${CARES_PLATFORM_INCLUDE_DIR}
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include
  PRIVATE ${_gRPC_PROTO_GENS_DIR}
)

target_link_libraries(grpc_plugin_support
  ${PROTOC_LIBRARIES}
  ${PROTOBUF_LIBRARIES}
  ${_gRPC_ALLTARGETS_LIBRARIES}
)

add_executable(grpc_cpp_plugin
  src/compiler/cpp_plugin.cc
)


target_include_directories(grpc_cpp_plugin
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  PRIVATE ${BORINGSSL_ROOT_DIR}/include
  PRIVATE ${PROTOBUF_INCLUDE_DIRS}  
#PRIVATE ${PROTOBUF_ROOT_DIR}/src
  PRIVATE ${BENCHMARK_ROOT_DIR}/include
  PRIVATE ${ZLIB_ROOT_DIR}
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib
  PRIVATE ${CARES_BUILD_INCLUDE_DIR}
  PRIVATE ${CARES_INCLUDE_DIR}
  PRIVATE ${CARES_PLATFORM_INCLUDE_DIR}
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include
  PRIVATE ${_gRPC_PROTO_GENS_DIR}
)

target_link_libraries(grpc_cpp_plugin
  ${PROTOC_LIBRARIES}
  ${PROTOBUF_LIBRARIES}
  grpc_plugin_support
)
