feat: emc mixedmode support (#997)
[FMS.git] / configure.ac
blobecaf54a9472bb8872621b7e3407114e4a6250221
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.03.0-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])
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])
88 # individual mixed precision overload macros
89 AC_ARG_ENABLE([overload-r4],
90   [AS_HELP_STRING([--enable-overload-r4],
91     [Enables the OVERLOAD_R4 macro to compile with 4 byte real routine overloads. (Default no)])])
92 AS_IF([test ${enable_overload_r4:-no} = yes],
93   [enable_overload_r4=yes],
94   [enable_overload_r4=no])
95 AC_ARG_ENABLE([overload-c4],
96   [AS_HELP_STRING([--enable-overload-c4],
97     [Enables the OVERLOAD_C4 macro to compile with 4 byte complex routine overloads. (Default no)])])
98 AS_IF([test ${enable_overload_c4:-no} = yes],
99   [enable_overload_c4=yes],
100   [enable_overload_c4=no])
101 AC_ARG_ENABLE([overload-c8],
102   [AS_HELP_STRING([--enable-overload-c8],
103     [Enables the OVERLOAD_C8 macro to compile with 8 byte real routine overloads. (Default no)])])
104 AS_IF([test ${enable_overload_c8:-no} = yes],
105   [enable_overload_c8=yes],
106   [enable_overload_c8=no])
107 AC_ARG_ENABLE([8byte-int],
108   [AS_HELP_STRING([--disable-8byte-int],
109     [Enables the no_8byte_integers macro to compile with only 4 byte integer routines. (Default no)])])
110 AS_IF([test ${enable_8byte_int:-no} = yes],
111   [enable_8byte_int=yes],
112   [enable_8byte_int=no])
114 # user enabled testing with input files
115 AC_MSG_CHECKING([whether to enable tests with input files])
116 AC_ARG_ENABLE([test-input],
117             [AS_HELP_STRING([--enable-test-input="path/to/input"],
118             [Enable tests using input netcdf files, if present in the given full directory.])])
119 AC_MSG_RESULT([$enable_test_input])
121 # require path to be given
122 AS_IF([test "x$enable_test_input" = "xyes"],
123     [AC_MSG_ERROR([Test input enabled, but no directory given with --enable-test-input=/path])],
124     [AS_IF([test "x$enable_test_input" != "xno"],
125         [TEST_INPUT_PATH="$enable_test_input"],[])]
128 # if set, check directory exists
129 AS_IF([test "$TEST_INPUT_PATH" = ""],
130   [],
131   [AS_IF([test -d $TEST_INPUT_PATH],[],
132     [AC_MSG_ERROR([Test input enabled, but directory $TEST_INPUT_PATH not found]) ]
133   )])
135 # substitute path for input
136 AC_SUBST([TEST_INPUT_PATH])
138 # Does the user want to build documentation?
139 AC_MSG_CHECKING([whether documentation should be built (requires doxygen)])
140 AC_ARG_ENABLE([docs],
141               [AS_HELP_STRING([--enable-docs],
142                               [enable building of documentation with doxygen.])])
143 test "x$enable_docs" = xyes || enable_docs=no
144 AC_MSG_RESULT([$enable_docs])
145 AM_CONDITIONAL(BUILD_DOCS, [test "x$enable_docs" = xyes])
147 # Is doxygen installed?
148 AC_CHECK_PROGS([DOXYGEN], [doxygen])
149 if test -z "$DOXYGEN" -a "x$enable_docs" = xyes; then
150    AC_MSG_ERROR([Doxygen not found but --enable-docs used.])
153 # If building docs, process Doxyfile.in into Doxyfile.
154 if test "x$enable_docs" = xyes; then
155    AC_CONFIG_FILES([docs/Doxyfile])
158 # Find the C compiler.
159 AC_PROG_CC
160 AM_PROG_CC_C_O
161 AC_C_CONST
162 AC_PROG_CPP
164 # Find the Fortran compiler.
165 AC_PROG_FC
166 AC_FC_MODULE_FLAG
167 AC_FC_MODULE_EXTENSION
168 AC_FC_MODULE_OUTPUT_FLAG
170 # Find the install program.
171 AC_PROG_INSTALL
173 # Check to see if any macros must be set to enable large (>2GB) files.
174 AC_SYS_LARGEFILE
176 # C specific checks
177 AC_LANG_PUSH(C)
178 if test $with_mpi = yes; then
179   # Require MPI
180   # We expect users to set CC and FC to MPI compiler wrappers, or that the correct
181   # CPPFLAGS, {C,FC}FLAGS, LDFLAGS and LIBS options are given.
182   AC_CHECK_HEADERS([mpi.h], [], [AC_MSG_ERROR([Can't find the MPI C header file.  Set CC/CPPFLAGS/CFLAGS])])
183   AC_CHECK_FUNC([MPI_Init], [], [AC_MSG_ERROR([Can't find the MPI C library.  Set CC/LDFLAGS/LIBS])])
186 # Require yaml
187 if test $with_yaml = yes; then
188   AC_CHECK_HEADERS([yaml.h], [], [AC_MSG_ERROR(["Can't find the libYAML C header file.  Set CC/CPPFLAGS/CFLAGS"])])
189   AC_SEARCH_LIBS([yaml_parser_initialize], [yaml], [], [AC_MSG_ERROR(["Can't find the libYAML C library.  Set CC/LDFLAGS/LIBS"])])
191   #If the test pass, define use_yaml macro
192   AC_DEFINE([use_yaml], [1], [This is required to use yaml parser])
194   AM_CONDITIONAL([SKIP_PARSER_TESTS], false )
195 else
196   AM_CONDITIONAL([SKIP_PARSER_TESTS], true )
199 # Require netCDF
200 AC_CHECK_HEADERS([netcdf.h], [], [AC_MSG_ERROR([Can't find the netCDF C header file.  Set CPPFLAGS/CFLAGS])])
201 AC_SEARCH_LIBS([nc_create], [netcdf], [], [AC_MSG_ERROR([Can't find the netCDF C library.  Set LDFLAGS/LIBS])])
203 # Require netCDF-4 (with HDF5).
204 AC_MSG_CHECKING([if netCDF was built with HDF5])
205 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
206 #include <netcdf_meta.h>
207 #if !(NC_HAS_NC4)
208       choke me
209 #endif]])], [nc_has_nc4=yes], [nc_has_nc4=no])
210 AC_MSG_RESULT([$nc_has_nc4])
211 if test $nc_has_nc4 = no; then
212   AC_MSG_ERROR([NetCDF must be built with HDF5.])
215 # Check if Linux gettid is avaiable
216 AC_CHECK_FUNCS([gettid], [], [])
218 # Check if Linux sched_getaffinity is available
219 AC_CHECK_FUNCS([sched_getaffinity], [], [])
221 # Check if the compiler needs special OpenMP flags
222 AC_OPENMP()
223 AC_LANG_POP(C)
225 # Fortran specific checks
226 AC_LANG_PUSH(Fortran)
227 if test $with_mpi = yes; then
228   # Require MPI
229   GX_FC_CHECK_MOD([mpi], [], [], [AC_MSG_ERROR([Can't find the MPI Fortran module.  Set FC/CPPFLAGS/FCFLAGS])])
230   AC_CHECK_FUNC([MPI_init], [], [AC_MSG_ERROR([Can't find the MPI Fortran library.  Set FC/LDFLAGS/LIBS])])
232 # check intel compiler and coverage tools are avaiable if code coverage is enabled
233 if test "$enable_code_coverage" = yes; then
234   if test ! -z "`$FC --version | grep ifort`"; then
235     AC_CHECK_PROGS([PROFMERGE],[profmerge])
236     AC_CHECK_PROGS([CODECOV], [codecov])
237   else
238     AC_MSG_ERROR([Intel compiler and coverage tools required for coverage report])
239   fi
241 AM_CONDITIONAL(COV, [test "$enable_code_coverage" = yes])
243 # Require netCDF
244 GX_FC_CHECK_MOD([netcdf], [], [], [AC_MSG_ERROR([Can't find the netCDF Fortran module.  Set CPPFLAGS/FCFLAGS])])
245 GX_FORTRAN_SEARCH_LIBS([nf90_create], [netcdff], [use netcdf], [iret = nf90_create('foo.nc', 1, ncid)], [],
246   [AC_MSG_ERROR([Can't find the netCDF Fortran library.  Set LDFLAGS/LIBS])])
248 # Check if Fortran compiler has the Class, Character array assign bug
249 GX_FC_CLASS_CHAR_ARRAY_BUG_CHECK()
251 # Check if Fortran compiler has Cray pointer support
252 GX_FC_CRAY_POINTER_FLAG()
254 # Check if Fortran compiler and system have quad precision support
255 GX_FC_QUAD_PRECISION()
257 # Check if Fortran compiler supports reading namelists from internal files
258 GX_FC_INTERNAL_FILE_NML()
260 # Check if the compiler needs special OpenMP flags
261 AC_OPENMP()
263 AC_LANG_POP(Fortran)
265 # We passed all the tests.  Set the required defines.
266 AC_DEFINE([use_netCDF], [1], [This is required for the library to build])
267 if test $with_mpi = yes; then
268   AC_DEFINE([use_libMPI], [1], [This is required for the library to build])
271 # Set any required compile flags.  This will not be done if the user wants to
272 # define all their own flags.
273 if test $enable_setting_flags = yes; then
274   # Make sure the compiler is seeing this as free-formatted, not
275   # fixed-formatted, fortran code.
276   AC_FC_FREEFORM()
278   # Check that long lines of Fortran code can be handled. This will add
279   # necessary fortran flags.
280   AC_FC_LINE_LENGTH([unlimited])
282   # Will we build with default 64-bit reals in Fortran, or do mixed mode?
283   if test $enable_mixed_mode = yes; then
284     GX_FC_DEFAULT_REAL_KIND4_FLAG([dnl
285       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
286     AC_DEFINE([OVERLOAD_R4], [1], [Set to overload the R4 Fortran routines])
287     AC_DEFINE([OVERLOAD_R8], [1], [Set to overload the R8 Fortran routines])
288   else
289     GX_FC_DEFAULT_REAL_KIND8_FLAG([dnl
290       FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
291   fi
292   # individual mixed precision overloads
293   if test $enable_overload_r4 = yes; then
294     AC_DEFINE([OVERLOAD_R4], [1], [Set to overload with the R4 Fortran routines])
295   fi
296   if test $enable_overload_c4 = yes; then
297     AC_DEFINE([OVERLOAD_C4], [1], [Set to overload with the C4 Fortran routines])
298   fi
299   if test $enable_overload_c8 = yes; then
300     AC_DEFINE([OVERLOAD_C8], [1], [Set to overload with the C8 Fortran routines])
301   fi
302   if test $enable_8byte_int = yes; then
303     AC_DEFINE([no_8byte_integers], [1], [Set to disable 8 byte integer Fortran routines])
304   fi
306   # Add Cray Pointer support flag
307   if test ! -z "$FC_CRAY_POINTER_FLAG"; then
308     FCFLAGS="$FCFLAGS $FC_CRAY_POINTER_FLAG"
309   fi
311   # Add OpenMP flags
312   if test ! -z "$OPENMP_CFLAGS"; then
313     CFLAGS="$CFLAGS $OPENMP_CFLAGS"
314     CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
315   fi
316   if test ! -z "$OPENMP_FCFLAGS"; then
317     FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS"
318   fi
320   # Add code coverage flags
321   if test $enable_code_coverage = yes; then
322     FCFLAGS="$FCFLAGS -prof-gen=srcpos"
323     CFLAGS="$CFLAGS -prof-gen=srcpos"
324   fi
327 # Find which mpi launcher to use
328 AC_CHECK_PROGS([MPI_LAUNCHER],[srun aprun mpirun])
330 # Check if the launcher can oversubscribe the MPI processes
331 AS_IF([$MPI_LAUNCHER --oversubscribe hostname >/dev/null 2>&1], \
332       [ AC_SUBST([OVERSUBSCRIBE], [--oversubscribe])])
335 # Compiler with version information. This consists of the full path
336 # name of the compiler and the reported version number.
337 AC_SUBST([CC_VERSION])
338 # Strip anything that looks like a flag off of $CC
339 CC_NOFLAGS=`echo $CC | sed 's/ -.*//'`
341 if `echo $CC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
342   CC_VERSION="$CC"
343 else
344   CC_VERSION="$CC";
345   for x in `echo $PATH | sed -e 's/:/ /g'`; do
346     if test -x $x/$CC_NOFLAGS; then
347       CC_VERSION="$x/$CC"
348       break
349     fi
350   done
352 if test -n "$cc_version_info"; then
353   CC_VERSION="$CC_VERSION ( $cc_version_info)"
356 AC_SUBST([FC_VERSION])
357 # Strip anything that looks like a flag off of $FC
358 FC_NOFLAGS=`echo $FC | sed 's/ -.*//'`
360 if `echo $FC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
361   FC_VERSION="$FC"
362 else
363   FC_VERSION="$FC";
364   for x in `echo $PATH | sed -e 's/:/ /g'`; do
365     if test -x $x/$FC_NOFLAGS; then
366       FC_VERSION="$x/$FC"
367       break
368     fi
369   done
371 if test -n "$fc_version_info"; then
372   FC_VERSION="$FC_VERSION ( $fc_version_info )"
375 # Check if gcc is 11.1 for class(*) select type bug
376 AC_MSG_CHECKING([if gcc 11.1.0 is loaded])
377 if [ test -n "`$FC --version | grep GNU | grep 11\.1\..`" ]; then
378   AC_MSG_RESULT([yes])
379   AC_MSG_ERROR([Compilation with gcc and gfortran 11.1.0 is unsupported \
380 by this version of FMS due to a bug in the compiler. Please use a different version of gcc/gfortran.])
381 else
382   AC_MSG_RESULT([no])
384 # Check if gcc >=10 is used with mpich
385 # adds compiler arg needed for mpich compilation if found
386 AC_MSG_CHECKING([if gcc 10 or greater is loaded with mpich])
387 if [ test "`$FC --version | grep GNU | grep -E ' 1[0-9]\.[0-9]*\.[0-9]*$'`" -a "`which $FC | grep -i mpich`" ]; then
388   AC_MSG_RESULT([yes])
389   AC_MSG_WARN([Adding -fallow-argument-mismatch to FCFLAGS to allow compilation with gcc >=10 and mpich])
390   FCFLAGS="$FCFLAGS -fallow-argument-mismatch"
391 else
392   AC_MSG_RESULT([no])
395 #####
396 # Create output variables from various
397 # shell variables, for use in generating
398 # libnetcdf.settings.
399 #####
400 AC_SUBST([enable_shared])
401 AC_SUBST([enable_static])
402 AC_SUBST([CFLAGS])
403 AC_SUBST([CPPFLAGS])
404 AC_SUBST([LDFLAGS])
405 AC_SUBST([AM_CFLAGS])
406 AC_SUBST([AM_CPPFLAGS])
407 AC_SUBST([AM_LDFLAGS])
408 AC_SUBST([NOUNDEFINED])
410 # Define the directory where *.mod files will reside.
411 # Used in Makefiles.
412 AC_SUBST([MODDIR],[\$\(top_builddir\)/.mods])
414 # These files will be created when the configure script is run.
415 AC_CONFIG_FILES([
416   Makefile
417   affinity/Makefile
418   amip_interp/Makefile
419   time_interp/Makefile
420   time_manager/Makefile
421   constants/Makefile
422   constants4/Makefile
423   platform/Makefile
424   fms/Makefile
425   fms2_io/Makefile
426   mpp/Makefile
427   tridiagonal/Makefile
428   tracer_manager/Makefile
429   topography/Makefile
430   mosaic/Makefile
431   mosaic2/Makefile
432   monin_obukhov/Makefile
433   memutils/Makefile
434   interpolator/Makefile
435   horiz_interp/Makefile
436   field_manager/Makefile
437   exchange/Makefile
438   drifters/Makefile
439   diag_manager/Makefile
440   data_override/Makefile
441   column_diagnostics/Makefile
442   block_control/Makefile
443   axis_utils/Makefile
444   astronomy/Makefile
445   coupler/Makefile
446   diag_integral/Makefile
447   sat_vapor_pres/Makefile
448   random_numbers/Makefile
449   libFMS/Makefile
450   docs/Makefile
451   parser/Makefile
452   string_utils/Makefile
453   test_fms/test-lib.sh
454   test_fms/intel_coverage.sh
455   test_fms/Makefile
456   test_fms/diag_manager/Makefile
457   test_fms/data_override/Makefile
458   test_fms/exchange/Makefile
459   test_fms/monin_obukhov/Makefile
460   test_fms/drifters/Makefile
461   test_fms/interpolator/Makefile
462   test_fms/fms2_io/Makefile
463   test_fms/fms/Makefile
464   test_fms/mpp/Makefile
465   test_fms/mpp_io/Makefile
466   test_fms/time_interp/Makefile
467   test_fms/time_manager/Makefile
468   test_fms/horiz_interp/Makefile
469   test_fms/field_manager/Makefile
470   test_fms/axis_utils/Makefile
471   test_fms/mosaic/Makefile
472   test_fms/affinity/Makefile
473   test_fms/coupler/Makefile
474   test_fms/parser/Makefile
475   test_fms/string_utils/Makefile
476   FMS.pc
477   ])
479 AC_OUTPUT()