pet.cc: pet_foreach_scop_in_C_source: return isl_stat
[pet.git] / m4 / ax_detect_clang.m4
blob536ce1c4e6c85a7257bcc9f9f09eec321b3f9ded
1 AC_DEFUN([AX_DETECT_CLANG], [
2 AC_SUBST(CLANG_CXXFLAGS)
3 AC_SUBST(CLANG_LDFLAGS)
4 AC_SUBST(CLANG_LIBS)
5 AC_SUBST(CLANG_RFLAG)
6 AX_SUBMODULE(clang,system,system)
7 llvm_config="llvm-config"
8 AC_CHECK_PROG([llvm_config_found], ["$llvm_config"], [yes])
9 if test "x$with_clang_prefix" != "x"; then
10         llvm_config="$with_clang_prefix/bin/llvm-config"
11         if test -x "$llvm_config"; then
12                 llvm_config_found=yes
13         fi
15 if test "$llvm_config_found" != yes; then
16         AC_MSG_ERROR([llvm-config not found])
18 CLANG_CXXFLAGS=`$llvm_config --cxxflags | \
19         $SED -e 's/-Wcovered-switch-default//;s/-gsplit-dwarf//'`
20 CLANG_LDFLAGS=`$llvm_config --ldflags`
21 CLANG_VERSION=`$llvm_config --version`
22 CLANG_LIB="LLVM-$CLANG_VERSION"
24 SAVE_LDFLAGS="$LDFLAGS"
25 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
26 AC_CHECK_LIB([$CLANG_LIB], [main], [have_lib_llvm=yes], [have_lib_llvm=no])
27 LDFLAGS="$SAVE_LDFLAGS"
29 # Use single libLLVM shared library when available.
30 # Otherwise, try and figure out all the required libraries
31 if test "$have_lib_llvm" = yes; then
32         # Construct a -R argument for libtool.
33         # This is apparently required to ensure that libpet.so
34         # keeps track of the location where libLLVM can be found.
35         CLANG_RFLAG=`echo "$CLANG_LDFLAGS" | $SED -e 's/-L/-R/g'`
36         CLANG_LIBS="-l$CLANG_LIB"
37 else
38         targets=`$llvm_config --targets-built`
39         components="$targets asmparser bitreader support mc"
40         $llvm_config --components | $GREP option > /dev/null 2> /dev/null
41         if test $? -eq 0; then
42                 components="$components option"
43         fi
44         CLANG_LIBS=`$llvm_config --libs $components`
46 systemlibs=`$llvm_config --system-libs 2> /dev/null | tail -1`
47 if test $? -eq 0; then
48         CLANG_LIBS="$CLANG_LIBS $systemlibs"
50 CLANG_PREFIX=`$llvm_config --prefix`
51 AC_DEFINE_UNQUOTED(CLANG_PREFIX, ["$CLANG_PREFIX"], [Clang installation prefix])
53 SAVE_CPPFLAGS="$CPPFLAGS"
54 CPPFLAGS="$CLANG_CXXFLAGS $CPPFLAGS"
55 AC_LANG_PUSH(C++)
56 AC_CHECK_HEADER([clang/Basic/SourceLocation.h], [],
57         [AC_ERROR([clang header file not found])])
58 AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [],
59         [AC_DEFINE([getDefaultTargetTriple], [getHostTriple],
60         [Define to getHostTriple for older versions of clang])])
61 AC_EGREP_HEADER([getExpansionLineNumber], [clang/Basic/SourceLocation.h], [],
62         [AC_DEFINE([getExpansionLineNumber], [getInstantiationLineNumber],
63         [Define to getInstantiationLineNumber for older versions of clang])])
64 AC_EGREP_HEADER([getExpansionColumnNumber], [clang/Basic/SourceLocation.h], [],
65         [AC_DEFINE([getExpansionColumnNumber], [getInstantiationColumnNumber],
66         [Define to getInstantiationColumnNumber for older versions of clang])])
67 AC_EGREP_HEADER([getExpansionLoc], [clang/Basic/SourceManager.h], [],
68         [AC_DEFINE([getExpansionLoc], [getInstantiationLoc],
69         [Define to getInstantiationLoc for older versions of clang])])
70 AC_EGREP_HEADER([DiagnosticConsumer], [clang/Basic/Diagnostic.h], [],
71         [AC_DEFINE([DiagnosticConsumer], [DiagnosticClient],
72         [Define to DiagnosticClient for older versions of clang])])
73 AC_EGREP_HEADER([DiagnosticsEngine], [clang/Basic/Diagnostic.h],
74         [AC_DEFINE([DiagnosticInfo], [Diagnostic],
75         [Define to Diagnostic for newer versions of clang])],
76         [AC_DEFINE([DiagnosticsEngine], [Diagnostic],
77         [Define to Diagnostic for older versions of clang])])
78 AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h],
79         [AC_DEFINE([USE_ARRAYREF], [],
80                 [Define if Driver::BuildCompilation takes ArrayRef])])
81 AC_EGREP_HEADER([getReturnType], [clang/AST/Decl.h], [],
82         [AC_DEFINE([getReturnType], [getResultType],
83         [Define to getResultType for older versions of clang])])
84 AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h],
85         [AC_DEFINE([HAVE_CXXISPRODUCTION], [],
86                 [Define if Driver constructor takes CXXIsProduction argument])])
87 AC_EGREP_HEADER([ IsProduction], [clang/Driver/Driver.h],
88         [AC_DEFINE([HAVE_ISPRODUCTION], [],
89                 [Define if Driver constructor takes IsProduction argument])])
90 AC_TRY_COMPILE([#include <clang/Driver/Driver.h>], [
91         using namespace clang;
92         DiagnosticsEngine *Diags;
93         new driver::Driver("", "", "", *Diags);
94 ], [AC_DEFINE([DRIVER_CTOR_TAKES_DEFAULTIMAGENAME], [],
95               [Define if Driver constructor takes default image name])])
96 AC_EGREP_HEADER([void HandleTopLevelDecl\(], [clang/AST/ASTConsumer.h],
97         [AC_DEFINE([HandleTopLevelDeclReturn], [void],
98                    [Return type of HandleTopLevelDeclReturn])
99          AC_DEFINE([HandleTopLevelDeclContinue], [],
100                    [Return type of HandleTopLevelDeclReturn])],
101         [AC_DEFINE([HandleTopLevelDeclReturn], [bool],
102                    [Return type of HandleTopLevelDeclReturn])
103          AC_DEFINE([HandleTopLevelDeclContinue], [true],
104                    [Return type of HandleTopLevelDeclReturn])])
105 AC_CHECK_HEADER([clang/Basic/DiagnosticOptions.h],
106         [AC_DEFINE([HAVE_BASIC_DIAGNOSTICOPTIONS_H], [],
107                    [Define if clang/Basic/DiagnosticOptions.h exists])])
108 AC_CHECK_HEADER([clang/Lex/HeaderSearchOptions.h],
109         [AC_DEFINE([HAVE_LEX_HEADERSEARCHOPTIONS_H], [],
110                    [Define if clang/Lex/HeaderSearchOptions.h exists])], [],
111         [#include <clang/Basic/LLVM.h>])
112 AC_CHECK_HEADER([clang/Lex/PreprocessorOptions.h],
113         [AC_DEFINE([HAVE_LEX_PREPROCESSOROPTIONS_H], [],
114                    [Define if clang/Lex/PreprocessorOptions.h exists])], [],
115         [#include <clang/Basic/LLVM.h>])
116 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
117         using namespace clang;
118         std::shared_ptr<TargetOptions> TO;
119         DiagnosticsEngine *Diags;
120         TargetInfo::CreateTargetInfo(*Diags, TO);
121 ], [AC_DEFINE([CREATETARGETINFO_TAKES_SHARED_PTR], [],
122               [Define if TargetInfo::CreateTargetInfo takes shared_ptr])])
123 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
124         using namespace clang;
125         TargetOptions *TO;
126         DiagnosticsEngine *Diags;
127         TargetInfo::CreateTargetInfo(*Diags, TO);
128 ], [AC_DEFINE([CREATETARGETINFO_TAKES_POINTER], [],
129               [Define if TargetInfo::CreateTargetInfo takes pointer])])
130 AC_EGREP_HEADER([getLangOpts], [clang/Lex/Preprocessor.h], [],
131         [AC_DEFINE([getLangOpts], [getLangOptions],
132         [Define to getLangOptions for older versions of clang])])
133 AC_EGREP_HEADER([findLocationAfterToken], [clang/Lex/Lexer.h],
134         [AC_DEFINE([HAVE_FINDLOCATIONAFTERTOKEN], [],
135         [Define if SourceManager has findLocationAfterToken method])])
136 AC_EGREP_HEADER([translateLineCol], [clang/Basic/SourceManager.h],
137         [AC_DEFINE([HAVE_TRANSLATELINECOL], [],
138         [Define if SourceManager has translateLineCol method])])
139 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
140         using namespace clang;
141         DiagnosticConsumer *client;
142         CompilerInstance *Clang;
143         Clang->createDiagnostics(client);
144 ], [], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_ARG], [],
145         [Define if CompilerInstance::createDiagnostics takes argc and argv])])
146 AC_TRY_COMPILE([#include <clang/Lex/HeaderSearchOptions.h>], [
147         using namespace clang;
148         HeaderSearchOptions HSO;
149         HSO.AddPath("", frontend::Angled, false, false);
150 ], [AC_DEFINE([ADDPATH_TAKES_4_ARGUMENTS], [],
151         [Define if HeaderSearchOptions::AddPath takes 4 arguments])])
152 AC_EGREP_HEADER([getLocWithOffset], [clang/Basic/SourceLocation.h], [],
153         [AC_DEFINE([getLocWithOffset], [getFileLocWithOffset],
154         [Define to getFileLocWithOffset for older versions of clang])])
155 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
156         using namespace clang;
157         CompilerInstance *Clang;
158         Clang->createPreprocessor(TU_Complete);
159 ], [AC_DEFINE([CREATEPREPROCESSOR_TAKES_TUKIND], [],
160 [Define if CompilerInstance::createPreprocessor takes TranslationUnitKind])])
161 AC_EGREP_HEADER([DecayedType], [clang/AST/Type.h],
162         [AC_DEFINE([HAVE_DECAYEDTYPE], [], [Define if DecayedType is defined])])
163 AC_EGREP_HEADER([setMainFileID], [clang/Basic/SourceManager.h],
164         [AC_DEFINE([HAVE_SETMAINFILEID], [],
165         [Define if SourceManager has a setMainFileID method])])
166 AC_CHECK_HEADER([llvm/ADT/OwningPtr.h],
167         [AC_DEFINE([HAVE_ADT_OWNINGPTR_H], [],
168                    [Define if llvm/ADT/OwningPtr.h exists])])
169 AC_EGREP_HEADER([TypeInfo getTypeInfo], [clang/AST/ASTContext.h],
170         [AC_DEFINE([GETTYPEINFORETURNSTYPEINFO], [],
171                 [Define if getTypeInfo returns TypeInfo object])])
172 AC_EGREP_HEADER([TypedefNameDecl], [clang/AST/Type.h], [],
173         [AC_DEFINE([TypedefNameDecl], [TypedefDecl],
174                 [Define to TypedefDecl for older versions of clang])
175          AC_DEFINE([getTypedefNameForAnonDecl], [getTypedefForAnonDecl],
176                 [Define to getTypedefForAnonDecl for older versions of clang])])
177 AC_EGREP_HEADER([StmtRange], [clang/AST/StmtIterator.h],
178         [AC_DEFINE([HAVE_STMTRANGE], [],
179         [Define if StmtRange class is available])])
180 AC_EGREP_HEADER([initializeBuiltins],
181         [clang/Basic/Builtins.h], [],
182         [AC_DEFINE([initializeBuiltins], [InitializeBuiltins],
183                 [Define to InitializeBuiltins for older versions of clang])])
184 AC_EGREP_HEADER([IK_C], [clang/Frontend/FrontendOptions.h], [],
185          [AC_DEFINE([IK_C], [InputKind::C],
186             [Define to InputKind::C for newer versions of clang])])
187 AC_TRY_COMPILE([
188         #include <clang/Basic/TargetOptions.h>
189         #include <clang/Lex/PreprocessorOptions.h>
190         #include <clang/Frontend/CompilerInstance.h>
191 ], [
192         using namespace clang;
193         CompilerInstance *Clang;
194         TargetOptions TO;
195         llvm::Triple T(TO.Triple);
196         PreprocessorOptions PO;
197         CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
198                         T, PO, LangStandard::lang_unspecified);
199 ], [AC_DEFINE([SETLANGDEFAULTS_TAKES_5_ARGUMENTS], [],
200         [Define if CompilerInvocation::setLangDefaults takes 5 arguments])])
201 AC_TRY_COMPILE([
202         #include <clang/Frontend/CompilerInstance.h>
203         #include <clang/Frontend/CompilerInvocation.h>
204 ], [
205         using namespace clang;
206         CompilerInvocation *invocation;
207         CompilerInstance *Clang;
208         Clang->setInvocation(std::make_shared<CompilerInvocation>(*invocation));
209 ], [AC_DEFINE([SETINVOCATION_TAKES_SHARED_PTR], [],
210         [Defined if CompilerInstance::setInvocation takes a shared_ptr])])
211 AC_LANG_POP
212 CPPFLAGS="$SAVE_CPPFLAGS"
214 SAVE_LDFLAGS="$LDFLAGS"
215 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
216 AC_SUBST(LIB_CLANG_EDIT)
217 AC_CHECK_LIB([clangEdit], [main], [LIB_CLANG_EDIT=-lclangEdit], [])
218 LDFLAGS="$SAVE_LDFLAGS"