isl_schedule_node.c: collect_filter_prefix*: return isl_stat
[isl.git] / m4 / ax_detect_clang.m4
blobfc16d72d7a47276c389e9db57c6f45e5ba808f7d
1 AC_DEFUN([AX_DETECT_CLANG], [
2 AC_SUBST(CLANG_CXXFLAGS)
3 AC_SUBST(CLANG_LDFLAGS)
4 AC_SUBST(CLANG_LIBS)
5 AC_PROG_GREP
6 AC_PROG_SED
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 targets=`$llvm_config --targets-built`
22 components="$targets asmparser bitreader support mc"
23 $llvm_config --components | $GREP option > /dev/null 2> /dev/null
24 if test $? -eq 0; then
25         components="$components option"
27 CLANG_LIBS=`$llvm_config --libs $components`
28 systemlibs=`$llvm_config --system-libs 2> /dev/null | tail -1`
29 if test $? -eq 0; then
30         CLANG_LIBS="$CLANG_LIBS $systemlibs"
32 CLANG_PREFIX=`$llvm_config --prefix`
33 AC_DEFINE_UNQUOTED(CLANG_PREFIX, ["$CLANG_PREFIX"], [Clang installation prefix])
35 SAVE_CPPFLAGS="$CPPFLAGS"
36 CPPFLAGS="$CLANG_CXXFLAGS $CPPFLAGS"
37 AC_LANG_PUSH(C++)
38 AC_CHECK_HEADER([clang/Basic/SourceLocation.h], [],
39         [AC_ERROR([clang header file not found])])
40 AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [],
41         [AC_DEFINE([getDefaultTargetTriple], [getHostTriple],
42         [Define to getHostTriple for older versions of clang])])
43 AC_EGREP_HEADER([getExpansionLineNumber], [clang/Basic/SourceLocation.h], [],
44         [AC_DEFINE([getExpansionLineNumber], [getInstantiationLineNumber],
45         [Define to getInstantiationLineNumber for older versions of clang])])
46 AC_EGREP_HEADER([getImmediateExpansionRange], [clang/Basic/SourceManager.h],
47         [],
48         [AC_DEFINE([getImmediateExpansionRange],
49         [getImmediateInstantiationRange],
50         [Define to getImmediateInstantiationRange for older versions of clang])]
52 AC_EGREP_HEADER([DiagnosticsEngine], [clang/Basic/Diagnostic.h], [],
53         [AC_DEFINE([DiagnosticsEngine], [Diagnostic],
54         [Define to Diagnostic for older versions of clang])])
55 AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h],
56         [AC_DEFINE([USE_ARRAYREF], [],
57                 [Define if Driver::BuildCompilation takes ArrayRef])])
58 AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h],
59         [AC_DEFINE([HAVE_CXXISPRODUCTION], [],
60                 [Define if Driver constructor takes CXXIsProduction argument])])
61 AC_EGREP_HEADER([ IsProduction], [clang/Driver/Driver.h],
62         [AC_DEFINE([HAVE_ISPRODUCTION], [],
63                 [Define if Driver constructor takes IsProduction argument])])
64 AC_TRY_COMPILE([#include <clang/Driver/Driver.h>], [
65         using namespace clang;
66         DiagnosticsEngine *Diags;
67         new driver::Driver("", "", "", *Diags);
68 ], [AC_DEFINE([DRIVER_CTOR_TAKES_DEFAULTIMAGENAME], [],
69               [Define if Driver constructor takes default image name])])
70 AC_EGREP_HEADER([void HandleTopLevelDecl\(], [clang/AST/ASTConsumer.h],
71         [AC_DEFINE([HandleTopLevelDeclReturn], [void],
72                    [Return type of HandleTopLevelDeclReturn])
73          AC_DEFINE([HandleTopLevelDeclContinue], [],
74                    [Return type of HandleTopLevelDeclReturn])],
75         [AC_DEFINE([HandleTopLevelDeclReturn], [bool],
76                    [Return type of HandleTopLevelDeclReturn])
77          AC_DEFINE([HandleTopLevelDeclContinue], [true],
78                    [Return type of HandleTopLevelDeclReturn])])
79 AC_CHECK_HEADER([clang/Basic/DiagnosticOptions.h],
80         [AC_DEFINE([HAVE_BASIC_DIAGNOSTICOPTIONS_H], [],
81                    [Define if clang/Basic/DiagnosticOptions.h exists])])
82 AC_CHECK_HEADER([clang/Lex/PreprocessorOptions.h],
83         [AC_DEFINE([HAVE_LEX_PREPROCESSOROPTIONS_H], [],
84                    [Define if clang/Lex/PreprocessorOptions.h exists])], [],
85         [#include <clang/Basic/LLVM.h>])
86 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
87         using namespace clang;
88         std::shared_ptr<TargetOptions> TO;
89         DiagnosticsEngine *Diags;
90         TargetInfo::CreateTargetInfo(*Diags, TO);
91 ], [AC_DEFINE([CREATETARGETINFO_TAKES_SHARED_PTR], [],
92               [Define if TargetInfo::CreateTargetInfo takes shared_ptr])])
93 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
94         using namespace clang;
95         TargetOptions *TO;
96         DiagnosticsEngine *Diags;
97         TargetInfo::CreateTargetInfo(*Diags, TO);
98 ], [AC_DEFINE([CREATETARGETINFO_TAKES_POINTER], [],
99               [Define if TargetInfo::CreateTargetInfo takes pointer])])
100 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
101         using namespace clang;
102         DiagnosticConsumer *client;
103         CompilerInstance *Clang;
104         Clang->createDiagnostics(client);
105 ], [], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_ARG], [],
106         [Define if CompilerInstance::createDiagnostics takes argc and argv])])
107 AC_TRY_COMPILE([#include <clang/Lex/HeaderSearchOptions.h>], [
108         using namespace clang;
109         HeaderSearchOptions HSO;
110         HSO.AddPath("", frontend::Angled, false, false);
111 ], [AC_DEFINE([ADDPATH_TAKES_4_ARGUMENTS], [],
112         [Define if HeaderSearchOptions::AddPath takes 4 arguments])])
113 AC_EGREP_HEADER([getNumParams],
114         [clang/AST/CanonicalType.h],
115         [AC_DEFINE([getNumArgs], [getNumParams],
116             [Define to getNumParams for newer versions of clang])
117          AC_DEFINE([getArgType], [getParamType],
118             [Define to getParamType for newer versions of clang])])
119 AC_EGREP_HEADER([getReturnType],
120         [clang/AST/CanonicalType.h], [],
121         [AC_DEFINE([getReturnType], [getResultType],
122             [Define to getResultType for older versions of clang])])
123 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
124         using namespace clang;
125         CompilerInstance *Clang;
126         Clang->createPreprocessor(TU_Complete);
127 ], [AC_DEFINE([CREATEPREPROCESSOR_TAKES_TUKIND], [],
128 [Define if CompilerInstance::createPreprocessor takes TranslationUnitKind])])
129 AC_EGREP_HEADER([setMainFileID], [clang/Basic/SourceManager.h],
130         [AC_DEFINE([HAVE_SETMAINFILEID], [],
131         [Define if SourceManager has a setMainFileID method])])
132 AC_CHECK_HEADER([llvm/ADT/OwningPtr.h],
133         [AC_DEFINE([HAVE_ADT_OWNINGPTR_H], [],
134                    [Define if llvm/ADT/OwningPtr.h exists])])
135 AC_EGREP_HEADER([initializeBuiltins],
136         [clang/Basic/Builtins.h], [],
137         [AC_DEFINE([initializeBuiltins], [InitializeBuiltins],
138                 [Define to InitializeBuiltins for older versions of clang])])
139 AC_EGREP_HEADER([IK_C], [clang/Frontend/FrontendOptions.h], [],
140          [AC_DEFINE([IK_C], [InputKind::C],
141             [Define to InputKind::C for newer versions of clang])])
142 AC_TRY_COMPILE([
143         #include <clang/Basic/TargetOptions.h>
144         #include <clang/Lex/PreprocessorOptions.h>
145         #include <clang/Frontend/CompilerInstance.h>
146 ], [
147         using namespace clang;
148         CompilerInstance *Clang;
149         TargetOptions TO;
150         llvm::Triple T(TO.Triple);
151         PreprocessorOptions PO;
152         CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
153                         T, PO, LangStandard::lang_unspecified);
154 ], [AC_DEFINE([SETLANGDEFAULTS_TAKES_5_ARGUMENTS], [],
155         [Define if CompilerInvocation::setLangDefaults takes 5 arguments])])
156 AC_TRY_COMPILE([
157         #include <clang/Frontend/CompilerInstance.h>
158         #include <clang/Frontend/CompilerInvocation.h>
159 ], [
160         using namespace clang;
161         CompilerInvocation *invocation;
162         CompilerInstance *Clang;
163         Clang->setInvocation(std::make_shared<CompilerInvocation>(*invocation));
164 ], [AC_DEFINE([SETINVOCATION_TAKES_SHARED_PTR], [],
165         [Defined if CompilerInstance::setInvocation takes a shared_ptr])])
166 AC_LANG_POP
167 CPPFLAGS="$SAVE_CPPFLAGS"
169 SAVE_LDFLAGS="$LDFLAGS"
170 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
171 AC_SUBST(LIB_CLANG_EDIT)
172 AC_CHECK_LIB([clangEdit], [main], [LIB_CLANG_EDIT=-lclangEdit], [])
173 LDFLAGS="$SAVE_LDFLAGS"