diff --git a/native/cpp/CommonCpp/grpc/CMakeLists.txt b/native/cpp/CommonCpp/grpc/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/grpc/CMakeLists.txt @@ -0,0 +1,106 @@ +project(grpc-comm) +cmake_minimum_required(VERSION 3.4) + +include(GNUInstallDirs) +find_package(protobuf REQUIRED) +find_package(gRPC REQUIRED) + +set(_components backup blob tunnelbroker) +set(TARGETS) +# Iterate through each protobuf file +# and create headers, sources, and export as component library +foreach(component ${_components}) + set(LIB_NAME comm-${component}-grpc) + set(TARGETS ${TARGETS} ${LIB_NAME}) + + set(PROTO_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${component}.pb.h + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${component}.grpc.pb.h + ) + + set(PROTO_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${component}.pb.cc + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${component}.grpc.pb.cc + ) + + add_library(${LIB_NAME} + ${PROTO_HDRS} ${PROTO_SRCS} + ) + + target_link_libraries(${LIB_NAME} + gRPC::grpc++ + protobuf::libprotobuf + ) + + # reference local directory when building + # use installation path when installing + target_include_directories(${LIB_NAME} + PUBLIC + $ + $ + $ + ) + + install(TARGETS ${LIB_NAME} EXPORT comm-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${LIB_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_NAME} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_NAME} + ) + + # ensure headers are also installed + install(FILES ${PROTO_HDRS} DESTINATION include/comm/grpc) +endforeach() + +set(CLIENT_HDRS + "Client.h" + "ClientGetReadReactor.h" + "GRPCStreamHostObject.h" +) + +set(CLIENT_SRCS + "Client.cpp" + "ClientGetReadReactor.cpp" + "GRPCStreamHostObject.cpp" +) + +add_library(comm-client + ${CLIENT_HDRS} + ${CLIENT_SRCS} +) + +target_link_libraries(comm-client + gRPC::grpc++ + protobuf::libprotobuf + comm-tunnelbroker-grpc +) + +target_include_directories(comm-client + PUBLIC + $ + $ + # HACK: add complete cmake support to react-native? + PRIVATE + "../../../node_modules/react-native/ReactCommon/callinvoker" + "../../../node_modules/react-native/ReactCommon/jsi" +) + +install(TARGETS comm-client EXPORT comm-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-client + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-client + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-client +) + +install(FILES ${CLIENT_HDRS} DESTINATION include/grpc) + +# For development purposes, able to reference build directory +export(TARGETS ${TARGETS} comm-client + NAMESPACE comm-grpc:: + FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/comm-grpc/comm-grpc-targets.cmake +) + +# For installation +install(EXPORT comm-export + FILE comm-grpc-targets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-grpc + NAMESPACE comm-grpc:: +)