From 8e16477b50be94cf8ec6424395cb830159d455b5 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 17 Aug 2020 12:58:31 +0300 Subject: [PATCH] 0031582: Configuration, CMake - OCCT fails to build with VTK 9.0 Handle "VTK::" prefix instead of "vtk" used by previous VTK versions for targets. Corrected unexpected location of endif() and broken indentation. Obsolete $VTK_USE_FILE is no more included (basing on VTK version check). Standard_WarningsDisable.hxx/Standard_WarningsRestore.hxx pair is now used to suppress VTK warnings instead of partial disabling. --- adm/cmake/occt_toolkit.cmake | 5 +- adm/cmake/vtk.cmake | 154 ++++++++++-------- src/IVtkDraw/IVtkDraw.cxx | 9 +- ...IVtkDraw_HighlightAndSelectionPipeline.cxx | 9 +- ...IVtkDraw_HighlightAndSelectionPipeline.hxx | 8 +- src/IVtkDraw/IVtkDraw_Interactor.cxx | 9 +- src/IVtkDraw/IVtkDraw_Interactor.hxx | 8 +- src/IVtkTools/IVtkTools_ShapeDataSource.hxx | 3 + src/IVtkTools/IVtkTools_ShapeObject.hxx | 8 +- src/IVtkTools/IVtkTools_ShapePicker.hxx | 8 +- src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx | 4 +- src/IVtkVTK/IVtkVTK_ShapeData.cxx | 8 +- src/IVtkVTK/IVtkVTK_ShapeData.hxx | 8 +- 13 files changed, 110 insertions(+), 131 deletions(-) diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake index 38c39ae0c1..ca84f4c3fc 100644 --- a/adm/cmake/occt_toolkit.cmake +++ b/adm/cmake/occt_toolkit.cmake @@ -323,7 +323,7 @@ endif() # Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used. # Add VTK_OPENGL2_BACKEND definition. -if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2") +if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2" OR IS_VTK_9XX) add_definitions(-DVTK_OPENGL2_BACKEND) foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL) list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND) @@ -347,6 +347,9 @@ else() endif() if (BUILD_SHARED_LIBS) + if(IS_VTK_9XX) + string (REGEX REPLACE "vtk" "VTK::" USED_TOOLKITS_BY_CURRENT_PROJECT "${USED_TOOLKITS_BY_CURRENT_PROJECT}") + endif() target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT}) endif() diff --git a/adm/cmake/vtk.cmake b/adm/cmake/vtk.cmake index c5692fd60e..a81cdf9bb2 100644 --- a/adm/cmake/vtk.cmake +++ b/adm/cmake/vtk.cmake @@ -66,10 +66,15 @@ if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}") set (ENV{VTK_DIR} ${CACHED_VTK_DIR}) endif() +unset (IS_VTK_9XX) if (VTK_FOUND) - - # add compiler flags, preprocessor definitions, include and link dirs - include (${VTK_USE_FILE}) + message ("VTK version (${VTK_VERSION})") + if(VTK_MAJOR_VERSION EQUAL 8 AND VTK_MINOR_VERSION GREATER 9 OR VTK_MAJOR_VERSION GREATER 8) + set (IS_VTK_9XX 1) + else() + # add compiler flags, preprocessor definitions, include and link dirs + include (${VTK_USE_FILE}) + endif() if (VTK_LIBRARIES) @@ -81,79 +86,83 @@ if (VTK_FOUND) # endif() foreach (VTK_LIBRARY ${VTK_LIBRARIES}) - string (REGEX MATCH "^vtk" IS_VTK_LIBRARY ${VTK_LIBRARY}) - if (IS_VTK_LIBRARY AND TARGET ${VTK_LIBRARY}) - # get paths from corresponding variables - if (${VTK_LIBRARY}_INCLUDE_DIRS AND EXISTS "${${VTK_LIBRARY}_INCLUDE_DIRS}") - list (APPEND 3RDPARTY_VTK_INCLUDE_DIRS "${${VTK_LIBRARY}_INCLUDE_DIRS}") + if (IS_VTK_9XX) + string (REGEX MATCH "^VTK::" IS_VTK_LIBRARY ${VTK_LIBRARY}) + else() + string (REGEX MATCH "^vtk" IS_VTK_LIBRARY ${VTK_LIBRARY}) + endif() + if (NOT IS_VTK_LIBRARY OR NOT TARGET ${VTK_LIBRARY}) + continue() + endif() + + # get paths from corresponding variables + if (${VTK_LIBRARY}_INCLUDE_DIRS AND EXISTS "${${VTK_LIBRARY}_INCLUDE_DIRS}") + list (APPEND 3RDPARTY_VTK_INCLUDE_DIRS "${${VTK_LIBRARY}_INCLUDE_DIRS}") + endif() + + if (${VTK_LIBRARY}_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_LIBRARY_DIRS}") + list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_LIBRARY_DIRS}") + endif() + + if (${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") + list (APPEND 3RDPARTY_VTK_DLL_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") + if (NOT WIN32) + list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") + endif() + endif() + + # get paths from corresponding properties + get_target_property (TARGET_VTK_IMPORT_CONFS ${VTK_LIBRARY} IMPORTED_CONFIGURATIONS) + if (TARGET_VTK_IMPORT_CONFS) + list (GET TARGET_VTK_IMPORT_CONFS 0 CHOSEN_IMPORT_CONF) + + # todo: choose configuration in connection with the build type + #if (CMAKE_BUILD_TYPE) + # foreach (IMPORT_CONF ${TARGET_VTK_IMPORT_CONFS}) + # endforeach() + #endif() + + # Work-around against link failure in case if VTK contains dependency + # on DirectX: its run-time is always present on Windows, but SDK can + # be absent on current workstation, while not actually needed for + # OCCT linking. + # VTK 6.1 for VC 10 + get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF}) + if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES) + string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") + if (HARDCODED_D3D9_LIB) + message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}") + + list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB}) + set_target_properties (${VTK_LIBRARY} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF} "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") + endif() + endif() + # VTK 6.1 for VC 12, 14 + get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} INTERFACE_LINK_LIBRARIES) + if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES) + string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") + if (HARDCODED_D3D9_LIB) + message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}") + + list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB}) + set_target_properties (${VTK_LIBRARY} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") + endif() endif() - if (${VTK_LIBRARY}_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_LIBRARY_DIRS}") - list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_LIBRARY_DIRS}") - endif() + get_target_property (TARGET_PROPERTY_IMP_PATH ${VTK_LIBRARY} IMPORTED_IMPLIB_${CHOSEN_IMPORT_CONF}) + if(TARGET_PROPERTY_IMP_PATH AND EXISTS "${TARGET_PROPERTY_IMP_PATH}") + get_filename_component (TARGET_PROPERTY_IMP_DIR "${TARGET_PROPERTY_IMP_PATH}" PATH) + list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_IMP_DIR}") + endif() - if (${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") - list (APPEND 3RDPARTY_VTK_DLL_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") - if (NOT WIN32) - list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}") - endif() - endif() + get_target_property (TARGET_PROPERTY_LOCATION_PATH ${VTK_LIBRARY} IMPORTED_LOCATION_${CHOSEN_IMPORT_CONF}) + if(TARGET_PROPERTY_LOCATION_PATH AND EXISTS "${TARGET_PROPERTY_LOCATION_PATH}") + get_filename_component (TARGET_PROPERTY_LOCATION_DIR "${TARGET_PROPERTY_LOCATION_PATH}" PATH) - # get paths from corresponding properties - get_target_property (TARGET_VTK_IMPORT_CONFS ${VTK_LIBRARY} IMPORTED_CONFIGURATIONS) - - if (TARGET_VTK_IMPORT_CONFS) - list (GET TARGET_VTK_IMPORT_CONFS 0 CHOSEN_IMPORT_CONF) - - # todo: choose configuration in connection with the build type - #if (CMAKE_BUILD_TYPE) - # foreach (IMPORT_CONF ${TARGET_VTK_IMPORT_CONFS}) - # endforeach() - #endif() - - # Work-around against link failure in case if VTK contains dependency - # on DirectX: its run-time is always present on Windows, but SDK can - # be absent on current workstation, while not actually needed for - # OCCT linking. - # VTK 6.1 for VC 10 - get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF}) - if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES) - string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") - if (HARDCODED_D3D9_LIB) - message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}") - - list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB}) - set_target_properties (${VTK_LIBRARY} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF} "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") - endif() - endif() - # VTK 6.1 for VC 12, 14 - get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} INTERFACE_LINK_LIBRARIES) - if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES) - string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") - if (HARDCODED_D3D9_LIB) - message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}") - - list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB}) - set_target_properties (${VTK_LIBRARY} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}") - endif() - endif() - - get_target_property (TARGET_PROPERTY_IMP_PATH ${VTK_LIBRARY} IMPORTED_IMPLIB_${CHOSEN_IMPORT_CONF}) - if(TARGET_PROPERTY_IMP_PATH AND EXISTS "${TARGET_PROPERTY_IMP_PATH}") - get_filename_component (TARGET_PROPERTY_IMP_DIR "${TARGET_PROPERTY_IMP_PATH}" PATH) - list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_IMP_DIR}") - endif() - - get_target_property (TARGET_PROPERTY_LOCATION_PATH ${VTK_LIBRARY} IMPORTED_LOCATION_${CHOSEN_IMPORT_CONF}) - if(TARGET_PROPERTY_LOCATION_PATH AND EXISTS "${TARGET_PROPERTY_LOCATION_PATH}") - get_filename_component (TARGET_PROPERTY_LOCATION_DIR "${TARGET_PROPERTY_LOCATION_PATH}" PATH) - - if (WIN32) - list (APPEND 3RDPARTY_VTK_DLL_DIRS "${TARGET_PROPERTY_LOCATION_DIR}") - else() - list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_LOCATION_DIR}") - endif() - endif() + if (WIN32) + list (APPEND 3RDPARTY_VTK_DLL_DIRS "${TARGET_PROPERTY_LOCATION_DIR}") + else() + list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_LOCATION_DIR}") endif() endif() endif() @@ -187,6 +196,7 @@ if (VTK_FOUND) endif() endif() # endif() +endif() if (3RDPARTY_VTK_INCLUDE_DIR AND EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}") list (APPEND 3RDPARTY_INCLUDE_DIRS ${3RDPARTY_VTK_INCLUDE_DIR}) diff --git a/src/IVtkDraw/IVtkDraw.cxx b/src/IVtkDraw/IVtkDraw.cxx index 747a7657f2..93d4a2fd1a 100644 --- a/src/IVtkDraw/IVtkDraw.cxx +++ b/src/IVtkDraw/IVtkDraw.cxx @@ -51,10 +51,7 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4244) -#endif +#include #include #include #include @@ -88,9 +85,7 @@ #include #include #endif -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include #if (VTK_MAJOR_VERSION > 8) || (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) #define HAVE_VTK_SRGB diff --git a/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.cxx b/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.cxx index d20883b008..07328f16fd 100644 --- a/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.cxx +++ b/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.cxx @@ -16,9 +16,7 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include #include @@ -26,16 +24,13 @@ #include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include #include #include #include #include - IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline,Standard_Transient) //=========================================================== diff --git a/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.hxx b/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.hxx index a8e8574cf0..9e8a4e028a 100644 --- a/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.hxx +++ b/src/IVtkDraw/IVtkDraw_HighlightAndSelectionPipeline.hxx @@ -22,17 +22,13 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include #include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include #include #include diff --git a/src/IVtkDraw/IVtkDraw_Interactor.cxx b/src/IVtkDraw/IVtkDraw_Interactor.cxx index 44efe5e964..f9f68c37b6 100644 --- a/src/IVtkDraw/IVtkDraw_Interactor.cxx +++ b/src/IVtkDraw/IVtkDraw_Interactor.cxx @@ -14,9 +14,7 @@ // commercial license or contractual agreement. // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #ifdef _WIN32 #include #include @@ -30,13 +28,10 @@ #include #include #include +#include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #include #include #include diff --git a/src/IVtkDraw/IVtkDraw_Interactor.hxx b/src/IVtkDraw/IVtkDraw_Interactor.hxx index 2bfe759781..41c92fb0fc 100644 --- a/src/IVtkDraw/IVtkDraw_Interactor.hxx +++ b/src/IVtkDraw/IVtkDraw_Interactor.hxx @@ -31,14 +31,10 @@ #endif // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include #include #include diff --git a/src/IVtkTools/IVtkTools_ShapeDataSource.hxx b/src/IVtkTools/IVtkTools_ShapeDataSource.hxx index c1a6ec5dc7..32ec632a2f 100644 --- a/src/IVtkTools/IVtkTools_ShapeDataSource.hxx +++ b/src/IVtkTools/IVtkTools_ShapeDataSource.hxx @@ -19,7 +19,10 @@ #include #include #include + +#include #include +#include class vtkIdTypeArray; class vtkPolyData; diff --git a/src/IVtkTools/IVtkTools_ShapeObject.hxx b/src/IVtkTools/IVtkTools_ShapeObject.hxx index 4624f84f97..6fff02468f 100644 --- a/src/IVtkTools/IVtkTools_ShapeObject.hxx +++ b/src/IVtkTools/IVtkTools_ShapeObject.hxx @@ -20,15 +20,11 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include class vtkActor; class vtkDataSet; diff --git a/src/IVtkTools/IVtkTools_ShapePicker.hxx b/src/IVtkTools/IVtkTools_ShapePicker.hxx index bac7074143..e7e0c1cee2 100644 --- a/src/IVtkTools/IVtkTools_ShapePicker.hxx +++ b/src/IVtkTools/IVtkTools_ShapePicker.hxx @@ -21,14 +21,10 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include class vtkRenderer; class vtkActorCollection; diff --git a/src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx b/src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx index 052a9a1750..e263a020f5 100644 --- a/src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx +++ b/src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx @@ -18,7 +18,9 @@ #include -#include "vtkPolyDataAlgorithm.h" +#include +#include +#include #ifdef _MSC_VER #pragma warning(push) diff --git a/src/IVtkVTK/IVtkVTK_ShapeData.cxx b/src/IVtkVTK/IVtkVTK_ShapeData.cxx index 97b10daa2b..e647fd8df8 100644 --- a/src/IVtkVTK/IVtkVTK_ShapeData.cxx +++ b/src/IVtkVTK/IVtkVTK_ShapeData.cxx @@ -16,17 +16,13 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include #include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData,IVtk_IShapeData) diff --git a/src/IVtkVTK/IVtkVTK_ShapeData.hxx b/src/IVtkVTK/IVtkVTK_ShapeData.hxx index 04ceac3371..0fda1748ab 100644 --- a/src/IVtkVTK/IVtkVTK_ShapeData.hxx +++ b/src/IVtkVTK/IVtkVTK_ShapeData.hxx @@ -19,15 +19,11 @@ #include // prevent disabling some MSVC warning messages by VTK headers -#ifdef _MSC_VER -#pragma warning(push) -#endif +#include #include #include #include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include class vtkIdTypeArray;