1dnl--------------------------------------------------------------------------------
2dnl
3dnl This file is part of Code_Saturne, a general-purpose CFD tool.
4dnl
5dnl Copyright (C) 1998-2021 EDF S.A.
6dnl
7dnl This program is free software; you can redistribute it and/or modify it under
8dnl the terms of the GNU General Public License as published by the Free Software
9dnl Foundation; either version 2 of the License, or (at your option) any later
10dnl version.
11dnl
12dnl This program is distributed in the hope that it will be useful, but WITHOUT
13dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14dnl FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15dnl details.
16dnl
17dnl You should have received a copy of the GNU General Public License along with
18dnl this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
19dnl Street, Fifth Floor, Boston, MA 02110-1301, USA.
20dnl
21dnl--------------------------------------------------------------------------------
22
23# CS_AC_TEST_CCM
24#---------------
25# modifies or sets cs_have_ccm, CCM_CPPFLAGS, CCM_LDFLAGS, and CCM_LIBS
26# depending on libraries found
27
28AC_DEFUN([CS_AC_TEST_CCM], [
29
30cs_have_ccm=no
31cs_have_ccm_headers=no
32
33AC_ARG_WITH(ccm,
34            [AS_HELP_STRING([--with-ccm=DIR],
35                            [specify prefix directory for CCMIO])],
36            [if test "x$withval" = "x"; then
37               with_ccm=yes
38             fi],
39            [with_ccm=check])
40
41AC_ARG_WITH(ccm-include,
42            [AS_HELP_STRING([--with-ccm-include=DIR],
43                            [specify directory for CCMIO include files])],
44            [if test "x$with_ccm" = "xcheck"; then
45               with_ccm=yes
46             fi
47             CCM_CPPFLAGS="-I$with_ccm_include"],
48            [if test "x$with_ccm" != "xno" -a "x$with_ccm" != "xyes" \
49	          -a "x$with_ccm" != "xcheck"; then
50               CCM_CPPFLAGS="-I$with_ccm/include"
51             fi])
52
53AC_ARG_WITH(ccm-lib,
54            [AS_HELP_STRING([--with-ccm-lib=DIR],
55                            [specify directory for CCMIO library])],
56            [if test "x$with_ccm" = "xcheck"; then
57               with_ccm=yes
58             fi
59             CCM_LDFLAGS="-L$with_ccm_lib"
60             # Add the libdir to the runpath as CCM is not libtoolized
61             CCMRUNPATH="-R$with_ccm_lib"],
62            [if test "x$with_ccm" != "xno" -a "x$with_ccm" != "xyes" \
63	          -a "x$with_ccm" != "xcheck"; then
64               CCM_LDFLAGS="-L$with_ccm/lib"
65               # Add the libdir to the runpath as CCM is not libtoolized
66               CCMRUNPATH="-R$with_ccm/lib"
67             fi])
68
69if test "x$with_ccm" != "xno" ; then
70
71  saved_CPPFLAGS="$CPPFLAGS"
72  saved_LDFLAGS="$LDFLAGS"
73  saved_LIBS="$LIBS"
74
75  # ADF is be provided directly (patched ADF with libccmio)
76  # We must be careful not to use CGNS's adf, as this leads to nonworking
77  # CCM-IO builds. CCM's LDFLAGS must thus come first...
78
79  CCM_LIBS="-lccmio -ladf"
80  CPPFLAGS="${CPPFLAGS} ${CCM_CPPFLAGS}"
81  LDFLAGS="${LDFLAGS} ${CCM_LDFLAGS}"
82  LIBS="${CCM_LIBS} ${LIBS}"
83
84# Check that CCMIO header files exist
85
86  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
87[[#include <libccmio/ccmio.h>]],
88[[int i = kCCMIONoErr;]])],
89                    [AC_MSG_RESULT([CCMIO headers found])
90                     cs_have_ccm_headers=yes
91                    ],
92                    [AC_MSG_RESULT([CCMIO headers not found])
93                    ])
94
95  if test "x$cs_have_ccm_headers" = "xyes"; then
96
97    AC_MSG_CHECKING([for CCM file support])
98    AC_LINK_IFELSE([AC_LANG_PROGRAM(
99[[#include <libccmio/ccmio.h>]],
100[[CCMIOID root;
101CCMIOError error = kCCMIONoErr;
102CCMIOOpenFile(&error, "test.ccm", kCCMIOWrite, &root);]])
103                   ],
104                   [ AC_DEFINE([HAVE_CCM], 1, [CCM file support])
105                     cs_have_ccm=yes
106                   ],
107                   [],
108                   )
109    AC_MSG_RESULT($cs_have_ccm)
110    if test "x$cs_have_ccm" = "xno" ; then
111      if test "x$with_ccm" != "xcheck" ; then
112        AC_MSG_FAILURE([CCM support is requested, but test for CCM failed!])
113      fi
114    fi
115  fi
116
117  if test "x$cs_have_ccm" != "xyes"; then
118    CCM_LIBS=""
119  fi
120
121  CPPFLAGS="$saved_CPPFLAGS"
122  LDFLAGS="$saved_LDFLAGS"
123  LIBS="$saved_LIBS"
124
125  unset saved_CPPFLAGS
126  unset saved_LDFLAGS
127  unset saved_LIBS
128
129fi
130
131AM_CONDITIONAL(HAVE_CCM, test x$cs_have_ccm = xyes)
132
133AC_SUBST(cs_have_ccm)
134AC_SUBST(CCM_CPPFLAGS)
135AC_SUBST(CCM_LDFLAGS)
136AC_SUBST(CCM_LIBS)
137AC_SUBST(CCMRUNPATH)
138
139])dnl
140
141