Simplify the CMake GRPC setup (#6852)

* Simplify GRPC CMake setup.
* Move pip install code to CMake rather than github action to ensure the same Python version
* Remove redunant NO_MODULE in GRPC cmakefiles
* Use old CMP0077 policy (changed in Cmake 3.13) because our base line is 3.12.
* Make GrpcInterface a separate Object Library
* Update pip command to include --user and setuptools
* Update grpc python generation
* Remove unity build from GrpcInterface library
* Update github action to explictly set up Python
This commit is contained in:
Gaute Lindkvist 2020-10-30 10:11:58 +01:00 committed by GitHub
parent 3e291e0c6b
commit 514cca5f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 333 additions and 337 deletions

View File

@ -57,6 +57,12 @@ jobs:
uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Download Ninja
uses: seanmiddleditch/gha-setup-ninja@master
with:
@ -113,11 +119,6 @@ jobs:
modules: qtscript
dir: '${{ github.workspace }}/Qt/'
cached: ${{ steps.cache-qt.outputs.cache-hit }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install grpcio-tools
pip install pytest
- name: Install Linux dependencies
if: "contains( matrix.config.os, 'ubuntu')"
run: sudo apt-get install libxkbcommon-x11-0 libgl1-mesa-dev mesa-common-dev libglfw3-dev libglu1-mesa-dev libhdf5-dev
@ -127,12 +128,11 @@ jobs:
path: ${{ github.workspace }}/ThirdParty/vcpkg/
# Ensure the cache is invalidated any time vcpkg version changes, or a different set of packages is being used.
key: ${{ hashFiles( format('{0}/{1}', github.workspace, matrix.config.vcpkg-response-file )) }}-${{ hashFiles('.git/modules/ThirdParty/vcpkg/HEAD') }}-${{ runner.os }}-v02
- name: Run vcpkg
uses: lukka/run-vcpkg@v1
id: runvcpkg
with:
vcpkgArguments: '@${{ github.workspace }}/${{ matrix.config.vcpkg-response-file }}'
vcpkgDirectory: '${{ github.workspace }}/ThirdParty/vcpkg'
- name: Get Python executable path
id: python-path
run: echo "::set-output name=PYTHON_EXECUTABLE::$(python -c 'import sys; import pathlib; print (pathlib.PurePath(sys.executable).as_posix())')"
- name: Print Python path
run: echo ${{ steps.python-path.outputs.PYTHON_EXECUTABLE }}
- name: Configure
shell: cmake -P {0}
run: |
@ -155,19 +155,20 @@ jobs:
set(path_separator ";")
endif()
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
execute_process(
COMMAND cmake
-S .
-B cmakebuild
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
-D CMAKE_INSTALL_PREFIX=cmakebuild/install
-D GSL_ENABLE=true
-D RESINSIGHT_ENABLE_UNITY_BUILD=true
-D RESINSIGHT_BUNDLE_OPENSSL=true
-D RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS=true
-D RESINSIGHT_TREAT_WARNINGS_AS_ERRORS=true
-D RESINSIGHT_ENABLE_GRPC=true
-D RESINSIGHT_GRPC_PYTHON_EXECUTABLE=python
-D RESINSIGHT_GRPC_PYTHON_EXECUTABLE=${{ steps.python-path.outputs.PYTHON_EXECUTABLE }}
-D RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE=true
-D VCPKG_TARGET_TRIPLET=${{ matrix.config.vcpkg-triplet }}
-D CMAKE_TOOLCHAIN_FILE=${{ matrix.config.cmake-toolchain }}
-G Ninja
@ -213,13 +214,13 @@ jobs:
shell: bash
run: |
cmakebuild/ApplicationCode/ResInsight --unittest
- name: Run pytest
- name: (Windows) Run pytest
if: contains( matrix.config.os, 'windows')
env:
RESINSIGHT_EXECUTABLE: ${{ runner.workspace }}/ResInsight/cmakebuild/ApplicationCode/ResInsight.exe
run: |
cd ApplicationCode/GrpcInterface/Python/rips
pytest --console
${{ steps.python-path.outputs.PYTHON_EXECUTABLE }} -m pytest --console
- name: Upload artifact
uses: actions/upload-artifact@v2
with:

View File

@ -65,6 +65,7 @@ jobs:
-DVCPKG_TARGET_TRIPLET=x64-linux \
-DCMAKE_TOOLCHAIN_FILE=../ThirdParty/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DRESINSIGHT_GRPC_PYTHON_EXECUTABLE=python \
-DRESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE=true\
..
make -j8

View File

@ -21,7 +21,12 @@ endif()
find_package( OpenGL )
option(RESINSIGHT_ENABLE_GRPC "Enable the gRPC scripting framework" OFF)
option(RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE "Bundle the gRPC python modules into the install folder" OFF)
if (RESINSIGHT_ENABLE_GRPC)
option(RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE "Download the gRPC python modules to enable generation of Python interface" ON)
option(RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE "Bundle the gRPC python modules into the install folder" OFF)
add_definitions(-DENABLE_GRPC)
endif()
option(RESINSIGHT_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors (stops build)" OFF)
find_package(Qt5 COMPONENTS Core QUIET)
@ -123,12 +128,6 @@ list( APPEND CPP_SOURCES
${UNIT_TEST_FILES}
)
if (RESINSIGHT_ENABLE_GRPC)
list( APPEND REFERENCED_CMAKE_FILES
GrpcInterface/CMakeLists.cmake
)
endif(RESINSIGHT_ENABLE_GRPC)
list( APPEND REFERENCED_CMAKE_FILES
Application/CMakeLists_files.cmake
Application/Tools/CMakeLists_files.cmake
@ -201,8 +200,15 @@ add_subdirectory(Commands)
set( RI_LIBRARIES
ResultStatisticsCache
Commands
)
if (RESINSIGHT_ENABLE_GRPC)
add_subdirectory(GrpcInterface)
list(APPEND RI_LIBRARIES GrpcInterface)
endif()
#
# Odb api
#
@ -313,14 +319,8 @@ source_group( "UnitTests" FILES ${UNIT_TEST_FILES} )
if (MSVC)
set( EXE_FILES WIN32)
if (RESINSIGHT_ENABLE_GRPC)
# GRPC generates a lot of harmless warnings on MSVC
set_source_files_properties(${GRPC_CPP_SOURCES} ${GRPC_UNIT_TEST_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "/wd4251 /wd4702 /wd4005 /wd4244 /wd4125 /wd4267")
endif(RESINSIGHT_ENABLE_GRPC)
elseif (APPLE)
set( EXE_FILES MACOSX_BUNDLE)
else()
set_source_files_properties(${GRPC_CPP_SOURCES} ${GRPC_UNIT_TESTS_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "-Wno-overloaded-virtual")
endif()
set( EXE_FILES
${EXE_FILES}
@ -335,24 +335,8 @@ set( EXE_FILES
.clang-format
.clang-tidy
Adm/RiaVersionInfo.h.cmake
$<TARGET_OBJECTS:cafCommandFeatures> # Needed for cmake version < 3.12. Remove when we can use target_link_libraries with OBJECT libraries
$<TARGET_OBJECTS:Commands> # Needed for cmake version < 3.12. Remove when we can use target_link_libraries with OBJECT libraries
)
if (RESINSIGHT_ENABLE_GRPC)
list(APPEND EXE_FILES
${GRPC_CPP_SOURCES}
${GRPC_HEADER_FILES}
${GRPC_PYTHON_SOURCES_FULL_PATH}
${GRPC_PROTO_FILES_FULL_PATH}
Adm/RiaVersionInfo.py.cmake
)
if (DEFINED GRPC_LIBRARY_DIRS)
message(STATUS "Using GRPC Library Dir: ${GRPC_LIBRARY_DIRS}")
link_directories(${GRPC_LIBRARY_DIRS})
endif(DEFINED GRPC_LIBRARY_DIRS)
endif(RESINSIGHT_ENABLE_GRPC)
add_executable( ResInsight ${EXE_FILES})
option(RESINSIGHT_ENABLE_PRECOMPILED_HEADERS "Use Precompiled Headers" OFF)
@ -431,18 +415,6 @@ set( LINK_LIBRARIES
${QT_LIBRARIES}
)
if (RESINSIGHT_ENABLE_GRPC)
if (UNIX)
foreach(GRPC_LIBRARY ${GRPC_LIBRARIES})
list(APPEND LINK_LIBRARIES "${GRPC_LIBRARY_DIRS}/lib${GRPC_LIBRARY}.a")
endforeach()
list(APPEND LINK_LIBRARIES ${GRPC_PACKAGE_LIBRARIES})
else()
list(APPEND LINK_LIBRARIES ${GRPC_LIBRARIES})
set_target_properties(ResInsight PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:MSVCRTD.lib")
endif()
endif()
# According to ivarun this is needed on OpenSuse, and Fedora. See: https://github.com/OPM/ResInsight/pull/7
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND EXTERNAL_LINK_LIBRARIES
@ -519,19 +491,14 @@ endforeach()
# Generate Python code in a target that is part of ALL_BUILD and depends on ResInsight
if (RESINSIGHT_ENABLE_GRPC)
set(RESINSIGHT_GRPC_PYTHON_EXECUTABLE "" CACHE FILEPATH "gRPC : Path to Python 3 executable, required to build the Python client library")
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
add_custom_command(OUTPUT ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/resinsight_classes.py
COMMAND ResInsight ARGS --console --generate ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/resinsight_classes.py
DEPENDS ResInsight
COMMENT "Generating ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/resinsight_classes.py"
)
list(APPEND GRPC_GENERATED_PYTHON_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/resinsight_classes.py)
add_custom_target(GeneratedPythonSources ALL DEPENDS ${GRPC_GENERATED_PYTHON_SOURCES})
add_dependencies(GeneratedPythonSources ResInsight)
else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not install GRPC Python code.")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py
COMMAND ResInsight ARGS --console --generate ${CMAKE_CURRENT_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py
DEPENDS ResInsight
COMMENT "Generating ${CMAKE_CURRENT_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py"
)
add_custom_target(ResInsightClassesPy ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py)
add_dependencies(ResInsightClassesPy ResInsight)
endif(RESINSIGHT_ENABLE_GRPC)
#############################################################################
@ -673,12 +640,13 @@ if (RESINSIGHT_PRIVATE_INSTALL)
)
endif()
# install GRPC-related DLLs
# install GRPC-related DLLs and resinsight_classes.py
if (RESINSIGHT_ENABLE_GRPC)
set (GRPC_DLL_NAMES libprotobuf cares zlib1 abseil_dll)
foreach (dllname ${GRPC_DLL_NAMES})
list(APPEND RESINSIGHT_FILES $<TARGET_FILE_DIR:ResInsight>/${dllname}.dll)
endforeach(dllname ${GRPC_DLL_NAMES})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python/rips/generated)
endif()
# OpenSSL
@ -706,24 +674,6 @@ if (RESINSIGHT_PRIVATE_INSTALL)
endif()
# install gRPC Python files
if (RESINSIGHT_ENABLE_GRPC)
message(STATUS "GRPC enabled")
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
message(STATUS "Python found")
if (RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE)
message(STATUS "Bundling Python GRPC modules")
add_custom_command(
TARGET ResInsight
POST_BUILD
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} -m pip install --target=${GRPC_PYTHON_SOURCE_PATH} grpcio-tools
)
endif()
install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python)
install(FILES ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/resinsight_classes.py DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python/rips/generated)
endif()
endif()
set (RESINSIGHT_FILES ${RESINSIGHT_FILES} ${RESINSIGHT_LICENSE_FILES})

View File

@ -1,248 +0,0 @@
cmake_minimum_required (VERSION 3.12)
set ( SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.inl
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.h
)
set ( SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.cpp
)
add_definitions(-DENABLE_GRPC)
if (MSVC)
add_definitions(-D_WIN32_WINNT=0x600)
# 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)
message(STATUS "Using protobuf ${protobuf_VERSION}")
else()
message(FATAL_ERROR "Protocol Buffers not found. This is required to build with gRPC")
endif()
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED NO_MODULE)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
set(_GRPC_GRPCPP_UNSECURE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
set(GRPC_LIBRARIES ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF})
set_target_properties(${GRPC_LIBRARIES} PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL RELEASE
MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE
)
else()
find_package(gRPC CONFIG)
if(gRPC_FOUND)
message(STATUS "Found GRPC using find_package(gRPC CONFIG) ")
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(GRPC_PACKAGE_LIBRARIES gRPC::gpr gRPC::grpc_unsecure gRPC::grpc++_unsecure)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
message(STATUS "_PROTOBUF_PROTOC : ${_PROTOBUF_PROTOC}")
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
message(STATUS "_GRPC_CPP_PLUGIN_EXECUTABLE : ${_GRPC_CPP_PLUGIN_EXECUTABLE}")
else()
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)
pkg_check_modules(GRPC REQUIRED grpc++_unsecure>=1.20 grpc_unsecure gpr protobuf)
set(_PROTOBUF_PROTOC "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/protoc")
set(_GRPC_CPP_PLUGIN_EXECUTABLE "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/grpc_cpp_plugin")
include_directories(AFTER ${GRPC_INCLUDE_DIRS})
endif()
endif()
# Cannot use the nice new FindPackage modules for python since that is CMake 3.12+
if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
message(STATUS "Using Python ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
# Proto files
set(PROTO_FILES
"Definitions"
"PdmObject"
"Case"
"SimulationWell"
"Project"
"Commands"
"NNCProperties"
"App"
"Properties"
"Grid"
)
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python")
foreach(proto_file ${PROTO_FILES})
get_filename_component(rips_proto "${CMAKE_CURRENT_LIST_DIR}/GrpcProtos/${proto_file}.proto" ABSOLUTE)
get_filename_component(rips_proto_path "${rips_proto}" PATH)
list(APPEND GRPC_PROTO_FILES_FULL_PATH ${rips_proto})
set(rips_proto_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.cc")
set(rips_proto_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.h")
set(rips_grpc_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.grpc.pb.cc")
set(rips_grpc_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.grpc.pb.h")
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}"
)
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
set(rips_proto_python "rips/generated/${proto_file}_pb2.py")
set(rips_grpc_python "rips/generated/${proto_file}_pb2_grpc.py")
add_custom_command(
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 "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
"${rips_proto}"
DEPENDS "${rips_proto}"
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
VERBATIM
)
list (APPEND GRPC_PYTHON_GENERATED_SOURCES
${rips_proto_python}
${rips_grpc_python}
)
else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not generate GRPC Python code.")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
list( APPEND GRPC_HEADER_FILES
${rips_proto_hdrs}
${rips_grpc_hdrs}
)
list( APPEND GRPC_CPP_SOURCES
${rips_proto_srcs}
${rips_grpc_srcs}
)
endforeach(proto_file)
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py)
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/setup.py)
list(APPEND GRPC_PYTHON_SOURCES
"rips/generated/RiaVersionInfo.py"
"rips/__init__.py"
"rips/case.py"
"rips/contour_map.py"
"rips/grid.py"
"rips/gridcasegroup.py"
"rips/instance.py"
"rips/pdmobject.py"
"rips/plot.py"
"rips/project.py"
"rips/simulation_well.py"
"rips/view.py"
"rips/well_log_plot.py"
"rips/PythonExamples/instance_example.py"
"rips/PythonExamples/command_example.py"
"rips/PythonExamples/case_grid_group.py"
"rips/PythonExamples/case_info_streaming_example.py"
"rips/PythonExamples/create_wbs_plot.py"
"rips/PythonExamples/export_plots.py"
"rips/PythonExamples/export_snapshots.py"
"rips/PythonExamples/error_handling.py"
"rips/PythonExamples/import_well_paths_and_logs.py"
"rips/PythonExamples/soil_porv_async.py"
"rips/PythonExamples/soil_porv_sync.py"
"rips/PythonExamples/selected_cases.py"
"rips/PythonExamples/all_cases.py"
"rips/PythonExamples/replace_case.py"
"rips/PythonExamples/set_grid_properties.py"
"rips/PythonExamples/set_cell_result.py"
"rips/PythonExamples/set_flow_diagnostics_result.py"
"rips/PythonExamples/grid_information.py"
"rips/PythonExamples/input_prop_test_sync.py"
"rips/PythonExamples/input_prop_test_async.py"
"rips/PythonExamples/soil_average_async.py"
"rips/PythonExamples/soil_average_sync.py"
"rips/PythonExamples/view_example.py"
"rips/tests/test_cases.py"
"rips/tests/test_grids.py"
"rips/tests/test_properties.py"
"rips/tests/test_project.py"
"rips/tests/conftest.py"
"rips/tests/dataroot.py"
"rips/tests/test_nnc_properties.py"
"rips/tests/test_simulation_wells.py"
"rips/tests/test_summary_cases.py"
"rips/tests/test_wells.py"
"requirements.txt"
"setup.py"
"README.md"
"LICENSE"
)
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}")
endforeach()
if (MSVC)
source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "GrpcInterface\\Python")
endif(MSVC)
else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not copy grpc Python code to build folder")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
list ( APPEND GRPC_CPP_SOURCES ${SOURCE_GROUP_SOURCE_FILES})
source_group( "GrpcInterface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.cmake )
source_group( "GrpcInterface\\GrpcProtos" FILES ${GRPC_PROTO_FILES_FULL_PATH} )

View File

@ -0,0 +1,292 @@
cmake_minimum_required (VERSION 3.12)
project (GrpcInterface)
message(STATUS "GRPC enabled")
add_definitions(-DENABLE_GRPC)
set(CMAKE_UNITY_BUILD false)
set(RESINSIGHT_GRPC_PYTHON_EXECUTABLE "" CACHE FILEPATH "gRPC : Path to Python 3 executable, required to build the Python client library")
if (MSVC)
add_definitions(-D_WIN32_WINNT=0x600)
endif()
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
set ( SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.inl
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.h
)
set ( SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.cpp
)
# 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)
message(STATUS "Using protobuf ${protobuf_VERSION}")
else()
message(FATAL_ERROR "Protocol Buffers not found. This is required to build with gRPC")
endif()
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
set(_GRPC_GRPCPP_UNSECURE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
set(GRPC_LIBRARIES ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF})
set_target_properties(${GRPC_LIBRARIES} PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL RELEASE
MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE
)
set( LINK_LIBRARIES
${QT_LIBRARIES}
${GRPC_LIBRARIES}
LibCore
cafCommand
cafPdmCvf
cafPdmScripting
cafTensor
cafViewer
cafVizExtensions
ecl
nightcharts
qwt
)
# Proto files
set(PROTO_FILES
"Definitions"
"PdmObject"
"Case"
"SimulationWell"
"Project"
"Commands"
"NNCProperties"
"App"
"Properties"
"Grid"
)
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python")
add_custom_target(PipInstall)
foreach(proto_file ${PROTO_FILES})
get_filename_component(rips_proto "${CMAKE_CURRENT_LIST_DIR}/GrpcProtos/${proto_file}.proto" ABSOLUTE)
get_filename_component(rips_proto_path "${rips_proto}" PATH)
list(APPEND GRPC_PROTO_FILES_FULL_PATH ${rips_proto})
set(rips_proto_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.cc")
set(rips_proto_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.h")
set(rips_grpc_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.grpc.pb.cc")
set(rips_grpc_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.grpc.pb.h")
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}"
)
set(rips_proto_python "rips/generated/${proto_file}_pb2.py")
set(rips_grpc_python "rips/generated/${proto_file}_pb2_grpc.py")
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
message(STATUS "Using Python Executable: ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}")
add_custom_command(
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 "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
"${rips_proto}"
DEPENDS "${rips_proto}"
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
VERBATIM
)
list (APPEND GRPC_PYTHON_GENERATED_SOURCES
${rips_proto_python}
${rips_grpc_python}
)
else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not install Python client code")
endif()
list( APPEND GRPC_HEADER_FILES
${rips_proto_hdrs}
${rips_grpc_hdrs}
)
list( APPEND GRPC_CPP_SOURCES
${rips_proto_srcs}
${rips_grpc_srcs}
)
endforeach(proto_file)
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py)
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/setup.py)
endif()
list(APPEND GRPC_PYTHON_SOURCES
"rips/generated/RiaVersionInfo.py"
"rips/__init__.py"
"rips/case.py"
"rips/contour_map.py"
"rips/grid.py"
"rips/gridcasegroup.py"
"rips/instance.py"
"rips/pdmobject.py"
"rips/plot.py"
"rips/project.py"
"rips/simulation_well.py"
"rips/view.py"
"rips/well_log_plot.py"
"rips/PythonExamples/instance_example.py"
"rips/PythonExamples/command_example.py"
"rips/PythonExamples/case_grid_group.py"
"rips/PythonExamples/case_info_streaming_example.py"
"rips/PythonExamples/create_wbs_plot.py"
"rips/PythonExamples/export_plots.py"
"rips/PythonExamples/export_snapshots.py"
"rips/PythonExamples/error_handling.py"
"rips/PythonExamples/import_well_paths_and_logs.py"
"rips/PythonExamples/soil_porv_async.py"
"rips/PythonExamples/soil_porv_sync.py"
"rips/PythonExamples/selected_cases.py"
"rips/PythonExamples/all_cases.py"
"rips/PythonExamples/replace_case.py"
"rips/PythonExamples/set_grid_properties.py"
"rips/PythonExamples/set_cell_result.py"
"rips/PythonExamples/set_flow_diagnostics_result.py"
"rips/PythonExamples/grid_information.py"
"rips/PythonExamples/input_prop_test_sync.py"
"rips/PythonExamples/input_prop_test_async.py"
"rips/PythonExamples/soil_average_async.py"
"rips/PythonExamples/soil_average_sync.py"
"rips/PythonExamples/view_example.py"
"rips/tests/test_cases.py"
"rips/tests/test_grids.py"
"rips/tests/test_properties.py"
"rips/tests/test_project.py"
"rips/tests/conftest.py"
"rips/tests/dataroot.py"
"rips/tests/test_nnc_properties.py"
"rips/tests/test_simulation_wells.py"
"rips/tests/test_summary_cases.py"
"rips/tests/test_wells.py"
"requirements.txt"
"setup.py"
"README.md"
"LICENSE"
)
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}")
endforeach()
endif()
add_library( ${PROJECT_NAME} OBJECT
${SOURCE_GROUP_HEADER_FILES}
${SOURCE_GROUP_SOURCE_FILES}
${GRPC_HEADER_FILES}
${GRPC_CPP_SOURCES}
)
target_link_libraries( ${PROJECT_NAME}
${LINK_LIBRARIES}
)
if (MSVC)
# GRPC generates a lot of harmless warnings on MSVC
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4251 /wd4702 /wd4005 /wd4244 /wd4125 /wd4267")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-Wno-overloaded-virtual")
endif()
# install gRPC Python files
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE)
message(STATUS "Installing Python modules")
add_custom_command(
TARGET PipInstall
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --upgrade pip
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --user wheel setuptools pytest
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --user grpcio-tools
)
endif()
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE)
message(STATUS "Bundling Python GRPC modules")
add_custom_command(
TARGET PipInstall
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --user --target=${GRPC_PYTHON_SOURCE_PATH} grpcio-tools
)
endif()
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
add_custom_target(GeneratedPythonSources ALL DEPENDS ${GRPC_PYTHON_SOURCES_FULL_PATH})
add_dependencies(${PROJECT_NAME} GeneratedPythonSources)
if (RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE)
add_dependencies(${PROJECT_NAME} PipInstall)
add_dependencies(GeneratedPythonSources PipInstall)
endif()
endif()
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python)
endif()
source_group( "GrpcInterface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.cmake )
source_group( "GrpcInterface\\GrpcProtos" FILES ${GRPC_PROTO_FILES_FULL_PATH} )
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "GrpcInterface\\Python")
endif()

View File

@ -6,8 +6,8 @@ project (ResInsight)
set (VIZ_MODULES_FOLDER_NAME Fwk/VizFwk)
cmake_policy(SET CMP0020 NEW)
cmake_policy(SET CMP0077 OLD)
# The new GLVND OpenGL-libraries may cause issues in some virtualized environments
if (UNIX)
option(RESINSIGHT_PREFER_LEGACY_OPENGL "Link with Legacy OpenGL libraries. This may be necessary in some virtualization environments" ON)
if (RESINSIGHT_PREFER_LEGACY_OPENGL)