diff --git a/ApplicationExeCode/CMakeLists.txt b/ApplicationExeCode/CMakeLists.txt index 87e8dcf6e3..92750e078b 100644 --- a/ApplicationExeCode/CMakeLists.txt +++ b/ApplicationExeCode/CMakeLists.txt @@ -210,17 +210,19 @@ set(LINK_LIBRARIES if(RESINSIGHT_ENABLE_GRPC) list(APPEND LINK_LIBRARIES GrpcInterface) + + # Scope to the one file that needs it, to avoid a full rebuild on toggle. + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/RiaMain.cpp PROPERTIES COMPILE_DEFINITIONS + ENABLE_GRPC + ) endif() if(RESINSIGHT_USE_ODB_API) - add_definitions(-DUSE_ODB_API) + target_compile_definitions(ResInsight PRIVATE USE_ODB_API) list(APPEND LINK_LIBRARIES RifOdbReader) endif() -if(RESINSIGHT_ENABLE_OPENVDS) - add_definitions(-DUSE_OPENVDS) -endif() - target_link_libraries(ResInsight PRIVATE ${LINK_LIBRARIES}) if(UNIX AND NOT APPLE) diff --git a/ApplicationLibCode/CMakeLists.txt b/ApplicationLibCode/CMakeLists.txt index 58dccbac4f..d6fd2b249e 100644 --- a/ApplicationLibCode/CMakeLists.txt +++ b/ApplicationLibCode/CMakeLists.txt @@ -169,22 +169,33 @@ list(APPEND CPP_SOURCES ${CODE_SOURCE_FILES}) # # Odb api # -if(RESINSIGHT_USE_ODB_API) - add_definitions(-DUSE_ODB_API) -endif() +# NOTE: USE_ODB_API is defined further down via target_compile_definitions(). # # OpenVDS # if(RESINSIGHT_ENABLE_OPENVDS) message(STATUS "OpenVDS support enabled") - add_definitions(-DUSE_OPENVDS) - list(APPEND RI_PRIVATE_INCLUDES ${RESINSIGHT_OPENVDS_API_DIR}/include) - list(APPEND CPP_SOURCES FileInterface/RifOpenVDSReader.cpp - FileInterface/RifOpenVDSReader.h + set(OPENVDS_FILES FileInterface/RifOpenVDSReader.cpp + FileInterface/RifOpenVDSReader.h + ) + list(APPEND CPP_SOURCES ${OPENVDS_FILES}) + + # Scope USE_OPENVDS to the files that need it, to avoid a full rebuild on + # toggle. + set_source_files_properties( + ${OPENVDS_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/Seismic/RimSeismicData.cpp + PROPERTIES COMPILE_DEFINITIONS USE_OPENVDS ) + # Only RifOpenVDSReader.cpp includes the OpenVDS SDK headers, so scope the + # include dir to just that file to avoid a full rebuild on toggle. + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/FileInterface/RifOpenVDSReader.cpp + PROPERTIES INCLUDE_DIRECTORIES ${RESINSIGHT_OPENVDS_API_DIR}/include + ) endif() # @@ -207,14 +218,35 @@ if(RESINSIGHT_FOUND_HDF5) list(APPEND CPP_SOURCES ${HDF5_FILES}) - add_definitions(-DUSE_HDF5) - add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB) + # Scope USE_HDF5/H5_BUILT_AS_DYNAMIC_LIB to the files that need it, to avoid a + # full rebuild on toggle. + set_source_files_properties( + ${HDF5_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/FileInterface/RifReaderEclipseSummary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FileInterface/RifReaderEclipseOutput.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Application/RiaPreferencesSummary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SocketInterface/RiaPropertyDataCommands.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/RimEmCase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/RimEclipseResultDefinition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/RimEclipseResultCase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp + PROPERTIES COMPILE_DEFINITIONS "USE_HDF5;H5_BUILT_AS_DYNAMIC_LIB" + ) if(MSVC) - list(APPEND RI_PRIVATE_INCLUDES ${RESINSIGHT_HDF5_DIR}/include) + set(RI_HDF5_INCLUDE_DIRS ${RESINSIGHT_HDF5_DIR}/include) else() - list(APPEND RI_PRIVATE_INCLUDES ${HDF5_INCLUDE_DIRS}) + set(RI_HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) endif() # MSVC + + # Only these files (and HDF5_FILES) include HDF5 headers directly, so scope + # the include dir to just them to avoid a full rebuild on toggle. + set_source_files_properties( + ${HDF5_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/FileInterface/RifReaderEclipseOutput.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/RimEmCase.cpp + PROPERTIES INCLUDE_DIRECTORIES "${RI_HDF5_INCLUDE_DIRS}" + ) endif() # @@ -234,6 +266,35 @@ list(APPEND ALL_SOURCE_FILES ${CPP_SOURCES} ${QRC_FILES}) add_library(${PROJECT_NAME} OBJECT ${ALL_SOURCE_FILES}) +# NOTE: Scope ENABLE_GRPC/USE_ODB_API to the few files that use them, to avoid a +# full rebuild of this target on toggle. RiaPreferences.cpp and +# RimContextCommandBuilder.cpp need both, so combine them into a single +# set_source_files_properties() call per file (a second call would overwrite, +# not add to, COMPILE_DEFINITIONS from the first). +set(RI_SHARED_DEFS_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Application/RiaPreferences.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/RimContextCommandBuilder.cpp +) +set(RI_SHARED_DEFS "") +if(RESINSIGHT_ENABLE_GRPC) + list(APPEND RI_SHARED_DEFS ENABLE_GRPC) +endif() +if(RESINSIGHT_USE_ODB_API) + list(APPEND RI_SHARED_DEFS USE_ODB_API) +endif() +if(RI_SHARED_DEFS) + set_source_files_properties( + ${RI_SHARED_DEFS_FILES} PROPERTIES COMPILE_DEFINITIONS "${RI_SHARED_DEFS}" + ) +endif() + +if(RESINSIGHT_USE_ODB_API) + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/UserInterface/RiuMainWindow.cpp + PROPERTIES COMPILE_DEFINITIONS USE_ODB_API + ) +endif() + option(RESINSIGHT_ENABLE_DYNAMIC_DEOPTIMALIZATION "Ensable Dynamic Deoptimalization" OFF ) @@ -338,7 +399,6 @@ target_include_directories( PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Commands ${CMAKE_CURRENT_SOURCE_DIR}/Commands/EclipseCommands ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModelCommands/CommandRouter - ${RI_PRIVATE_INCLUDES} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Adm ${CMAKE_CURRENT_SOURCE_DIR}/Application diff --git a/ApplicationLibCode/Commands/CMakeLists.txt b/ApplicationLibCode/Commands/CMakeLists.txt index e764a88842..b66abb0f8d 100644 --- a/ApplicationLibCode/Commands/CMakeLists.txt +++ b/ApplicationLibCode/Commands/CMakeLists.txt @@ -75,8 +75,37 @@ find_package(Eigen3 REQUIRED) add_library(${PROJECT_NAME} OBJECT ${COMMAND_CODE_SOURCE_FILES}) +# Scope USE_OPENVDS/USE_ODB_API to the files that use them, to avoid a full +# rebuild on toggle. if(RESINSIGHT_ENABLE_OPENVDS) - add_definitions(-DUSE_OPENVDS) + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/SeismicCommands/RicImportSeismicFeature.cpp + PROPERTIES COMPILE_DEFINITIONS USE_OPENVDS + ) +endif() + +if(RESINSIGHT_USE_ODB_API) + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/GeoMechCommands/RicGeoMechCopyCaseFeature.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/GeoMechCommands/RicImportGeoMechCaseFeature.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/GeoMechCommands/RicImportGeoMechCaseTimeStepFilterFeature.cpp + PROPERTIES COMPILE_DEFINITIONS USE_ODB_API + ) +endif() + +# RicHelpFeatures.cpp references both USE_ODB_API and USE_HDF5. +if(RESINSIGHT_USE_ODB_API OR RESINSIGHT_FOUND_HDF5) + set(RIC_HELP_FEATURES_DEFS "") + if(RESINSIGHT_USE_ODB_API) + list(APPEND RIC_HELP_FEATURES_DEFS USE_ODB_API) + endif() + if(RESINSIGHT_FOUND_HDF5) + list(APPEND RIC_HELP_FEATURES_DEFS USE_HDF5) + endif() + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/ApplicationCommands/RicHelpFeatures.cpp + PROPERTIES COMPILE_DEFINITIONS "${RIC_HELP_FEATURES_DEFS}" + ) endif() if(RESINSIGHT_ENABLE_PRECOMPILED_HEADERS) diff --git a/ApplicationLibCode/FeatureTests/CMakeLists.txt b/ApplicationLibCode/FeatureTests/CMakeLists.txt index 8bf67535e2..5e7c5a2639 100644 --- a/ApplicationLibCode/FeatureTests/CMakeLists.txt +++ b/ApplicationLibCode/FeatureTests/CMakeLists.txt @@ -79,7 +79,6 @@ target_include_directories( ResInsight-featuretests PUBLIC ${CMAKE_BINARY_DIR}/Generated "$" - ${RI_PRIVATE_INCLUDES} ${PROJECT_SOURCE_DIR}/Commands ${PROJECT_SOURCE_DIR}/Commands/CompletionExportCommands ${CMAKE_CURRENT_LIST_DIR} diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt b/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt index 18c087a42b..8d04836890 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt @@ -112,6 +112,10 @@ add_library( target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +if(RESINSIGHT_USE_ODB_API) + target_compile_definitions(${PROJECT_NAME} PRIVATE USE_ODB_API) +endif() + target_link_libraries( RigGeoMechDataModel PUBLIC LibCore cafPdmCvf cafTensor cafUserInterface CommonCode ResultStatisticsCache diff --git a/ApplicationLibCode/GeoMech/OdbReader/CMakeLists.txt b/ApplicationLibCode/GeoMech/OdbReader/CMakeLists.txt index 8eda4b2bdb..170466a3cf 100644 --- a/ApplicationLibCode/GeoMech/OdbReader/CMakeLists.txt +++ b/ApplicationLibCode/GeoMech/OdbReader/CMakeLists.txt @@ -3,6 +3,9 @@ project(RifOdbReader) if(MSVC) add_definitions(-DHKS_NT) add_definitions(-DABQ_WIN86_64) + # Needed for omi_types.h to typedef int64/uint64, used unconditionally + # elsewhere in the SDK headers (e.g. atr_translate.h). + add_definitions(-D_WINDOWS_SOURCE) else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -w -Wno-deprecated") diff --git a/ApplicationLibCode/GeoMech/OdbReader/RifOdbReader.cpp b/ApplicationLibCode/GeoMech/OdbReader/RifOdbReader.cpp index 2d4afe8031..bdc345328e 100644 --- a/ApplicationLibCode/GeoMech/OdbReader/RifOdbReader.cpp +++ b/ApplicationLibCode/GeoMech/OdbReader/RifOdbReader.cpp @@ -303,7 +303,10 @@ bool RifOdbReader::readFemParts( RigFemPartCollection* femParts ) CAF_ASSERT( femParts ); CAF_ASSERT( m_odb != NULL ); - odb_InstanceRepository instanceRepository = m_odb->rootAssembly().instances(); + // Use a reference, not a copy: MSVC's strict conformance mode (required by Qt) finds the + // implicit copy constructor of odb_InstanceRepository ambiguous (diamond inheritance in the + // ODB API headers). + odb_InstanceRepository& instanceRepository = m_odb->rootAssembly().instances(); odb_InstanceRepositoryIT iter( instanceRepository ); caf::ProgressInfo modelProgress( instanceRepository.size() * (size_t)( 2 + 4 ), "Reading Odb Parts" ); diff --git a/ApplicationLibCode/UnitTests/CMakeLists.txt b/ApplicationLibCode/UnitTests/CMakeLists.txt index 2ab221faef..646c75f38a 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists.txt +++ b/ApplicationLibCode/UnitTests/CMakeLists.txt @@ -272,6 +272,31 @@ set_property(TARGET PreBuildFileCopyTest PROPERTY FOLDER "FileCopyTargetsTest") qt_add_executable(ResInsight-tests ${SOURCE_UNITTEST_FILES} main.cpp) +# Scope USE_HDF5 and its include dir to the 3 test files that need them, to +# avoid a full rebuild on toggle. +if(RESINSIGHT_FOUND_HDF5) + set(RI_HDF5_TEST_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/HDF5FileReader-Test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/HDF5FileWriter-Test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/RimEmReader-Test.cpp + ) + set_source_files_properties( + ${RI_HDF5_TEST_FILES} PROPERTIES COMPILE_DEFINITIONS + "USE_HDF5;H5_BUILT_AS_DYNAMIC_LIB" + ) + if(MSVC) + set_source_files_properties( + ${RI_HDF5_TEST_FILES} PROPERTIES INCLUDE_DIRECTORIES + ${RESINSIGHT_HDF5_DIR}/include + ) + else() + set_source_files_properties( + ${RI_HDF5_TEST_FILES} PROPERTIES INCLUDE_DIRECTORIES + "${HDF5_INCLUDE_DIRS}" + ) + endif() +endif() + # Make ResInsight-tests depend on the prebuild target. add_dependencies(ResInsight-tests PreBuildFileCopyTest) @@ -289,7 +314,6 @@ target_include_directories( ResInsight-tests PUBLIC ${CMAKE_BINARY_DIR}/Generated "$" - ${RI_PRIVATE_INCLUDES} ${PROJECT_SOURCE_DIR}/Commands ${PROJECT_SOURCE_DIR}/Commands/CompletionExportCommands ${CMAKE_CURRENT_LIST_DIR}/../TestModels diff --git a/CMakeLists.txt b/CMakeLists.txt index ccd85a3505..d6f71adfd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,17 +259,14 @@ if(RESINSIGHT_DOWNLOAD_ODB_FROM_SERVER) endif() if(NOT ${RESINSIGHT_ODB_API_DIR} EQUAL "") - add_definitions(-DUSE_ODB_API) set(RESINSIGHT_USE_ODB_API 1) message( STATUS "Using ODB-Api ${RESINSIGHT_ODB_VERSION} from : ${RESINSIGHT_ODB_API_DIR}" ) - if(MSVC) - add_definitions(-D_WINDOWS_SOURCE) - else() - add_definitions(-D_LINUX_SOURCE) - endif() + # NOTE: USE_ODB_API is defined per-target (see ApplicationLibCode, Commands, + # GeoMechDataModel, ApplicationExeCode), to avoid a full project rebuild on + # toggle. endif() # ############################################################################## @@ -311,7 +308,9 @@ if(RESINSIGHT_ENABLE_GRPC) option(RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE "Bundle the gRPC python modules into the install folder" OFF ) - add_definitions(-DENABLE_GRPC) + # NOTE: ENABLE_GRPC is defined per-target (see ApplicationLibCode, + # ApplicationExeCode, GrpcInterface), to avoid a full project rebuild on + # toggle. endif() # ############################################################################## diff --git a/GrpcInterface/CMakeLists.txt b/GrpcInterface/CMakeLists.txt index d110637fc9..7228bad3a5 100644 --- a/GrpcInterface/CMakeLists.txt +++ b/GrpcInterface/CMakeLists.txt @@ -1,7 +1,6 @@ project(GrpcInterface) message(STATUS "GRPC enabled") -add_definitions(-DENABLE_GRPC) set(CMAKE_UNITY_BUILD false) set(RESINSIGHT_GRPC_PYTHON_EXECUTABLE @@ -17,32 +16,8 @@ endif() set(CMAKE_CXX_STANDARD 23) - add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) -set(SOURCE_GROUP_HEADER_FILES - RiaGrpcServer.h - RiaGrpcHelper.h - RiaGrpcCallbacks.h - RiaGrpcCallbacks.inl - RiaGrpcServiceInterface.h - RiaGrpcCaseService.h - RiaGrpcSimulationWellService.h - RiaGrpcGridService.h - RiaGrpcProjectService.h - RiaGrpcCommandService.h - RiaGrpcAppService.h - RiaGrpcPropertiesService.h - RiaGrpcKeyValueStoreService.h - RiaGrpcNNCPropertiesService.h - RiaGrpcPdmObjectService.h - RiaGrpcApplicationInterface.h - RiaGrpcWellPathService.h - RiaWellPathDataToGrpcConverter.h - RiaGrpcActiveCellInfoStateHandler.h - RiaGrpcSelectedCellsStateHandler.h - ) - set(SOURCE_GROUP_SOURCE_FILES RiaGrpcServer.cpp RiaGrpcHelper.cpp @@ -85,15 +60,22 @@ if(Protobuf_FOUND) set(GRPC_LINK_LIBRARIES ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF}) set_target_properties( - ${GRPC_LINK_LIBRARIES} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL RELEASE - MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE) + ${GRPC_LINK_LIBRARIES} + PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL RELEASE + MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE + ) else() - message(STATUS "Using RESINSIGHT_GRPC_INSTALL_PREFIX=${RESINSIGHT_GRPC_INSTALL_PREFIX}") + message( + STATUS + "Using RESINSIGHT_GRPC_INSTALL_PREFIX=${RESINSIGHT_GRPC_INSTALL_PREFIX}" + ) set(RESINSIGHT_GRPC_INSTALL_PREFIX "" - CACHE PATH "gRPC : Install prefix for gRPC") + CACHE PATH "gRPC : Install prefix for gRPC" + ) if(NOT DEFINED RESINSIGHT_GRPC_INSTALL_PREFIX - OR NOT EXISTS ${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" @@ -101,23 +83,34 @@ else() endif() set(ENV{PKG_CONFIG_PATH} "${RESINSIGHT_GRPC_INSTALL_PREFIX}/lib/pkgconfig") find_package(PkgConfig REQUIRED) - pkg_check_modules(GRPC REQUIRED grpc grpc++_unsecure>=1.20 grpc_unsecure gpr - protobuf libcares) + pkg_check_modules( + GRPC + REQUIRED + grpc + grpc++_unsecure>=1.20 + grpc_unsecure + gpr + protobuf + libcares + ) 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") + "${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") + "${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") + "${RESINSIGHT_GRPC_INSTALL_PREFIX}/tools/grpc/grpc_cpp_plugin" + ) endif() include_directories(AFTER ${GRPC_INCLUDE_DIRS}) endif() @@ -131,7 +124,8 @@ set(_LINK_LIBRARIES cafCommandFeatures cafProjectDataModel cafPdmScripting - ApplicationLibCode) + ApplicationLibCode +) # Proto files file(GLOB GRPC_PROTO_FILES GrpcProtos/*.proto) @@ -141,26 +135,39 @@ set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Python") add_custom_target(PipInstall) if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) - message(STATUS "Using Python Executable: ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}") - - 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 Executable: ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}" + ) - message(STATUS "Using Python grpc protoc compiler: ${PYTHON_GRPC_PROTOC_VERSION}") + 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}" + ) else() - message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not install Python client code") + message( + STATUS + "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not install Python client code" + ) endif() 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) - 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") + 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" + ) add_custom_command( OUTPUT "${rips_proto_srcs}" "${rips_proto_hdrs}" "${rips_grpc_srcs}" @@ -169,7 +176,8 @@ foreach(rips_proto ${GRPC_PROTO_FILES}) ${_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}") + DEPENDS "${rips_proto}" + ) set(rips_proto_python "rips/generated/${rips_proto_name}_pb2.py") set(rips_grpc_python "rips/generated/${rips_proto_name}_pb2_grpc.py") @@ -186,8 +194,11 @@ foreach(rips_proto ${GRPC_PROTO_FILES}) "${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 "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}") + VERBATIM + ) + list(APPEND GRPC_PYTHON_GENERATED_SOURCES + "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}" + ) endif() list(APPEND GRPC_HEADER_FILES ${rips_proto_hdrs} ${rips_grpc_hdrs}) @@ -197,18 +208,29 @@ foreach(rips_proto ${GRPC_PROTO_FILES}) endforeach(rips_proto) if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) - configure_file(${CMAKE_SOURCE_DIR}/ApplicationLibCode/Adm/RiaVersionInfo.py.cmake - ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py) - configure_file(${GRPC_PYTHON_SOURCE_PATH}/rips/_version.py.cmake - ${GRPC_PYTHON_SOURCE_PATH}/rips/_version.py) + configure_file( + ${CMAKE_SOURCE_DIR}/ApplicationLibCode/Adm/RiaVersionInfo.py.cmake + ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py + ) + configure_file( + ${GRPC_PYTHON_SOURCE_PATH}/rips/_version.py.cmake + ${GRPC_PYTHON_SOURCE_PATH}/rips/_version.py + ) endif() -list (APPEND GRPC_PYTHON_GENERATED_SOURCES ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py) +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_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}/pyproject.toml" "${GRPC_PYTHON_SOURCE_PATH}/README.md" "${GRPC_PYTHON_SOURCE_PATH}/LICENSE") +file(GLOB GRPC_PYTHON_OTHER_FILES "${GRPC_PYTHON_SOURCE_PATH}/pyproject.toml" + "${GRPC_PYTHON_SOURCE_PATH}/README.md" + "${GRPC_PYTHON_SOURCE_PATH}/LICENSE" +) list( APPEND @@ -223,27 +245,27 @@ list( list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES}) add_library( - ${PROJECT_NAME} OBJECT - ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} - ${GRPC_HEADER_FILES} ${GRPC_CPP_SOURCES}) + ${PROJECT_NAME} OBJECT ${SOURCE_GROUP_SOURCE_FILES} ${GRPC_HEADER_FILES} + ${GRPC_CPP_SOURCES} +) -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE - ${GRPC_INCLUDE_DIRS} - ${CMAKE_BINARY_DIR}/Generated +# PRIVATE: consumers must scope ENABLE_GRPC per-file themselves to avoid forcing +# a full rebuild on toggle (see ApplicationExeCode/CMakeLists.txt). +target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_GRPC) + +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}) if(MSVC) - target_compile_options( - GrpcInterface - PRIVATE /wd4251 /wd4244 /wd4267) + target_compile_options(GrpcInterface PRIVATE /wd4251 /wd4244 /wd4267) else() target_compile_options( - GrpcInterface - PRIVATE -Wno-switch -Wno-overloaded-virtual + GrpcInterface PRIVATE -Wno-switch -Wno-overloaded-virtual ) endif() @@ -251,8 +273,9 @@ endif() if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE) message(STATUS "Installing Python dev modules") add_custom_command( - TARGET PipInstall - COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install -e ${GRPC_PYTHON_SOURCE_PATH}[dev] ) + TARGET PipInstall COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip + install -e ${GRPC_PYTHON_SOURCE_PATH}[dev] + ) endif() if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE) @@ -260,12 +283,12 @@ if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE AND RESINSIGHT_GRPC_BUNDLE_PYTHON_MODULE) add_custom_command( TARGET PipInstall COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} ARGS -m pip install --user - --target=${GRPC_PYTHON_SOURCE_PATH} grpcio-tools) + --target=${GRPC_PYTHON_SOURCE_PATH} grpcio-tools + ) endif() if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) - add_custom_target(Rips ALL - SOURCES ${GRPC_PYTHON_SOURCES}) + add_custom_target(Rips ALL SOURCES ${GRPC_PYTHON_SOURCES}) add_dependencies(${PROJECT_NAME} Rips) if(RESINSIGHT_GRPC_DOWNLOAD_PYTHON_MODULE) @@ -276,5 +299,6 @@ endif() if(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ - DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python) + DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python + ) endif()