1 AC_DEFUN([AX_DETECT_CLANG], [
2 AC_SUBST(CLANG_CXXFLAGS)
3 AC_SUBST(CLANG_LDFLAGS)
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
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"
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([DiagnosticsEngine], [clang/Basic/Diagnostic.h], [],
47 [AC_DEFINE([DiagnosticsEngine], [Diagnostic],
48 [Define to Diagnostic for older versions of clang])])
49 AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h],
50 [AC_DEFINE([USE_ARRAYREF], [],
51 [Define if Driver::BuildCompilation takes ArrayRef])])
52 AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h],
53 [AC_DEFINE([HAVE_CXXISPRODUCTION], [],
54 [Define if Driver constructor takes CXXIsProduction argument])])
55 AC_EGREP_HEADER([ IsProduction], [clang/Driver/Driver.h],
56 [AC_DEFINE([HAVE_ISPRODUCTION], [],
57 [Define if Driver constructor takes IsProduction argument])])
58 AC_TRY_COMPILE([#include <clang/Driver/Driver.h>], [
59 using namespace clang;
60 DiagnosticsEngine *Diags;
61 new driver::Driver("", "", "", *Diags);
62 ], [AC_DEFINE([DRIVER_CTOR_TAKES_DEFAULTIMAGENAME], [],
63 [Define if Driver constructor takes default image name])])
64 AC_EGREP_HEADER([void HandleTopLevelDecl\(], [clang/AST/ASTConsumer.h],
65 [AC_DEFINE([HandleTopLevelDeclReturn], [void],
66 [Return type of HandleTopLevelDeclReturn])
67 AC_DEFINE([HandleTopLevelDeclContinue], [],
68 [Return type of HandleTopLevelDeclReturn])],
69 [AC_DEFINE([HandleTopLevelDeclReturn], [bool],
70 [Return type of HandleTopLevelDeclReturn])
71 AC_DEFINE([HandleTopLevelDeclContinue], [true],
72 [Return type of HandleTopLevelDeclReturn])])
73 AC_CHECK_HEADER([clang/Basic/DiagnosticOptions.h],
74 [AC_DEFINE([HAVE_BASIC_DIAGNOSTICOPTIONS_H], [],
75 [Define if clang/Basic/DiagnosticOptions.h exists])])
76 AC_CHECK_HEADER([clang/Lex/PreprocessorOptions.h],
77 [AC_DEFINE([HAVE_LEX_PREPROCESSOROPTIONS_H], [],
78 [Define if clang/Lex/PreprocessorOptions.h exists])], [],
79 [#include <clang/Basic/LLVM.h>])
80 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
81 using namespace clang;
82 std::shared_ptr<TargetOptions> TO;
83 DiagnosticsEngine *Diags;
84 TargetInfo::CreateTargetInfo(*Diags, TO);
85 ], [AC_DEFINE([CREATETARGETINFO_TAKES_SHARED_PTR], [],
86 [Define if TargetInfo::CreateTargetInfo takes shared_ptr])])
87 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
88 using namespace clang;
90 DiagnosticsEngine *Diags;
91 TargetInfo::CreateTargetInfo(*Diags, TO);
92 ], [AC_DEFINE([CREATETARGETINFO_TAKES_POINTER], [],
93 [Define if TargetInfo::CreateTargetInfo takes pointer])])
94 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
95 using namespace clang;
96 DiagnosticConsumer *client;
97 CompilerInstance *Clang;
98 Clang->createDiagnostics(client);
99 ], [], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_ARG], [],
100 [Define if CompilerInstance::createDiagnostics takes argc and argv])])
101 AC_TRY_COMPILE([#include <clang/Lex/HeaderSearchOptions.h>], [
102 using namespace clang;
103 HeaderSearchOptions HSO;
104 HSO.AddPath("", frontend::Angled, false, false);
105 ], [AC_DEFINE([ADDPATH_TAKES_4_ARGUMENTS], [],
106 [Define if HeaderSearchOptions::AddPath takes 4 arguments])])
107 AC_EGREP_HEADER([getNumParams],
108 [clang/AST/CanonicalType.h],
109 [AC_DEFINE([getNumArgs], [getNumParams],
110 [Define to getNumParams for newer versions of clang])
111 AC_DEFINE([getArgType], [getParamType],
112 [Define to getParamType for newer versions of clang])])
113 AC_EGREP_HEADER([getReturnType],
114 [clang/AST/CanonicalType.h], [],
115 [AC_DEFINE([getReturnType], [getResultType],
116 [Define to getResultType for older versions of clang])])
117 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
118 using namespace clang;
119 CompilerInstance *Clang;
120 Clang->createPreprocessor(TU_Complete);
121 ], [AC_DEFINE([CREATEPREPROCESSOR_TAKES_TUKIND], [],
122 [Define if CompilerInstance::createPreprocessor takes TranslationUnitKind])])
123 AC_EGREP_HEADER([setMainFileID], [clang/Basic/SourceManager.h],
124 [AC_DEFINE([HAVE_SETMAINFILEID], [],
125 [Define if SourceManager has a setMainFileID method])])
126 AC_CHECK_HEADER([llvm/ADT/OwningPtr.h],
127 [AC_DEFINE([HAVE_ADT_OWNINGPTR_H], [],
128 [Define if llvm/ADT/OwningPtr.h exists])])
129 AC_EGREP_HEADER([initializeBuiltins],
130 [clang/Basic/Builtins.h], [],
131 [AC_DEFINE([initializeBuiltins], [InitializeBuiltins],
132 [Define to InitializeBuiltins for older versions of clang])])
133 AC_EGREP_HEADER([IK_C], [clang/Frontend/FrontendOptions.h], [],
134 [AC_DEFINE([IK_C], [InputKind::C],
135 [Define to InputKind::C for newer versions of clang])])
137 #include <clang/Basic/TargetOptions.h>
138 #include <clang/Lex/PreprocessorOptions.h>
139 #include <clang/Frontend/CompilerInstance.h>
141 using namespace clang;
142 CompilerInstance *Clang;
144 llvm::Triple T(TO.Triple);
145 PreprocessorOptions PO;
146 CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
147 T, PO, LangStandard::lang_unspecified);
148 ], [AC_DEFINE([SETLANGDEFAULTS_TAKES_5_ARGUMENTS], [],
149 [Define if CompilerInvocation::setLangDefaults takes 5 arguments])])
151 #include <clang/Frontend/CompilerInstance.h>
152 #include <clang/Frontend/CompilerInvocation.h>
154 using namespace clang;
155 CompilerInvocation *invocation;
156 CompilerInstance *Clang;
157 Clang->setInvocation(std::make_shared<CompilerInvocation>(*invocation));
158 ], [AC_DEFINE([SETINVOCATION_TAKES_SHARED_PTR], [],
159 [Defined if CompilerInstance::setInvocation takes a shared_ptr])])
161 CPPFLAGS="$SAVE_CPPFLAGS"
163 SAVE_LDFLAGS="$LDFLAGS"
164 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
165 AC_SUBST(LIB_CLANG_EDIT)
166 AC_CHECK_LIB([clangEdit], [main], [LIB_CLANG_EDIT=-lclangEdit], [])
167 LDFLAGS="$SAVE_LDFLAGS"