From 26f5a091fec6811bf95acb718cf79e2554a33fe3 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 23 Jan 2020 13:16:23 +0100 Subject: [PATCH] ENH: support plugin building for paraview-5.7 Note For paraview-5.7 (and later?) plugins are built into their own subdirs. It also is not possible to suppress creation of static libraries in the process. The current solution is still a bit ugly - install into a local "staged" location (within the build directory) - use rsync to relocate to the .so files to the plugin directory --- src/paraview-plugins/Allwmake | 57 ++++++++++++++-- .../blockMeshReader/CMakeLists-Project57.txt | 42 +++++++++++- .../blockMeshReader/plugin/CMakeLists.txt | 32 +++++++++ .../blockMeshReader/plugin/paraview.plugin | 12 ++++ .../plugin/reader/CMakeLists.txt | 64 ++++++++++++++++++ .../blockMeshReader/plugin/reader/vtk.module | 9 +++ .../foamReader/CMakeLists-Project57.txt | 41 +++++++++++- .../foamReader/plugin/CMakeLists.txt | 32 +++++++++ .../foamReader/plugin/paraview.plugin | 12 ++++ .../foamReader/plugin/reader/CMakeLists.txt | 66 +++++++++++++++++++ .../foamReader/plugin/reader/vtk.module | 9 +++ 11 files changed, 369 insertions(+), 7 deletions(-) create mode 100644 src/paraview-plugins/blockMeshReader/plugin/CMakeLists.txt create mode 100644 src/paraview-plugins/blockMeshReader/plugin/paraview.plugin create mode 100644 src/paraview-plugins/blockMeshReader/plugin/reader/CMakeLists.txt create mode 100644 src/paraview-plugins/blockMeshReader/plugin/reader/vtk.module create mode 100644 src/paraview-plugins/foamReader/plugin/CMakeLists.txt create mode 100644 src/paraview-plugins/foamReader/plugin/paraview.plugin create mode 100644 src/paraview-plugins/foamReader/plugin/reader/CMakeLists.txt create mode 100644 src/paraview-plugins/foamReader/plugin/reader/vtk.module diff --git a/src/paraview-plugins/Allwmake b/src/paraview-plugins/Allwmake index 6dbaa02..2cc1bfa 100755 --- a/src/paraview-plugins/Allwmake +++ b/src/paraview-plugins/Allwmake @@ -3,7 +3,19 @@ cd "${0%/*}" || exit # Run from this directory export WM_CONTINUE_ON_ERROR=true # Optional unit . ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments . ${WM_PROJECT_DIR:?}/wmake/scripts/paraviewFunctions # CMake, PV functions -# ----------------------------------------------------------------------------- +#------------------------------------------------------------------------------ +# Copyright (C) 2020 OpenCFD Ltd. +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# Note +# For paraview-5.7 (and later?) plugins are built into their own subdirs. +# It also is not possible to suppress creation of static libraries in the +# process. +# +# Current solution (ugly) +# - install into a local "staged" location (within the build directory) +# - use rsync to relocate to the .so files to the plugin directory +#------------------------------------------------------------------------------ warnIncomplete() { @@ -20,6 +32,7 @@ then wmakeLibPv foamReader/library unset cmakeOpts cmakeType + unset installDir if [ "$targetType" != objects ] then @@ -28,16 +41,50 @@ then cmakeType="cmakePv" ;; (*) - # cmakeType="cmakePvInstall" - warnIncomplete "(unknown/unsupported version: $PARAVIEW_API)" + if installDir=$(findObjectDir '.') + then + installDir="$installDir/install-prefix" + + # Require an absolute directory for CMake + if [ "${installDir#/}" = "$installDir" ] + then + installDir="$PWD/$installDir" + fi + + cmakeOpts="$cmakeOpts -DSTAGED_INSTALL_PREFIX=$installDir" + cmakeType="cmakePvInstall" + else + cmakeType="cmakePv" # cmakeType="cmakePvInstall" + fi ;; esac fi + rm -rf "$installDir" + if [ -n "$cmakeType" ] then - "$cmakeType" $PWD/blockMeshReader "$cmakeOpts" || warnIncomplete "blockMesh" - "$cmakeType" $PWD/foamReader "$cmakeOpts" || warnIncomplete "OpenFOAM" + "$cmakeType" "$PWD"/blockMeshReader "$cmakeOpts" || warnIncomplete "blockMesh" + "$cmakeType" "$PWD"/foamReader "$cmakeOpts" || warnIncomplete "OpenFOAM" + fi + + if [ -d "$installDir" ] + then + [ -d "$FOAM_PV_PLUGIN_LIBBIN" ] || mkdir -p "$FOAM_PV_PLUGIN_LIBBIN" + + # TODO: handle via targets via CMake + for dir in "$installDir/lib" "$installDir/lib64" + do + if [ -d "$dir" ] + then + echo + for libName in $(find "$dir" -name '*.so') + do + echo "Plugin: ${FOAM_PV_PLUGIN_LIBBIN##*/}/${libName##*/}" + rsync -a "$libName" "$FOAM_PV_PLUGIN_LIBBIN" + done + fi + done fi ) fi diff --git a/src/paraview-plugins/blockMeshReader/CMakeLists-Project57.txt b/src/paraview-plugins/blockMeshReader/CMakeLists-Project57.txt index 718a531..600f23f 100644 --- a/src/paraview-plugins/blockMeshReader/CMakeLists-Project57.txt +++ b/src/paraview-plugins/blockMeshReader/CMakeLists-Project57.txt @@ -1,6 +1,46 @@ #----------------------------------------------------------------------------- # OpenFOAM blockMeshDict reader plugin for ParaView GUI (5.7+) -message(FATAL_ERROR "paraview-${pv_api} not yet supported") +set(CMAKE_BUILD_TYPE Release) + +cmake_minimum_required(VERSION 3.8) +project(ParaFoamBlockReader) +find_package(ParaView REQUIRED) + +include(GNUInstallDirs) +if (STAGED_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "${STAGED_INSTALL_PREFIX}") + ## message("use staged install: ${STAGED_INSTALL_PREFIX}") +else() + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}") +endif() + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + +set(PARAVIEW_PLUGIN_ENABLE_ParaFoamBlockReader TRUE) + +set("_paraview_plugin_default_${CMAKE_PROJECT_NAME}" ON) +paraview_plugin_scan( + PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin" + PROVIDES_PLUGINS plugins + REQUIRES_MODULES required_modules) + +foreach(module IN LISTS required_modules) + if(NOT TARGET "${module}") + message("Missing required module: ${module}") + return() + endif() +endforeach() + +# Install under <platform>/<arch>/lib, not lib64 +paraview_plugin_build( + PLUGINS ${plugins} + AUTOLOAD ${plugins} + RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY_SUBDIRECTORY "${PARAVIEW_PLUGIN_SUBDIR}" +) #----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/blockMeshReader/plugin/CMakeLists.txt b/src/paraview-plugins/blockMeshReader/plugin/CMakeLists.txt new file mode 100644 index 0000000..ee33da9 --- /dev/null +++ b/src/paraview-plugins/blockMeshReader/plugin/CMakeLists.txt @@ -0,0 +1,32 @@ +#----------------------------------------------------------------------------- +# OpenFOAM blockMesh reader plugin for ParaView GUI + +qt5_wrap_cpp(MOC_SRCS pqFoamBlockMeshControls.h) + +paraview_plugin_add_property_widget( + KIND GROUP_WIDGET + TYPE "openfoam_blockreader_general_controls" + CLASS_NAME pqFoamBlockMeshControls + INTERFACES IFACES0 + SOURCES IFACES0_SRCS) + +set(BUILD_SHARED_LIBS_BACKUP ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS ON) +paraview_add_plugin(ParaFoamBlockReader + VERSION "${foam_api}" + UI_INTERFACES + ${IFACES0} + SOURCES + ${IFACES0_SRCS} + ${MOC_SRCS} + pqFoamBlockMeshControls.cxx + MODULES blockMeshReader + MODULE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/reader/vtk.module" + SERVER_MANAGER_XML ParaFoamBlockReader.xml +) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_BACKUP}) + +target_link_libraries(ParaFoamBlockReader + PUBLIC ParaView::pqApplicationComponents) + +#----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/blockMeshReader/plugin/paraview.plugin b/src/paraview-plugins/blockMeshReader/plugin/paraview.plugin new file mode 100644 index 0000000..8a8fa77 --- /dev/null +++ b/src/paraview-plugins/blockMeshReader/plugin/paraview.plugin @@ -0,0 +1,12 @@ +NAME + ParaFoamBlockReader +DESCRIPTION + Provides an OpenFOAM blockMesh reader plugin for ParaView GUI +CONDITION + PARAVIEW_BUILD_QT_GUI +REQUIRES_MODULES + ParaView::Core + ParaView::ClientServerCoreCore + ParaView::ServerManagerCore + ParaView::ServerManagerRendering + ParaView::pqApplicationComponents diff --git a/src/paraview-plugins/blockMeshReader/plugin/reader/CMakeLists.txt b/src/paraview-plugins/blockMeshReader/plugin/reader/CMakeLists.txt new file mode 100644 index 0000000..6e0fb65 --- /dev/null +++ b/src/paraview-plugins/blockMeshReader/plugin/reader/CMakeLists.txt @@ -0,0 +1,64 @@ +#----------------------------------------------------------------------------- +set(classes vtkPVblockMeshReader) + +vtk_module_add_module(blockMeshReader + FORCE_STATIC + CLASSES ${classes}) + +target_include_directories(blockMeshReader + PUBLIC + ${LIB_SRC}/OpenFOAM/include + ${LIB_SRC}/OpenFOAM/lnInclude + ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude + ${LIB_SRC}/fileFormats/lnInclude + ${LIB_SRC}/conversion/lnInclude + ${LIB_SRC}/meshTools/lnInclude + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/library +) + +set(OPENFOAM_LIBNAMES + OpenFOAM + fileFormats + conversion + meshTools +) + + +# With cmake 3.12 and newer, can simply use target_link_directories + +# target_link_directories(blockMeshReader +# PUBLIC +# $ENV{FOAM_LIBBIN} +# ) + +# target_link_libraries(blockMeshReader +# PUBLIC +# vtkPVFoamCommon${foamPvLibQualifier} +# vtkPVblockReader${foamPvLibQualifier} +# ${OPENFOAM_LIBNAMES} +# ) + + +# Older cmake. Do manually + +link_directories( + $ENV{FOAM_LIBBIN} +) + +unset(OPENFOAM_LIBS) + +foreach(libname ${OPENFOAM_LIBNAMES}) + unset(libpath CACHE) + find_library(libpath ${libname} PATHS $ENV{FOAM_LIBBIN}) + list(APPEND OPENFOAM_LIBS ${libpath}) +endforeach(libname) + +target_link_libraries(blockMeshReader + PUBLIC + vtkPVFoamCommon${foamPvLibQualifier} + vtkPVblockReader${foamPvLibQualifier} + ${OPENFOAM_LIBS} +) + +#----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/blockMeshReader/plugin/reader/vtk.module b/src/paraview-plugins/blockMeshReader/plugin/reader/vtk.module new file mode 100644 index 0000000..9d12c71 --- /dev/null +++ b/src/paraview-plugins/blockMeshReader/plugin/reader/vtk.module @@ -0,0 +1,9 @@ +NAME + blockMeshReader +DEPENDS + VTK::CommonCore + VTK::CommonDataModel + VTK::CommonExecutionModel +PRIVATE_DEPENDS + ParaView::pqCore + ParaView::ServerManagerRendering diff --git a/src/paraview-plugins/foamReader/CMakeLists-Project57.txt b/src/paraview-plugins/foamReader/CMakeLists-Project57.txt index c5d5236..6e2da83 100644 --- a/src/paraview-plugins/foamReader/CMakeLists-Project57.txt +++ b/src/paraview-plugins/foamReader/CMakeLists-Project57.txt @@ -1,6 +1,45 @@ #----------------------------------------------------------------------------- # OpenFOAM reader plugin for ParaView GUI (5.7+) -message(FATAL_ERROR "paraview-${pv_api} not yet supported") +set(CMAKE_BUILD_TYPE Release) + +cmake_minimum_required(VERSION 3.8) +project(ParaFoamReader) +find_package(ParaView REQUIRED) + +include(GNUInstallDirs) +if (STAGED_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "${STAGED_INSTALL_PREFIX}") + ## message("use staged install: ${STAGED_INSTALL_PREFIX}") +else() + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}") +endif() + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + +set(PARAVIEW_PLUGIN_ENABLE_ParaFoamReader TRUE) + +set("_paraview_plugin_default_${CMAKE_PROJECT_NAME}" ON) +paraview_plugin_scan( + PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin" + PROVIDES_PLUGINS plugins + REQUIRES_MODULES required_modules) + +foreach(module IN LISTS required_modules) + if(NOT TARGET "${module}") + message("Missing required module: ${module}") + return() + endif() +endforeach() + +paraview_plugin_build( + PLUGINS ${plugins} + AUTOLOAD ${plugins} + RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY_SUBDIRECTORY "${PARAVIEW_PLUGIN_SUBDIR}" +) #----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/foamReader/plugin/CMakeLists.txt b/src/paraview-plugins/foamReader/plugin/CMakeLists.txt new file mode 100644 index 0000000..9727894 --- /dev/null +++ b/src/paraview-plugins/foamReader/plugin/CMakeLists.txt @@ -0,0 +1,32 @@ +#----------------------------------------------------------------------------- +# OpenFOAM reader plugin for ParaView GUI + +qt5_wrap_cpp(MOC_SRCS pqFoamReaderControls.h) + +paraview_plugin_add_property_widget( + KIND GROUP_WIDGET + TYPE "openfoam_reader_general_controls" + CLASS_NAME pqFoamReaderControls + INTERFACES IFACES0 + SOURCES IFACES0_SRCS) + +set(BUILD_SHARED_LIBS_BACKUP ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS ON) +paraview_add_plugin(ParaFoamReader + VERSION "${foam_api}" + UI_INTERFACES + ${IFACES0} + SOURCES + ${IFACES0_SRCS} + ${MOC_SRCS} + pqFoamReaderControls.cxx + MODULES FoamReader + MODULE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/reader/vtk.module" + SERVER_MANAGER_XML ParaFoamReader.xml +) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_BACKUP}) + +target_link_libraries(ParaFoamReader + PUBLIC ParaView::pqApplicationComponents) + +#----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/foamReader/plugin/paraview.plugin b/src/paraview-plugins/foamReader/plugin/paraview.plugin new file mode 100644 index 0000000..5699c8c --- /dev/null +++ b/src/paraview-plugins/foamReader/plugin/paraview.plugin @@ -0,0 +1,12 @@ +NAME + ParaFoamReader +DESCRIPTION + Provides an OpenFOAM reader plugin for ParaView GUI +CONDITION + PARAVIEW_BUILD_QT_GUI +REQUIRES_MODULES + ParaView::Core + ParaView::ClientServerCoreCore + ParaView::ServerManagerCore + ParaView::ServerManagerRendering + ParaView::pqApplicationComponents diff --git a/src/paraview-plugins/foamReader/plugin/reader/CMakeLists.txt b/src/paraview-plugins/foamReader/plugin/reader/CMakeLists.txt new file mode 100644 index 0000000..54a2bd6 --- /dev/null +++ b/src/paraview-plugins/foamReader/plugin/reader/CMakeLists.txt @@ -0,0 +1,66 @@ +#----------------------------------------------------------------------------- +set(classes vtkPVFoamReader) + +vtk_module_add_module(FoamReader + FORCE_STATIC + CLASSES ${classes}) + +target_include_directories(FoamReader + PUBLIC + ${LIB_SRC}/OpenFOAM/include + ${LIB_SRC}/OpenFOAM/lnInclude + ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude + ${LIB_SRC}/fileFormats/lnInclude + ${LIB_SRC}/conversion/lnInclude + ${LIB_SRC}/finiteArea/lnInclude + ${LIB_SRC}/finiteVolume/lnInclude + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/library +) + +set(OPENFOAM_LIBNAMES + OpenFOAM + fileFormats + conversion + finiteArea + finiteVolume +) + + +# With cmake 3.12 and newer, can simply use target_link_directories + +# target_link_directories(FoamReader +# PUBLIC +# $ENV{FOAM_LIBBIN} +# ) + +# target_link_libraries(FoamReader +# PUBLIC +# vtkPVFoamCommon${foamPvLibQualifier} +# vtkPVFoamReader${foamPvLibQualifier} +# ${OPENFOAM_LIBNAMES} +# ) + + +# Older cmake. Do manually + +link_directories( + $ENV{FOAM_LIBBIN} +) + +unset(OPENFOAM_LIBS) + +foreach(libname ${OPENFOAM_LIBNAMES}) + unset(libpath CACHE) + find_library(libpath ${libname} PATHS $ENV{FOAM_LIBBIN}) + list(APPEND OPENFOAM_LIBS ${libpath}) +endforeach(libname) + +target_link_libraries(FoamReader + PUBLIC + vtkPVFoamCommon${foamPvLibQualifier} + vtkPVFoamReader${foamPvLibQualifier} + ${OPENFOAM_LIBS} +) + +#----------------------------------------------------------------------------- diff --git a/src/paraview-plugins/foamReader/plugin/reader/vtk.module b/src/paraview-plugins/foamReader/plugin/reader/vtk.module new file mode 100644 index 0000000..a750e5a --- /dev/null +++ b/src/paraview-plugins/foamReader/plugin/reader/vtk.module @@ -0,0 +1,9 @@ +NAME + FoamReader +DEPENDS + VTK::CommonCore + VTK::CommonDataModel + VTK::CommonExecutionModel +PRIVATE_DEPENDS + ParaView::pqCore + ParaView::ServerManagerRendering -- GitLab