paraviewFunctions 6.38 KB
Newer Older
Mark Olesen's avatar
Mark Olesen committed
1
2
3
4
#----------------------------------*-sh-*--------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
#   \\  /    A nd           | www.openfoam.com
Mark Olesen's avatar
Mark Olesen committed
6
7
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
8
#     Copyright (C) 2018-2020 OpenCFD Ltd.
OpenFOAM bot's avatar
OpenFOAM bot committed
9
#------------------------------------------------------------------------------
Mark Olesen's avatar
Mark Olesen committed
10
# License
Mark Olesen's avatar
Mark Olesen committed
11
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Mark Olesen's avatar
Mark Olesen committed
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# Script
#     paraviewFunctions
#
# Description
#     Helper functions for CMake with ParaView.
#     Setup of variables for creating ParaView plugins
#
# Requires
#     ParaView_DIR  (unless system)
#     PV_PLUGIN_PATH
#
# Provides Functions
25
#     get_pvplugin_api, have_pvplugin_support, no_paraview, echo_paraview
26
#     cmakeVtk, cmakePv, cmakePvInstall
Mark Olesen's avatar
Mark Olesen committed
27
28
29
30
#
# Variables on success
#     HAVE_PVPLUGIN_SUPPORT
#     FOAM_PV_PLUGIN_LIBBIN
31
#     PARAVIEW_API - the paraview major/minor numbers (eg 5.6)
Mark Olesen's avatar
Mark Olesen committed
32
33
34
35
36
37
38
#     PARAVIEW_INC_DIR
#
# Note
#     The OpenFOAM plugin must be the first in PV_PLUGIN_PATH and have
#     paraview-major.minor encoded in its name.
#
#------------------------------------------------------------------------------
39
40
. ${WM_PROJECT_DIR:?}/wmake/scripts/sysFunctions    # General system functions
. ${WM_PROJECT_DIR:?}/wmake/scripts/cmakeFunctions  # Require cmake functions
Mark Olesen's avatar
Mark Olesen committed
41
42
43
44
45
46
47

#------------------------------------------------------------------------------

# Reset variables
no_paraview()
{
    unset HAVE_PVPLUGIN_SUPPORT FOAM_PV_PLUGIN_LIBBIN
48
    unset PARAVIEW_API PARAVIEW_INC_DIR
Mark Olesen's avatar
Mark Olesen committed
49
50
51
52
53
54
55
56
57
58
59
    return 0
}


# Report
echo_paraview()
{
    echo "paraview=${HAVE_PVPLUGIN_SUPPORT:-false}"
    echo "root=$ParaView_DIR"
    echo "include=$PARAVIEW_INC_DIR"
    echo "plugin=$FOAM_PV_PLUGIN_LIBBIN"
60
    echo "api=$PARAVIEW_API"
Mark Olesen's avatar
Mark Olesen committed
61
62
63
64
}


# CMake into objectsDir with VTK_DIR dependency
65
66
# 1 - sourceDir
# 2.. optional cmake defines
Mark Olesen's avatar
Mark Olesen committed
67
68
cmakeVtk()
{
69
    cmakeVersioned "VTK_DIR=$VTK_DIR" "$@"
Mark Olesen's avatar
Mark Olesen committed
70
71
72
73
}


# CMake into objectsDir with ParaView_DIR dependency
74
75
# 1 - sourceDir
# 2.. optional cmake defines
Mark Olesen's avatar
Mark Olesen committed
76
77
cmakePv()
{
78
    cmakeVersioned "ParaView_DIR=$ParaView_DIR" "$@"
Mark Olesen's avatar
Mark Olesen committed
79
80
}

81
# CMake into objectsDir with ParaView_DIR dependency
82
83
# 1 - sourceDir
# 2.. optional cmake defines
84
85
cmakePvInstall()
{
86
    cmakeVersionedInstall "ParaView_DIR=$ParaView_DIR" "$@"
87
88
}

Mark Olesen's avatar
Mark Olesen committed
89
90
91
92
93
94
95
96
97
98
#
# Build library - use sentinel file(s) to handle paraview version changes
#
wmakeLibPv()
{
    local depend="ParaView_DIR=$ParaView_DIR"
    local sentinel

    for libName
    do
99
        sentinel=$(sameDependency "$depend" "$libName") || \
Mark Olesen's avatar
Mark Olesen committed
100
101
102
            wclean $libName

        wmake $targetType $libName \
103
        && storeDependency "$depend" "$sentinel"
Mark Olesen's avatar
Mark Olesen committed
104
105
106
107
    done
}


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Extract ParaView plugin api number from PV_PLUGIN_PATH
# On success, return 0 and export variables
# -> FOAM_PV_PLUGIN_LIBBIN, PARAVIEW_API
#
get_pvplugin_api()
{
    # OK
    unset FOAM_PV_PLUGIN_LIBBIN  PARAVIEW_API
    local pv_api targetDir

    # The OpenFOAM plugin must be the first in PV_PLUGIN_PATH
    # and must have the paraview major+minor version encoded in its name!
    # Eg, PV_PLUGIN_PATH="$FOAM_LIBBIN/paraview-5.5"

    # Get the first entry from PV_PLUGIN_PATH=dir1;dir2;...
    targetDir="${PV_PLUGIN_PATH##;}"
    targetDir="${targetDir%%;*}"

    # Extract paraview major+minor version from the directory name
    # From /path/paraview-5.6 -> 5.6
    pv_api=$(echo "$targetDir" | \
        sed -ne 's@^.*/@@;s/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p')

    [ -n "$pv_api" ] || return 1

    # OK
    export FOAM_PV_PLUGIN_LIBBIN="$targetDir"
    export PARAVIEW_API="$pv_api"

    return 0 # success
}


Mark Olesen's avatar
Mark Olesen committed
141
142
143
# Test if a ParaView plugin can be built.
# On success, return 0 and export variables
# -> HAVE_PVPLUGIN_SUPPORT, FOAM_PV_PLUGIN_LIBBIN,
144
#    PARAVIEW_API, PARAVIEW_INC_DIR
Mark Olesen's avatar
Mark Olesen committed
145
146
147
148
149
#
# There are several prerequisites for building plugins
#
have_pvplugin_support()
{
150
    local header warn pv_api installDir binDir includeDir targetDir
Mark Olesen's avatar
Mark Olesen committed
151
152
153
    warn="==> skip paraview-plugin"

    # Trivial check
154
    command -v cmake >/dev/null || {
Mark Olesen's avatar
Mark Olesen committed
155
156
157
158
        echo "$warn (no cmake)"
        return 1
    }

159
160
161
162
163
164
    if get_pvplugin_api
    then
        targetDir="$FOAM_PV_PLUGIN_LIBBIN"
        pv_api="$PARAVIEW_API"
    fi
    unset FOAM_PV_PLUGIN_LIBBIN PARAVIEW_API
Mark Olesen's avatar
Mark Olesen committed
165

166
167
168
    if [ -z "$targetDir" ] || [ -z "$pv_api" ]
    then
        echo "$warn (could not determine target or major.minor version)"
Mark Olesen's avatar
Mark Olesen committed
169
170
        echo "    PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-???}"
        return 1
171
    fi
Mark Olesen's avatar
Mark Olesen committed
172

173
    # Include/library names
Mark Olesen's avatar
Mark Olesen committed
174
175
176
177
178
179
180
    header="pqServerManagerModel.h"

    if [ -n "$ParaView_DIR" ]
    then
        # ParaView_DIR defined. Look for include/

        header=$(findFirstFile \
181
            "$ParaView_DIR/include/paraview-$pv_api/$header" \
Mark Olesen's avatar
Mark Olesen committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
            "$ParaView_DIR/include/paraview/$header"
        )

    else
        # No ParaView_DIR defined
        # - use location of 'paraview' to guess an equivalent ParaView_DIR
        # - assume we can use paraview-config

        binDir="$(command -v paraview 2>/dev/null)"
        binDir="${binDir%/*}"       # Eg, /usr/bin/paraview -> /usr/bin
        installDir="${binDir%/*}"   # Eg, /usr/bin -> /usr

        case "$installDir" in
        (/*)    # An absolute path
            includeDir="$installDir/include"  # Eg, /usr -> /usr/include
        ;;
        esac

        header=$(findFirstFile \
            "$(paraview-config --include 2>/dev/null |sed -ne 's/^ *-I//p')/$header"\
202
            "${includeDir:+$includeDir/paraview-$pv_api/$header}" \
Mark Olesen's avatar
Mark Olesen committed
203
            "${includeDir:+$includeDir/paraview/$header}" \
204
            /usr/local/include/"paraview-$pv_api/$header" \
Mark Olesen's avatar
Mark Olesen committed
205
            /usr/local/include/paraview/"$header" \
206
            /usr/include/"paraview-$pv_api/$header" \
Mark Olesen's avatar
Mark Olesen committed
207
208
209
210
            /usr/include/paraview/"$header" \
            )
    fi

211
    # ----------------------------------
Mark Olesen's avatar
Mark Olesen committed
212

213
    # Header
Mark Olesen's avatar
Mark Olesen committed
214
215
216
217
218
    [ -n "$header" ] || {
        [ -n "$warn" ] && echo "$warn (no header)"
        return 2
    }

219
220
    # ----------------------------------

Mark Olesen's avatar
Mark Olesen committed
221
    # OK
Mark Olesen's avatar
Mark Olesen committed
222
223
    export HAVE_PVPLUGIN_SUPPORT=true
    export FOAM_PV_PLUGIN_LIBBIN="$targetDir"
224
    export PARAVIEW_API="$pv_api"
Mark Olesen's avatar
Mark Olesen committed
225
226
227
228
229
230
231
232
233
    export PARAVIEW_INC_DIR="${header%/*}"      # Basename

    return 0 # success
}


# Force reset of old variables
no_paraview

Mark Olesen's avatar
Mark Olesen committed
234
235
236
# Test/query
case "$1" in
-test)
Mark Olesen's avatar
Mark Olesen committed
237
238
    have_pvplugin_support
    echo_paraview
Mark Olesen's avatar
Mark Olesen committed
239
240
241
242
243
    ;;
-query)
    ## query_paraview
    ;;
esac
Mark Olesen's avatar
Mark Olesen committed
244
245

#------------------------------------------------------------------------------