-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
configure.ac
140 lines (123 loc) · 3.49 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
### configure.ac -*- Autoconf -*-
# Template used by Autoconf to generate 'configure' script. For more see:
# * https://unconj.ca/blog/an-autoconf-primer-for-r-package-authors.html
# * https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Configure-and-cleanup
AC_PREREQ(2.69)
AC_INIT([lightgbm], [~~VERSION~~], [], [lightgbm], [])
###########################
# find compiler and flags #
###########################
AC_MSG_CHECKING([location of R])
AC_MSG_RESULT([${R_HOME}])
# set up CPP flags
# find the compiler and compiler flags used by R.
: ${R_HOME=`R HOME`}
if test -z "${R_HOME}"; then
echo "could not determine R_HOME"
exit 1
fi
CC=`"${R_HOME}/bin/R" CMD config CC`
CXX=`"${R_HOME}/bin/R" CMD config CXX11`
# LightGBM-specific flags
LGB_CPPFLAGS=""
#########
# Eigen #
#########
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DEIGEN_MPL2_ONLY"
###############
# MM_PREFETCH #
###############
AC_MSG_CHECKING([whether MM_PREFETCH works])
ac_mmprefetch=no
AC_LANG(C++)
AC_LANG_CONFTEST(
[
AC_LANG_PROGRAM(
[[
#include <xmmintrin.h>
]],
[[
int a = 0;
_mm_prefetch(&a, _MM_HINT_NTA);
return 0;
]]
)
]
)
${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mmprefetch=yes
AC_MSG_RESULT([${ac_mmprefetch}])
if test "${ac_mmprefetch}" = yes; then
LGB_CPPFLAGS+=" -DMM_PREFETCH=1"
fi
############
# MM_ALLOC #
############
AC_MSG_CHECKING([whether MM_MALLOC works])
ac_mm_malloc=no
AC_LANG(C++)
AC_LANG_CONFTEST(
[
AC_LANG_PROGRAM(
[[
#include <mm_malloc.h>
]],
[[
char *a = (char*)_mm_malloc(8, 16);
_mm_free(a);
return 0;
]]
)
]
)
${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mm_malloc=yes
AC_MSG_RESULT([${ac_mm_malloc}])
if test "${ac_mm_malloc}" = yes; then
LGB_CPPFLAGS+=" -DMM_MALLOC=1"
fi
##########
# OpenMP #
##########
OPENMP_CXXFLAGS=""
if test `uname -s` = "Linux"
then
OPENMP_CXXFLAGS="\$(SHLIB_OPENMP_CXXFLAGS)"
fi
if test `uname -s` = "Darwin"
then
OPENMP_CXXFLAGS='-Xclang -fopenmp'
OPENMP_LIB='-lomp'
ac_pkg_openmp=no
AC_MSG_CHECKING([whether OpenMP will work in a package])
AC_LANG(C)
AC_LANG_CONFTEST(
[
AC_LANG_PROGRAM(
[[
#include <omp.h>
]],
[[
return (omp_get_max_threads() <= 1);
]]
)
]
)
${CC} -o conftest conftest.c ${OPENMP_LIB} ${OPENMP_CXXFLAGS} 2>/dev/null && ./conftest && ac_pkg_openmp=yes
AC_MSG_RESULT([${ac_pkg_openmp}])
if test "${ac_pkg_openmp}" = no; then
OPENMP_CXXFLAGS=''
OPENMP_LIB=''
echo '***********************************************************************************************'
echo ' OpenMP is unavailable on this macOS system. LightGBM code will run single-threaded as a result.'
echo ' To use all CPU cores for training jobs, you should install OpenMP by running'
echo ''
echo ' brew install libomp'
echo '***********************************************************************************************'
fi
fi
# substitute variables from this script into Makevars.in
AC_SUBST(OPENMP_CXXFLAGS)
AC_SUBST(OPENMP_LIB)
AC_SUBST(LGB_CPPFLAGS)
AC_CONFIG_FILES([src/Makevars])
# write out Autoconf output
AC_OUTPUT