forked from paesanilab/MBX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.ac
263 lines (226 loc) · 7.38 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# Require a version of Autoconf more recent than 2.69
AC_PREREQ([2.69])
# Initialize AC
AC_INIT([MBX], [1.1.0], [[email protected]])
# Put the auxiliary files in a different folder to not overcrowd the main directory
AC_CONFIG_AUX_DIR([build-aux])
# Directory where the M4 macros are. Created automatically.
AC_CONFIG_MACRO_DIR([m4])
# Look for the archiver AR to make the static lib
AM_PROG_AR
# Initialize the LIBTOOLS lib to make the .la libraries, from where the .so and .a will be created
LT_INIT([disable-shared])
# Initialize Automake. Warnings will be treated as errors.
AM_INIT_AUTOMAKE([subdir-objects -Wall foreign])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
src/unittests/Makefile
plugins/Makefile
plugins/i-pi/Makefile
])
# Helper function to add the proper flags to CPPFLAGS and LDFLAGS
# MBX_CHECK_PACKAGE(path_to_home)
AC_DEFUN([MBX_CHECK_PACKAGE], [
# Check if a path to the home dir of lib has been given
if ! test $1 == none; then
LDFLAGS="$LDFLAGS -L$1/lib"
CPPFLAGS="$CPPFLAGS -I$1/include"
fi
])
# Helper function to see if compiler accepts a flag
# MBX_CHECK_CXXFLAG(flag)
# use it to check if a flag is available on this compiler
AC_DEFUN([MBX_CHECK_CXXFLAG], [
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
AC_MSG_CHECKING([whether $CXX accepts $1])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes]); EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $1"],
[AC_MSG_RESULT([not linking]); CXXFLAGS="$save_CXXFLAGS"])
],
[AC_MSG_RESULT([no]); CXXFLAGS="$save_CXXFLAGS"]
)
CXXFLAGS="$save_CXXFLAGS"
])
# MBX_CHECK_REQ_CXXFLAG(flag)
# use it to check if a required flag is available on this compiler
AC_DEFUN([MBX_CHECK_REQ_CXXFLAG], [
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
AC_MSG_CHECKING([whether $CXX accepts $1])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([not linking]); AC_MSG_ERROR([please ensure that your $CXX compiler is able to accept $1])])
],
[AC_MSG_RESULT([no]); AC_MSG_ERROR([please ensure that your $CXX compiler is able to accept $1])]
)
CXXFLAGS="$save_CXXFLAGS"
EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $1"
])
# Helper function to set the enables
# MBX_CONFIG_ENABLE(variablename,optionname,doc,default)
# notice that variablename and optionname are likely identical,
# they just need to be different with optionname contains a "-"
# (not allowed in shell variable names)
AC_DEFUN([MBX_CONFIG_ENABLE], [
m4_bpatsubst([$1],-,_)=
AC_ARG_ENABLE([$1],
AS_HELP_STRING([--enable-$1], [enable $2, default: $3]),
[case "${enableval}" in
(yes) m4_bpatsubst([$1],-,_)=true ;;
(no) m4_bpatsubst([$1],-,_)=false ;;
(*) AC_MSG_ERROR([wrong argument to --enable-$1]) ;;
esac],
[case "$3" in
(yes) m4_bpatsubst([$1],-,_)=true ;;
(no) m4_bpatsubst([$1],-,_)=false ;;
esac]
)
])
# Everything is in C++, so are the tests
AC_LANG(C++)
# Checks for programs.
AC_PROG_CXX
CXXFLAGS=''
EXTRA_CXXFLAGS=''
AC_OPENMP
# Check compiler is working
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[],
[AC_MSG_ERROR([C++ compiler ${CXX} is not working])]
)
# Checks for libraries.
AC_CHECK_LIB([m],[cos])
AC_SEARCH_LIBS([omp_get_thread_num],[iomp5 gomp])
# FFTW
# Look for possible environment variables known to have FFTW home
fftw_dir=none
fftw_dir_name=none
if test "$FFTW_HOME" != ""; then
fftw_dir="$FFTW_HOME"
fftw_dir_name="FFTW_HOME"
elif test "$FFTWHOME" != ""; then
fftw_dir="$FFTWHOME"
fftw_dir_name="FFTWHOME"
elif test "$FFTW_ROOT" != "" ; then
fftw_dir="$FFTW_ROOT"
fftw_dir_name="FFTW_ROOT"
elif test "$FFTWROOT" != "" ; then
fftw_dir="$FFTWROOT"
fftw_dir_name="FFTWROOT"
fi
AC_MSG_NOTICE([fftw_dir: ${fftw_dir_name}=${fftw_dir}])
MBX_CHECK_PACKAGE([$fftw_dir])
AC_CHECK_LIB([fftw3],[fftw_plan_dft],[
CPPFLAGS="$CPPFLAGS -DHAVE_FFTWD=1"
LIBS="-lfftw3 $LIBS"
],[
AC_MSG_ERROR([fftw3 cannot be linked. Please define FFTW_HOME.])
])
# GSL
# Look for possible environment variables known to have GSL home
gsl_dir=none
if test "$GSL_HOME" != ""; then
gsl_dir="$GSL_HOME"
elif test "$GSLHOME" != ""; then
gsl_dir="$GSLHOME"
elif test "$GSL_ROOT" != "" ; then
gsl_dir="$GSL_ROOT"
elif test "$GSLROOT" != "" ; then
gsl_dir="$GSLROOT"
elif test "$GSL_ROOT_DIR" != "" ; then
gsl_dir="$GSL_ROOT_DIR"
fi
MBX_CHECK_PACKAGE([$gsl_dir])
AC_CHECK_LIB([gslcblas],[cblas_dgemm])
AC_CHECK_LIB([gsl],[gsl_blas_dgemm],[
LIBS="-lgsl $LIBS"
AM_CONDITIONAL([HASGSL], [test x == x])
],[
AM_CONDITIONAL([HASGSL], [test x == y])
AC_MSG_WARN([gsl cannot be found. Will not install the normal modes executable.])
])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Check for C++11
MBX_CHECK_REQ_CXXFLAG([-std=c++11])
# Check for enable flags
MBX_CONFIG_ENABLE([debug],[debugging],[no])
MBX_CONFIG_ENABLE([verbose],[verbose debug output],[no])
MBX_CONFIG_ENABLE([optimization],[compile with optimization],[yes])
MBX_CONFIG_ENABLE([mpi],[compile with mpi],[no])
MBX_CONFIG_ENABLE([coverage],[compile with coverage flags],[no])
MBX_CONFIG_ENABLE([optreport],[write optimization reports],[no])
MBX_CONFIG_ENABLE([ttmnrg],[enable ttm-nrg calculations],[no])
# Act on enable flags
if test $debug == true; then
MBX_CHECK_REQ_CXXFLAG([-g]) # allow debugging using gdb
fi
if test $verbose == true; then
MBX_CHECK_CXXFLAG([-DDEBUG]) # verbose debug output
fi
if test $optimization == true; then
MBX_CHECK_REQ_CXXFLAG([-O2])
else
MBX_CHECK_REQ_CXXFLAG([-O0])
fi
if test $coverage == true; then
MBX_CHECK_CXXFLAG([--coverage]) # allow coverage analysis using codecov
fi
# deprecated ttm-nrg mode
if test $ttmnrg == true; then
AC_MSG_WARN([ttm-nrg is deprecated.])
MBX_CHECK_CXXFLAG([-DTTMNRG])
fi
if test $optreport == true; then
MBX_CHECK_CXXFLAG([-qopt-report=1])
MBX_CHECK_CXXFLAG([-qopt-report-phase=vec])
fi
# Add flags to variable
AC_SUBST(EXTRA_CXXFLAGS_AM,["$EXTRA_CXXFLAGS "])
# MPI
# Set AutoMake flag to true
AM_CONDITIONAL([ISMPI], [test $mpi == true])
if test $mpi == true; then
# Look for possible environment variables known to have MPI home
mpi_dir=none
mpi_dir_name=none
if test "$MPI_HOME" != ""; then
mpi_dir="$MPI_HOME"
mpi_dir_name="MPI_HOME"
elif test "$MPIHOME" != ""; then
mpi_dir="$MPIHOME"
mpi_dir_name="MPIHOME"
elif test "$MPI_ROOT" != "" ; then
mpi_dir="$MPI_ROOT"
mpi_dir_name="MPI_ROOT"
elif test "$MPIROOT" != "" ; then
mpi_dir="$MPIROOT"
mpi_dir_name="MPIROOT"
fi
AC_MSG_NOTICE([mpi_dir: ${mpi_dir_name}=${mpi_dir}])
MBX_CHECK_PACKAGE([$mpi_dir])
AC_CHECK_LIB([mpi],[MPI_Init],[
CPPFLAGS="$CPPFLAGS -DHAVE_MPI=1"
LIBS="-lmpi $LIBS"
],
[
AC_MSG_ERROR([mpi lib is missing])
])
AC_MSG_CHECKING([if compiler ${CXX} is able to find mpi.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]])],[AC_MSG_RESULT(yes)], [
AC_MSG_RESULT(no)
AC_MSG_ERROR([compiler ${CXX} is not able to find mpi.h])
])
fi
# Checks for library functions.
AC_PREFIX_DEFAULT([`pwd`])
AC_OUTPUT