Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cpp-client): Generate protos for C++ as part of the build #6136

Merged
merged 10 commits into from
Sep 26, 2024
113 changes: 61 additions & 52 deletions cpp-client/deephaven/dhclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@ find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_package(Threads REQUIRED)

set(PROTO_SRC_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/../../../proto/proto-backplane-grpc/src/main/proto")
set(PROTO_GEN_DIR
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}/proto")
set(PROTO_OUT_DIR "${PROTO_GEN_DIR}/deephaven/proto")

set(PROTO_FILES
"${PROTO_SRC_DIR}/deephaven/proto/application.proto"
"${PROTO_SRC_DIR}/deephaven/proto/config.proto"
"${PROTO_SRC_DIR}/deephaven/proto/console.proto"
"${PROTO_SRC_DIR}/deephaven/proto/hierarchicaltable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/inputtable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/object.proto"
"${PROTO_SRC_DIR}/deephaven/proto/partitionedtable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/session.proto"
"${PROTO_SRC_DIR}/deephaven/proto/storage.proto"
"${PROTO_SRC_DIR}/deephaven/proto/table.proto"
"${PROTO_SRC_DIR}/deephaven/proto/ticket.proto"
)

foreach(PROTO_FILE ${PROTO_FILES})
get_filename_component(BASENAME ${PROTO_FILE} NAME_WLE)
list(APPEND PROTO_GEN_FILES
"${PROTO_OUT_DIR}/${BASENAME}.grpc.pb.cc"
"${PROTO_OUT_DIR}/${BASENAME}.grpc.pb.h"
"${PROTO_OUT_DIR}/${BASENAME}.pb.cc"
"${PROTO_OUT_DIR}/${BASENAME}.pb.h"
)
endforeach()

add_custom_command(
OUTPUT ${PROTO_GEN_FILES}
COMMAND mkdir
ARGS -p "${PROTO_OUT_DIR}"
COMMAND protobuf::protoc
ARGS "--plugin=protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
"--cpp_out=${PROTO_GEN_DIR}"
"--grpc_out=${PROTO_GEN_DIR}"
"-I${PROTO_SRC_DIR}"
${PROTO_FILES}
DEPENDS ${PROTO_FILES}
COMMENT "Generating protos"
)

set(ALL_FILES
src/server/server.cc
include/private/deephaven/client/server/server.h
Expand Down Expand Up @@ -65,74 +109,39 @@ set(ALL_FILES
include/public/deephaven/client/utility/arrow_util.h
include/public/deephaven/client/utility/misc_types.h
include/public/deephaven/client/utility/table_maker.h

proto/deephaven/proto/application.grpc.pb.cc
proto/deephaven/proto/application.grpc.pb.h
proto/deephaven/proto/application.pb.cc
proto/deephaven/proto/application.pb.h
proto/deephaven/proto/config.grpc.pb.cc
proto/deephaven/proto/config.grpc.pb.h
proto/deephaven/proto/config.pb.cc
proto/deephaven/proto/config.pb.h
proto/deephaven/proto/console.grpc.pb.cc
proto/deephaven/proto/console.grpc.pb.h
proto/deephaven/proto/console.pb.cc
proto/deephaven/proto/console.pb.h
proto/deephaven/proto/inputtable.grpc.pb.cc
proto/deephaven/proto/inputtable.grpc.pb.h
proto/deephaven/proto/inputtable.pb.cc
proto/deephaven/proto/inputtable.pb.h
proto/deephaven/proto/object.grpc.pb.cc
proto/deephaven/proto/object.grpc.pb.h
proto/deephaven/proto/object.pb.cc
proto/deephaven/proto/object.pb.h
proto/deephaven/proto/partitionedtable.grpc.pb.cc
proto/deephaven/proto/partitionedtable.grpc.pb.h
proto/deephaven/proto/partitionedtable.pb.cc
proto/deephaven/proto/partitionedtable.pb.h
proto/deephaven/proto/session.grpc.pb.cc
proto/deephaven/proto/session.grpc.pb.h
proto/deephaven/proto/session.pb.cc
proto/deephaven/proto/session.pb.h
proto/deephaven/proto/table.grpc.pb.cc
proto/deephaven/proto/table.grpc.pb.h
proto/deephaven/proto/table.pb.cc
proto/deephaven/proto/table.pb.h
proto/deephaven/proto/ticket.grpc.pb.cc
proto/deephaven/proto/ticket.grpc.pb.h
proto/deephaven/proto/ticket.pb.cc
proto/deephaven/proto/ticket.pb.h
)

list(APPEND ALL_FILES ${PROTO_GEN_FILES})

add_library(dhclient SHARED ${ALL_FILES})

# This is so deephaven::client works both when using the installed CMake config
# and when using this project as a CMake subdirectory of your own project.
add_library(deephaven::client ALIAS dhclient)
add_library(deephaven::client ALIAS ${PROJECT_NAME})

set_property(TARGET dhclient PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

if (LINUX)
target_compile_options(dhclient PRIVATE -Wall -Werror -Wno-deprecated-declarations)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror -Wno-deprecated-declarations)
endif()

if (WIN32)
set_property(TARGET dhclient PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
# /Wall is a bit too chatty so we stick with /W3
# /bigobj needed because ticking/immer_table_state.cc compiles to something too large apparently
target_compile_options(dhclient PRIVATE /W3 /bigobj)
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /bigobj)
endif()

target_include_directories(dhclient PRIVATE include/private)
target_include_directories(dhclient PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>)
target_include_directories(${PROJECT_NAME} PRIVATE include/private)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>)
# Protos and flatbuf are doing their own thing.
target_include_directories(dhclient PRIVATE "./proto")
target_include_directories(dhclient PRIVATE "./flatbuf")
target_include_directories(${PROJECT_NAME} PRIVATE "${PROTO_GEN_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "./flatbuf")

target_link_libraries(dhclient PUBLIC deephaven::dhcore)
target_link_libraries(${PROJECT_NAME} PUBLIC deephaven::dhcore)

target_link_libraries(dhclient PUBLIC ArrowFlight::arrow_flight_shared)
target_link_libraries(dhclient PUBLIC Arrow::arrow_shared)
target_link_libraries(dhclient PRIVATE protobuf::libprotobuf)
target_link_libraries(dhclient PRIVATE gRPC::grpc++)
target_link_libraries(dhclient PRIVATE Threads::Threads)
target_link_libraries(${PROJECT_NAME} PUBLIC ArrowFlight::arrow_flight_shared)
target_link_libraries(${PROJECT_NAME} PUBLIC Arrow::arrow_shared)
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf)
target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::grpc++)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)

This file was deleted.

Loading
Loading