chore: 2022.01 release changes (#941)
[FMS.git] / configure.ac
blob4cfc8ac705a0dbeee370adb619f23af8b534e5d2
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   [2022.01.0],
29   [gfdl.climate.model.info@noaa.gov],
30   [FMS],
31   [https://www.gfdl.noaa.gov/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])
43 AC_REQUIRE_AUX_FILE([tap-driver.sh])
45 # Set up libtool.
46 LT_PREREQ([2.4])
47 LT_INIT()
49 # If building on a Cray PE system, check if CRAYPE_LINK_TYPE is 'static'.  If it
50 # is, then disable building shared libraries.  Note, the user can still override
51 # this by using --enable-shared when running the configure script.
52 AS_IF([test x${CRAYPE_VERSION:+yes} = "xyes"],[
53   AS_IF([test x${CRAYPE_LINK_TYPE} = "xstatic"],
54         [AC_DISABLE_SHARED])])
57 # Process user optons.
58 AC_ARG_ENABLE([mixed-mode],
59   [AS_HELP_STRING([--enable-mixed-mode],
60     [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.])])
61 AS_IF([test ${enable_mixed_mode:-no} = no],
62   [enable_mixed_mode=no],
63   [enable_mixed_mode=yes])
64 AC_ARG_WITH([mpi],
65   [AS_HELP_STRING([--with-mpi],
66     [Build with MPI support.  This option will be ignored if --disable-fortran-flag-setting is also given. (Default yes)])])
67 AS_IF([test ${with_mpi:-yes} = yes],
68   [with_mpi=yes],
69   [with_mpi=no])
70 AC_ARG_WITH([yaml],
71   [AS_HELP_STRING([--with-yaml],
72     [Build with YAML support.  This option will be ignored if --disable-fortran-flag-setting is also given. (Default no)])])
73 AS_IF([test ${with_yaml:-no} = no],
74   [with_yaml=no],
75   [with_yaml=yes])
76 AC_ARG_ENABLE([setting-flags],
77   [AS_HELP_STRING([--enable-setting-flags],
78     [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)])])
79 AS_IF([test ${enable_setting_flags:-yes} = yes],
80   [enable_setting_flags=yes],
81   [enable_setting_flags=no])
82 AC_ARG_ENABLE([code-coverage],
83   [AS_HELP_STRING([--enable-code-coverage],
84     [Allow configure to set flags and add check-code-coverage target for code coverage analysis (Default no)])])
85 AS_IF([test ${enable_code_coverage:-no} = no],
86   [enable_code_coverage=no],
87   [enable_code_coverage=yes])
89 # user enabled testing with input files
90 AC_MSG_CHECKING([whether to enable tests with input files])
91 AC_ARG_ENABLE([test-input],
92             [AS_HELP_STRING([--enable-test-input="path/to/input"],
93             [Enable tests using input netcdf files, if present in the given full directory.])])
94 AC_MSG_RESULT([$enable_test_input])
96 # require path to be given
97 AS_IF([test "x$enable_test_input" = "xyes"],
98     [AC_MSG_ERROR([Test input enabled, but no directory given with --enable-test-input=/path])],
99     [AS_IF([test "x$enable_test_input" != "xno"],
100         [TEST_INPUT_PATH="$enable_test_input"],[])]
103 # if set, check directory exists
104 AS_IF([test "$TEST_INPUT_PATH" = ""],
105   [],
106   [AS_IF([test -d $TEST_INPUT_PATH],[],
107     [AC_MSG_ERROR([Test input enabled, but directory $TEST_INPUT_PATH not found]) ]
108   )])
110 # substitute path for input
111 AC_SUBST([TEST_INPUT_PATH])
113 # Does the user want to build documentation?
114 AC_MSG_CHECKING([whether documentation should be built (requires doxygen)])
115 AC_ARG_ENABLE([docs],
116               [AS_HELP_STRING([--enable-docs],
117                               [enable building of documentation with doxygen.])])
118 test "x$enable_docs" = xyes || enable_docs=no
119 AC_MSG_RESULT([$enable_docs])
120 AM_CONDITIONAL(BUILD_DOCS, [test "x$enable_docs" = xyes])
122 # Is doxygen installed?
123 AC_CHECK_PROGS([DOXYGEN], [doxygen])
124 if test -z "$DOXYGEN" -a "x$enable_docs" = xyes; then
125    AC_MSG_ERROR([Doxygen not found but --enable-docs used.])
128 # If building docs, process Doxyfile.in into Doxyfile.
129 if test "x$enable_docs" = xyes; then
130    AC_CONFIG_FILES([docs/Doxyfile])
133 # Find the C compiler.
134 AC_PROG_CC
135 AM_PROG_CC_C_O
136 AC_C_CONST
137 AC_PROG_CPP
139 # Find the Fortran compiler.
140 AC_PROG_FC
141 AC_FC_MODULE_FLAG
142 AC_FC_MODULE_EXTENSION
143 AC_FC_MODULE_OUTPUT_FLAG
145 # Find the install program.
146 AC_PROG_INSTALL
148 # Check to see if any macros must be set to enable large (>2GB) files.
149 AC_SYS_LARGEFILE
151 # C specific checks
152 AC_LANG_PUSH(C)
153 if test $with_mpi = yes; then
154   # Require MPI
155   # We expect users to set CC and FC to MPI compiler wrappers, or that the correct
156   # CPPFLAGS, {C,FC}FLAGS, LDFLAGS and LIBS options are given.
157   AC_CHECK_HEADERS([mpi.h], [], [AC_MSG_ERROR([Can't find the MPI C header file.  Set CC/CPPFLAGS/CFLAGS])])
158   AC_CHECK_FUNC([MPI_Init], [], [AC_MSG_ERROR([Can't find the MPI C library.  Set CC/LDFLAGS/LIBS])])
161 # Require yaml
162 if test $with_yaml = yes; then
163   AC_CHECK_HEADERS([yaml.h], [], [AC_MSG_ERROR(["Can't find the libYAML C header file.  Set CC/CPPFLAGS/CFLAGS"])])
164   AC_SEARCH_LIBS([yaml_parser_initialize], [yaml], [], [AC_MSG_ERROR(["Can't find the libYAML C library.  Set CC/LDFLAGS/LIBS"])])
166   #If the test pass, define use_yaml macro
167   AC_DEFINE([use_yaml], [1], [This is required to use yaml parser])
169   AM_CONDITIONAL([SKIP_PARSER_TESTS], false )
170 else
171   AM_CONDITIONAL([SKIP_PARSER_TESTS], true )
174 # Require netCDF
175 AC_CHECK_HEADERS([netcdf.h], [], [AC_MSG_ERROR([Can't find the netCDF C header file.  Set CPPFLAGS/CFLAGS])])
176 AC_SEARCH_LIBS([nc_create], [netcdf], [], [AC_MSG_ERROR([Can't find the netCDF C library.  Set LDFLAGS/LIBS])])
178 # Require netCDF-4 (with HDF5).
179 AC_MSG_CHECKING([if netCDF was built with HDF5])
180 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
181 #include <netcdf_meta.h>
182 #if !(NC_HAS_NC4)
183       choke me
184 #endif]])], [nc_has_nc4=yes], [nc_has_nc4=no])
185 AC_MSG_RESULT([$nc_has_nc4])
186 if test $nc_has_nc4 = no; then
187   AC_MSG_ERROR([NetCDF must be built with HDF5.])
190 # Check if Linux gettid is avaiable
191 AC_CHECK_FUNCS([gettid], [], [])
193 # Check if Linux sched_getaffinity is available
194 AC_CHECK_FUNCS([sched_getaffinity], [], [])
196 # Check if the compiler needs special OpenMP flags
197 AC_OPENMP()
198 AC_LANG_POP(C)
200 # Fortran specific checks
201 AC_LANG_PUSH(Fortran)
202 if test $with_mpi = yes; then
203   # Require MPI
204   GX_FC_CHECK_MOD([mpi], [], [], [AC_MSG_ERROR([Can't find the MPI Fortran module.  Set FC/CPPFLAGS/FCFLAGS])])
205   AC_CHECK_FUNC([MPI_init], [], [AC_MSG_ERROR([Can't find the MPI Fortran library.  Set FC/LDFLAGS/LIBS])])
207 # check intel compiler and coverage tools are avaiable if code coverage is enabled
208 if test "$enable_code_coverage" = yes; then
209   if test ! -z "`$FC --version | grep ifort`"; then
210     AC_CHECK_PROGS([PROFMERGE],[profmerge])
211     AC_CHECK_PROGS([CODECOV], [codecov])
212   else
213     AC_MSG_ERROR([Intel compiler and coverage tools required for coverage report])
214   fi
216 AM_CONDITIONAL(COV, [test "$enable_code_coverage" = yes])
218 # Require netCDF
219 GX_FC_CHECK_MOD([netcdf], [], [], [AC_MSG_ERROR([Can't find the netCDF Fortran module.  Set CPPFLAGS/FCFLAGS])])
220 GX_FORTRAN_SEARCH_LIBS([nf90_create], [netcdff], [use netcdf], [iret = nf90_create('foo.nc', 1, ncid)], [],
221   [AC_MSG_ERROR([Can't find the netCDF Fortran library.  Set LDFLAGS/LIBS])])
223 # Check if Fortran compiler has the Class, Character array assign bug
224 GX_FC_CLASS_CHAR_ARRAY_BUG_CHECK()
226 # Check if Fortran compiler has Cray pointer support
227 GX_FC_CRAY_POINTER_FLAG()
229 # Check if Fortran compiler and system have quad precision support
230 GX_FC_QUAD_PRECISION()
232 # Check if Fortran compiler supports reading namelists from internal files
233 GX_FC_INTERNAL_FILE_NML()
235 # Check if the compiler needs special OpenMP flags
236 AC_OPENMP()
238 AC_LANG_POP(Fortran)
240 # We passed all the tests.  Set the required defines.
241 AC_DEFINE([use_netCDF], [1], [This is required for the library to build])
242 if test $with_mpi = yes; then
243   AC_DEFINE([use_libMPI], [1], [This is required for the library to build])
246 # Set any required compile flags.  This will not be done if the user wants to
247 # define all their own flags.
248 if test $enable_setting_flags = yes; then
249   # Make sure the compiler is seeing this as free-formatted, not
250   # fixed-formatted, fortran code.
251   AC_FC_FREEFORM()
253   # Check that long lines of Fortran code can be handled. This will add
254   # necessary fortran flags.
255   AC_FC_LINE_LENGTH([unlimited])
257   # Will we build with default 64-bit reals in Fortran, or do mixed mode?
258   if test $enable_mixed_mode = yes; then
259     GX_FC_DEFAULT_REAL_KIND4_FLAG([dnl
260       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
261     AC_DEFINE([OVERLOAD_R4], [1], [Set to overload the R4 Fortran routines])
262     AC_DEFINE([OVERLOAD_R8], [1], [Set to overload the R8 Fortran routines])
263   else
264     GX_FC_DEFAULT_REAL_KIND8_FLAG([dnl
265       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
266   fi
268   # Add Cray Pointer support flag
269   if test ! -z "$FC_CRAY_POINTER_FLAG"; then
270     FCFLAGS="$FCFLAGS $FC_CRAY_POINTER_FLAG"
271   fi
273   # Add OpenMP flags
274   if test ! -z "$OPENMP_CFLAGS"; then
275     CFLAGS="$CFLAGS $OPENMP_CFLAGS"
276     CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
277   fi
278   if test ! -z "$OPENMP_FCFLAGS"; then
279     FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS"
280   fi
282   # Add code coverage flags
283   if test $enable_code_coverage = yes; then
284     FCFLAGS="$FCFLAGS -prof-gen=srcpos"
285     CFLAGS="$CFLAGS -prof-gen=srcpos"
286   fi
289 # Find which mpi launcher to use
290 AC_CHECK_PROGS([MPI_LAUNCHER],[srun aprun mpirun])
292 # Check if the launcher can oversubscribe the MPI processes
293 AS_IF([$MPI_LAUNCHER --oversubscribe hostname >/dev/null 2>&1], \
294       [ AC_SUBST([OVERSUBSCRIBE], [--oversubscribe])])
297 # Compiler with version information. This consists of the full path
298 # name of the compiler and the reported version number.
299 AC_SUBST([CC_VERSION])
300 # Strip anything that looks like a flag off of $CC
301 CC_NOFLAGS=`echo $CC | sed 's/ -.*//'`
303 if `echo $CC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
304   CC_VERSION="$CC"
305 else
306   CC_VERSION="$CC";
307   for x in `echo $PATH | sed -e 's/:/ /g'`; do
308     if test -x $x/$CC_NOFLAGS; then
309       CC_VERSION="$x/$CC"
310       break
311     fi
312   done
314 if test -n "$cc_version_info"; then
315   CC_VERSION="$CC_VERSION ( $cc_version_info)"
318 AC_SUBST([FC_VERSION])
319 # Strip anything that looks like a flag off of $FC
320 FC_NOFLAGS=`echo $FC | sed 's/ -.*//'`
322 if `echo $FC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
323   FC_VERSION="$FC"
324 else
325   FC_VERSION="$FC";
326   for x in `echo $PATH | sed -e 's/:/ /g'`; do
327     if test -x $x/$FC_NOFLAGS; then
328       FC_VERSION="$x/$FC"
329       break
330     fi
331   done
333 if test -n "$fc_version_info"; then
334   FC_VERSION="$FC_VERSION ( $fc_version_info )"
337 # Check if gcc is 11.1 for class(*) select type bug
338 AC_MSG_CHECKING([if gcc 11.1.0 is loaded])
339 if [ test -n "`$FC --version | grep GNU | grep 11\.1\..`" ]; then
340   AC_MSG_RESULT([yes])
341   AC_MSG_ERROR([Compilation with gcc and gfortran 11.1.0 is unsupported \
342 by this version of FMS due to a bug in the compiler. Please use a different version of gcc/gfortran.])
343 else
344   AC_MSG_RESULT([no])
347 #####
348 # Create output variables from various
349 # shell variables, for use in generating
350 # libnetcdf.settings.
351 #####
352 AC_SUBST([enable_shared])
353 AC_SUBST([enable_static])
354 AC_SUBST([CFLAGS])
355 AC_SUBST([CPPFLAGS])
356 AC_SUBST([LDFLAGS])
357 AC_SUBST([AM_CFLAGS])
358 AC_SUBST([AM_CPPFLAGS])
359 AC_SUBST([AM_LDFLAGS])
360 AC_SUBST([NOUNDEFINED])
362 # Define the directory where *.mod files will reside.
363 # Used in Makefiles.
364 AC_SUBST([MODDIR],[\$\(top_builddir\)/.mods])
366 # These files will be created when the configure script is run.
367 AC_CONFIG_FILES([
368   Makefile
369   affinity/Makefile
370   amip_interp/Makefile
371   time_interp/Makefile
372   time_manager/Makefile
373   constants/Makefile
374   platform/Makefile
375   fms/Makefile
376   fms2_io/Makefile
377   mpp/Makefile
378   tridiagonal/Makefile
379   tracer_manager/Makefile
380   topography/Makefile
381   mosaic/Makefile
382   mosaic2/Makefile
383   monin_obukhov/Makefile
384   memutils/Makefile
385   interpolator/Makefile
386   horiz_interp/Makefile
387   field_manager/Makefile
388   exchange/Makefile
389   drifters/Makefile
390   diag_manager/Makefile
391   data_override/Makefile
392   column_diagnostics/Makefile
393   block_control/Makefile
394   axis_utils/Makefile
395   astronomy/Makefile
396   coupler/Makefile
397   diag_integral/Makefile
398   sat_vapor_pres/Makefile
399   random_numbers/Makefile
400   libFMS/Makefile
401   docs/Makefile
402   parser/Makefile
403   test_fms/test-lib.sh
404   test_fms/intel_coverage.sh
405   test_fms/Makefile
406   test_fms/diag_manager/Makefile
407   test_fms/data_override/Makefile
408   test_fms/exchange/Makefile
409   test_fms/monin_obukhov/Makefile
410   test_fms/drifters/Makefile
411   test_fms/interpolator/Makefile
412   test_fms/fms2_io/Makefile
413   test_fms/fms/Makefile
414   test_fms/mpp/Makefile
415   test_fms/mpp_io/Makefile
416   test_fms/time_interp/Makefile
417   test_fms/time_manager/Makefile
418   test_fms/horiz_interp/Makefile
419   test_fms/field_manager/Makefile
420   test_fms/axis_utils/Makefile
421   test_fms/mosaic/Makefile
422   test_fms/affinity/Makefile
423   test_fms/coupler/Makefile
424   test_fms/parser/Makefile
425   FMS.pc
426   ])
428 AC_OUTPUT()