@@ -12,7 +12,7 @@ dnl Copyright (c) 2004-2006 The Regents of the University of California.
1212dnl All rights reserved.
1313dnl Copyright (c) 2007-2009 Sun Microsystems, Inc. All rights reserved.
1414dnl Copyright (c) 2008-2015 Cisco Systems, Inc. All rights reserved.
15- dnl Copyright (c) 2012 Los Alamos National Security, LLC. All rights
15+ dnl Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1616dnl reserved.
1717dnl Copyright (c) 2015 Research Organization for Information Science
1818dnl and Technology (RIST). All rights reserved.
2323dnl $HEADER $
2424dnl
2525
26+ AC_DEFUN([OPAL_CC_HELPER],[
27+ OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper_tmp])
28+ AC_MSG_CHECKING([$1 ])
29+
30+ opal_prog_cc_c11_helper_tmp= 0
31+
32+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$3 ],[$4 ])],[
33+ $2 = yes
34+ opal_prog_cc_c11_helper_tmp= 1], [$2 = no])
35+
36+ AC_DEFINE_UNQUOTED([$5 ], [$opal_prog_cc_c11_helper_tmp ], [$6 ])
37+
38+ AC_MSG_RESULT([$$ 2])
39+ OPAL_VAR_SCOPE_POP
40+ ])
41+
42+
43+ AC_DEFUN([OPAL_PROG_CC_C11_HELPER],[
44+ OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper_CFLAGS_save opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available])
45+
46+ opal_prog_cc_c11_helper_CFLAGS_save= $CFLAGS
47+ CFLAGS= " $CFLAGS $1 "
48+
49+ OPAL_CC_HELPER([if $CC $1 supports C11 thread local storage], [opal_prog_cc_c11_helper__Thread_local_available],
50+ [],[[static _Thread_local int foo = 1; ++foo; ]], [OPAL_C_HAVE__THREAD_LOCAL],
51+ [Whether C compiler supports __Thread_local])
52+
53+ OPAL_CC_HELPER([if $CC $1 supports C11 atomic variables], [opal_prog_cc_c11_helper_atomic_var_available],
54+ [[# include <stdatomic.h>]], [[static atomic_long foo = 1;++foo;]], [OPAL_C_HAVE_ATOMIC_CONV_VAR],
55+ [Whether C compiler support atomic convenience variables in stdatomic.h])
56+
57+ OPAL_CC_HELPER([if $CC $1 supports C11 _Atomic keyword], [opal_prog_cc_c11_helper__Atomic_available],
58+ [[# include <stdatomic.h>]],[[static _Atomic long foo = 1;++foo;]], [OPAL_C_HAVE__ATOMIC],
59+ [Whether C compiler supports __Atomic keyword])
60+
61+ OPAL_CC_HELPER([if $CC $1 supports C11 _Generic keyword], [opal_prog_cc_c11_helper__Generic_available],
62+ [[# define FOO(x) (_Generic (x, int: 1))]], [[static int x, y; y = FOO(x);]], [OPAL_C_HAVE__GENERIC],
63+ [Whether C compiler supports __Generic keyword])
64+
65+ OPAL_CC_HELPER([if $CC $1 supports C11 _Static_assert], [opal_prog_cc_c11_helper__static_assert_available],
66+ [[# include <stdint.h>]],[[_Static_assert(sizeof(int64_t) == 8, "WTH");]], [OPAL_C_HAVE__STATIC_ASSERT],
67+ [Whether C compiler support _Static_assert keyword])
68+
69+ dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
70+ dnl will likely be required in the future.
71+ AS_IF([test " x$opal_prog_cc_c11_helper__Thread_local_available " = " xyes" && test " x$opal_prog_cc_c11_helper_atomic_var_available " = " xyes" ],
72+ [$2 ], [$3 ])
73+
74+ CFLAGS= $opal_prog_cc_c11_helper_CFLAGS_save
75+
76+ OPAL_VAR_SCOPE_POP
77+ ])
78+
79+ AC_DEFUN([OPAL_PROG_CC_C11],[
80+ OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_flags])
81+ if test -z " $opal_cv_c11_supported " ; then
82+ opal_cv_c11_supported=no
83+ opal_cv_c11_flag_required=yes
84+
85+ AC_MSG_CHECKING([if $CC requires a flag for C11])
86+
87+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
88+ # if __STDC_VERSION__ < 201112L
89+ # error "Without any CLI flags, this compiler does not support C11"
90+ # endif
91+ ]],[])],
92+ [opal_cv_c11_flag_required= no])
93+
94+ AC_MSG_RESULT([$opal_cv_c11_flag_required ])
95+
96+ if test " x$opal_cv_c11_flag_required " = " xno" ; then
97+ AC_MSG_NOTICE([verifying $CC supports C11 without a flag])
98+ OPAL_PROG_CC_C11_HELPER([], [], [opal_cv_c11_flag_required= yes])
99+ fi
100+
101+ if test " x$opal_cv_c11_flag_required " = " xyes" ; then
102+ opal_prog_cc_c11_flags=" -std=gnu11 -std=c11 -c11"
103+
104+ AC_MSG_NOTICE([checking if $CC supports C11 with a flag])
105+ opal_cv_c11_flag=
106+ for flag in $( echo $opal_prog_cc_c11_flags | tr ' ' ' \n' ) ; do
107+ OPAL_PROG_CC_C11_HELPER([$flag ],[opal_cv_c11_flag= $flag ],[])
108+ if test " x$opal_cv_c11_flag " ! = " x" ; then
109+ CFLAGS=" $CFLAGS $opal_cv_c11_flag "
110+ AC_MSG_NOTICE([using $flag to enable C11 support])
111+ opal_cv_c11_supported=yes
112+ break
113+ fi
114+ done
115+ else
116+ AC_MSG_NOTICE([no flag required for C11 support])
117+ opal_cv_c11_supported=yes
118+ fi
119+ fi
120+
121+ OPAL_VAR_SCOPE_POP
122+ ])
123+
124+
26125# OPAL_SETUP_CC()
27126# ---------------
28127# Do everything required to setup the C compiler. Safe to AC_REQUIRE
@@ -41,14 +140,25 @@ AC_DEFUN([OPAL_SETUP_CC],[
41140 WRAPPER_CC= " $CC "
42141 AC_SUBST([WRAPPER_CC])
43142
44- # From Open MPI 1.7 on we require a C99 compiant compiler
45- AC_PROG_CC_C99
46- # The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
47- if test " x$ac_cv_prog_cc_c99 " = xno ; then
48- AC_MSG_WARN([Open MPI requires a C99 compiler])
49- AC_MSG_ERROR([Aborting.])
50- fi
143+ OPAL_PROG_CC_C11
144+
145+ if test $opal_cv_c11_supported = no ; then
146+ # It is not currently an error if C11 support is not available. Uncomment the
147+ # following lines and update the warning when we require a C11 compiler.
148+ # AC_MSG_WARNING([Open MPI requires a C11 (or newer) compiler])
149+ # AC_MSG_ERROR([Aborting.])
150+ # From Open MPI 1.7 on we require a C99 compiant compiler
151+ AC_PROG_CC_C99
152+ # The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
153+ if test " x$ac_cv_prog_cc_c99 " = xno ; then
154+ AC_MSG_WARN([Open MPI requires a C99 (or newer) compiler. C11 is recommended.])
155+ AC_MSG_ERROR([Aborting.])
156+ fi
51157
158+ # Get the correct result for C11 support flags now that the compiler flags have
159+ # changed
160+ OPAL_PROG_CC_C11_HELPER([],[],[])
161+ fi
52162
53163 OPAL_C_COMPILER_VENDOR([opal_c_vendor])
54164
0 commit comments