fix: out-of-bounds memory access in axis_utils2 (#1157)
[FMS.git] / configure.ac
blob82588b6c84928a9a1338c836e39e402e94b36376
1 #***********************************************************************
2 #*                   GNU Lesser General Public License
3 #*
4 #* This file is part of the GFDL Flexible Modeling System (FMS).
5 #*
6 #* FMS is free software: you can redistribute it and/or modify it under
7 #* the terms of the GNU Lesser General Public License as published by
8 #* the Free Software Foundation, either version 3 of the License, or (at
9 #* your option) any later version.
11 #* FMS is distributed in the hope that it will be useful, but WITHOUT
12 #* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 #* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 #* for more details.
16 #* You should have received a copy of the GNU Lesser General Public
17 #* License along with FMS.  If not, see <http://www.gnu.org/licenses/>.
18 #***********************************************************************
20 # This is the main configure file for the FMS package.
21 # Ed Hartnett 2/21/2019
22 # Seth Underwood 10/2/2019
24 AC_PREREQ([2.69])
26 # Initialize with name, version, and support email address.
27 AC_INIT([GFDL FMS Library],
28   [2023.01.00-dev],
29   [gfdl.climate.model.info@noaa.gov],
30   [FMS],
31   [https://www.github.com/NOAA-GFDL/FMS])
33 # Find out about the host we're building on.
34 AC_CANONICAL_HOST
35 AC_CANONICAL_BUILD
37 # Find out about the target we're building for.
38 AC_CANONICAL_TARGET
40 AC_CONFIG_MACRO_DIR([m4])
42 AM_INIT_AUTOMAKE([foreign dist-zip subdir-objects])
44 # Set up libtool.
45 LT_PREREQ([2.4])
46 LT_INIT()
48 # If building on a Cray PE system, check if CRAYPE_LINK_TYPE is 'static'.  If it
49 # is, then disable building shared libraries.  Note, the user can still override
50 # this by using --enable-shared when running the configure script.
51 AS_IF([test x${CRAYPE_VERSION:+yes} = "xyes"],[
52   AS_IF([test x${CRAYPE_LINK_TYPE} = "xstatic"],
53         [AC_DISABLE_SHARED])])
56 # Process user optons.
57 AC_ARG_ENABLE([mixed-mode],
58   [AS_HELP_STRING([--enable-mixed-mode],
59     [Build using mixed mode.  Enables both 64-bit and 32-bit reals in Fortran. This option will be ignored if --disable-fortran-flag-setting is also given.])])
60 AS_IF([test ${enable_mixed_mode:-no} = no],
61   [enable_mixed_mode=no],
62   [enable_mixed_mode=yes])
63 AC_ARG_WITH([mpi],
64   [AS_HELP_STRING([--with-mpi],
65     [Build with MPI support.  This option will be ignored if --disable-fortran-flag-setting is also given. (Default yes)])])
66 AS_IF([test ${with_mpi:-yes} = yes],
67   [with_mpi=yes],
68   [with_mpi=no])
69 AC_ARG_WITH([yaml],
70   [AS_HELP_STRING([--with-yaml],
71     [Build with YAML support.  This option will be ignored if --disable-fortran-flag-setting is also given. (Default no)])])
72 AS_IF([test ${with_yaml:-no} = no],
73   [with_yaml=no],
74   [with_yaml=yes])
75 AC_ARG_ENABLE([setting-flags],
76   [AS_HELP_STRING([--enable-setting-flags],
77     [Allow configure to set some compiler flags.  Disabling this will also disable any other --with or --enable options that set flags, and will only use user-provided falgs. (Default yes)])])
78 AS_IF([test ${enable_setting_flags:-yes} = yes],
79   [enable_setting_flags=yes],
80   [enable_setting_flags=no])
81 AC_ARG_ENABLE([code-coverage],
82   [AS_HELP_STRING([--enable-code-coverage],
83     [Allow configure to set flags and add check-code-coverage target for code coverage analysis (Default no)])])
84 AS_IF([test ${enable_code_coverage:-no} = no],
85   [enable_code_coverage=no],
86   [enable_code_coverage=yes])
87 # individual mixed precision overload macros
88 AC_ARG_ENABLE([overload-r4],
89   [AS_HELP_STRING([--enable-overload-r4],
90     [Enables the OVERLOAD_R4 macro to compile with 4 byte real routine overloads. (Default no)])])
91 AS_IF([test ${enable_overload_r4:-no} = yes],
92   [enable_overload_r4=yes],
93   [enable_overload_r4=no])
94 AC_ARG_ENABLE([overload-c4],
95   [AS_HELP_STRING([--enable-overload-c4],
96     [Enables the OVERLOAD_C4 macro to compile with 4 byte complex routine overloads. (Default no)])])
97 AS_IF([test ${enable_overload_c4:-no} = yes],
98   [enable_overload_c4=yes],
99   [enable_overload_c4=no])
100 AC_ARG_ENABLE([overload-c8],
101   [AS_HELP_STRING([--enable-overload-c8],
102     [Enables the OVERLOAD_C8 macro to compile with 8 byte real routine overloads. (Default no)])])
103 AS_IF([test ${enable_overload_c8:-no} = yes],
104   [enable_overload_c8=yes],
105   [enable_overload_c8=no])
106 AC_ARG_ENABLE([8byte-int],
107   [AS_HELP_STRING([--disable-8byte-int],
108     [Enables the no_8byte_integers macro to compile with only 4 byte integer routines. (Default no)])])
109 AS_IF([test ${enable_8byte_int:-no} = yes],
110   [enable_8byte_int=yes],
111   [enable_8byte_int=no])
113 AC_ARG_ENABLE([deprecated-io],
114   [AS_HELP_STRING([--enable-deprecated-io],
115     [Enables compilation of deprecated mpp_io and fms_io modules in addition to the updated fms2_io modules (default no)])])
116 AS_IF([test ${enable_deprecated_io:-no} = yes],
117   [enable_deprecated_io=yes],
118   [enable_deprecated_io=no])
120 # user enabled testing with input files
121 AC_MSG_CHECKING([whether to enable tests with input files])
122 AC_ARG_ENABLE([test-input],
123             [AS_HELP_STRING([--enable-test-input="path/to/input"],
124             [Enable tests using input netcdf files, if present in the given full directory.])])
125 AC_MSG_RESULT([$enable_test_input])
127 # require path to be given
128 AS_IF([test "x$enable_test_input" = "xyes"],
129     [AC_MSG_ERROR([Test input enabled, but no directory given with --enable-test-input=/path])],
130     [AS_IF([test "x$enable_test_input" != "xno"],
131         [TEST_INPUT_PATH="$enable_test_input"],[])]
134 # if set, check directory exists
135 AS_IF([test "$TEST_INPUT_PATH" = ""],
136   [],
137   [AS_IF([test -d $TEST_INPUT_PATH],[],
138     [AC_MSG_ERROR([Test input enabled, but directory $TEST_INPUT_PATH not found]) ]
139   )])
141 # substitute path for input
142 AC_SUBST([TEST_INPUT_PATH])
144 # Does the user want to build documentation?
145 AC_MSG_CHECKING([whether documentation should be built (requires doxygen)])
146 AC_ARG_ENABLE([docs],
147               [AS_HELP_STRING([--enable-docs],
148                               [enable building of documentation with doxygen.])])
149 test "x$enable_docs" = xyes || enable_docs=no
150 AC_MSG_RESULT([$enable_docs])
151 AM_CONDITIONAL(BUILD_DOCS, [test "x$enable_docs" = xyes])
153 # Is doxygen installed?
154 AC_CHECK_PROGS([DOXYGEN], [doxygen])
155 if test -z "$DOXYGEN" -a "x$enable_docs" = xyes; then
156    AC_MSG_ERROR([Doxygen not found but --enable-docs used.])
159 # If building docs, process Doxyfile.in into Doxyfile.
160 if test "x$enable_docs" = xyes; then
161    AC_CONFIG_FILES([docs/Doxyfile])
164 # Find the C compiler.
165 AC_PROG_CC
166 AM_PROG_CC_C_O
167 AC_C_CONST
168 AC_PROG_CPP
170 # Find the Fortran compiler.
171 AC_PROG_FC
172 AC_FC_MODULE_FLAG
173 AC_FC_MODULE_EXTENSION
174 AC_FC_MODULE_OUTPUT_FLAG
176 # Find the install program.
177 AC_PROG_INSTALL
179 # Check to see if any macros must be set to enable large (>2GB) files.
180 AC_SYS_LARGEFILE
182 # C specific checks
183 AC_LANG_PUSH(C)
184 if test $with_mpi = yes; then
185   # Require MPI
186   # We expect users to set CC and FC to MPI compiler wrappers, or that the correct
187   # CPPFLAGS, {C,FC}FLAGS, LDFLAGS and LIBS options are given.
188   GX_MPI()
191 # Require yaml
192 if test $with_yaml = yes; then
193   AC_CHECK_HEADERS([yaml.h], [], [AC_MSG_ERROR(["Can't find the libYAML C header file.  Set CC/CPPFLAGS/CFLAGS"])])
194   AC_SEARCH_LIBS([yaml_parser_initialize], [yaml], [], [AC_MSG_ERROR(["Can't find the libYAML C library.  Set CC/LDFLAGS/LIBS"])])
196   #If the test pass, define use_yaml macro
197   AC_DEFINE([use_yaml], [1], [This is required to use yaml parser])
199   AM_CONDITIONAL([SKIP_PARSER_TESTS], false )
200 else
201   AM_CONDITIONAL([SKIP_PARSER_TESTS], true )
204 # Require netCDF
205 AC_CHECK_HEADERS([netcdf.h], [], [AC_MSG_ERROR([Can't find the netCDF C header file.  Set CPPFLAGS/CFLAGS])])
206 AC_SEARCH_LIBS([nc_create], [netcdf], [], [AC_MSG_ERROR([Can't find the netCDF C library.  Set LDFLAGS/LIBS])])
208 # Require netCDF-4 (with HDF5).
209 AC_MSG_CHECKING([if netCDF was built with HDF5])
210 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
211 #include <netcdf_meta.h>
212 #if !(NC_HAS_NC4)
213 #endif]])], [nc_has_nc4=yes], [nc_has_nc4=no])
214 AC_MSG_RESULT([$nc_has_nc4])
215 if test $nc_has_nc4 = no; then
216   AC_MSG_ERROR([NetCDF must be built with HDF5.])
219 # Check if ncdump is avaiable
220 AC_CHECK_PROG([USE_NCDUMP],[ncdump], [yes], [no])
221 if test $USE_NCDUMP = yes; then
222   AM_CONDITIONAL([SKIP_NCDUMP_CHECKS], true )
223 else
224   AM_CONDITIONAL([SKIP_NCDUMP_CHECKS], false )
227 # Check if Linux gettid is avaiable
228 AC_CHECK_FUNCS([gettid], [], [])
230 # Check if Linux sched_getaffinity is available
231 AC_CHECK_FUNCS([sched_getaffinity], [], [])
233 # Check if the compiler needs special OpenMP flags
234 AC_OPENMP()
235 AC_LANG_POP(C)
237 # Fortran specific checks
238 AC_LANG_PUSH(Fortran)
239 if test $with_mpi = yes; then
240   # Require MPI
241   GX_MPI()
242   GX_MPI_FC_LEGACY_INTERFACE()
243   # Determine if a flag is required to allow external procedure argument mismatch when
244   # an explicit interface does not exist
245   if test ! -z "$HAVE_MPI_FC_LEGACY"; then
246     GX_FC_ALLOW_ARG_MISMATCH([dnl
247     FCFLAGS="$FCFLAGS $FC_ALLOW_ARG_MISMATCH_FLAG"])
248   fi
251 # check intel compiler and coverage tools are avaiable if code coverage is enabled
252 if test "$enable_code_coverage" = yes; then
253   if test ! -z "`$FC --version | grep ifort`"; then
254     AC_CHECK_PROGS([PROFMERGE],[profmerge])
255     AC_CHECK_PROGS([CODECOV], [codecov])
256   else
257     AC_MSG_ERROR([Intel compiler and coverage tools required for coverage report])
258   fi
260 AM_CONDITIONAL(COV, [test "$enable_code_coverage" = yes])
262 # Require netCDF
263 GX_FC_CHECK_MOD([netcdf], [], [], [AC_MSG_ERROR([Can't find the netCDF Fortran module.  Set CPPFLAGS/FCFLAGS])])
264 GX_FORTRAN_SEARCH_LIBS([nf90_create], [netcdff], [use netcdf], [iret = nf90_create('foo.nc', 1, ncid)], [],
265   [AC_MSG_ERROR([Can't find the netCDF Fortran library.  Set LDFLAGS/LIBS])])
267 # Check if Fortran compiler has the Class, Character array assign bug
268 GX_FC_CLASS_CHAR_ARRAY_BUG_CHECK()
270 # Check if Fortran compiler has Cray pointer support
271 GX_FC_CRAY_POINTER_FLAG()
273 # Check if Fortran compiler and system have quad precision support
274 GX_FC_QUAD_PRECISION()
276 # Check if Fortran compiler supports reading namelists from internal files
277 GX_FC_INTERNAL_FILE_NML()
279 # Check if the compiler needs special OpenMP flags
280 AC_OPENMP()
282 AC_LANG_POP(Fortran)
284 # We passed all the tests.  Set the required defines.
285 AC_DEFINE([use_netCDF], [1], [This is required for the library to build])
286 if test $with_mpi = yes; then
287   AC_DEFINE([use_libMPI], [1], [This is required for the library to build])
290 # check if compiling old io
291 if test $enable_deprecated_io = yes; then
292   #If the test pass, define use_deprecated_io macro and skip it's unit tests
293   AC_DEFINE([use_deprecated_io], [1], [This is required to use mpp_io and fms_io modules])
294   AM_CONDITIONAL([SKIP_DEPRECATED_IO_TESTS], true)
295 else
296   AM_CONDITIONAL([SKIP_DEPRECATED_IO_TESTS], false)
299 # Set any required compile flags.  This will not be done if the user wants to
300 # define all their own flags.
301 if test $enable_setting_flags = yes; then
302   # Make sure the compiler is seeing this as free-formatted, not
303   # fixed-formatted, fortran code.
304   AC_FC_FREEFORM()
306   # Check that long lines of Fortran code can be handled. This will add
307   # necessary fortran flags.
308   AC_FC_LINE_LENGTH([unlimited])
310   # Will we build with default 64-bit reals in Fortran, or do mixed mode?
311   if test $enable_mixed_mode = yes; then
312     GX_FC_DEFAULT_REAL_KIND4_FLAG([dnl
313       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
314     AC_DEFINE([OVERLOAD_R4], [1], [Set to overload the R4 Fortran routines])
315     AC_DEFINE([OVERLOAD_R8], [1], [Set to overload the R8 Fortran routines])
316   else
317     GX_FC_DEFAULT_REAL_KIND8_FLAG([dnl
318       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
319   fi
320   # individual mixed precision overloads
321   if test $enable_overload_r4 = yes; then
322     AC_DEFINE([OVERLOAD_R4], [1], [Set to overload with the R4 Fortran routines])
323   fi
324   if test $enable_overload_c4 = yes; then
325     AC_DEFINE([OVERLOAD_C4], [1], [Set to overload with the C4 Fortran routines])
326   fi
327   if test $enable_overload_c8 = yes; then
328     AC_DEFINE([OVERLOAD_C8], [1], [Set to overload with the C8 Fortran routines])
329   fi
330   if test $enable_8byte_int = yes; then
331     AC_DEFINE([no_8byte_integers], [1], [Set to disable 8 byte integer Fortran routines])
332   fi
334   # Add Cray Pointer support flag
335   if test ! -z "$FC_CRAY_POINTER_FLAG"; then
336     FCFLAGS="$FCFLAGS $FC_CRAY_POINTER_FLAG"
337   fi
339   # Add OpenMP flags
340   if test ! -z "$OPENMP_CFLAGS"; then
341     CFLAGS="$CFLAGS $OPENMP_CFLAGS"
342     CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
343   fi
344   if test ! -z "$OPENMP_FCFLAGS"; then
345     FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS"
346   fi
348   # Add code coverage flags
349   if test $enable_code_coverage = yes; then
350     FCFLAGS="$FCFLAGS -prof-gen=srcpos"
351     CFLAGS="$CFLAGS -prof-gen=srcpos"
352   fi
353   # add yaml flag
354   if test $with_yaml = yes; then
355     LDFLAGS="$LDFLAGS -lyaml"
356   fi
359 # Find which mpi launcher to use
360 AC_CHECK_PROGS([MPI_LAUNCHER],[srun aprun mpirun])
362 # Check if the launcher can oversubscribe the MPI processes
363 AS_IF([$MPI_LAUNCHER --oversubscribe hostname >/dev/null 2>&1], \
364       [ AC_SUBST([OVERSUBSCRIBE], [--oversubscribe])])
367 # Compiler with version information. This consists of the full path
368 # name of the compiler and the reported version number.
369 AC_SUBST([CC_VERSION])
370 # Strip anything that looks like a flag off of $CC
371 CC_NOFLAGS=`echo $CC | sed 's/ -.*//'`
373 if `echo $CC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
374   CC_VERSION="$CC"
375 else
376   CC_VERSION="$CC";
377   for x in `echo $PATH | sed -e 's/:/ /g'`; do
378     if test -x $x/$CC_NOFLAGS; then
379       CC_VERSION="$x/$CC"
380       break
381     fi
382   done
384 if test -n "$cc_version_info"; then
385   CC_VERSION="$CC_VERSION ( $cc_version_info)"
388 AC_SUBST([FC_VERSION])
389 # Strip anything that looks like a flag off of $FC
390 FC_NOFLAGS=`echo $FC | sed 's/ -.*//'`
392 if `echo $FC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
393   FC_VERSION="$FC"
394 else
395   FC_VERSION="$FC";
396   for x in `echo $PATH | sed -e 's/:/ /g'`; do
397     if test -x $x/$FC_NOFLAGS; then
398       FC_VERSION="$x/$FC"
399       break
400     fi
401   done
403 if test -n "$fc_version_info"; then
404   FC_VERSION="$FC_VERSION ( $fc_version_info )"
407 # Check if gcc is 11.1 for class(*) select type bug
408 AC_MSG_CHECKING([if using gcc 11.1.0])
409 if [ test -n "`$FC --version | grep GNU | grep 11\.1\..`" ]; then
410   AC_MSG_RESULT([yes])
411   AC_MSG_ERROR([Compilation with gcc and gfortran 11.1.0 is unsupported \
412 by this version of FMS due to a bug in the compiler. Please use a different version of gcc/gfortran.])
413 else
414   AC_MSG_RESULT([no])
417 #####
418 # Create output variables from various
419 # shell variables, for use in generating
420 # libnetcdf.settings.
421 #####
422 AC_SUBST([enable_shared])
423 AC_SUBST([enable_static])
424 AC_SUBST([CFLAGS])
425 AC_SUBST([CPPFLAGS])
426 AC_SUBST([LDFLAGS])
427 AC_SUBST([AM_CFLAGS])
428 AC_SUBST([AM_CPPFLAGS])
429 AC_SUBST([AM_LDFLAGS])
430 AC_SUBST([NOUNDEFINED])
432 # Define the directory where *.mod files will reside.
433 # Used in Makefiles.
434 AC_SUBST([MODDIR],[\$\(top_builddir\)/.mods])
436 # These files will be created when the configure script is run.
437 AC_CONFIG_FILES([
438   Makefile
439   affinity/Makefile
440   amip_interp/Makefile
441   time_interp/Makefile
442   time_manager/Makefile
443   constants/Makefile
444   constants4/Makefile
445   platform/Makefile
446   fms/Makefile
447   fms2_io/Makefile
448   mpp/Makefile
449   tridiagonal/Makefile
450   tracer_manager/Makefile
451   topography/Makefile
452   mosaic/Makefile
453   mosaic2/Makefile
454   monin_obukhov/Makefile
455   memutils/Makefile
456   interpolator/Makefile
457   horiz_interp/Makefile
458   field_manager/Makefile
459   exchange/Makefile
460   drifters/Makefile
461   diag_manager/Makefile
462   data_override/Makefile
463   column_diagnostics/Makefile
464   block_control/Makefile
465   axis_utils/Makefile
466   astronomy/Makefile
467   coupler/Makefile
468   diag_integral/Makefile
469   sat_vapor_pres/Makefile
470   random_numbers/Makefile
471   libFMS/Makefile
472   docs/Makefile
473   parser/Makefile
474   string_utils/Makefile
475   test_fms/test-lib.sh
476   test_fms/intel_coverage.sh
477   test_fms/Makefile
478   test_fms/diag_manager/Makefile
479   test_fms/data_override/Makefile
480   test_fms/exchange/Makefile
481   test_fms/monin_obukhov/Makefile
482   test_fms/drifters/Makefile
483   test_fms/interpolator/Makefile
484   test_fms/fms2_io/Makefile
485   test_fms/fms/Makefile
486   test_fms/mpp/Makefile
487   test_fms/mpp_io/Makefile
488   test_fms/time_interp/Makefile
489   test_fms/time_manager/Makefile
490   test_fms/horiz_interp/Makefile
491   test_fms/field_manager/Makefile
492   test_fms/axis_utils/Makefile
493   test_fms/mosaic/Makefile
494   test_fms/affinity/Makefile
495   test_fms/coupler/Makefile
496   test_fms/parser/Makefile
497   test_fms/string_utils/Makefile
498   test_fms/sat_vapor_pres/Makefile
499   FMS.pc
500   ])
502 AC_OUTPUT()