2020-10-30 06:31:16 -05:00
|
|
|
project(GrpcInterface)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
|
|
|
message(STATUS "GRPC enabled")
|
|
|
|
add_definitions(-DENABLE_GRPC)
|
|
|
|
|
|
|
|
set(CMAKE_UNITY_BUILD false)
|
2020-10-30 06:31:16 -05:00
|
|
|
set(RESINSIGHT_GRPC_PYTHON_EXECUTABLE
|
|
|
|
""
|
|
|
|
CACHE
|
|
|
|
FILEPATH
|
|
|
|
"gRPC : Path to Python 3 executable, required to build the Python client library"
|
|
|
|
)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-D_WIN32_WINNT=0x600)
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2023-01-19 01:20:07 -06:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
|
|
|
|
2020-10-30 04:11:58 -05:00
|
|
|
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
set(SOURCE_GROUP_HEADER_FILES
|
2021-01-06 08:03:38 -06:00
|
|
|
RiaGrpcServer.h
|
|
|
|
RiaGrpcHelper.h
|
|
|
|
RiaGrpcCallbacks.h
|
|
|
|
RiaGrpcCallbacks.inl
|
|
|
|
RiaGrpcServiceInterface.h
|
|
|
|
RiaGrpcCaseService.h
|
|
|
|
RiaGrpcSimulationWellService.h
|
|
|
|
RiaGrpcGridService.h
|
|
|
|
RiaGrpcProjectService.h
|
|
|
|
RiaGrpcCommandService.h
|
|
|
|
RiaGrpcAppService.h
|
|
|
|
RiaGrpcPropertiesService.h
|
|
|
|
RiaGrpcNNCPropertiesService.h
|
|
|
|
RiaGrpcPdmObjectService.h
|
|
|
|
RiaGrpcApplicationInterface.h
|
|
|
|
)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
set(SOURCE_GROUP_SOURCE_FILES
|
2021-01-06 08:03:38 -06:00
|
|
|
RiaGrpcServer.cpp
|
|
|
|
RiaGrpcHelper.cpp
|
|
|
|
RiaGrpcServiceInterface.cpp
|
|
|
|
RiaGrpcCaseService.cpp
|
|
|
|
RiaGrpcSimulationWellService.cpp
|
|
|
|
RiaGrpcGridService.cpp
|
|
|
|
RiaGrpcProjectService.cpp
|
|
|
|
RiaGrpcCommandService.cpp
|
|
|
|
RiaGrpcAppService.cpp
|
|
|
|
RiaGrpcPropertiesService.cpp
|
|
|
|
RiaGrpcNNCPropertiesService.cpp
|
|
|
|
RiaGrpcPdmObjectService.cpp
|
|
|
|
RiaGrpcApplicationInterface.cpp)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-11-03 02:12:32 -06:00
|
|
|
# Find Protobuf installation Looks for protobuf-config.cmake file installed by
|
|
|
|
# Protobuf's cmake installation.
|
|
|
|
set(protobuf_MODULE_COMPATIBLE ON)
|
|
|
|
find_package(Protobuf CONFIG 3.0 QUIET)
|
|
|
|
|
|
|
|
if(Protobuf_FOUND)
|
2020-11-03 03:42:30 -06:00
|
|
|
message(STATUS "Using protobuf ${protobuf_VERSION}")
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-11-03 03:42:30 -06:00
|
|
|
# Find gRPC installation Looks for gRPCConfig.cmake file installed by gRPC's
|
|
|
|
# cmake installation.
|
|
|
|
find_package(gRPC CONFIG REQUIRED)
|
2023-06-29 07:07:04 -05:00
|
|
|
message(STATUS "Generate C++ code using grpc : ${gRPC_VERSION}")
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-11-03 03:42:30 -06:00
|
|
|
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
|
|
|
|
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-11-03 03:42:30 -06:00
|
|
|
set(_GRPC_GRPCPP_UNSECURE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr)
|
|
|
|
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
|
2021-01-06 08:03:38 -06:00
|
|
|
set(GRPC_LINK_LIBRARIES ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF})
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-11-03 03:42:30 -06:00
|
|
|
set_target_properties(
|
2021-01-06 08:03:38 -06:00
|
|
|
${GRPC_LINK_LIBRARIES} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL RELEASE
|
2020-11-03 01:38:43 -06:00
|
|
|
MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
|
|
|
|
else()
|
2020-11-03 07:15:37 -06:00
|
|
|
message(STATUS "Using RESINSIGHT_GRPC_INSTALL_PREFIX=${RESINSIGHT_GRPC_INSTALL_PREFIX}")
|
2020-11-03 03:42:30 -06:00
|
|
|
set(RESINSIGHT_GRPC_INSTALL_PREFIX
|
|
|
|
""
|
|
|
|
CACHE PATH "gRPC : Install prefix for gRPC")
|
|
|
|
if(NOT DEFINED RESINSIGHT_GRPC_INSTALL_PREFIX
|
|
|
|
OR NOT EXISTS ${RESINSIGHT_GRPC_INSTALL_PREFIX})
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"You need a valid RESINSIGHT_GRPC_INSTALL_PREFIX set to build with gRPC"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "${RESINSIGHT_GRPC_INSTALL_PREFIX}/lib/pkgconfig")
|
|
|
|
find_package(PkgConfig REQUIRED)
|
2020-11-03 07:15:37 -06:00
|
|
|
pkg_check_modules(GRPC REQUIRED grpc grpc++_unsecure>=1.20 grpc_unsecure gpr
|
|
|
|
protobuf libcares)
|
2020-11-03 04:12:57 -06:00
|
|
|
if(EXISTS "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/protoc")
|
|
|
|
set(_PROTOBUF_PROTOC "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/protoc")
|
|
|
|
elseif(EXISTS "${RESINSIGHT_GRPC_INSTALL_PREFIX}/tools/protobuf/protoc")
|
|
|
|
set(_PROTOBUF_PROTOC
|
|
|
|
"${RESINSIGHT_GRPC_INSTALL_PREFIX}/tools/protobuf/protoc")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Could not find the protobuf compiler (protoc)")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(EXISTS "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/grpc_cpp_plugin")
|
|
|
|
set(_GRPC_CPP_PLUGIN_EXECUTABLE
|
|
|
|
"${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/grpc_cpp_plugin")
|
|
|
|
elseif(EXISTS "${RESINSIGHT_GRPC_INSTALL_PREFIX}/tools/grpc/grpc_cpp_plugin")
|
|
|
|
set(_GRPC_CPP_PLUGIN_EXECUTABLE
|
|
|
|
"${RESINSIGHT_GRPC_INSTALL_PREFIX}/tools/grpc/grpc_cpp_plugin")
|
|
|
|
endif()
|
2020-11-03 03:42:30 -06:00
|
|
|
include_directories(AFTER ${GRPC_INCLUDE_DIRS})
|
2020-11-03 01:38:43 -06:00
|
|
|
endif()
|
2020-10-30 06:31:16 -05:00
|
|
|
|
2020-11-03 07:15:37 -06:00
|
|
|
set(_LINK_LIBRARIES
|
2020-10-30 06:31:16 -05:00
|
|
|
${QT_LIBRARIES}
|
2021-01-06 08:03:38 -06:00
|
|
|
${GRPC_LINK_LIBRARIES}
|
2020-10-30 06:31:16 -05:00
|
|
|
LibCore
|
2021-01-06 08:03:38 -06:00
|
|
|
CommonCode
|
2020-10-30 06:31:16 -05:00
|
|
|
cafCommand
|
2021-01-06 08:03:38 -06:00
|
|
|
cafCommandFeatures
|
|
|
|
cafProjectDataModel
|
2020-10-30 06:31:16 -05:00
|
|
|
cafPdmScripting
|
2021-01-06 08:03:38 -06:00
|
|
|
ApplicationLibCode)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
|
|
|
# Proto files
|
2021-01-21 01:41:37 -06:00
|
|
|
file(GLOB GRPC_PROTO_FILES GrpcProtos/*.proto)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2021-01-06 08:03:38 -06:00
|
|
|
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Python")
|
2020-10-30 04:11:58 -05:00
|
|
|
|
|
|
|
add_custom_target(PipInstall)
|
|
|
|
|
2021-01-06 08:03:38 -06:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
|
|
|
message(STATUS "Using Python Executable: ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}")
|
2023-06-29 07:07:04 -05:00
|
|
|
|
|
|
|
execute_process(COMMAND "${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}" -m grpc_tools.protoc --version
|
|
|
|
OUTPUT_VARIABLE PYTHON_GRPC_PROTOC_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
message(STATUS "Using Python grpc protoc compiler: ${PYTHON_GRPC_PROTOC_VERSION}")
|
2021-01-06 08:03:38 -06:00
|
|
|
else()
|
|
|
|
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not install Python client code")
|
|
|
|
endif()
|
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
foreach(rips_proto ${GRPC_PROTO_FILES})
|
|
|
|
get_filename_component(rips_proto_name ${rips_proto} NAME_WE)
|
|
|
|
get_filename_component(rips_proto_path ${rips_proto} PATH)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
set(rips_proto_srcs "${CMAKE_BINARY_DIR}/Generated/${rips_proto_name}.pb.cc")
|
|
|
|
set(rips_proto_hdrs "${CMAKE_BINARY_DIR}/Generated/${rips_proto_name}.pb.h")
|
|
|
|
set(rips_grpc_srcs "${CMAKE_BINARY_DIR}/Generated/${rips_proto_name}.grpc.pb.cc")
|
|
|
|
set(rips_grpc_hdrs "${CMAKE_BINARY_DIR}/Generated/${rips_proto_name}.grpc.pb.h")
|
2020-10-30 06:31:16 -05:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${rips_proto_srcs}" "${rips_proto_hdrs}" "${rips_grpc_srcs}"
|
|
|
|
"${rips_grpc_hdrs}"
|
|
|
|
COMMAND
|
|
|
|
${_PROTOBUF_PROTOC} ARGS --grpc_out "${CMAKE_BINARY_DIR}/Generated"
|
|
|
|
--cpp_out "${CMAKE_BINARY_DIR}/Generated" -I "${rips_proto_path}"
|
|
|
|
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" "${rips_proto}"
|
|
|
|
DEPENDS "${rips_proto}")
|
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
set(rips_proto_python "rips/generated/${rips_proto_name}_pb2.py")
|
|
|
|
set(rips_grpc_python "rips/generated/${rips_proto_name}_pb2_grpc.py")
|
2020-10-30 06:31:16 -05:00
|
|
|
|
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
2020-10-30 04:11:58 -05:00
|
|
|
add_custom_command(
|
2020-10-30 06:31:16 -05:00
|
|
|
OUTPUT "${GRPC_PYTHON_SOURCE_PATH}/${rips_proto_python}"
|
|
|
|
"${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}"
|
|
|
|
COMMAND
|
|
|
|
${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m grpc_tools.protoc -I
|
|
|
|
"${rips_proto_path}" --python_out
|
|
|
|
"${GRPC_PYTHON_SOURCE_PATH}/rips/generated" --grpc_python_out
|
2023-07-12 04:42:17 -05:00
|
|
|
"${GRPC_PYTHON_SOURCE_PATH}/rips/generated" --pyi_out
|
2020-10-30 06:31:16 -05:00
|
|
|
"${GRPC_PYTHON_SOURCE_PATH}/rips/generated" "${rips_proto}"
|
|
|
|
DEPENDS "${rips_proto}"
|
|
|
|
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
|
|
|
|
VERBATIM)
|
2021-01-21 01:41:37 -06:00
|
|
|
list(APPEND GRPC_PYTHON_GENERATED_SOURCES "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}")
|
2020-10-30 06:31:16 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND GRPC_HEADER_FILES ${rips_proto_hdrs} ${rips_grpc_hdrs})
|
|
|
|
|
|
|
|
list(APPEND GRPC_CPP_SOURCES ${rips_proto_srcs} ${rips_grpc_srcs})
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
endforeach(rips_proto)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
2021-01-06 08:03:38 -06:00
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/ApplicationLibCode/Adm/RiaVersionInfo.py.cmake
|
2020-10-30 06:31:16 -05:00
|
|
|
${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py)
|
|
|
|
configure_file(${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
|
|
|
|
${GRPC_PYTHON_SOURCE_PATH}/setup.py)
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
list (APPEND GRPC_PYTHON_GENERATED_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py)
|
|
|
|
|
|
|
|
file(GLOB GRPC_PYTHON_RIPS_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/*.py)
|
|
|
|
file(GLOB GRPC_PYTHON_EXAMPLE_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/PythonExamples/*.py)
|
|
|
|
file(GLOB GRPC_PYTHON_TEST_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/tests/*.py)
|
|
|
|
file(GLOB GRPC_PYTHON_OTHER_FILES "${GRPC_PYTHON_SOURCE_PATH}/setup.py" "${GRPC_PYTHON_SOURCE_PATH}/requirements.txt" "${GRPC_PYTHON_SOURCE_PATH}/README.md" "${GRPC_PYTHON_SOURCE_PATH}/LICENSE")
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
list(
|
|
|
|
APPEND
|
|
|
|
GRPC_PYTHON_SOURCES
|
2021-01-21 01:41:37 -06:00
|
|
|
${GRPC_PYTHON_RIPS_SOURCES}
|
|
|
|
${GRPC_PYTHON_EXAMPLE_SOURCES}
|
|
|
|
${GRPC_PYTHON_TEST_SOURCES}
|
|
|
|
${GRPC_PYTHON_OTHER_FILES}
|
|
|
|
${GRPC_PROTO_FILES}
|
|
|
|
)
|
2020-10-30 06:31:16 -05:00
|
|
|
|
2020-10-30 04:11:58 -05:00
|
|
|
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
add_library(
|
|
|
|
${PROJECT_NAME} OBJECT
|
|
|
|
${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES}
|
|
|
|
${GRPC_HEADER_FILES} ${GRPC_CPP_SOURCES})
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2021-01-06 08:03:38 -06:00
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
PRIVATE
|
|
|
|
${GRPC_INCLUDE_DIRS}
|
|
|
|
${CMAKE_BINARY_DIR}/Generated
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${_LINK_LIBRARIES})
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(MSVC)
|
2022-01-26 03:08:28 -06:00
|
|
|
target_compile_options(
|
|
|
|
GrpcInterface
|
|
|
|
PRIVATE /wd4251 /wd4244 /wd4267)
|
2020-10-30 04:11:58 -05:00
|
|
|
else()
|
2022-01-26 03:08:28 -06:00
|
|
|
target_compile_options(
|
|
|
|
GrpcInterface
|
|
|
|
PRIVATE -Wno-switch -Wno-overloaded-virtual
|
|
|
|
)
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# install gRPC Python files
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE)
|
2024-02-15 02:47:20 -06:00
|
|
|
message(STATUS "Installing Python modules (dev-requirements.txt)")
|
2020-10-30 04:11:58 -05:00
|
|
|
add_custom_command(
|
|
|
|
TARGET PipInstall
|
2024-09-16 01:53:19 -05:00
|
|
|
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install -r ${GRPC_PYTHON_SOURCE_PATH}/dev-requirements.txt )
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE)
|
2020-10-30 04:11:58 -05:00
|
|
|
message(STATUS "Bundling Python GRPC modules")
|
|
|
|
add_custom_command(
|
|
|
|
TARGET PipInstall
|
2020-10-30 06:31:16 -05:00
|
|
|
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --user
|
|
|
|
--target=${GRPC_PYTHON_SOURCE_PATH} grpcio-tools)
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
2021-01-21 01:41:37 -06:00
|
|
|
add_custom_target(Rips ALL
|
|
|
|
SOURCES ${GRPC_PYTHON_SOURCES})
|
|
|
|
add_dependencies(${PROJECT_NAME} Rips)
|
2020-10-30 04:11:58 -05:00
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE)
|
2020-10-30 04:11:58 -05:00
|
|
|
add_dependencies(${PROJECT_NAME} PipInstall)
|
2021-01-21 01:41:37 -06:00
|
|
|
add_dependencies(Rips PipInstall)
|
2020-10-30 06:31:16 -05:00
|
|
|
endif()
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2020-10-30 06:31:16 -05:00
|
|
|
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
|
|
|
install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/
|
|
|
|
DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python)
|
2020-10-30 04:11:58 -05:00
|
|
|
endif()
|
|
|
|
|
2021-01-21 01:41:37 -06:00
|
|
|
source_group("Generated" FILES ${GRPC_PYTHON_GENERATED_SOURCES})
|
|
|
|
source_group("Sources" FILES ${GRPC_PYTHON_RIPS_SOURCES})
|
|
|
|
source_group("Protos" FILES ${GRPC_PROTO_FILES})
|
|
|
|
source_group("PythonExamples" FILES ${GRPC_PYTHON_EXAMPLE_SOURCES})
|
|
|
|
source_group("Tests" FILES ${GRPC_PYTHON_TEST_SOURCES})
|